Sha256: 790ee07e2a1c6ffe26f533102a032a50174010af6d927c7ad3e1b1bc0d169418

Contents?: true

Size: 1.1 KB

Versions: 30

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'

describe Picky::API::Search::Boost do
  let(:object) do
    Class.new do
      include Picky::API::Search::Boost
    end.new
  end
  context 'boost_for' do
    context 'with a Hash' do
      it 'returns a boosts object' do
        combinations = [
          double(:combination, :category_name => :bla)
        ]

        object.extract_boosts([:bla] => +7.77).boost_for(combinations).should == 7.77
      end
    end
    context 'with a boosts object' do
      let(:booster) do
        Class.new do
          def boost_for whatever
            7.0
          end
        end.new
      end
      it 'returns a boosts object' do
        object.extract_boosts(booster).boost_for(:anything).should == 7.0
      end
    end
    context 'invalid weight' do
      it 'raises with a nice error message' do
        expect {
          object.extract_boosts Object.new
        }.to raise_error(<<-ERROR)
boost options for a Search should be either
* for example a Hash { [:name, :surname] => +3 }
or
* an object that responds to #boost_for(combinations) and returns a boost float
ERROR
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
picky-4.31.3 spec/lib/api/search/boost_spec.rb
picky-4.31.2 spec/lib/api/search/boost_spec.rb
picky-4.31.1 spec/lib/api/search/boost_spec.rb
picky-4.31.0 spec/lib/api/search/boost_spec.rb
picky-4.30.0 spec/lib/api/search/boost_spec.rb
picky-4.29.0 spec/lib/api/search/boost_spec.rb
picky-4.28.1 spec/lib/api/search/boost_spec.rb
picky-4.27.1 spec/lib/api/search/boost_spec.rb
picky-4.27.0 spec/lib/api/search/boost_spec.rb
picky-4.26.2 spec/lib/api/search/boost_spec.rb
picky-4.26.1 spec/lib/api/search/boost_spec.rb
picky-4.26.0 spec/lib/api/search/boost_spec.rb
picky-4.25.3 spec/lib/api/search/boost_spec.rb
picky-4.25.2 spec/lib/api/search/boost_spec.rb
picky-4.25.1 spec/lib/api/search/boost_spec.rb
picky-4.25.0 spec/lib/api/search/boost_spec.rb
picky-4.24.0 spec/lib/api/search/boost_spec.rb
picky-4.23.2 spec/lib/api/search/boost_spec.rb
picky-4.23.1 spec/lib/api/search/boost_spec.rb
picky-4.23.0 spec/lib/api/search/boost_spec.rb