Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #2 from ebryn/update-or-create-bug

Fix a bug inside Identity#update_or_create!
  • Loading branch information...
commit cd5c75d55c9b3c4e3206ce13942aac013503596f 2 parents 6e178f8 + d260924
@jamesarosen authored
Showing with 16 additions and 1 deletion.
  1. +2 −1  lib/billfold/identity.rb
  2. +14 −0 spec/models/identity_spec.rb
View
3  lib/billfold/identity.rb
@@ -66,9 +66,10 @@ def update_or_create!(attributes = {})
identity = with_provider_and_value(attributes[:provider], attributes[:value])
if identity
old_owner, new_owner = identity.user, attributes[:user]
+ attributes.delete(:user) if attributes[:user].nil?
transaction do
identity.update_attributes!(attributes)
- old_owner.merge_into!(new_owner) if old_owner != new_owner
+ old_owner.merge_into!(new_owner) if new_owner && old_owner != new_owner
end
else
identity = new(attributes)
View
14 spec/models/identity_spec.rb
@@ -116,6 +116,20 @@
})
end
end
+
+ context 'and a UID previously used with a nil user' do
+ before(:each) do
+ @result = subject.update_or_create!({
+ :provider => 'twitter',
+ :value => identity.value,
+ :user => nil
+ })
+ end
+
+ it 'uses the existing user' do
+ @result.user.should == identity.user
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.