summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorazul <azul@leap.se>2014-06-18 22:08:31 +0200
committerazul <azul@leap.se>2014-06-18 22:08:31 +0200
commit3051a51a4b7d51994e7cd8d90f0cdf5f237a0a4d (patch)
tree77afce7a62f1c40e594659e96abca712aa1f8768 /app/models
parent9fa52ed80d71ec56ed5acf18dfd63bd03b201cc5 (diff)
parent280a46b5c4958cb183427028a8e66059856d46aa (diff)
Merge pull request #171 from elijh/feature/identityfail
if identity fails to be created, destroy the user.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account.rb15
-rw-r--r--app/models/identity.rb1
2 files changed, 13 insertions, 3 deletions
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
diff --git a/app/models/identity.rb b/app/models/identity.rb
index 2f6241c..e7b5785 100644
--- a/app/models/identity.rb
+++ b/app/models/identity.rb
@@ -163,4 +163,5 @@ class Identity < CouchRest::Model::Base
end
end
+ ActiveSupport.run_load_hooks(:identity, self)
end