spec/lib/query/allocation_spec.rb in picky-3.0.1 vs spec/lib/query/allocation_spec.rb in picky-3.1.0

- old
+ new

@@ -1,12 +1,14 @@ require 'spec_helper' describe Picky::Query::Allocation do before(:each) do + @backend = stub :backend + @index = stub :index, :result_identifier => :some_result_identifier, :backend => @backend @combinations = stub :combinations - @allocation = described_class.new @combinations, :some_result_identifier + @allocation = described_class.new @index, @combinations end describe "eql?" do # TODO This works, but is not acceptable. # @@ -128,54 +130,62 @@ end describe 'to_result' do context 'with few combinations' do before(:each) do - @allocation = described_class.new stub(:combinations, :ids => [1,2,3], :to_result => [:some_result]), :some_result_identifier + @allocation = described_class.new @index, stub(:combinations, :to_result => [:some_result]) @allocation.instance_variable_set :@score, :some_score end context 'with ids' do it 'should output an array of information' do + @backend.stub! :ids => [1,2,3] + @allocation.process! 20, 0 @allocation.to_result.should == [:some_result_identifier, :some_score, 3, [:some_result], [1, 2, 3]] end end end context 'with results' do before(:each) do - combinations = stub :combinations, :ids => [1,2,3], :to_result => [:some_result1, :some_result2] - @allocation = described_class.new combinations, :some_result_identifier + combinations = stub :combinations, :to_result => [:some_result1, :some_result2] + @allocation = described_class.new @index, combinations @allocation.instance_variable_set :@score, :some_score end context 'with ids' do it 'should output an array of information' do + @backend.stub! :ids => [1,2,3] + @allocation.process! 20, 0 @allocation.to_result.should == [:some_result_identifier, :some_score, 3, [:some_result1, :some_result2], [1, 2, 3]] end end end context 'without results' do before(:each) do - @allocation = described_class.new stub(:combinations, :ids => [], :to_result => []), :some_result_identifier + @allocation = described_class.new @index, stub(:combinations, :to_result => []) @allocation.instance_variable_set :@score, :some_score end it 'should return nil' do + @backend.stub! :ids => [] + @allocation.process! 20, 0 @allocation.to_result.should == nil end end end describe 'to_json' do before(:each) do - @allocation = described_class.new stub(:combination, :ids => [1,2,3,4,5,6,7], :to_result => [:some_result1, :some_result2]), :some_result_identifier + @allocation = described_class.new @index, stub(:combination, :to_result => [:some_result1, :some_result2]) @allocation.instance_variable_set :@score, :some_score end it 'should output the correct json string' do + @backend.stub! :ids => [1,2,3,4,5,6,7] + @allocation.process! 20, 0 @allocation.to_json.should == '["some_result_identifier","some_score",7,["some_result1","some_result2"],[1,2,3,4,5,6,7]]' end end @@ -188,25 +198,25 @@ end end describe "<=>" do it "should sort higher first" do - first = described_class.new [], :some_result_identifier + first = described_class.new @index, [] first.instance_variable_set :@score, 20 - second = described_class.new [], :some_result_identifier + second = described_class.new @index, [] second.instance_variable_set :@score, 10 first.<=>(second).should == -1 end end describe "sort!" do it "should sort correctly" do - first = described_class.new :whatever, :some_result_identifier + first = described_class.new @index, :whatever first.instance_variable_set :@score, 20 - second = described_class.new :whatever, :some_result_identifier + second = described_class.new @index, :whatever second.instance_variable_set :@score, 10 - third = described_class.new :whatever, :some_result_identifier + third = described_class.new @index, :whatever third.instance_variable_set :@score, 5 allocations = [second, third, first] allocations.sort!.should == [first, second, third] \ No newline at end of file