Sha256: baff4b2fd547ef23dd87f0ca534815ba6cf68391d99a7b9967807f9860d38a40

Contents?: true

Size: 1.46 KB

Versions: 64

Compression:

Stored size: 1.46 KB

Contents

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

64 entries across 64 versions & 14 rubygems

Version Path
Chrononaut-sunspot-client-0.9.4 spec/integration/dynamic_fields_spec.rb
UnderpantsGnome-sunspot-0.9.1.1 spec/integration/dynamic_fields_spec.rb
UnderpantsGnome-sunspot-0.9.8.1 spec/integration/dynamic_fields_spec.rb
benjaminkrause-sunspot-0.9.7 spec/integration/dynamic_fields_spec.rb
benjaminkrause-sunspot-0.9.8 spec/integration/dynamic_fields_spec.rb
kristopher-sunspot-0.9.8 spec/integration/dynamic_fields_spec.rb
kuahyeow-sunspot-0.9.7 spec/integration/dynamic_fields_spec.rb
kuahyeow-sunspot-0.9.8 spec/integration/dynamic_fields_spec.rb
outoftime-sunspot-0.8.0 spec/integration/dynamic_fields_spec.rb
outoftime-sunspot-0.8.1 spec/integration/dynamic_fields_spec.rb
outoftime-sunspot-0.8.2 spec/integration/dynamic_fields_spec.rb
outoftime-sunspot-0.8.3 spec/integration/dynamic_fields_spec.rb
outoftime-sunspot-0.8.4 spec/integration/dynamic_fields_spec.rb
outoftime-sunspot-0.8.5 spec/integration/dynamic_fields_spec.rb
outoftime-sunspot-0.8.8 spec/integration/dynamic_fields_spec.rb
outoftime-sunspot-0.8.9 spec/integration/dynamic_fields_spec.rb
outoftime-sunspot-0.9.0 spec/integration/dynamic_fields_spec.rb
outoftime-sunspot-0.9.1 spec/integration/dynamic_fields_spec.rb
outoftime-sunspot-0.9.2 spec/integration/dynamic_fields_spec.rb
outoftime-sunspot-0.9.3 spec/integration/dynamic_fields_spec.rb