Sha256: 1773c6125e4d8aa220b5960e04564d4184302cc9c208492508b58c50a32e492b

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' do
  it 'should index non-multivalued field with newlines' do
    expect do
      Sunspot.index!(Post.new(:title => "A\nTitle"))
    end.not_to raise_error
  end

  it 'should correctly remove by model instance' do
    post = Post.new(:title => 'test post')
    Sunspot.index!(post)
    Sunspot.remove!(post)
    expect(Sunspot.search(Post) { with(:title, 'test post') }.results).to be_empty
  end

  it 'should correctly delete by ID' do
    post = Post.new(:title => 'test post')
    Sunspot.index!(post)
    Sunspot.remove_by_id!(Post, post.id)
    expect(Sunspot.search(Post) { with(:title, 'test post') }.results).to be_empty
  end

  it 'removes documents by query' do
    Sunspot.remove_all!
    posts = [Post.new(:title => 'birds'), Post.new(:title => 'monkeys')]
    Sunspot.index!(posts)

    Sunspot.remove!(Post) do
      with(:title, 'birds')
    end
    expect(Sunspot.search(Post).results.size).to eq(1)
  end


  describe "in batches" do
    let(:post_1) { Post.new :title => 'A tittle' }
    let(:post_2) { Post.new :title => 'Another title' }

    describe "nested" do
      let(:a_nested_batch) do
        Sunspot.batch do
          Sunspot.index post_1

          Sunspot.batch do
            Sunspot.index post_2
          end
        end
      end

      it "does not fail" do
        expect { a_nested_batch }.to_not raise_error
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sunspot-2.7.1 spec/integration/indexing_spec.rb
sunspot-2.7.0 spec/integration/indexing_spec.rb
sunspot-2.6.0 spec/integration/indexing_spec.rb
sunspot-2.5.0 spec/integration/indexing_spec.rb
sunspot-2.4.0 spec/integration/indexing_spec.rb
sunspot-2.3.0 spec/integration/indexing_spec.rb
sunspot-2.2.8 spec/integration/indexing_spec.rb