Sha256: 6d328cf41b12b824ee3dc98ab5ed0a83359b6cabb804f58cce0d3b1eedc60ebb

Contents?: true

Size: 1.74 KB

Versions: 5

Compression:

Stored size: 1.74 KB

Contents

require File.expand_path('../spec_helper', File.dirname(__FILE__))

shared_examples 'dynamic fields' do
  before :each do
    Sunspot.remove_all
    @posts = Post.new(field_name => { :cuisine => 'Pizza' }),
             Post.new(field_name => { :cuisine => 'Greek' }),
             Post.new(field_name => { :cuisine => 'Greek' })
    Sunspot.index!(@posts)
  end

  it 'should search for dynamic string field' do
    Sunspot.search(Post) do
      dynamic(field_name) do
        with(:cuisine, 'Pizza')
      end
    end.results.should == [@posts.first]
  end

  describe 'faceting' do
    before :each do
      @search = Sunspot.search(Post) do
        dynamic field_name do
          facet :cuisine
        end
      end
    end

    it 'should return value "value" with count 2' do
      row = @search.dynamic_facet(field_name, :cuisine).rows[0]
      row.value.should == 'Greek'
      row.count.should == 2
    end

    it 'should return value "other" with count 1' do
      row = @search.dynamic_facet(field_name, :cuisine).rows[1]
      row.value.should == 'Pizza'
      row.count.should == 1
    end
  end

  it 'should order by dynamic string field ascending' do
    Sunspot.search(Post) do
      dynamic field_name do
        order_by :cuisine, :asc
      end
    end.results.last.should == @posts.first
  end

  it 'should order by dynamic string field descending' do
    Sunspot.search(Post) do
      dynamic field_name do
        order_by :cuisine, :desc
      end
    end.results.first.should == @posts.first
  end
end

describe "default separator" do
  it_behaves_like "dynamic fields" do
    let(:field_name) { :custom_string }
  end
end
describe "custom separator" do
  it_behaves_like "dynamic fields" do
    let(:field_name) { :custom_underscored_string }
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/spec/integration/dynamic_fields_spec.rb
sunspot-2.2.7 spec/integration/dynamic_fields_spec.rb
sunspot-2.2.6 spec/integration/dynamic_fields_spec.rb
sunspot-2.2.5 spec/integration/dynamic_fields_spec.rb
sunspot-2.2.4 spec/integration/dynamic_fields_spec.rb