sunspot_rails 2.0.0 → 2.1.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.
- data/History.txt +6 -1
- data/README.rdoc +0 -26
- data/dev_tasks/spec.rake +15 -24
- data/gemfiles/{rails-2.3.16 → rails-3.0.0} +11 -5
- data/gemfiles/{rails-3.0.20 → rails-3.1.0} +11 -4
- data/gemfiles/{rails-3.1.10 → rails-3.2.0} +11 -4
- data/gemfiles/rails-4.0.0 +20 -0
- data/generators/sunspot/templates/sunspot.yml +7 -4
- data/lib/generators/sunspot_rails/install/templates/config/sunspot.yml +4 -0
- data/lib/sunspot/rails/adapters.rb +12 -11
- data/lib/sunspot/rails/configuration.rb +2 -2
- data/lib/sunspot/rails/log_subscriber.rb +11 -6
- data/lib/sunspot/rails/railtie.rb +1 -1
- data/lib/sunspot/rails/searchable.rb +10 -15
- data/lib/sunspot/rails/solr_instrumentation.rb +7 -5
- data/lib/sunspot/rails/solr_logging.rb +2 -5
- data/lib/sunspot/rails/stub_session_proxy.rb +14 -0
- data/lib/sunspot/rails/tasks.rb +47 -42
- data/lib/sunspot_rails.rb +2 -7
- data/spec/configuration_spec.rb +10 -10
- data/spec/model_spec.rb +38 -29
- data/spec/rails_template/app/models/post_with_default_scope.rb +3 -1
- data/spec/rails_template/app/models/rake_task_auto_load_test_model.rb +13 -0
- data/spec/rails_template/config/database.yml +11 -0
- data/spec/rails_template/config/routes.rb +3 -9
- data/spec/rake_task_spec.rb +40 -0
- data/spec/searchable_spec.rb +3 -0
- data/spec/session_spec.rb +1 -1
- data/spec/spec_helper.rb +59 -32
- data/spec/stub_session_proxy_spec.rb +8 -4
- data/sunspot_rails.gemspec +1 -0
- metadata +42 -22
- data/gemfiles/rails-3.2.11 +0 -12
- data/spec/rails_template/config/boot.rb +0 -127
- data/spec/rails_template/config/preinitializer.rb +0 -22
@@ -82,10 +82,16 @@ module Sunspot
|
|
82
82
|
0
|
83
83
|
end
|
84
84
|
|
85
|
+
def facets
|
86
|
+
[]
|
87
|
+
end
|
88
|
+
|
85
89
|
def facet(name)
|
90
|
+
FacetStub.new
|
86
91
|
end
|
87
92
|
|
88
93
|
def dynamic_facet(name)
|
94
|
+
FacetStub.new
|
89
95
|
end
|
90
96
|
|
91
97
|
def execute
|
@@ -140,6 +146,14 @@ module Sunspot
|
|
140
146
|
end
|
141
147
|
|
142
148
|
end
|
149
|
+
|
150
|
+
class FacetStub
|
151
|
+
|
152
|
+
def rows
|
153
|
+
[]
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
143
157
|
|
144
158
|
end
|
145
159
|
end
|
data/lib/sunspot/rails/tasks.rb
CHANGED
@@ -14,55 +14,60 @@ namespace :sunspot do
|
|
14
14
|
# $ rake sunspot:reindex[1000,Post] # reindex only the Post model in
|
15
15
|
# # batchs of 1000
|
16
16
|
# $ rake sunspot:reindex[,Post+Author] # reindex Post and Author model
|
17
|
-
task :reindex, [:batch_size, :models] => [:environment] do |t, args|
|
18
|
-
puts "*Note: the reindex task will remove your current indexes and start from scratch."
|
19
|
-
puts "If you have a large dataset, reindexing can take a very long time, possibly weeks."
|
20
|
-
puts "This is not encouraged if you have anywhere near or over 1 million rows."
|
21
|
-
puts "Are you sure you want to drop your indexes and completely reindex? (y/n)"
|
22
|
-
answer = STDIN.gets.chomp
|
23
|
-
return false if answer == "n"
|
24
|
-
|
17
|
+
task :reindex, [:batch_size, :models, :silence] => [:environment] do |t, args|
|
25
18
|
# Retry once or gracefully fail for a 5xx error so we don't break reindexing
|
26
|
-
Sunspot
|
27
|
-
|
28
|
-
# Set up general options for reindexing
|
29
|
-
reindex_options = { :batch_commit => false }
|
19
|
+
with_session(Sunspot::SessionProxy::Retry5xxSessionProxy.new(Sunspot.session)) do
|
30
20
|
|
31
|
-
|
32
|
-
|
33
|
-
reindex_options[:batch_size] = nil
|
34
|
-
when /^\d+$/
|
35
|
-
reindex_options[:batch_size] = args[:batch_size].to_i if args[:batch_size].to_i > 0
|
36
|
-
end
|
21
|
+
# Set up general options for reindexing
|
22
|
+
reindex_options = { :batch_commit => false }
|
37
23
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
24
|
+
case args[:batch_size]
|
25
|
+
when 'false'
|
26
|
+
reindex_options[:batch_size] = nil
|
27
|
+
when /^\d+$/
|
28
|
+
reindex_options[:batch_size] = args[:batch_size].to_i if args[:batch_size].to_i > 0
|
29
|
+
end
|
44
30
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
31
|
+
# Load all the application's models. Models which invoke 'searchable' will register themselves
|
32
|
+
# in Sunspot.searchable.
|
33
|
+
Rails.application.eager_load!
|
34
|
+
|
35
|
+
if args[:models].present?
|
36
|
+
# Choose a specific subset of models, if requested
|
37
|
+
model_names = args[:models].split(/[+ ]/)
|
38
|
+
sunspot_models = model_names.map{ |m| m.constantize }
|
39
|
+
else
|
40
|
+
# By default, reindex all searchable models
|
41
|
+
sunspot_models = Sunspot.searchable
|
42
|
+
end
|
50
43
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
44
|
+
# Set up progress_bar to, ah, report progress unless the user has chosen to silence output
|
45
|
+
begin
|
46
|
+
require 'progress_bar'
|
47
|
+
total_documents = sunspot_models.map { | m | m.count }.sum
|
48
|
+
reindex_options[:progress_bar] = ProgressBar.new(total_documents)
|
49
|
+
rescue LoadError => e
|
50
|
+
$stdout.puts "Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile"
|
51
|
+
rescue Exception => e
|
52
|
+
$stderr.puts "Error using progress bar: #{e.message}"
|
53
|
+
end unless args[:silence]
|
54
|
+
|
55
|
+
# Finally, invoke the class-level solr_reindex on each model
|
56
|
+
sunspot_models.each do |model|
|
57
|
+
model.solr_reindex(reindex_options)
|
58
|
+
end
|
60
59
|
end
|
60
|
+
end
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
# Swaps sunspot sessions for the duration of the block
|
63
|
+
# Ensures the session is returned to normal in case this task is called from within the rails app
|
64
|
+
# and not just a one-off from the command line
|
65
|
+
def with_session(new_session)
|
66
|
+
original_session = Sunspot.session
|
67
|
+
Sunspot.session = new_session
|
68
|
+
yield
|
69
|
+
ensure
|
70
|
+
Sunspot.session = original_session
|
66
71
|
end
|
67
72
|
|
68
73
|
def sunspot_solr_in_load_path?
|
data/lib/sunspot_rails.rb
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
# This needs to be loaded before sunspot/search/paginated_collection
|
2
2
|
# or #to_json gets defined in Object breaking delegation to Array via
|
3
3
|
# method_missing
|
4
|
-
require 'active_support/core_ext/object/to_json'
|
4
|
+
require 'active_support/core_ext/object/to_json'
|
5
5
|
|
6
6
|
require 'sunspot/rails'
|
7
|
-
|
8
|
-
if ::Rails.version >= '3'
|
9
|
-
require 'sunspot/rails/railtie'
|
10
|
-
else
|
11
|
-
require 'sunspot/rails/init'
|
12
|
-
end
|
7
|
+
require 'sunspot/rails/railtie'
|
data/spec/configuration_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
describe Sunspot::Rails::Configuration, "default values without a sunspot.yml" do
|
4
4
|
before(:each) do
|
5
|
-
File.stub
|
5
|
+
File.stub(:exist?).and_return(false) # simulate sunspot.yml not existing
|
6
6
|
@config = Sunspot::Rails::Configuration.new
|
7
7
|
end
|
8
8
|
|
@@ -11,27 +11,27 @@ describe Sunspot::Rails::Configuration, "default values without a sunspot.yml" d
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should handle the 'path' property when not set" do
|
14
|
-
@config.path.should == '/solr'
|
14
|
+
@config.path.should == '/solr/default'
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "port" do
|
18
18
|
it "should default to port 8981 in test" do
|
19
|
-
::Rails.stub
|
19
|
+
::Rails.stub(:env => 'test')
|
20
20
|
@config = Sunspot::Rails::Configuration.new
|
21
21
|
@config.port.should == 8981
|
22
22
|
end
|
23
23
|
it "should default to port 8982 in development" do
|
24
|
-
::Rails.stub
|
24
|
+
::Rails.stub(:env => 'development')
|
25
25
|
@config = Sunspot::Rails::Configuration.new
|
26
26
|
@config.port.should == 8982
|
27
27
|
end
|
28
28
|
it "should default to 8983 in production" do
|
29
|
-
::Rails.stub
|
29
|
+
::Rails.stub(:env => 'production')
|
30
30
|
@config = Sunspot::Rails::Configuration.new
|
31
31
|
@config.port.should == 8983
|
32
32
|
end
|
33
33
|
it "should generally default to 8983" do
|
34
|
-
::Rails.stub
|
34
|
+
::Rails.stub(:env => 'staging')
|
35
35
|
@config = Sunspot::Rails::Configuration.new
|
36
36
|
@config.port.should == 8983
|
37
37
|
end
|
@@ -88,7 +88,7 @@ end
|
|
88
88
|
|
89
89
|
describe Sunspot::Rails::Configuration, "user provided sunspot.yml" do
|
90
90
|
before(:each) do
|
91
|
-
::Rails.stub
|
91
|
+
::Rails.stub(:env => 'config_test')
|
92
92
|
@config = Sunspot::Rails::Configuration.new
|
93
93
|
end
|
94
94
|
|
@@ -145,7 +145,7 @@ end
|
|
145
145
|
|
146
146
|
describe Sunspot::Rails::Configuration, "with disabled: true in sunspot.yml" do
|
147
147
|
before(:each) do
|
148
|
-
::Rails.stub
|
148
|
+
::Rails.stub(:env => 'config_disabled_test')
|
149
149
|
@config = Sunspot::Rails::Configuration.new
|
150
150
|
end
|
151
151
|
|
@@ -160,7 +160,7 @@ describe Sunspot::Rails::Configuration, "with ENV['SOLR_URL'] overriding sunspot
|
|
160
160
|
end
|
161
161
|
|
162
162
|
before(:each) do
|
163
|
-
::Rails.stub
|
163
|
+
::Rails.stub(:env => 'config_test')
|
164
164
|
@config = Sunspot::Rails::Configuration.new
|
165
165
|
end
|
166
166
|
|
@@ -187,7 +187,7 @@ describe Sunspot::Rails::Configuration, "with ENV['WEBSOLR_URL'] overriding suns
|
|
187
187
|
end
|
188
188
|
|
189
189
|
before(:each) do
|
190
|
-
::Rails.stub
|
190
|
+
::Rails.stub(:env => 'config_test')
|
191
191
|
@config = Sunspot::Rails::Configuration.new
|
192
192
|
end
|
193
193
|
|
data/spec/model_spec.rb
CHANGED
@@ -119,46 +119,50 @@ describe 'ActiveRecord mixin' do
|
|
119
119
|
with :title, 'Bogus Post'
|
120
120
|
end.results.should be_empty
|
121
121
|
end
|
122
|
-
|
123
|
-
it 'should
|
124
|
-
Post.
|
125
|
-
Post.search do
|
126
|
-
with :title, 'Test Post'
|
127
|
-
data_accessor_for(Post).include = [:blog]
|
128
|
-
end.results.should == [@post]
|
122
|
+
|
123
|
+
it 'should not allow bogus options to search' do
|
124
|
+
lambda { Post.search(:bogus => :option) }.should raise_error(ArgumentError)
|
129
125
|
end
|
130
126
|
|
131
127
|
it 'should pass :include option from search call to data accessor' do
|
132
|
-
Post.
|
133
|
-
Post.search(:include => [:blog]) do
|
128
|
+
Post.search(:include => [:location]) do
|
134
129
|
with :title, 'Test Post'
|
135
|
-
end.
|
130
|
+
end.data_accessor_for(Post).include.should == [:location]
|
136
131
|
end
|
137
132
|
|
138
|
-
it 'should use the
|
139
|
-
|
140
|
-
Post.search
|
133
|
+
it 'should use the include option on the data accessor when specified' do
|
134
|
+
@post.update_attribute(:location, Location.create)
|
135
|
+
post = Post.search do
|
141
136
|
with :title, 'Test Post'
|
142
|
-
|
143
|
-
|
137
|
+
data_accessor_for(Post).include = [:location]
|
138
|
+
end.results.first
|
144
139
|
|
145
|
-
|
146
|
-
|
140
|
+
(Rails.version >= '3.1' ? post.association(:location).loaded? : post.loaded_location?).should be_true # Rails 3.1 removed "loaded_#{association}" method
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should use the select option from search call to data accessor' do
|
144
|
+
Post.search(:select => 'id, title, body') do
|
145
|
+
with :title, 'Test Post'
|
146
|
+
end.data_accessor_for(Post).select.should == 'id, title, body'
|
147
147
|
end
|
148
148
|
|
149
149
|
it 'should use the select option on the data accessor when specified' do
|
150
|
-
Post.should_receive(:all).with(hash_including(:select => 'title, published_at')).and_return([@post])
|
151
150
|
Post.search do
|
152
151
|
with :title, 'Test Post'
|
153
|
-
data_accessor_for(Post).select =
|
154
|
-
end.results.should == [
|
152
|
+
data_accessor_for(Post).select = 'id, title, body'
|
153
|
+
end.results.first.attribute_names.sort.should == ['body', 'id', 'title']
|
155
154
|
end
|
156
155
|
|
157
156
|
it 'should not use the select option on the data accessor when not specified' do
|
158
|
-
Post.should_receive(:all).with(hash_not_including(:select)).and_return([@post])
|
159
157
|
Post.search do
|
160
158
|
with :title, 'Test Post'
|
161
|
-
end.results.should ==
|
159
|
+
end.results.first.attribute_names.should == Post.first.attribute_names
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should accept an array as a select option' do
|
163
|
+
Post.search(:select => ['id', 'title', 'body']) do
|
164
|
+
with :title, 'Test Post'
|
165
|
+
end.results.first.attribute_names.sort.should == ['body', 'id', 'title']
|
162
166
|
end
|
163
167
|
|
164
168
|
it 'should gracefully handle nonexistent records' do
|
@@ -286,15 +290,20 @@ describe 'ActiveRecord mixin' do
|
|
286
290
|
@posts = Array.new(2) { Post.create }
|
287
291
|
end
|
288
292
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
Post.reindex(:batch_size => nil)
|
294
|
-
end
|
293
|
+
it "should use batches if the batch_size is specified" do
|
294
|
+
relation(Post).class.any_instance.should_receive(:find_in_batches)
|
295
|
+
Post.reindex(:batch_size => 50)
|
296
|
+
end
|
295
297
|
|
298
|
+
it "should select all if the batch_size isn't greater than 0" do
|
299
|
+
relation(Post).class.any_instance.should_not_receive(:find_in_batches)
|
300
|
+
Post.reindex(:batch_size => nil)
|
301
|
+
Post.reindex(:batch_size => 0)
|
302
|
+
end
|
303
|
+
|
304
|
+
describe "when not using batches" do
|
296
305
|
it "should search for models with includes" do
|
297
|
-
Post.should_receive(:
|
306
|
+
Post.should_receive(:includes).with(:author).and_return(relation(Post))
|
298
307
|
Post.reindex(:batch_size => nil, :include => :author)
|
299
308
|
end
|
300
309
|
|
@@ -5,7 +5,9 @@ class PostWithDefaultScope < ActiveRecord::Base
|
|
5
5
|
|
6
6
|
attr_accessible :title, :type, :location_id, :body, :blog
|
7
7
|
|
8
|
-
|
8
|
+
def self.default_scope
|
9
|
+
order(:title)
|
10
|
+
end
|
9
11
|
|
10
12
|
searchable :auto_index => false, :auto_remove => false do
|
11
13
|
string :title
|
@@ -0,0 +1,13 @@
|
|
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
|
+
class RakeTaskAutoLoadTestModel < ActiveRecord::Base
|
6
|
+
def self.table_name
|
7
|
+
'posts'
|
8
|
+
end
|
9
|
+
|
10
|
+
searchable do
|
11
|
+
string :name
|
12
|
+
end
|
13
|
+
end
|
@@ -1,9 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
end
|
5
|
-
elsif Rails::VERSION::MAJOR == 3
|
6
|
-
Rails.application.routes.draw do
|
7
|
-
resources :posts, :only => :create
|
8
|
-
end
|
9
|
-
end
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
resources :posts, :only => :create
|
3
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
describe 'sunspot namespace rake task' do
|
5
|
+
before :all do
|
6
|
+
require "#{Rails.root}/../../lib/sunspot/rails/tasks"
|
7
|
+
Rake::Task.define_task(:environment)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'sunspot:reindex' do
|
11
|
+
it "should reindex all models if none are specified" do
|
12
|
+
run_rake_task("sunspot:reindex", '', '', true)
|
13
|
+
|
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')
|
16
|
+
end
|
17
|
+
|
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)
|
22
|
+
|
23
|
+
run_rake_task("sunspot:reindex", '', "Post Author", true)
|
24
|
+
end
|
25
|
+
|
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)
|
30
|
+
|
31
|
+
run_rake_task("sunspot:reindex", '', "Post+Author", true)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def run_rake_task(task_name, *task_args)
|
37
|
+
task = Rake::Task[task_name.to_s]
|
38
|
+
task.reenable
|
39
|
+
task.invoke(*task_args) # Invoke but skip the reindex warning
|
40
|
+
end
|
data/spec/searchable_spec.rb
CHANGED
@@ -3,6 +3,9 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
|
|
3
3
|
describe Sunspot::Rails::Searchable do
|
4
4
|
describe '#searchable' do
|
5
5
|
it "should register models with Sunspot.searchable (via Sunspot.setup)" do
|
6
|
+
# Rspec runs tests in random order, causing this test to fail on occasion unless we ensure the models have loaded.
|
7
|
+
Author; Blog; Post;
|
8
|
+
|
6
9
|
Sunspot.searchable.should_not be_empty
|
7
10
|
Sunspot.searchable.should include(Author)
|
8
11
|
Sunspot.searchable.should include(Blog)
|
data/spec/session_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,48 +1,75 @@
|
|
1
|
-
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
2
3
|
if rsolr_version = ENV['RSOLR_GEM_VERSION']
|
3
4
|
STDERR.puts("Forcing RSolr version #{rsolr_version}")
|
4
5
|
gem "rsolr", rsolr_version
|
5
6
|
end
|
6
7
|
|
7
|
-
|
8
|
+
# Require the Database-specific gems
|
9
|
+
ENV['DB'] ||= 'sqlite'
|
10
|
+
Bundler.require(ENV['DB'])
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
rescue LoadError => e
|
13
|
-
require 'spec'
|
14
|
-
require 'spec/rails'
|
15
|
-
end
|
16
|
-
require 'rake'
|
12
|
+
require File.expand_path('config/environment', ENV['RAILS_ROOT'])
|
13
|
+
require 'rspec/rails'
|
14
|
+
require 'rspec/autorun'
|
17
15
|
require File.join('sunspot', 'rails', 'solr_logging')
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
stderr = $stderr
|
28
|
-
$stderr = StringIO.new
|
29
|
-
yield
|
30
|
-
$stderr = stderr
|
31
|
-
end
|
32
|
-
|
33
|
-
rspec =
|
34
|
-
begin
|
35
|
-
RSpec
|
36
|
-
rescue NameError, ArgumentError
|
37
|
-
Spec::Runner
|
38
|
-
end
|
17
|
+
# Requires supporting ruby files with custom matchers and macros, etc, in
|
18
|
+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
19
|
+
# run as spec files by default. This means that files in spec/support that end
|
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 }
|
39
25
|
|
40
26
|
# Load all shared examples
|
41
27
|
Dir[File.expand_path("shared_examples/*.rb", File.dirname(__FILE__))].each {|f| require f}
|
42
28
|
|
43
|
-
|
29
|
+
# Load the schema
|
30
|
+
load File.join(ENV['RAILS_ROOT'], 'db', 'schema.rb')
|
31
|
+
|
32
|
+
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
|
+
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
|
+
config.infer_base_class_for_anonymous_controllers = false
|
53
|
+
|
54
|
+
# Run specs in random order to surface order dependencies. If you find an
|
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"
|
59
|
+
|
44
60
|
config.before(:each) do
|
45
|
-
|
61
|
+
empty_tables
|
46
62
|
Sunspot.remove_all!
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def empty_tables
|
67
|
+
ActiveRecord::Base.connection.tables.each do |table_name|
|
68
|
+
ActiveRecord::Base.connection.execute("DELETE FROM #{table_name}") unless table_name == 'schema_migrations'
|
47
69
|
end
|
48
70
|
end
|
71
|
+
|
72
|
+
# COMPATIBILITY: Rails 4 has deprecated the 'scoped' method in favour of 'all'
|
73
|
+
def relation(clazz)
|
74
|
+
::Rails.version >= '4' ? clazz.all : clazz.scoped
|
75
|
+
end
|