Sha256: a25330c567aacb8f25eb5d29161ae9d1c70efa92822cba7e520e4c923c336675

Contents?: true

Size: 1.52 KB

Versions: 32

Compression:

Stored size: 1.52 KB

Contents

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

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

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

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

    it 'should return value "value" with count 2' do
      row = @search.dynamic_facet(:custom_string, :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(:custom_string, :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 :custom_string 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 :custom_string do
        order_by :cuisine, :desc
      end
    end.results.first.should == @posts.first
  end
end

Version data entries

32 entries across 32 versions & 6 rubygems

Version Path
sunspot-2.2.3 spec/integration/dynamic_fields_spec.rb
sunspot-2.2.2 spec/integration/dynamic_fields_spec.rb
sunspot-2.2.1 spec/integration/dynamic_fields_spec.rb
sunspot-2.2.0 spec/integration/dynamic_fields_spec.rb
sunspot-2.1.1 spec/integration/dynamic_fields_spec.rb
sunspot-2.1.0 spec/integration/dynamic_fields_spec.rb
sunspot-2.0.0 spec/integration/dynamic_fields_spec.rb
sunspot-2.0.0.pre.130115 spec/integration/dynamic_fields_spec.rb
gojee-sunspot-2.0.5 spec/integration/dynamic_fields_spec.rb
sunspot-2.0.0.pre.120925 spec/integration/dynamic_fields_spec.rb
sunspot_solr-2.0.0.pre.120924 sunspot/spec/integration/dynamic_fields_spec.rb
sunspot_rails-2.0.0.pre.120924 sunspot/spec/integration/dynamic_fields_spec.rb
sunspot-2.0.0.pre.120924 sunspot/spec/integration/dynamic_fields_spec.rb
gojee-sunspot-2.0.4 spec/integration/dynamic_fields_spec.rb
gojee-sunspot-2.0.2 spec/integration/dynamic_fields_spec.rb
sunspot-2.0.0.pre.120720 spec/integration/dynamic_fields_spec.rb
sunspot-1.3.3 spec/integration/dynamic_fields_spec.rb
sunspot-1.3.2 spec/integration/dynamic_fields_spec.rb
sunspot-2.0.0.pre.120417 spec/integration/dynamic_fields_spec.rb
sunspot-2.0.0.pre.120415 spec/integration/dynamic_fields_spec.rb