sunspot_rails 2.2.7 → 2.2.8
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 +60 -0
- data/Gemfile +3 -0
- data/gemfiles/.gitkeep +0 -0
- data/lib/sunspot/rails/solr_logging.rb +3 -3
- data/spec/configuration_spec.rb +67 -67
- 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 -0
- data/spec/{rails_template → rails_app}/app/models/blog.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/location.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/photo_post.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/post.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/post_with_auto.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/post_with_default_scope.rb +0 -0
- data/spec/{rails_template → rails_app}/app/models/post_with_only_some_attributes_triggering_reindex.rb +0 -0
- 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 +38 -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 +0 -0
- data/spec/rails_app/db/schema.rb +26 -0
- data/spec/rake_task_spec.rb +8 -8
- data/spec/request_lifecycle_spec.rb +12 -16
- 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 +36 -36
- data/sunspot_rails.gemspec +6 -3
- metadata +94 -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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
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,38 @@
|
|
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
|
+
# Print deprecation notices to the stderr
|
37
|
+
config.active_support.deprecation = :stderr
|
38
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
Rails.application.config.secret_key_base = '_secret_key_base_'
|
File without changes
|
File without changes
|
@@ -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,26 +15,22 @@ 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
|
@@ -42,20 +38,20 @@ describe PostsController, :type => :controller do
|
|
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
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
|