Sha256: 59512dfb3ab3a64fa92421ff55203747e10e5071761140d71144d0747c0502f7

Contents?: true

Size: 1.58 KB

Versions: 24

Compression:

Stored size: 1.58 KB

Contents

require File.dirname(__FILE__) + '/spec_helper'

describe 'searchable with lifecycle' do
  describe 'on create' do
    before :each do
      @post = PostWithAuto.create
      Sunspot.commit
    end

    it 'should automatically index' do
      PostWithAuto.search.results.should == [@post]
    end
  end

  describe 'on update' do
    before :each do
      @post = PostWithAuto.create
      @post.update_attributes(:title => 'Test 1')
      Sunspot.commit
    end

    it 'should automatically update index' do
      PostWithAuto.search { with :title, 'Test 1' }.results.should == [@post]
    end

    it "should index model if relevant attribute changed" do
      @post = PostWithAuto.create!
      @post.title = 'new title'
      @post.should_receive :solr_index
      @post.save!
    end

    it "should not index model if relevant attribute not changed" do
      @post = PostWithAuto.create!
      @post.updated_at = Date.tomorrow
      @post.should_not_receive :solr_index
      @post.save!
    end
  end
  
  describe 'on destroy' do
    before :each do
      @post = PostWithAuto.create
      @post.destroy
      Sunspot.commit
    end

    it 'should automatically remove it from the index' do
      PostWithAuto.search_ids.should be_empty
    end
  end
end

describe 'searchable with lifecycle - ignoring specific attributes' do
  before(:each) do
    @post = PostWithAuto.create
  end
  
  it "should not reindex the object on an update_at change, because it is marked as to-ignore" do
    Sunspot.should_not_receive(:index).with(@post)
    @post.update_attribute :updated_at, 123.seconds.from_now
  end
end

Version data entries

24 entries across 24 versions & 7 rubygems

Version Path
erichummel-sunspot_rails-1.2.1g spec/model_lifecycle_spec.rb
erichummel-sunspot_rails-1.2.1f spec/model_lifecycle_spec.rb
erichummel-sunspot_rails-1.2.1e spec/model_lifecycle_spec.rb
erichummel-sunspot_rails-1.2.1d spec/model_lifecycle_spec.rb
erichummel-sunspot_rails-1.2.1c spec/model_lifecycle_spec.rb
erichummel-sunspot_rails-1.2.1b spec/model_lifecycle_spec.rb
erichummel-sunspot_rails-1.2.1a spec/model_lifecycle_spec.rb
sunspot_rails_rbg-1.3.1 spec/model_lifecycle_spec.rb
sunspot_rails_rbg-1.3.0 spec/model_lifecycle_spec.rb
ruben_sunspot_rails-1.1.4 spec/model_lifecycle_spec.rb
ruben_sunspot_rails-1.1.3 spec/model_lifecycle_spec.rb
ruben_sunspot_rails-1.1.2 spec/model_lifecycle_spec.rb
sunspot_rails_mongoid-1.2.1 spec/model_lifecycle_spec.rb
sunspot_rails-1.2.1 spec/model_lifecycle_spec.rb
sunspot_rails-1.2.0 spec/model_lifecycle_spec.rb
ruben_sunspot_rails-1.1.1 spec/model_lifecycle_spec.rb
ruben_sunspot_rails-1.1.0 spec/model_lifecycle_spec.rb
nuatt_sunspot_rails-1.1.0.3 spec/model_lifecycle_spec.rb
robsharp-sunspot_rails-1.1.0.2 spec/model_lifecycle_spec.rb
sunspot_rails-1.1.0 spec/model_lifecycle_spec.rb