spec/riak/bucket_spec.rb in riak-client-1.2.0 vs spec/riak/bucket_spec.rb in riak-client-1.4.0
- old
+ new
@@ -14,10 +14,11 @@
lambda { Riak::Bucket.new }.should raise_error
lambda { Riak::Bucket.new(@client) }.should raise_error
lambda { Riak::Bucket.new("foo") }.should raise_error
lambda { Riak::Bucket.new("foo", @client) }.should raise_error
lambda { Riak::Bucket.new(@client, "foo") }.should_not raise_error
+ expect { Riak::Bucket.new(@client, '') }.to raise_error(ArgumentError)
end
it "should set the client and name attributes" do
bucket = Riak::Bucket.new(@client, "foo")
bucket.client.should == @client
@@ -25,37 +26,55 @@
end
end
describe "accessing keys" do
it "should list the keys" do
- @backend.should_receive(:list_keys).with(@bucket).and_return(["bar"])
+ @backend.should_receive(:list_keys).with(@bucket, {}).and_return(["bar"])
@bucket.keys.should == ["bar"]
end
it "should allow streaming keys through block" do
- @backend.should_receive(:list_keys).with(@bucket).and_yield([]).and_yield(["bar"]).and_yield(["baz"])
+ @backend.should_receive(:list_keys).with(@bucket, {}).and_yield([]).and_yield(["bar"]).and_yield(["baz"])
all_keys = []
@bucket.keys do |list|
all_keys.concat(list)
end
all_keys.should == ["bar", "baz"]
end
it "should not cache the list of keys" do
- @backend.should_receive(:list_keys).with(@bucket).twice.and_return(["bar"])
+ @backend.should_receive(:list_keys).with(@bucket, {}).twice.and_return(["bar"])
2.times { @bucket.keys.should == ['bar'] }
end
it "should warn about the expense of list-keys when warnings are not disabled" do
Riak.disable_list_keys_warnings = false
@backend.stub!(:list_keys).and_return(%w{test test2})
@bucket.should_receive(:warn)
@bucket.keys
Riak.disable_list_keys_warnings = true
end
+
+ it "should allow a specified timeout when listing keys" do
+ @backend.should_receive(:list_keys).with(@bucket, timeout: 1234).and_return(%w{bar})
+
+ keys = @bucket.keys timeout: 1234
+
+ keys.should == %w{bar}
+ end
end
+ describe "accessing a counter" do
+ it "should return a counter object" do
+ Riak::Counter.should_receive(:new).with(@bucket, 'asdf').and_return('example counter')
+
+ new_counter = @bucket.counter 'asdf'
+
+ new_counter.should == 'example counter'
+ end
+ end
+
describe "setting the bucket properties" do
it "should prefetch the properties when they are not present" do
@backend.stub!(:set_bucket_props)
@backend.should_receive(:get_bucket_props).with(@bucket).and_return({"name" => "foo"})
@bucket.props = {"precommit" => []}
@@ -102,10 +121,16 @@
it "should use the specified R quroum" do
@backend.should_receive(:fetch_object).with(@bucket, "db", {:r => 2}).and_return(nil)
@bucket.get("db", :r => 2)
end
+
+ it "should disallow fetching an object with a zero-length key" do
+ ## TODO: This actually tests the Client object, but there is no suite
+ ## of tests for its generic interface.
+ expect { @bucket.get('') }.to raise_error(ArgumentError)
+ end
end
describe "creating a new blank object" do
it "should instantiate the object with the given key, default to JSON" do
obj = @bucket.new('bar')
@@ -139,13 +164,38 @@
@backend.should_receive(:fetch_object).with(@bucket,"db", {:r => "all"}).and_return(@object)
@bucket.get_or_new('db', :r => "all").should == @object
end
end
+ describe "fetching multiple objects" do
+ it 'should get each object individually' do
+ @object1 = mock('obj1')
+ @object2 = mock('obj2')
+ @bucket.should_receive(:[]).with('key1').and_return(@object1)
+ @bucket.should_receive(:[]).with('key2').and_return(@object2)
+
+ @results = @bucket.get_many %w{key1 key2}
+
+ @results['key1'].should == @object1
+ @results['key2'].should == @object2
+ end
+ end
+
describe "querying an index" do
it "should list the matching keys" do
- @backend.should_receive(:get_index).with(@bucket, "test_bin", "testing").and_return(["bar"])
- @bucket.get_index("test_bin", "testing").should == ["bar"]
+ @backend.
+ should_receive(:get_index).
+ with(@bucket, "test_bin", "testing", {return_terms: true}).
+ and_return(Riak::IndexCollection.new_from_json({
+ 'results' => [
+ {'testing' => 'asdf'},
+ {'testing' => 'hjkl'}]
+ }.to_json))
+ result = @bucket.get_index("test_bin", "testing", return_terms: true)
+
+ result.should be_a Riak::IndexCollection
+ result.to_a.should == %w{asdf hjkl}
+ result.with_terms.should == {'testing' => %w{asdf hjkl}}
end
end
describe "get/set allow_mult property" do
before :each do