sunspot_rails 2.2.7 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -2
  3. data/Appraisals +63 -0
  4. data/Gemfile +3 -0
  5. data/gemfiles/.gitkeep +0 -0
  6. data/lib/sunspot/rails.rb +2 -0
  7. data/lib/sunspot/rails/configuration.rb +4 -0
  8. data/lib/sunspot/rails/searchable.rb +9 -3
  9. data/lib/sunspot/rails/solr_logging.rb +3 -3
  10. data/lib/sunspot/rails/stub_session_proxy.rb +4 -0
  11. data/spec/configuration_spec.rb +77 -69
  12. data/spec/model_lifecycle_spec.rb +8 -8
  13. data/spec/model_spec.rb +72 -71
  14. data/spec/rails_app/app/controllers/application_controller.rb +4 -0
  15. data/spec/rails_app/app/controllers/posts_controller.rb +16 -0
  16. data/spec/{rails_template → rails_app}/app/models/author.rb +0 -2
  17. data/spec/{rails_template → rails_app}/app/models/blog.rb +0 -2
  18. data/spec/{rails_template → rails_app}/app/models/location.rb +0 -1
  19. data/spec/{rails_template → rails_app}/app/models/photo_post.rb +0 -0
  20. data/spec/{rails_template → rails_app}/app/models/post.rb +0 -2
  21. data/spec/{rails_template → rails_app}/app/models/post_with_auto.rb +0 -2
  22. data/spec/{rails_template → rails_app}/app/models/post_with_default_scope.rb +0 -2
  23. data/spec/{rails_template → rails_app}/app/models/post_with_only_some_attributes_triggering_reindex.rb +0 -2
  24. data/spec/{rails_template → rails_app}/app/models/rake_task_auto_load_test_model.rb +0 -0
  25. data/spec/rails_app/config.ru +4 -0
  26. data/spec/rails_app/config/application.rb +14 -0
  27. data/spec/rails_app/config/boot.rb +6 -0
  28. data/spec/rails_app/config/database.yml +5 -0
  29. data/spec/rails_app/config/environment.rb +5 -0
  30. data/spec/rails_app/config/environments/test.rb +41 -0
  31. data/spec/{rails_template → rails_app}/config/initializers/rails_5_override.rb +0 -0
  32. data/spec/rails_app/config/initializers/secret_token.rb +1 -0
  33. data/spec/rails_app/config/initializers/session_store.rb +3 -0
  34. data/spec/{rails_template → rails_app}/config/routes.rb +0 -0
  35. data/spec/{rails_template → rails_app}/config/sunspot.yml +2 -0
  36. data/spec/rails_app/db/schema.rb +26 -0
  37. data/spec/rake_task_spec.rb +8 -8
  38. data/spec/request_lifecycle_spec.rb +17 -21
  39. data/spec/schema.rb +8 -9
  40. data/spec/searchable_spec.rb +4 -4
  41. data/spec/server_spec.rb +7 -7
  42. data/spec/session_spec.rb +3 -3
  43. data/spec/shared_examples/indexed_after_save.rb +1 -1
  44. data/spec/shared_examples/not_indexed_after_save.rb +1 -1
  45. data/spec/spec_helper.rb +18 -51
  46. data/spec/stub_session_proxy_spec.rb +40 -36
  47. data/sunspot_rails.gemspec +15 -6
  48. metadata +93 -58
  49. data/dev_tasks/spec.rake +0 -97
  50. data/gemfiles/rails-3.0.0 +0 -21
  51. data/gemfiles/rails-3.1.0 +0 -21
  52. data/gemfiles/rails-3.2.0 +0 -21
  53. data/gemfiles/rails-4.0.0 +0 -25
  54. data/gemfiles/rails-4.1.0 +0 -24
  55. data/gemfiles/rails-4.2.0 +0 -24
  56. data/gemfiles/rails-5.0 +0 -20
  57. data/spec/rails_template/app/controllers/application_controller.rb +0 -10
  58. data/spec/rails_template/app/controllers/posts_controller.rb +0 -6
  59. data/spec/rails_template/config/database.yml +0 -11
  60. data/spec/rails_template/db/schema.rb +0 -27
@@ -0,0 +1,4 @@
1
+ class ApplicationController < ActionController::Base
2
+ helper :all
3
+ protect_from_forgery
4
+ end
@@ -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
@@ -2,8 +2,6 @@ class Author < ActiveRecord::Base
2
2
  self.table_name = :writers
3
3
  self.primary_key = :writer_id
4
4
 
5
- attr_accessible :name
6
-
7
5
  searchable do
8
6
  string :name
9
7
  end
@@ -2,8 +2,6 @@ class Blog < ActiveRecord::Base
2
2
  has_many :posts
3
3
  has_many :comments, :through => :posts
4
4
 
5
- attr_accessible :name, :subdomain
6
-
7
5
  searchable :include => { :posts => :author } do
8
6
  string :subdomain
9
7
  text :name
@@ -1,3 +1,2 @@
1
1
  class Location < ActiveRecord::Base
2
- attr_accessible :lat, :lng
3
2
  end
@@ -3,8 +3,6 @@ class Post < ActiveRecord::Base
3
3
  belongs_to :author
4
4
  has_many :comments
5
5
 
6
- attr_accessible :title, :type, :location_id, :body, :blog
7
-
8
6
  searchable :auto_index => false, :auto_remove => false do
9
7
  string :title
10
8
  text :body, :more_like_this => true
@@ -3,8 +3,6 @@ class PostWithAuto < ActiveRecord::Base
3
3
  'posts'
4
4
  end
5
5
 
6
- attr_accessible :title, :type, :location_id, :body, :blog
7
-
8
6
  searchable :ignore_attribute_changes_of => [ :updated_at ] do
9
7
  string :title
10
8
  text :body, :more_like_this => true
@@ -3,8 +3,6 @@ class PostWithDefaultScope < ActiveRecord::Base
3
3
  'posts'
4
4
  end
5
5
 
6
- attr_accessible :title, :type, :location_id, :body, :blog
7
-
8
6
  def self.default_scope
9
7
  order(:title)
10
8
  end
@@ -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
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run RailsApp::Application
@@ -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,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: ':memory:'
4
+ pool: 5
5
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ RailsApp::Application.initialize!
@@ -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
@@ -0,0 +1 @@
1
+ Rails.application.config.secret_key_base = '_secret_key_base_'
@@ -0,0 +1,3 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails.application.config.session_store :cookie_store, :key => '_rails_app_session'
@@ -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
@@ -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).should include('RakeTaskAutoLoadTestModel')
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.should_receive(:solr_reindex)
20
- Author.should_receive(:solr_reindex)
21
- Blog.should_not_receive(:solr_reindex)
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.should_receive(:solr_reindex)
28
- Author.should_receive(:solr_reindex)
29
- Blog.should_not_receive(:solr_reindex)
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.should_receive(:puts).with("You have no data in the database. Reindexing does nothing here.")
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.should_receive(:commit_if_dirty)
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.should_not_receive(:commit_if_dirty)
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.should_receive(:commit_if_dirty)
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.should_receive(:commit_if_delete_dirty)
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.should_not_receive(:commit_if_delete_dirty)
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.should_not_receive(:commit_if_delete_dirty)
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
@@ -1,27 +1,26 @@
1
- ActiveRecord::Schema.define(:version => 0) do
2
- create_table :posts, :force => true do |t|
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, :force => true do |t|
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, :force => true do |t|
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, :force => true, :primary_key => :writer_id do |t|
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
@@ -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.should_not be_empty
10
- Sunspot.searchable.should include(Author)
11
- Sunspot.searchable.should include(Blog)
12
- Sunspot.searchable.should include(Post)
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
@@ -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.stub(:configuration){ @config }
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.should == @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.should == File.join(@server.pid_dir, 'sunspot-solr-test.pid')
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.should == 8983
20
+ expect(@server.port).to eq(8983)
21
21
  end
22
22
 
23
23
  it "sets the log level using configuration" do
24
- @config.stub(:log_level){ 'WARNING' }
25
- @server.log_level.should == "WARNING"
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.should == File.join(Rails.root, 'log', 'sunspot-solr-test.log')
29
+ expect(@server.log_file).to eq(File.join(Rails.root, 'log', 'sunspot-solr-test.log'))
30
30
  end
31
31
  end
@@ -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.should == object_ids
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.stub(:env).and_return("config_disabled_test")
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.should be_a_kind_of(Sunspot::Rails::StubSessionProxy)
42
+ expect(Sunspot::Rails.build_session).to be_a_kind_of(Sunspot::Rails::StubSessionProxy)
43
43
  end
44
44
  end
45
45