spec/value_spec.rb in rico-0.0.1 vs spec/value_spec.rb in rico-0.1.0

- old
+ new

@@ -40,16 +40,56 @@ b = Rico::Value.new RiakHelpers.bucket, "value_set" b.get.should eql "john" end end + describe "#setnx" do + it "writes the value, returns true if new" do + a = Rico::Value.new RiakHelpers.bucket, "setnx_new" + a.setnx("value").should eql true + b = Rico::Value.new RiakHelpers.bucket, "setnx_new" + b.get.should eql "value" + end + + it "does nothing, returns false if the value exists" do + a = Rico::Value.new RiakHelpers.bucket, "setnx_exists" + a.set "value" + b = Rico::Value.new RiakHelpers.bucket, "setnx_exists" + b.setnx("other").should eql false + b.get.should eql "value" + c = Rico::Value.new RiakHelpers.bucket, "setnx_exists" + c.get.should eql "value" + end + end + describe "#delete" do it "deletes an existing object" do a = Rico::Value.new RiakHelpers.bucket, "delete_existing" a.set "john" a.delete b = Rico::Value.new RiakHelpers.bucket, "delete_existing" b.exists?.should eql false b.get.should eql nil end end + + describe ".resolve" do + it "just returns the first sibling" do + datas = ["Tom", "Jerry"] + conflicted = RiakHelpers.build_conflicted_robject "value_resolve_simple", datas + result = Rico::Value.resolve(conflicted) + result.data.should eql "Tom" + end + + it "properly deletes deleted values after resolve" do + datas = [ + { "_type" => "array", "_values" => [1,2,3,4] }, + { "_type" => "array", "_values" => [1,2,3], "_deletes" => [4] } + ] + conflicted = RiakHelpers.build_conflicted_robject "array_resolve_delete", datas + result = Rico::Array.resolve(conflicted) + result.data["_values"].should eql [1,2,3] + result.data["_deletes"].should eql [4] + end + end + end