Sha256: 2664f73a467c96b122bd20cf044604ffe26315024da35589934f16eac4d70b92

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require 'spec_helper'
require 'rake'

describe 'sunspot namespace rake task' do
  before :all do
    require "#{Rails.root}/../../lib/sunspot/rails/tasks"
    Rake::Task.define_task(:environment)
  end

  describe 'sunspot:reindex' do
    it "should reindex all models if none are specified" do
      run_rake_task("sunspot:reindex", '', '', true)

      # This model should not be used by any other test and therefore should only be loaded by this test
      Sunspot.searchable.collect(&:name).should include('RakeTaskAutoLoadTestModel')
    end

    it "should accept a space delimited list of models to reindex" do
      Post.should_receive(:solr_reindex)
      Author.should_receive(:solr_reindex)
      Blog.should_not_receive(:solr_reindex)

      run_rake_task("sunspot:reindex", '', "Post Author", true)
    end

    it "should accept a plus delimited list of models to reindex" do
      Post.should_receive(:solr_reindex)
      Author.should_receive(:solr_reindex)
      Blog.should_not_receive(:solr_reindex)

      run_rake_task("sunspot:reindex", '', "Post+Author", true)
    end
  end
end

def run_rake_task(task_name, *task_args)
  task = Rake::Task[task_name.to_s]
  task.reenable
  task.invoke(*task_args) # Invoke but skip the reindex warning
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sunspot_rails-2.2.0 spec/rake_task_spec.rb
sunspot_rails-2.1.1 spec/rake_task_spec.rb
sunspot_rails-2.1.0 spec/rake_task_spec.rb