spec/unit/ridley/resources/search_spec.rb in ridley-0.7.0.beta vs spec/unit/ridley/resources/search_spec.rb in ridley-0.7.0.rc1

- old
+ new

@@ -1,9 +1,13 @@ require 'spec_helper' -describe Ridley::Search do - let(:connection) { double('connection') } +describe Ridley::Search do\ + let(:client) do + double('client', + connection: double('connection') + ) + end let(:index) { :role } let(:query) { "*:*" } let(:response) do double( "response", @@ -17,57 +21,57 @@ describe "ClassMethods" do subject { Ridley::Search } describe "::indexes" do - it "sends a get request to the connection to receive the indexes" do - connection.should_receive(:get).with("search").and_return(response) + it "sends a get request to the client to receive the indexes" do + client.connection.should_receive(:get).with("search").and_return(response) - subject.indexes(connection) + subject.indexes(client) end end end describe "#run" do subject do - Ridley::Search.new(connection, index, query) + Ridley::Search.new(client, index, query) end - it "sends a get request to the connection to the index's location with the given query" do - connection.should_receive(:get).with("search/#{index}", q: query).and_return(response) + it "sends a get request to the client to the index's location with the given query" do + client.connection.should_receive(:get).with("search/#{index}", q: query).and_return(response) subject.run end context "when 'sort' is set" do let(:sort) { "DESC" } before(:each) { subject.sort = sort } - it "sends a get request to the connection with a query parameter for 'set'" do - connection.should_receive(:get).with("search/#{index}", q: query, sort: sort).and_return(response) + it "sends a get request to the client with a query parameter for 'set'" do + client.connection.should_receive(:get).with("search/#{index}", q: query, sort: sort).and_return(response) subject.run end end context "when 'start' is set" do let(:start) { 1 } before(:each) { subject.start = start } - it "sends a get request to the connection with a query parameter for 'start'" do - connection.should_receive(:get).with("search/#{index}", q: query, start: start).and_return(response) + it "sends a get request to the client with a query parameter for 'start'" do + client.connection.should_receive(:get).with("search/#{index}", q: query, start: start).and_return(response) subject.run end end context "when 'rows' is set" do let(:rows) { 1 } before(:each) { subject.rows = rows } - it "sends a get request to the connection with a query parameter for 'rows'" do - connection.should_receive(:get).with("search/#{index}", q: query, rows: rows).and_return(response) + it "sends a get request to the client with a query parameter for 'rows'" do + client.connection.should_receive(:get).with("search/#{index}", q: query, rows: rows).and_return(response) subject.run end end @@ -97,18 +101,18 @@ start: 0 } ) end - subject { Ridley::Search.new(connection, index, query) } + subject { Ridley::Search.new(client, index, query) } - it "returns an array of Ridley::Node" do - connection.should_receive(:get).with("search/#{index}", q: query).and_return(response) + it "returns an array of Ridley::NodeResource" do + client.connection.should_receive(:get).with("search/#{index}", q: query).and_return(response) result = subject.run result.should be_a(Array) - result.should each be_a(Ridley::Node) + result.should each be_a(Ridley::NodeResource) end end context "when ':role' is given as index" do let(:index) { :role } @@ -132,18 +136,18 @@ start: 0 } ) end - subject { Ridley::Search.new(connection, index, query) } + subject { Ridley::Search.new(client, index, query) } - it "returns an array of Ridley::Role" do - connection.should_receive(:get).with("search/#{index}", q: query).and_return(response) + it "returns an array of Ridley::RoleResource" do + client.connection.should_receive(:get).with("search/#{index}", q: query).and_return(response) result = subject.run result.should be_a(Array) - result.should each be_a(Ridley::Role) + result.should each be_a(Ridley::RoleResource) end end context "when ':environment' is given as index" do let(:index) { :environment } @@ -166,18 +170,18 @@ start: 0 } ) end - subject { Ridley::Search.new(connection, index, query) } + subject { Ridley::Search.new(client, index, query) } - it "returns an array of Ridley::Environment" do - connection.should_receive(:get).with("search/#{index}", q: query).and_return(response) + it "returns an array of Ridley::EnvironmentResource" do + client.connection.should_receive(:get).with("search/#{index}", q: query).and_return(response) result = subject.run result.should be_a(Array) - result.should each be_a(Ridley::Environment) + result.should each be_a(Ridley::EnvironmentResource) end end context "when ':client' is given as index" do let(:index) { :client } @@ -201,17 +205,17 @@ start: 0 } ) end - subject { Ridley::Search.new(connection, index, query) } + subject { Ridley::Search.new(client, index, query) } - it "returns an array of Ridley::Client" do - connection.should_receive(:get).with("search/#{index}", q: query).and_return(response) + it "returns an array of Ridley::ClientResource" do + client.connection.should_receive(:get).with("search/#{index}", q: query).and_return(response) result = subject.run result.should be_a(Array) - result.should each be_a(Ridley::Client) + result.should each be_a(Ridley::ClientResource) end end end end