spec/ripple/persistence_spec.rb in ripple-0.7.1 vs spec/ripple/persistence_spec.rb in ripple-0.8.0.beta
- old
+ new
@@ -31,19 +31,38 @@
@widget.save
@widget.key.should == "new_widget"
@widget.should_not be_a_new_record
@widget.changes.should be_blank
end
-
+
+ it "should modify attributes and save a new object" do
+ json = @widget.attributes.merge("_type" => "Widget", "size" => 5).to_json
+ @http.should_receive(:post).with(201, "/riak/", "widgets", an_instance_of(Hash), json, hash_including("Content-Type" => "application/json")).and_return(:code => 201, :headers => {'location' => ["/riak/widgets/new_widget"]})
+ @widget.update_attributes(:size => 5)
+ @widget.key.should == "new_widget"
+ @widget.should_not be_a_new_record
+ @widget.changes.should be_blank
+ end
+
+ it "should modify a single attribute and save a new object" do
+ json = @widget.attributes.merge("_type" => "Widget", "size" => 5).to_json
+ @http.should_receive(:post).with(201, "/riak/", "widgets", an_instance_of(Hash), json, hash_including("Content-Type" => "application/json")).and_return(:code => 201, :headers => {'location' => ["/riak/widgets/new_widget"]})
+ @widget.update_attribute(:size, 5)
+ @widget.key.should == "new_widget"
+ @widget.should_not be_a_new_record
+ @widget.changes.should be_blank
+ @widget.size.should == 5
+ end
+
it "should instantiate and save a new object to riak" do
json = @widget.attributes.merge(:size => 10, :_type => 'Widget').to_json
@http.should_receive(:post).with(201, "/riak/", "widgets", an_instance_of(Hash), json, hash_including("Content-Type" => "application/json")).and_return(:code => 201, :headers => {'location' => ["/riak/widgets/new_widget"]})
@widget = Widget.create(:size => 10)
@widget.size.should == 10
@widget.should_not be_a_new_record
end
-
+
it "should instantiate and save a new object to riak and allow its attributes to be set via a block" do
json = @widget.attributes.merge(:size => 10, :_type => 'Widget').to_json
@http.should_receive(:post).with(201, "/riak/", "widgets", an_instance_of(Hash), json, hash_including("Content-Type" => "application/json")).and_return(:code => 201, :headers => {'location' => ["/riak/widgets/new_widget"]})
@widget = Widget.create do |widget|
widget.size = 10
@@ -80,19 +99,16 @@
it "should freeze an unsaved object when destroying" do
@http.should_not_receive(:delete)
@widget.destroy.should be_true
@widget.should be_frozen
end
-
+
it "should be a root document" do
@widget._root_document.should == @widget
end
describe "when storing a class using single-bucket inheritance" do
-
- class Cog < Widget; property :name, String, :default => "cog"; end
-
before :each do
@cog = Cog.new(:size => 1000)
end
it "should store the _type field as the class name" do
@@ -100,7 +116,37 @@
@http.should_receive(:post).and_return(:code => 201, :headers => {'location' => ["/riak/widgets/new_widget"]})
@cog.save
@cog.should_not be_new_record
end
+ end
+
+ describe "modifying the default quorum values" do
+ before :each do
+ Widget.set_quorums :r => 1, :w => 1, :dw => 0, :rw => 1
+ @bucket = mock("bucket", :name => "widgets")
+ @robject = mock("object", :data => {"name" => "bar"}, :key => "gear")
+ Widget.stub(:bucket).and_return(@bucket)
+ end
+
+ it "should use the supplied R value when reading" do
+ @bucket.should_receive(:get).with("gear", :r => 1).and_return(@robject)
+ Widget.find("gear")
+ end
+
+ it "should use the supplied W and DW values when storing" do
+ Widget.new do |widget|
+ widget.key = "gear"
+ widget.send(:robject).should_receive(:store).with({:w => 1, :dw => 0})
+ widget.save
+ end
+ end
+
+ it "should use the supplied RW when deleting" do
+ widget = Widget.new
+ widget.key = "gear"
+ widget.instance_variable_set(:@new, false)
+ widget.send(:robject).should_receive(:delete).with({:rw => 1})
+ widget.destroy
+ end
end
end