diff options
author | Azul <azul@leap.se> | 2014-07-01 09:26:54 +0200 |
---|---|---|
committer | Azul <azul@leap.se> | 2014-07-01 09:26:54 +0200 |
commit | b3c23c534f21b0a920815734637aff46816f7039 (patch) | |
tree | 77b332962db5d24afcc6de897a63dd5039a10b0d /app/models | |
parent | 728d6d3985126c2890638bb2ee24020fa0e36a80 (diff) | |
parent | 470bc1e35f22c1fe5813a1754e52b3fbc2bb951b (diff) |
Merge tag '0.5.3'
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 18 | ||||
-rw-r--r-- | app/models/identity.rb | 1 |
2 files changed, 15 insertions, 4 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 32ed445..67fec58 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -16,11 +16,21 @@ class Account # Returns the user record so it can be used in views. def self.create(attrs) - @user = User.create(attrs) + @user = User.new(attrs) + @user.save 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 && @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 |