Sha256: 4f82ea7922f3b372f5408536217d87c01827f32809c37fbe555b9feb03ccfba0

Contents?: true

Size: 1.91 KB

Versions: 15

Compression:

Stored size: 1.91 KB

Contents

# coding: utf-8
#
require 'spec_helper'

describe Picky::Query::Combinations do

  before(:each) do
    @combinations_ary = stub :combinations_ary

    @combinations = described_class.new @combinations_ary
  end

  describe "to_result" do
    before(:each) do
      @combination1 = stub :combination1, :to_result => :result1
      @combination2 = stub :combination2, :to_result => :result2

      @combinations_ary = [@combination1, @combination2]

      @combinations = described_class.new @combinations_ary
    end
    it "resultifies the combinations" do
      @combinations.to_result.should == [:result1, :result2]
    end
  end

  describe "weighted_score" do
    it "uses the weights' score method" do
      boosts = stub :boosts
      boosts.should_receive(:boost_for).once.with @combinations_ary

      @combinations.boost_for boosts
    end
  end

  describe "total_score" do
    before(:each) do
      @combination1 = stub :combination1, :weight => 3.14
      @combination2 = stub :combination2, :weight => 2.76

      @combinations_ary = [@combination1, @combination2]

      @combinations = described_class.new @combinations_ary
    end
    it "sums the scores" do
      @combinations.score.should == 5.90
    end
  end

  # describe 'hash' do
  #   it "forwards to the combinations array" do
  #     @combinations_ary.should_receive(:hash).once.with
  # 
  #     @combinations.hash
  #   end
  # end

  describe 'remove' do
    before(:each) do
      @combination1 = stub :combination1, :category => stub(:other, :name => :other)
      @combination2 = stub :combination2, :category => stub(:to_remove, :name => :to_remove)
      @combination3 = stub :combination3, :category => stub(:to_remove, :name => :to_remove)

      @combinations = described_class.new [@combination1, @combination2, @combination3]
    end
    it 'should remove the combinations' do
      @combinations.remove([:to_remove]).should == [@combination1]
    end
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
picky-4.17.1 spec/lib/query/combinations_spec.rb
picky-4.17.0 spec/lib/query/combinations_spec.rb
picky-4.16.0 spec/lib/query/combinations_spec.rb
picky-4.15.1 spec/lib/query/combinations_spec.rb
picky-4.15.0 spec/lib/query/combinations_spec.rb
picky-4.14.0 spec/lib/query/combinations_spec.rb
picky-4.13.1 spec/lib/query/combinations_spec.rb
picky-4.13.0 spec/lib/query/combinations_spec.rb
picky-4.12.13 spec/lib/query/combinations_spec.rb
picky-4.12.12 spec/lib/query/combinations_spec.rb
picky-4.12.11 spec/lib/query/combinations_spec.rb
picky-4.12.10 spec/lib/query/combinations_spec.rb
picky-4.12.8 spec/lib/query/combinations_spec.rb
picky-4.12.7 spec/lib/query/combinations_spec.rb
picky-4.12.6 spec/lib/query/combinations_spec.rb