spec/riak/client_spec.rb in riak-client-0.9.8 vs spec/riak/client_spec.rb in riak-client-1.0.0.beta

- old
+ new

@@ -1,19 +1,6 @@ -# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -require File.expand_path("../spec_helper", File.dirname(__FILE__)) +require 'spec_helper' describe Riak::Client do describe "when initializing" do it "should default to the local interface on port 8098 (8087 for protobuffs)" do client = Riak::Client.new @@ -72,27 +59,37 @@ Riak::Client.new.prefix.should == "/riak/" end it "should accept a mapreduce path" do client = Riak::Client.new(:mapred => "/mr") - client.mapred.should == "/mr" + client.http_paths[:mapred].should == "/mr" end it "should default the mapreduce path to /mapred if not specified" do - Riak::Client.new.mapred.should == "/mapred" + Riak::Client.new.http_paths[:mapred].should == "/mapred" end it "should accept a luwak path" do client = Riak::Client.new(:luwak => "/beans") - client.luwak.should == "/beans" + client.http_paths[:luwak].should == "/beans" end it "should default the luwak path to /luwak if not specified" do - Riak::Client.new.luwak.should == "/luwak" + Riak::Client.new.http_paths[:luwak].should == "/luwak" end + + it "should accept a solr path" do + client = Riak::Client.new(:solr => "/solar") + client.http_paths[:solr].should == "/solar" + end end + it "should expose a Stamp object" do + subject.should respond_to(:stamp) + subject.stamp.should be_kind_of(Riak::Stamp) + end + describe "reconfiguring" do before :each do @client = Riak::Client.new end @@ -178,10 +175,12 @@ lambda { @client.basic_auth ="user" }.should raise_error(ArgumentError, "basic auth must be set using 'user:pass'") end end it "should allow setting the prefix" do + @client.http_paths.should be_kind_of(Hash) + @client.http_paths.include?(:prefix).should == true @client.should respond_to(:prefix=) @client.prefix = "/another-prefix" @client.prefix.should == "/another-prefix" end @@ -208,15 +207,13 @@ it "should choose the selected backend" do @client.http_backend = :NetHTTP @client.http.should be_instance_of(Riak::Client::NetHTTPBackend) - unless defined? JRUBY_VERSION - @client = Riak::Client.new - @client.http_backend = :Curb - @client.http.should be_instance_of(Riak::Client::CurbBackend) - end + @client = Riak::Client.new + @client.http_backend = :Excon + @client.http.should be_instance_of(Riak::Client::ExconBackend) end it "should raise an error when the chosen backend is not valid" do Riak::Client::NetHTTPBackend.should_receive(:configured?).and_return(false) lambda { @client.http }.should raise_error @@ -271,32 +268,41 @@ it "should fetch bucket properties if asked" do @backend.should_receive(:get_bucket_props) {|b| b.name.should == "foo"; {} } @client.bucket("foo", :props => true) end - it "should fetch keys if asked" do - @backend.should_receive(:list_keys) {|b| b.name.should == "foo"; ["bar"] } - @client.bucket("foo", :keys => true) - end - it "should memoize bucket parameters" do @bucket = mock("Bucket") Riak::Bucket.should_receive(:new).with(@client, "baz").once.and_return(@bucket) @client.bucket("baz").should == @bucket @client.bucket("baz").should == @bucket end end - it "should list buckets" do - @client = Riak::Client.new - @backend = mock("Backend") - @client.stub!(:backend).and_return(@backend) - @backend.should_receive(:list_buckets).and_return(%w{test test2}) - buckets = @client.buckets - buckets.should have(2).items - buckets.should be_all {|b| b.is_a?(Riak::Bucket) } - buckets[0].name.should == "test" - buckets[1].name.should == "test2" + describe "listing buckets" do + before do + @client = Riak::Client.new + @backend = mock("Backend") + @client.stub!(:backend).and_return(@backend) + end + + after { Riak.disable_list_keys_warnings = true } + + it "should list buckets" do + @backend.should_receive(:list_buckets).and_return(%w{test test2}) + buckets = @client.buckets + buckets.should have(2).items + buckets.should be_all {|b| b.is_a?(Riak::Bucket) } + buckets[0].name.should == "test" + buckets[1].name.should == "test2" + end + + it "should warn about the expense of list-buckets when warnings are not disabled" do + Riak.disable_list_keys_warnings = false + @backend.stub!(:list_buckets).and_return(%w{test test2}) + @client.should_receive(:warn) + @client.buckets + end end describe "Luwak (large-files) support" do describe "storing a file" do before :each do