Sha256: d80a518a54192610e01e4bf9e6a70e24f1e74eef161151cbb7e50bba4f94c588

Contents?: true

Size: 1.1 KB

Versions: 39

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 = [
          stub(: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

39 entries across 39 versions & 1 rubygems

Version Path
picky-4.19.4 spec/lib/api/search/boost_spec.rb
picky-4.19.3 spec/lib/api/search/boost_spec.rb
picky-4.19.2 spec/lib/api/search/boost_spec.rb
picky-4.19.1 spec/lib/api/search/boost_spec.rb
picky-4.19.0 spec/lib/api/search/boost_spec.rb
picky-4.18.0 spec/lib/api/search/boost_spec.rb
picky-4.17.1 spec/lib/api/search/boost_spec.rb
picky-4.17.0 spec/lib/api/search/boost_spec.rb
picky-4.16.0 spec/lib/api/search/boost_spec.rb
picky-4.15.1 spec/lib/api/search/boost_spec.rb
picky-4.15.0 spec/lib/api/search/boost_spec.rb
picky-4.14.0 spec/lib/api/search/boost_spec.rb
picky-4.13.1 spec/lib/api/search/boost_spec.rb
picky-4.13.0 spec/lib/api/search/boost_spec.rb
picky-4.12.13 spec/lib/api/search/boost_spec.rb
picky-4.12.12 spec/lib/api/search/boost_spec.rb
picky-4.12.11 spec/lib/api/search/boost_spec.rb
picky-4.12.10 spec/lib/api/search/boost_spec.rb
picky-4.12.8 spec/lib/api/search/boost_spec.rb
picky-4.12.7 spec/lib/api/search/boost_spec.rb