sunspot_rails 2.2.6 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -2
- data/Appraisals +64 -0
- data/Gemfile +3 -0
- data/lib/sunspot/rails/configuration.rb +4 -0
- data/lib/sunspot/rails/request_lifecycle.rb +3 -1
- data/lib/sunspot/rails/searchable.rb +15 -7
- data/lib/sunspot/rails/solr_instrumentation.rb +2 -2
- data/lib/sunspot/rails/solr_logging.rb +5 -10
- data/lib/sunspot/rails/stub_session_proxy.rb +9 -2
- data/lib/sunspot/rails/tasks.rb +0 -1
- data/lib/sunspot/rails.rb +2 -0
- data/spec/configuration_spec.rb +77 -69
- data/spec/model_lifecycle_spec.rb +8 -8
- data/spec/model_spec.rb +72 -71
- data/spec/rails_app/app/controllers/application_controller.rb +4 -0
- data/spec/rails_app/app/controllers/posts_controller.rb +16 -0
- data/spec/{rails_template → rails_app}/app/models/author.rb +0 -2
- data/spec/{rails_template → rails_app}/app/models/blog.rb +0 -2
- data/spec/{rails_template → rails_app}/app/models/location.rb +0 -1
- data/spec/{rails_template → rails_app}/app/models/post.rb +0 -2
- data/spec/{rails_template → rails_app}/app/models/post_with_auto.rb +0 -2
- data/spec/{rails_template → rails_app}/app/models/post_with_default_scope.rb +0 -2
- data/spec/{rails_template → rails_app}/app/models/post_with_only_some_attributes_triggering_reindex.rb +0 -2
- data/spec/rails_app/config/application.rb +17 -0
- data/spec/rails_app/config/boot.rb +6 -0
- data/spec/rails_app/config/database.yml +5 -0
- data/spec/rails_app/config/environment.rb +5 -0
- data/spec/rails_app/config/environments/test.rb +41 -0
- data/spec/rails_app/config/initializers/rails_5_override.rb +1 -0
- data/spec/rails_app/config/initializers/secret_token.rb +1 -0
- data/spec/rails_app/config/initializers/session_store.rb +3 -0
- data/spec/{rails_template → rails_app}/config/sunspot.yml +2 -0
- data/spec/rails_app/config.ru +4 -0
- data/spec/rails_app/db/schema.rb +26 -0
- data/spec/rails_app/vendor/engines/test_engine/app/models/test_engine/rake_task_auto_load_test_model.rb +15 -0
- data/spec/rails_app/vendor/engines/test_engine/lib/test_engine/engine.rb +5 -0
- data/spec/rails_app/vendor/engines/test_engine/lib/test_engine.rb +4 -0
- data/spec/rake_task_spec.rb +9 -9
- data/spec/request_lifecycle_spec.rb +17 -21
- data/spec/schema.rb +8 -9
- data/spec/searchable_spec.rb +4 -4
- data/spec/server_spec.rb +7 -7
- data/spec/session_spec.rb +3 -3
- data/spec/shared_examples/indexed_after_save.rb +1 -1
- data/spec/shared_examples/not_indexed_after_save.rb +1 -1
- data/spec/spec_helper.rb +18 -51
- data/spec/stub_session_proxy_spec.rb +40 -36
- data/sunspot_rails.gemspec +15 -8
- metadata +102 -58
- data/dev_tasks/spec.rake +0 -97
- data/gemfiles/rails-3.0.0 +0 -21
- data/gemfiles/rails-3.1.0 +0 -21
- data/gemfiles/rails-3.2.0 +0 -21
- data/gemfiles/rails-4.0.0 +0 -25
- data/gemfiles/rails-4.1.0 +0 -24
- data/gemfiles/rails-4.2.0 +0 -24
- data/spec/rails_template/app/controllers/application_controller.rb +0 -10
- data/spec/rails_template/app/controllers/posts_controller.rb +0 -6
- data/spec/rails_template/config/database.yml +0 -11
- data/spec/rails_template/db/schema.rb +0 -27
- /data/{tmp → gemfiles}/.gitkeep +0 -0
- /data/spec/{rails_template → rails_app}/app/models/photo_post.rb +0 -0
- /data/spec/{rails_template → rails_app}/app/models/rake_task_auto_load_test_model.rb +0 -0
- /data/spec/{rails_template → rails_app}/config/routes.rb +0 -0
@@ -2,6 +2,7 @@ test:
|
|
2
2
|
solr:
|
3
3
|
hostname: localhost
|
4
4
|
port: 8983
|
5
|
+
update_format: <%= ENV.fetch('UPDATE_FORMAT', 'xml') %>
|
5
6
|
auto_index_callback: after_save
|
6
7
|
auto_remove_callback: after_destroy
|
7
8
|
development:
|
@@ -22,6 +23,7 @@ config_test:
|
|
22
23
|
bind_address: 127.0.0.1
|
23
24
|
read_timeout: 2
|
24
25
|
open_timeout: 0.5
|
26
|
+
update_format: json
|
25
27
|
proxy: http://proxy.com:12345
|
26
28
|
auto_commit_after_request: false
|
27
29
|
auto_commit_after_delete_request: true
|
@@ -0,0 +1,26 @@
|
|
1
|
+
ActiveRecord::Schema.define(version: 0) do
|
2
|
+
create_table :posts, force: :cascade do |t|
|
3
|
+
t.string :title
|
4
|
+
t.string :type
|
5
|
+
t.integer :location_id
|
6
|
+
t.text :body
|
7
|
+
t.references :blog
|
8
|
+
t.timestamps null: true
|
9
|
+
end
|
10
|
+
|
11
|
+
create_table :locations, force: :cascade do |t|
|
12
|
+
t.float :lat
|
13
|
+
t.float :lng
|
14
|
+
end
|
15
|
+
|
16
|
+
create_table :blogs, force: :cascade do |t|
|
17
|
+
t.string :name
|
18
|
+
t.string :subdomain
|
19
|
+
t.timestamps null: true
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table :writers, force: :cascade, primary_key: :writer_id do |t|
|
23
|
+
t.string :name
|
24
|
+
t.timestamps null: true
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This model should not be used for any test other than the spec test that
|
2
|
+
# checks if all models are loaded. We don't want to pre-load this model in
|
3
|
+
# another test because we're checking to see if it will be auto-loaded by
|
4
|
+
# the reindex task
|
5
|
+
module TestEngine
|
6
|
+
class RakeTaskAutoLoadTestModel < ActiveRecord::Base
|
7
|
+
def self.table_name
|
8
|
+
'posts'
|
9
|
+
end
|
10
|
+
|
11
|
+
searchable do
|
12
|
+
string :name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/rake_task_spec.rb
CHANGED
@@ -11,28 +11,28 @@ describe 'sunspot namespace rake task' do
|
|
11
11
|
it "should reindex all models if none are specified" do
|
12
12
|
run_rake_task("sunspot:reindex", '', '', true)
|
13
13
|
|
14
|
-
# This
|
15
|
-
Sunspot.searchable.collect(&:name).
|
14
|
+
# This models should not be used by any other test and therefore should only be loaded by this test
|
15
|
+
expect(Sunspot.searchable.collect(&:name)).to include('RakeTaskAutoLoadTestModel', 'TestEngine::RakeTaskAutoLoadTestModel')
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should accept a space delimited list of models to reindex" do
|
19
|
-
Post.
|
20
|
-
Author.
|
21
|
-
Blog.
|
19
|
+
expect(Post).to receive(:solr_reindex)
|
20
|
+
expect(Author).to receive(:solr_reindex)
|
21
|
+
expect(Blog).not_to receive(:solr_reindex)
|
22
22
|
|
23
23
|
run_rake_task("sunspot:reindex", '', "Post Author", true)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should accept a plus delimited list of models to reindex" do
|
27
|
-
Post.
|
28
|
-
Author.
|
29
|
-
Blog.
|
27
|
+
expect(Post).to receive(:solr_reindex)
|
28
|
+
expect(Author).to receive(:solr_reindex)
|
29
|
+
expect(Blog).not_to receive(:solr_reindex)
|
30
30
|
|
31
31
|
run_rake_task("sunspot:reindex", '', "Post+Author", true)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should raise exception when all tables of sunspot models are empty" do
|
35
|
-
STDOUT.
|
35
|
+
expect(STDOUT).to receive(:puts).with("You have no data in the database. Reindexing does nothing here.")
|
36
36
|
empty_tables
|
37
37
|
run_rake_task("sunspot:reindex")
|
38
38
|
end
|
@@ -15,47 +15,43 @@ describe PostsController, :type => :controller do
|
|
15
15
|
Sunspot::Rails.configuration = nil
|
16
16
|
end
|
17
17
|
|
18
|
-
unless respond_to?(:describes)
|
19
|
-
controller_name :posts # RSpec 1
|
20
|
-
end
|
21
|
-
|
22
18
|
it 'should automatically commit after each action if specified' do
|
23
19
|
@configuration.user_configuration = { 'auto_commit_after_request' => true }
|
24
|
-
Sunspot.
|
25
|
-
post :create, :post => { :title => 'Test 1' }
|
20
|
+
expect(Sunspot).to receive(:commit_if_dirty)
|
21
|
+
post :create, :params => { :post => { :title => 'Test 1' } }
|
26
22
|
end
|
27
|
-
|
23
|
+
|
28
24
|
it 'should not commit, if configuration is set to false' do
|
29
25
|
@configuration.user_configuration = { 'auto_commit_after_request' => false }
|
30
|
-
Sunspot.
|
31
|
-
post :create, :post => { :title => 'Test 1' }
|
26
|
+
expect(Sunspot).not_to receive(:commit_if_dirty)
|
27
|
+
post :create, :params => { :post => { :title => 'Test 1' } }
|
32
28
|
end
|
33
29
|
|
34
30
|
it 'should commit if configuration is not specified' do
|
35
31
|
@configuration.user_configuration = {}
|
36
|
-
Sunspot.
|
37
|
-
post :create, :post => { :title => 'Test 1' }
|
32
|
+
expect(Sunspot).to receive(:commit_if_dirty)
|
33
|
+
post :create, :params => { :post => { :title => 'Test 1' } }
|
38
34
|
end
|
39
|
-
|
35
|
+
|
40
36
|
### auto_commit_if_delete_dirty
|
41
|
-
|
37
|
+
|
42
38
|
it 'should automatically commit after each delete if specified' do
|
43
39
|
@configuration.user_configuration = { 'auto_commit_after_request' => false,
|
44
40
|
'auto_commit_after_delete_request' => true }
|
45
|
-
Sunspot.
|
46
|
-
post :create, :post => { :title => 'Test 1' }
|
41
|
+
expect(Sunspot).to receive(:commit_if_delete_dirty)
|
42
|
+
post :create, :params => { :post => { :title => 'Test 1' } }
|
47
43
|
end
|
48
|
-
|
44
|
+
|
49
45
|
it 'should not automatically commit on delete if configuration is set to false' do
|
50
46
|
@configuration.user_configuration = { 'auto_commit_after_request' => false,
|
51
47
|
'auto_commit_after_delete_request' => false }
|
52
|
-
Sunspot.
|
53
|
-
post :create, :post => { :title => 'Test 1' }
|
48
|
+
expect(Sunspot).not_to receive(:commit_if_delete_dirty)
|
49
|
+
post :create, :params => { :post => { :title => 'Test 1' } }
|
54
50
|
end
|
55
51
|
|
56
52
|
it 'should not automatically commit on delete if configuration is not specified' do
|
57
53
|
@configuration.user_configuration = { 'auto_commit_after_request' => false }
|
58
|
-
Sunspot.
|
59
|
-
post :create, :post => { :title => 'Test 1' }
|
54
|
+
expect(Sunspot).not_to receive(:commit_if_delete_dirty)
|
55
|
+
post :create, :params => { :post => { :title => 'Test 1' } }
|
60
56
|
end
|
61
|
-
end
|
57
|
+
end
|
data/spec/schema.rb
CHANGED
@@ -1,27 +1,26 @@
|
|
1
|
-
ActiveRecord::Schema.define(:
|
2
|
-
create_table :posts, :
|
1
|
+
ActiveRecord::Schema.define(version: 0) do
|
2
|
+
create_table :posts, force: true do |t|
|
3
3
|
t.string :title
|
4
4
|
t.string :type
|
5
5
|
t.integer :location_id
|
6
6
|
t.text :body
|
7
7
|
t.references :blog
|
8
|
-
t.timestamps
|
8
|
+
t.timestamps null: true
|
9
9
|
end
|
10
10
|
|
11
|
-
create_table :locations, :
|
11
|
+
create_table :locations, force: true do |t|
|
12
12
|
t.float :lat
|
13
13
|
t.float :lng
|
14
14
|
end
|
15
15
|
|
16
|
-
create_table :blogs, :
|
16
|
+
create_table :blogs, force: true do |t|
|
17
17
|
t.string :name
|
18
18
|
t.string :subdomain
|
19
|
-
t.timestamps
|
19
|
+
t.timestamps null: true
|
20
20
|
end
|
21
21
|
|
22
|
-
create_table :writers, :
|
22
|
+
create_table :writers, force: true, primary_key: :writer_id do |t|
|
23
23
|
t.string :name
|
24
|
-
t.timestamps
|
24
|
+
t.timestamps null: true
|
25
25
|
end
|
26
|
-
|
27
26
|
end
|
data/spec/searchable_spec.rb
CHANGED
@@ -6,10 +6,10 @@ describe Sunspot::Rails::Searchable do
|
|
6
6
|
# Rspec runs tests in random order, causing this test to fail on occasion unless we ensure the models have loaded.
|
7
7
|
Author; Blog; Post;
|
8
8
|
|
9
|
-
Sunspot.searchable.
|
10
|
-
Sunspot.searchable.
|
11
|
-
Sunspot.searchable.
|
12
|
-
Sunspot.searchable.
|
9
|
+
expect(Sunspot.searchable).not_to be_empty
|
10
|
+
expect(Sunspot.searchable).to include(Author)
|
11
|
+
expect(Sunspot.searchable).to include(Blog)
|
12
|
+
expect(Sunspot.searchable).to include(Post)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/spec/server_spec.rb
CHANGED
@@ -4,28 +4,28 @@ describe Sunspot::Rails::Server do
|
|
4
4
|
before :each do
|
5
5
|
@server = Sunspot::Rails::Server.new
|
6
6
|
@config = Sunspot::Rails::Configuration.new
|
7
|
-
@server.
|
7
|
+
allow(@server).to receive(:configuration){ @config }
|
8
8
|
@solr_home = File.join(@config.solr_home)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "sets the correct Solr home" do
|
12
|
-
@server.solr_home.
|
12
|
+
expect(@server.solr_home).to eq(@solr_home)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "sets the correct Solr PID path" do
|
16
|
-
@server.pid_path.
|
16
|
+
expect(@server.pid_path).to eq(File.join(@server.pid_dir, 'sunspot-solr-test.pid'))
|
17
17
|
end
|
18
18
|
|
19
19
|
it "sets the correct port" do
|
20
|
-
@server.port.
|
20
|
+
expect(@server.port).to eq(8983)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "sets the log level using configuration" do
|
24
|
-
@config.
|
25
|
-
@server.log_level.
|
24
|
+
allow(@config).to receive(:log_level){ 'WARNING' }
|
25
|
+
expect(@server.log_level).to eq("WARNING")
|
26
26
|
end
|
27
27
|
|
28
28
|
it "sets the correct log file" do
|
29
|
-
@server.log_file.
|
29
|
+
expect(@server.log_file).to eq(File.join(Rails.root, 'log', 'sunspot-solr-test.log'))
|
30
30
|
end
|
31
31
|
end
|
data/spec/session_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe 'Sunspot::Rails session' do
|
|
19
19
|
|
20
20
|
# There should be no items in the queue with the same object_id
|
21
21
|
object_ids = sessions.map(&:object_id)
|
22
|
-
object_ids.uniq.
|
22
|
+
expect(object_ids.uniq).to eq(object_ids)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should create a separate master/slave session if configured' do
|
@@ -31,7 +31,7 @@ describe 'Sunspot::Rails session' do
|
|
31
31
|
context 'disabled' do
|
32
32
|
before do
|
33
33
|
Sunspot::Rails.reset
|
34
|
-
::Rails.
|
34
|
+
allow(::Rails).to receive(:env).and_return("config_disabled_test")
|
35
35
|
end
|
36
36
|
|
37
37
|
after do
|
@@ -39,7 +39,7 @@ describe 'Sunspot::Rails session' do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'sets the session proxy as a stub' do
|
42
|
-
Sunspot::Rails.build_session.
|
42
|
+
expect(Sunspot::Rails.build_session).to be_a_kind_of(Sunspot::Rails::StubSessionProxy)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,75 +1,42 @@
|
|
1
|
-
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
1
|
ENV["RAILS_ENV"] ||= 'test'
|
3
|
-
if rsolr_version = ENV['RSOLR_GEM_VERSION']
|
4
|
-
STDERR.puts("Forcing RSolr version #{rsolr_version}")
|
5
|
-
gem "rsolr", rsolr_version
|
6
|
-
end
|
7
|
-
|
8
|
-
# Require the Database-specific gems
|
9
|
-
ENV['DB'] ||= 'sqlite'
|
10
|
-
Bundler.require(ENV['DB'])
|
11
2
|
|
12
|
-
require File.expand_path('config/environment',
|
3
|
+
require File.expand_path('config/environment', File.expand_path('../rails_app', __FILE__))
|
4
|
+
require File.expand_path('../../lib/sunspot_rails', __FILE__)
|
13
5
|
require 'rspec/rails'
|
14
|
-
require 'rspec/autorun'
|
15
|
-
require File.join('sunspot', 'rails', 'solr_logging')
|
16
6
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
# in _spec.rb will both be required and run as specs, causing the specs to be
|
21
|
-
# run twice. It is recommended that you do not name files matching this glob to
|
22
|
-
# end with _spec.rb. You can configure this pattern with with the --pattern
|
23
|
-
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
24
|
-
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
7
|
+
if RSolr::VERSION >= '2'
|
8
|
+
require File.join('sunspot', 'rails', 'solr_logging')
|
9
|
+
end
|
25
10
|
|
26
11
|
# Load all shared examples
|
27
|
-
Dir[File.expand_path("shared_examples/*.rb", File.dirname(__FILE__))].each {|f| require f}
|
12
|
+
Dir[File.expand_path("shared_examples/*.rb", File.dirname(__FILE__))].each { |f| require f }
|
28
13
|
|
29
14
|
# Load the schema
|
30
|
-
load File.join(
|
15
|
+
load File.join(File.expand_path('../rails_app', __FILE__), 'db', 'schema.rb')
|
31
16
|
|
32
17
|
RSpec.configure do |config|
|
33
|
-
# ## Mock Framework
|
34
|
-
#
|
35
|
-
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
36
|
-
#
|
37
|
-
# config.mock_with :mocha
|
38
|
-
# config.mock_with :flexmock
|
39
|
-
# config.mock_with :rr
|
40
|
-
|
41
|
-
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
42
|
-
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
43
|
-
|
44
|
-
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
45
|
-
# examples within a transaction, remove the following line or assign false
|
46
|
-
# instead of true.
|
47
18
|
config.use_transactional_fixtures = true
|
48
|
-
|
49
|
-
# If true, the base class of anonymous controllers will be inferred
|
50
|
-
# automatically. This will be the default behavior in future versions of
|
51
|
-
# rspec-rails.
|
52
19
|
config.infer_base_class_for_anonymous_controllers = false
|
53
|
-
|
54
|
-
|
55
|
-
# order dependency and want to debug it, you can fix the order by providing
|
56
|
-
# the seed, which is printed after each run.
|
57
|
-
# --seed 1234
|
58
|
-
config.order = "random"
|
20
|
+
config.order = 'random'
|
21
|
+
config.infer_spec_type_from_file_location!
|
59
22
|
|
60
23
|
config.before(:each) do
|
61
24
|
empty_tables
|
62
25
|
Sunspot.remove_all!
|
63
|
-
end
|
26
|
+
end
|
64
27
|
end
|
65
28
|
|
66
29
|
def empty_tables
|
67
|
-
|
30
|
+
sources = if Rails::VERSION::MAJOR > 4
|
31
|
+
ActiveRecord::Base.connection.data_sources
|
32
|
+
else
|
33
|
+
ActiveRecord::Base.connection.tables
|
34
|
+
end
|
35
|
+
sources.each do |table_name|
|
68
36
|
ActiveRecord::Base.connection.execute("DELETE FROM #{table_name}") unless table_name == 'schema_migrations'
|
69
37
|
end
|
70
38
|
end
|
71
39
|
|
72
|
-
# COMPATIBILITY: Rails 4 has deprecated the 'scoped' method in favour of 'all'
|
73
40
|
def relation(clazz)
|
74
|
-
::
|
75
|
-
end
|
41
|
+
Rails::VERSION::MAJOR >= 4 ? clazz.all : clazz.scoped
|
42
|
+
end
|
@@ -13,142 +13,146 @@ describe 'specs with Sunspot stubbed' do
|
|
13
13
|
foo = double('Foo')
|
14
14
|
block = lambda { foo.bar }
|
15
15
|
|
16
|
-
foo.
|
16
|
+
expect(foo).to receive(:bar)
|
17
17
|
|
18
18
|
Sunspot.batch(&block)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should not send index to session' do
|
22
|
-
@session.
|
22
|
+
expect(@session).not_to receive(:index)
|
23
23
|
@post.index
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should not send index! to session' do
|
27
|
-
@session.
|
27
|
+
expect(@session).not_to receive(:index!)
|
28
28
|
@post.index!
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'should not send atomic_update to session' do
|
32
|
-
@session.
|
32
|
+
expect(@session).not_to receive(:atomic_update)
|
33
33
|
@post.index
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'should not send atomic_update! to session' do
|
37
|
-
@session.
|
37
|
+
expect(@session).not_to receive(:atomic_update!)
|
38
38
|
@post.index!
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'should not send commit to session' do
|
42
|
-
@session.
|
42
|
+
expect(@session).not_to receive(:commit)
|
43
43
|
Sunspot.commit
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should not send remove to session' do
|
47
|
-
@session.
|
47
|
+
expect(@session).not_to receive(:remove)
|
48
48
|
@post.remove_from_index
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should not send remove! to session' do
|
52
|
-
@session.
|
52
|
+
expect(@session).not_to receive(:remove)
|
53
53
|
@post.remove_from_index!
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should not send remove_by_id to session' do
|
57
|
-
@session.
|
57
|
+
expect(@session).not_to receive(:remove_by_id)
|
58
58
|
Sunspot.remove_by_id(Post, 1)
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'should not send remove_by_id! to session' do
|
62
|
-
@session.
|
62
|
+
expect(@session).not_to receive(:remove_by_id!)
|
63
63
|
Sunspot.remove_by_id!(Post, 1)
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'should not send remove_all to session' do
|
67
|
-
@session.
|
67
|
+
expect(@session).not_to receive(:remove_all)
|
68
68
|
Post.remove_all_from_index
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'should not send remove_all! to session' do
|
72
|
-
@session.
|
72
|
+
expect(@session).not_to receive(:remove_all!)
|
73
73
|
Post.remove_all_from_index!
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'should not send optimize to session' do
|
77
|
-
@session.
|
77
|
+
expect(@session).not_to receive(:optimize)
|
78
78
|
Sunspot.optimize
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'should return false for dirty?' do
|
82
|
-
@session.
|
83
|
-
Sunspot.dirty
|
82
|
+
expect(@session).not_to receive(:dirty?)
|
83
|
+
expect(Sunspot.dirty?).to eq(false)
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'should not send commit_if_dirty to session' do
|
87
|
-
@session.
|
87
|
+
expect(@session).not_to receive(:commit_if_dirty)
|
88
88
|
Sunspot.commit_if_dirty
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'should return false for delete_dirty?' do
|
92
|
-
@session.
|
93
|
-
Sunspot.delete_dirty
|
92
|
+
expect(@session).not_to receive(:delete_dirty?)
|
93
|
+
expect(Sunspot.delete_dirty?).to eq(false)
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'should not send commit_if_delete_dirty to session' do
|
97
|
-
@session.
|
97
|
+
expect(@session).not_to receive(:commit_if_delete_dirty)
|
98
98
|
Sunspot.commit_if_delete_dirty
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'should not execute a search when #search called' do
|
102
|
-
@session.
|
102
|
+
expect(@session).not_to receive(:search)
|
103
103
|
Post.search
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'should not execute a search when #search called with parameters' do
|
107
|
-
@session.
|
107
|
+
expect(@session).not_to receive(:search)
|
108
108
|
Post.search(:include => :blog, :select => 'id, title')
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'should return a new search' do
|
112
|
-
@session.
|
113
|
-
Sunspot.new_search(Post).
|
112
|
+
expect(@session).not_to receive(:new_search)
|
113
|
+
expect(Sunspot.new_search(Post)).to respond_to(:execute)
|
114
114
|
end
|
115
115
|
|
116
116
|
it 'should not send more_like_this to session' do
|
117
|
-
@session.
|
117
|
+
expect(@session).not_to receive(:more_like_this)
|
118
118
|
Sunspot.more_like_this(@post)
|
119
119
|
end
|
120
120
|
|
121
|
+
it 'should not raise error when reindexing scope' do
|
122
|
+
expect{ Post.solr_index }.to_not raise_error
|
123
|
+
end
|
124
|
+
|
121
125
|
describe 'stub search' do
|
122
126
|
before :each do
|
123
127
|
@search = Post.search
|
124
128
|
end
|
125
129
|
|
126
130
|
it 'should return empty results' do
|
127
|
-
@search.results.
|
131
|
+
expect(@search.results).to eq([])
|
128
132
|
end
|
129
133
|
|
130
134
|
it 'should return empty hits' do
|
131
|
-
@search.hits.
|
135
|
+
expect(@search.hits).to eq([])
|
132
136
|
end
|
133
137
|
|
134
138
|
it 'should return the same for raw_results as hits' do
|
135
|
-
@search.raw_results.
|
139
|
+
expect(@search.raw_results).to eq(@search.hits)
|
136
140
|
end
|
137
141
|
|
138
142
|
it 'should return zero total' do
|
139
|
-
@search.total.
|
143
|
+
expect(@search.total).to eq(0)
|
140
144
|
end
|
141
145
|
|
142
146
|
it 'should return empty results for a given facet' do
|
143
|
-
@search.facet(:category_id).rows.
|
147
|
+
expect(@search.facet(:category_id).rows).to eq([])
|
144
148
|
end
|
145
149
|
|
146
150
|
it 'should return empty results for a given dynamic facet' do
|
147
|
-
@search.dynamic_facet(:custom).rows.
|
151
|
+
expect(@search.dynamic_facet(:custom).rows).to eq([])
|
148
152
|
end
|
149
153
|
|
150
154
|
it 'should return empty array if listing facets' do
|
151
|
-
@search.facets.
|
155
|
+
expect(@search.facets).to eq([])
|
152
156
|
end
|
153
157
|
|
154
158
|
describe '#data_accessor_for' do
|
@@ -157,11 +161,11 @@ describe 'specs with Sunspot stubbed' do
|
|
157
161
|
end
|
158
162
|
|
159
163
|
it 'should provide accessor for select' do
|
160
|
-
@accessor.
|
164
|
+
expect(@accessor).to respond_to(:select, :select=)
|
161
165
|
end
|
162
166
|
|
163
167
|
it 'should provide accessor for include' do
|
164
|
-
@accessor.
|
168
|
+
expect(@accessor).to respond_to(:include, :include=)
|
165
169
|
end
|
166
170
|
end
|
167
171
|
|
@@ -171,7 +175,7 @@ describe 'specs with Sunspot stubbed' do
|
|
171
175
|
end
|
172
176
|
|
173
177
|
it 'should response to all the available data methods' do
|
174
|
-
@stats.
|
178
|
+
expect(@stats).to respond_to(
|
175
179
|
:min,
|
176
180
|
:max,
|
177
181
|
:count,
|
@@ -183,11 +187,11 @@ describe 'specs with Sunspot stubbed' do
|
|
183
187
|
end
|
184
188
|
|
185
189
|
it 'should return empty results for a given facet' do
|
186
|
-
@stats.facet(:category_id).rows.
|
190
|
+
expect(@stats.facet(:category_id).rows).to eq([])
|
187
191
|
end
|
188
192
|
|
189
193
|
it 'should return empty array if listing facets' do
|
190
|
-
@stats.facets.
|
194
|
+
expect(@stats.facets).to eq([])
|
191
195
|
end
|
192
196
|
|
193
197
|
end
|