From 280a46b5c4958cb183427028a8e66059856d46aa Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 17 Jun 2014 01:57:15 -0700 Subject: if identity fails to be created, destroy the user. also, pass through identity errors to user and add identity class hook. --- app/models/account.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'app/models/account.rb') diff --git a/app/models/account.rb b/app/models/account.rb index 32ed445..bee540e 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -18,9 +18,18 @@ class Account def self.create(attrs) @user = User.create(attrs) if @user.persisted? - identity = @user.identity - identity.user_id = @user.id - identity.save + @identity = @user.identity + @identity.user_id = @user.id + @identity.save + @identity.errors.each do |attr, msg| + @user.errors.add(attr, msg) + end + end + rescue StandardError => ex + @user.errors.add(:base, ex.to_s) + ensure + if @user.persisted? && (@identity.nil? || !@identity.persisted?) + @user.destroy end return @user end -- cgit v1.2.3