Sha256: f3498925e89b7d5d09cf05627e06ca6c27ba6208dc5b5db5c0829cc0b3ec0d75

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 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
      expect(Sunspot.searchable.collect(&:name)).to include('RakeTaskAutoLoadTestModel')
    end

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

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

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

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

    it "should raise exception when all tables of sunspot models are empty" do
      expect(STDOUT).to receive(:puts).with("You have no data in the database. Reindexing does nothing here.")
      empty_tables
      run_rake_task("sunspot:reindex")
    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

4 entries across 4 versions & 1 rubygems

Version Path
sunspot_rails-2.5.0 spec/rake_task_spec.rb
sunspot_rails-2.4.0 spec/rake_task_spec.rb
sunspot_rails-2.3.0 spec/rake_task_spec.rb
sunspot_rails-2.2.8 spec/rake_task_spec.rb