Sha256: 1b3cb776e2422600246255f452714c2ef117010e1c12afacc8a67471ab9c0a8c

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

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

describe 'fields lists' do
  before :all do
    Sunspot.remove_all
    @post = Post.new(title: 'A Title', body: 'A Body', featured: true, tags: ['tag'])
    Sunspot.index!(@post)
  end

  let(:stored_field_names) do
    (Sunspot::Setup.for(Post).fields + Sunspot::Setup.for(Post).all_text_fields)
      .select { |f| f.stored? }
      .map { |f| f.name }
  end

  it 'loads all stored fields by dafault' do
    hit = Sunspot.search(Post).hits.first

    stored_field_names.each do |field|
      expect(hit.stored(field)).not_to be_nil
    end
  end

  it 'loads only filtered fields' do
    hit = Sunspot.search(Post) { field_list(:title) }.hits.first

    expect(hit.stored(:title)).to eq(@post.title)

    (stored_field_names - [:title]).each do |field|
      expect(hit.stored(field)).to be_nil
    end
  end

  it 'does not load any stored fields' do
    hit = Sunspot.search(Post) { without_stored_fields }.hits.first

    stored_field_names.each do |field|
      expect(hit.stored(field)).to be_nil
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sunspot-2.4.0 spec/integration/field_lists_spec.rb
sunspot-2.3.0 spec/integration/field_lists_spec.rb
sunspot-2.2.8 spec/integration/field_lists_spec.rb