sunspot_rails 2.2.7 → 2.5.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 +63 -0
- data/Gemfile +3 -0
- data/gemfiles/.gitkeep +0 -0
- data/lib/sunspot/rails.rb +2 -0
- data/lib/sunspot/rails/configuration.rb +4 -0
- data/lib/sunspot/rails/searchable.rb +9 -3
- data/lib/sunspot/rails/solr_logging.rb +3 -3
- data/lib/sunspot/rails/stub_session_proxy.rb +4 -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/photo_post.rb +0 -0
- 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_template → rails_app}/app/models/rake_task_auto_load_test_model.rb +0 -0
- data/spec/rails_app/config.ru +4 -0
- data/spec/rails_app/config/application.rb +14 -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_template → rails_app}/config/initializers/rails_5_override.rb +0 -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/routes.rb +0 -0
- data/spec/{rails_template → rails_app}/config/sunspot.yml +2 -0
- data/spec/rails_app/db/schema.rb +26 -0
- data/spec/rake_task_spec.rb +8 -8
- 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 -6
- metadata +93 -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/gemfiles/rails-5.0 +0 -20
- 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
@@ -0,0 +1,16 @@
|
|
1
|
+
class PostsController < ApplicationController
|
2
|
+
def create
|
3
|
+
PostWithAuto.create(permitted_params[:post])
|
4
|
+
head(:ok)
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def permitted_params
|
10
|
+
if ::Rails::VERSION::MAJOR >= 4
|
11
|
+
params.permit! # ActionController::Parameters
|
12
|
+
else
|
13
|
+
params
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
File without changes
|
@@ -3,8 +3,6 @@ class PostWithOnlySomeAttributesTriggeringReindex < ActiveRecord::Base
|
|
3
3
|
'posts'
|
4
4
|
end
|
5
5
|
|
6
|
-
attr_accessible :title, :type, :location_id, :body, :blog
|
7
|
-
|
8
6
|
searchable :only_reindex_attribute_changes_of => [ :title, :body ] do
|
9
7
|
string :title
|
10
8
|
text :body, :more_like_this => true
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
6
|
+
|
7
|
+
module RailsApp
|
8
|
+
class Application < Rails::Application
|
9
|
+
config.encoding = 'utf-8'
|
10
|
+
|
11
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
12
|
+
config.filter_parameters += [:password]
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
RailsApp::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Eager load code on boot. This eager loads most of Rails and
|
11
|
+
# your application in memory, allowing both thread web servers
|
12
|
+
# and those relying on copy on write to perform better.
|
13
|
+
# Rake tasks automatically ignore this option for performance.
|
14
|
+
config.eager_load = true
|
15
|
+
|
16
|
+
# Show full error reports and disable caching
|
17
|
+
config.consider_all_requests_local = true
|
18
|
+
config.action_controller.perform_caching = false
|
19
|
+
|
20
|
+
# Raise exceptions instead of rendering exception templates
|
21
|
+
config.action_dispatch.show_exceptions = false
|
22
|
+
|
23
|
+
# Disable request forgery protection in test environment
|
24
|
+
config.action_controller.allow_forgery_protection = false
|
25
|
+
|
26
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
27
|
+
# The :test delivery method accumulates sent emails in the
|
28
|
+
# ActionMailer::Base.deliveries array.
|
29
|
+
config.action_mailer.delivery_method = :test
|
30
|
+
|
31
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
32
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
33
|
+
# like if you have constraints or database-specific column types
|
34
|
+
# config.active_record.schema_format = :sql
|
35
|
+
|
36
|
+
# mute Rails 5.2 deprecation warning
|
37
|
+
config.active_record.sqlite3.represent_boolean_as_integer = true if config.active_record.sqlite3
|
38
|
+
|
39
|
+
# Print deprecation notices to the stderr
|
40
|
+
config.active_support.deprecation = :stderr
|
41
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
Rails.application.config.secret_key_base = '_secret_key_base_'
|
File without changes
|
@@ -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
|
data/spec/rake_task_spec.rb
CHANGED
@@ -12,27 +12,27 @@ describe 'sunspot namespace rake task' do
|
|
12
12
|
run_rake_task("sunspot:reindex", '', '', true)
|
13
13
|
|
14
14
|
# This model should not be used by any other test and therefore should only be loaded by this test
|
15
|
-
Sunspot.searchable.collect(&:name).
|
15
|
+
expect(Sunspot.searchable.collect(&:name)).to include('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
|
|