Sha256: b5de144207cbe3989c8740d0a440147b9d82ba4b520eb2701126d64d2acbc852

Contents?: true

Size: 1.43 KB

Versions: 7

Compression:

Stored size: 1.43 KB

Contents

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

describe 'indexing dynamic fields' do
  it 'indexes string data' do
    session.index(post(:custom_string => { :test => 'string' }))
    expect(connection).to have_add_with(:"custom_string:test_ss" => 'string')
  end

  it 'indexes integer data with virtual accessor' do
    session.index(post(:category_ids => [1, 2]))
    expect(connection).to have_add_with(:"custom_integer:1_i" => '1', :"custom_integer:2_i" => '1')
  end

  it 'indexes float data' do
    session.index(post(:custom_fl => { :test => 1.5 }))
    expect(connection).to have_add_with(:"custom_float:test_fm" => '1.5')
  end

  it 'indexes time data' do
    session.index(post(:custom_time => { :test => Time.parse('2009-05-18 18:05:00 -0400') }))
    expect(connection).to have_add_with(:"custom_time:test_d" => '2009-05-18T22:05:00Z')
  end

  it 'indexes boolean data' do
    session.index(post(:custom_boolean => { :test => false }))
    expect(connection).to have_add_with(:"custom_boolean:test_b" => 'false')
  end

  it 'indexes multiple values for a field' do
    session.index(post(:custom_fl => { :test => [1.0, 2.1, 3.2] }))
    expect(connection).to have_add_with(:"custom_float:test_fm" => %w(1.0 2.1 3.2))
  end

  it 'should throw a NoMethodError if dynamic text field defined' do
    expect do
      Sunspot.setup(Post) do
        dynamic_text :custom_text
      end
    end.to raise_error(NoMethodError)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sunspot-2.7.1 spec/api/indexer/dynamic_fields_spec.rb
sunspot-2.7.0 spec/api/indexer/dynamic_fields_spec.rb
sunspot-2.6.0 spec/api/indexer/dynamic_fields_spec.rb
sunspot-2.5.0 spec/api/indexer/dynamic_fields_spec.rb
sunspot-2.4.0 spec/api/indexer/dynamic_fields_spec.rb
sunspot-2.3.0 spec/api/indexer/dynamic_fields_spec.rb
sunspot-2.2.8 spec/api/indexer/dynamic_fields_spec.rb