Permalink
Browse files

Removed atomic_update_attributes.

  • Loading branch information...
1 parent d872362 commit 34b6edf8f0d4be74a7751aca1576e6cb391ae8f6 @jnunemaker committed May 19, 2012
Showing with 0 additions and 74 deletions.
  1. +0 −16 lib/toy/mongo/querying.rb
  2. +0 −58 spec/toy/mongo/querying_spec.rb
View
@@ -69,22 +69,6 @@ def persistable_changes
attrs
end
- def atomic_update_attributes(attrs={})
- self.attributes = attrs
- if valid?
- run_callbacks(:save) do
- run_callbacks(:update) do
- criteria = {'_id' => id}
- update = {'$set' => persistable_changes}
- adapter.client.update(criteria, update, {:safe => adapter.options[:safe]})
- true
- end
- end
- else
- false
- end
- end
-
def atomic_update(update, opts={})
options = {}
criteria = {'_id' => id}
@@ -113,64 +113,6 @@
end
end
- describe "#atomic_update_attributes" do
- before(:each) do
- @user = User.create(:name => 'John', :bio => 'I make things simple.')
- end
-
- it "updates document" do
- @user.atomic_update_attributes(:name => 'Frank')
- @user.reload
- @user.name.should == 'Frank'
- end
-
- it "returns true if valid" do
- @user.atomic_update_attributes(:name => 'Frank').should be_true
- end
-
- it "returns false if invalid" do
- User.validates_presence_of(:name)
- @user.atomic_update_attributes(:name => '').should be_false
- end
-
- it "only persists changes" do
- query = {'_id' => @user.id}
- update = {'$set' => {'name' => 'Frank'}}
- @user.adapter.client.should_receive(:update).with(query, update, {:safe => nil})
- @user.atomic_update_attributes(:name => 'Frank')
- end
-
- it "persists changes with safe option from adapter" do
- User.adapter(:mongo, STORE, :safe => true)
- query = {'_id' => @user.id}
- update = {'$set' => {'name' => 'Frank'}}
- @user.adapter.client.should_receive(:update).with(query, update, {:safe => true})
- @user.atomic_update_attributes(:name => 'Frank')
- end
-
- it "runs callbacks in correct order" do
- doc = User.create.tap(&:clear_history)
- doc.name = 'John Nunemaker'
- doc.atomic_update_attributes
- doc.history.should == [:before_save, :before_update, :after_update, :after_save]
- end
-
- it "persists changes that happen in callbacks" do
- User.class_eval do
- attribute :name_lower, String
-
- before_save do |record|
- record.name_lower = name
- end
- end
-
- user = User.create(:name => 'Frank')
- user.atomic_update_attributes('name' => 'John')
- user.name_lower.should == 'John'
- user.reload.name_lower.should == 'John'
- end
- end
-
describe "#get" do
before(:each) do
@user = User.create

0 comments on commit 34b6edf

Please sign in to comment.