Commit 2bf04852c78739c4321eca7cbd06dd8241857a08
Committed by
Rodrigo Souto
1 parent
906d142c
Exists in
master
and in
29 other branches
Put solr start/stop code before core's test_helper
Showing
18 changed files
with
107 additions
and
115 deletions
Show diff stats
plugins/solr/test/functional/search_controller_test.rb
1 | -require 'test_helper' | |
2 | -require File.dirname(__FILE__) + '/../test_solr_helper' | |
1 | +require "#{File.dirname(__FILE__)}/../test_helper" | |
3 | 2 | require File.dirname(__FILE__) + '/../../lib/ext/facets_browse' |
4 | 3 | |
5 | 4 | # Re-raise errors caught by the controller. |
... | ... | @@ -228,9 +227,9 @@ class SearchControllerTest < ActionController::TestCase |
228 | 227 | prod2.update_attribute :updated_at, Time.now |
229 | 228 | Product.record_timestamps = true |
230 | 229 | |
231 | - get :products, :query => 'product', :order_by => :more_recent | |
230 | + get :products, :query => 'product', :order_by => :more_recent | |
232 | 231 | |
233 | - assert_equal [prod2, prod1, prod3], assigns(:searches)[:products][:results].docs | |
232 | + assert_equal [prod2, prod1, prod3], assigns(:searches)[:products][:results].docs | |
234 | 233 | end |
235 | 234 | |
236 | 235 | should 'only list products from enabled enterprises' do |
... | ... | @@ -257,7 +256,7 @@ class SearchControllerTest < ActionController::TestCase |
257 | 256 | |
258 | 257 | get :products, :query => 'product', :order_by => :name |
259 | 258 | |
260 | - assert_equal [prod3, prod2, prod1], assigns(:searches)[:products][:results].docs | |
259 | + assert_equal [prod3, prod2, prod1], assigns(:searches)[:products][:results].docs | |
261 | 260 | end |
262 | 261 | |
263 | 262 | should 'order product results by closest when requested' do |
... | ... | @@ -267,7 +266,7 @@ class SearchControllerTest < ActionController::TestCase |
267 | 266 | # trigger geosearch |
268 | 267 | SearchController.any_instance.stubs(:logged_in?).returns(true) |
269 | 268 | SearchController.any_instance.stubs(:current_user).returns(user) |
270 | - | |
269 | + | |
271 | 270 | cat = fast_create(ProductCategory) |
272 | 271 | ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '-5.0', :lng => '-5.0') |
273 | 272 | prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent1.id, :product_category_id => cat.id) |
... | ... | @@ -280,7 +279,7 @@ class SearchControllerTest < ActionController::TestCase |
280 | 279 | assert_equal [prod2, prod1, prod3], assigns(:searches)[:products][:results].docs |
281 | 280 | end |
282 | 281 | |
283 | - | |
282 | + | |
284 | 283 | should 'order events by name when requested' do |
285 | 284 | person = create_user('someone').person |
286 | 285 | ev1 = create_event(person, :name => 'party B', :category_ids => [@category.id], :start_date => Date.today - 1.day) |
... | ... | @@ -295,7 +294,7 @@ class SearchControllerTest < ActionController::TestCase |
295 | 294 | art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id) |
296 | 295 | art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id) |
297 | 296 | art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id) |
298 | - | |
297 | + | |
299 | 298 | get :articles, :query => 'review', :order_by => :name |
300 | 299 | |
301 | 300 | assert_equal [art2, art3, art1], assigns(:searches)[:articles][:results].docs |
... | ... | @@ -305,7 +304,7 @@ class SearchControllerTest < ActionController::TestCase |
305 | 304 | ent1 = Enterprise.create!(:name => 'Company B', :identifier => 'com_b') |
306 | 305 | ent2 = Enterprise.create!(:name => 'Company A', :identifier => 'com_a') |
307 | 306 | ent3 = Enterprise.create!(:name => 'Company C', :identifier => 'com_c') |
308 | - | |
307 | + | |
309 | 308 | get :enterprises, :query => 'Company', :order_by => :name |
310 | 309 | |
311 | 310 | assert_equal [ent2, ent1, ent3], assigns(:searches)[:enterprises][:results].docs |
... | ... | @@ -317,8 +316,8 @@ class SearchControllerTest < ActionController::TestCase |
317 | 316 | person3 = Person.create!(:name => 'Ausêncio Silva', :identifier => 'ause', :user_id => fast_create(User).id) |
318 | 317 | |
319 | 318 | get :people, :query => 'Silva', :order_by => :name |
320 | - | |
321 | - assert_equal [person3, person1, person2], assigns(:searches)[:people][:results].docs | |
319 | + | |
320 | + assert_equal [person3, person1, person2], assigns(:searches)[:people][:results].docs | |
322 | 321 | end |
323 | 322 | |
324 | 323 | should 'order community results by name when requested' do | ... | ... |
... | ... | @@ -0,0 +1,69 @@ |
1 | +# Solr start/stop | |
2 | +if not $test_helper_loaded | |
3 | + ENV["RAILS_ENV"] = "test" | |
4 | + abort unless system 'rake -s solr:start' | |
5 | + at_exit { system 'rake -s solr:stop' } | |
6 | + $test_helper_loaded = true | |
7 | +end | |
8 | + | |
9 | +require 'test_helper' | |
10 | + | |
11 | +class ActsAsSolr::Post | |
12 | + class << self | |
13 | + alias_method :execute_orig, :execute | |
14 | + end | |
15 | +end | |
16 | +module ActsAsSolr::ParserMethods | |
17 | + alias_method :parse_results_orig, :parse_results | |
18 | +end | |
19 | + | |
20 | +class TestSolr | |
21 | + | |
22 | + def self.enable | |
23 | + ActsAsSolr::Post.class_eval do | |
24 | + def self.execute(*args) | |
25 | + execute_orig *args | |
26 | + end | |
27 | + end | |
28 | + ActsAsSolr::ParserMethods.module_eval do | |
29 | + def parse_results(*args) | |
30 | + parse_results_orig *args | |
31 | + end | |
32 | + end | |
33 | + | |
34 | + # clear index | |
35 | + ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => '*:*')) | |
36 | + | |
37 | + @solr_disabled = false | |
38 | + end | |
39 | + | |
40 | + def self.disable | |
41 | + return if @solr_disabled | |
42 | + | |
43 | + ActsAsSolr::Post.class_eval do | |
44 | + def self.execute(*args) | |
45 | + true | |
46 | + end | |
47 | + end | |
48 | + ActsAsSolr::ParserMethods.module_eval do | |
49 | + def parse_results(*args) | |
50 | + parse_results_orig nil, args[1] | |
51 | + end | |
52 | + end | |
53 | + | |
54 | + @solr_disabled = true | |
55 | + end | |
56 | + | |
57 | +end | |
58 | + | |
59 | +class ActiveSupport::TestCase | |
60 | + def fast_create_with_solr(name, attrs = {}, options = {}) | |
61 | + obj = fast_create_without_solr(name, attrs, options) | |
62 | + obj.solr_save if options[:search] | |
63 | + obj | |
64 | + end | |
65 | + alias_method_chain :fast_create, :solr | |
66 | +end | |
67 | + | |
68 | +# disable solr actions by default | |
69 | +TestSolr.disable | ... | ... |
plugins/solr/test/test_solr_helper.rb
... | ... | @@ -1,67 +0,0 @@ |
1 | -# Start/stop Solr | |
2 | -# FIXME Not working properly... | |
3 | -if not $test_helper_loaded | |
4 | - abort unless system 'rake -s solr:start' | |
5 | -# at_exit { system 'rake -s solr:stop' } | |
6 | - $test_helper_loaded = true | |
7 | -end | |
8 | - | |
9 | -class ActsAsSolr::Post | |
10 | - class << self | |
11 | - alias_method :execute_orig, :execute | |
12 | - end | |
13 | -end | |
14 | -module ActsAsSolr::ParserMethods | |
15 | - alias_method :parse_results_orig, :parse_results | |
16 | -end | |
17 | - | |
18 | -class TestSolr | |
19 | - | |
20 | - def self.enable | |
21 | - ActsAsSolr::Post.class_eval do | |
22 | - def self.execute(*args) | |
23 | - execute_orig *args | |
24 | - end | |
25 | - end | |
26 | - ActsAsSolr::ParserMethods.module_eval do | |
27 | - def parse_results(*args) | |
28 | - parse_results_orig *args | |
29 | - end | |
30 | - end | |
31 | - | |
32 | - # clear index | |
33 | - ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => '*:*')) | |
34 | - | |
35 | - @solr_disabled = false | |
36 | - end | |
37 | - | |
38 | - def self.disable | |
39 | - return if @solr_disabled | |
40 | - | |
41 | - ActsAsSolr::Post.class_eval do | |
42 | - def self.execute(*args) | |
43 | - true | |
44 | - end | |
45 | - end | |
46 | - ActsAsSolr::ParserMethods.module_eval do | |
47 | - def parse_results(*args) | |
48 | - parse_results_orig nil, args[1] | |
49 | - end | |
50 | - end | |
51 | - | |
52 | - @solr_disabled = true | |
53 | - end | |
54 | - | |
55 | -end | |
56 | - | |
57 | -class ActiveSupport::TestCase | |
58 | - def fast_create_with_solr(name, attrs = {}, options = {}) | |
59 | - obj = fast_create_without_solr(name, attrs, options) | |
60 | - obj.solr_save if options[:search] | |
61 | - obj | |
62 | - end | |
63 | - alias_method_chain :fast_create, :solr | |
64 | -end | |
65 | - | |
66 | -# disable solr actions by default | |
67 | -TestSolr.disable |
plugins/solr/test/unit/article_test.rb
plugins/solr/test/unit/category_test.rb
plugins/solr/test/unit/certifier_test.rb
plugins/solr/test/unit/comment_test.rb
plugins/solr/test/unit/enterprise_test.rb
plugins/solr/test/unit/environment_test.rb
plugins/solr/test/unit/event_test.rb
plugins/solr/test/unit/product_category_test.rb
plugins/solr/test/unit/product_test.rb
plugins/solr/test/unit/profile_test.rb
1 | -require 'test_helper' | |
2 | -require File.dirname(__FILE__) + '/../test_solr_helper' | |
1 | +require "#{File.dirname(__FILE__)}/../test_helper" | |
3 | 2 | |
4 | 3 | class ProfileTest < ActiveSupport::TestCase |
5 | 4 | def setup |
... | ... | @@ -113,7 +112,7 @@ class ProfileTest < ActiveSupport::TestCase |
113 | 112 | TestSolr.enable |
114 | 113 | e = fast_create(Enterprise, {:lat => 45, :lng => 45}, :search => true) |
115 | 114 | |
116 | - assert_includes Enterprise.find_by_contents('', {}, {:radius => 2, :latitude => 45, :longitude => 45})[:results].docs, e | |
115 | + assert_includes Enterprise.find_by_contents('', {}, {:radius => 2, :latitude => 45, :longitude => 45})[:results].docs, e | |
117 | 116 | end |
118 | 117 | |
119 | 118 | should 'index profile identifier for searching' do | ... | ... |
plugins/solr/test/unit/qualifier_test.rb
plugins/solr/test/unit/search_helper_test.rb
1 | -require 'test_helper' | |
1 | +require "#{File.dirname(__FILE__)}/../test_helper" | |
2 | 2 | |
3 | 3 | class SearchHelperTest < ActiveSupport::TestCase |
4 | 4 | |
... | ... | @@ -21,7 +21,7 @@ class SearchHelperTest < ActiveSupport::TestCase |
21 | 21 | expects(:javascript_tag).with(regexp_matches(/id.*[\'array_item\'].*json_message/m)).returns( |
22 | 22 | '<javascript_tag_return>') |
23 | 23 | stubs(:jquery_token_input_messages_json).returns('json_message') |
24 | - assert_equal '<text_field_tag_return><javascript_tag_return>', | |
24 | + assert_equal '<text_field_tag_return><javascript_tag_return>', | |
25 | 25 | facet_javascript('id', '', ['array_item']) |
26 | 26 | end |
27 | 27 | |
... | ... | @@ -30,13 +30,13 @@ class SearchHelperTest < ActiveSupport::TestCase |
30 | 30 | expects(:javascript_tag).with(regexp_matches(/id.*\[\].*json_message/m)).returns( |
31 | 31 | '<javascript_tag_return>') |
32 | 32 | stubs(:jquery_token_input_messages_json).returns('json_message') |
33 | - assert_equal '<text_field_tag_return><javascript_tag_return>', | |
33 | + assert_equal '<text_field_tag_return><javascript_tag_return>', | |
34 | 34 | facet_javascript('id', '', []) |
35 | 35 | end |
36 | 36 | |
37 | 37 | should 'return html code for facet link' do |
38 | 38 | facet = { |
39 | - :solr_field => 'facet_solr_field', | |
39 | + :solr_field => 'facet_solr_field', | |
40 | 40 | :label_id => 'facet_label_id' |
41 | 41 | } |
42 | 42 | params = {} |
... | ... | @@ -51,13 +51,13 @@ class SearchHelperTest < ActiveSupport::TestCase |
51 | 51 | stubs(:content_tag).with(anything, ' (1)', anything).returns('<content_tag_count>') |
52 | 52 | stubs(:content_tag).with(anything, '<link_to_result><content_tag_extra><content_tag_count>', anything).returns('<content_tag_final_result>') |
53 | 53 | |
54 | - assert_equal '<content_tag_final_result>', | |
54 | + assert_equal '<content_tag_final_result>', | |
55 | 55 | facet_link_html(facet, params, value, label, count) |
56 | 56 | end |
57 | 57 | |
58 | 58 | should 'return html code for facet link with extra label' do |
59 | 59 | facet = { |
60 | - :solr_field => 'facet_solr_field', | |
60 | + :solr_field => 'facet_solr_field', | |
61 | 61 | :label_id => 'facet_label_id' |
62 | 62 | } |
63 | 63 | params = {} |
... | ... | @@ -72,13 +72,13 @@ class SearchHelperTest < ActiveSupport::TestCase |
72 | 72 | stubs(:content_tag).with(anything, ' (1)', anything).returns('<content_tag_count>') |
73 | 73 | stubs(:content_tag).with(anything, '<link_to_result><content_tag_extra><content_tag_count>', anything).returns('<content_tag_final_result>') |
74 | 74 | |
75 | - assert_equal '<content_tag_final_result>', | |
75 | + assert_equal '<content_tag_final_result>', | |
76 | 76 | facet_link_html(facet, params, value, label, count) |
77 | 77 | end |
78 | 78 | |
79 | 79 | should 'return html code for selected facet link' do |
80 | 80 | facet = { |
81 | - :solr_field => 'facet_solr_field' | |
81 | + :solr_field => 'facet_solr_field' | |
82 | 82 | } |
83 | 83 | params = {:facet => {'facet_solr_field' => 'facet_value'}} |
84 | 84 | value = 'facet_value' |
... | ... | @@ -92,7 +92,7 @@ class SearchHelperTest < ActiveSupport::TestCase |
92 | 92 | stubs(:content_tag).with(anything, ' (1)', anything).returns('<content_tag_count>') |
93 | 93 | stubs(:content_tag).with(anything, '<link_to_result><content_tag_extra><content_tag_count>', {:class => 'facet-menu-item facet-result-link-selected'}).returns('<content_tag_final_result>') |
94 | 94 | |
95 | - assert_equal '<content_tag_final_result>', | |
95 | + assert_equal '<content_tag_final_result>', | |
96 | 96 | facet_link_html(facet, params, value, label, count) |
97 | 97 | end |
98 | 98 | |
... | ... | @@ -102,7 +102,7 @@ class SearchHelperTest < ActiveSupport::TestCase |
102 | 102 | klass.stubs(:facet_label).with('klass_facet_by_id').returns('klass_facet_label') |
103 | 103 | klass.stubs(:facet_result_name).with('klass_facet_by_id', 'facet_value').returns('klass_facet_result_name') |
104 | 104 | params = {:facet => {:facet_id => 'facet_value'}} |
105 | - | |
105 | + | |
106 | 106 | expects(:content_tag).with(anything, 'klass_facet_label', anything).returns('<content_tag_label>') |
107 | 107 | expects(:content_tag).with(anything, 'klass_facet_result_name', anything).returns('<content_tag_name>') |
108 | 108 | expects(:link_to).with(anything, {:facet => {}}, anything).returns('<link_to_url>') |
... | ... | @@ -110,7 +110,7 @@ class SearchHelperTest < ActiveSupport::TestCase |
110 | 110 | |
111 | 111 | environment = mock |
112 | 112 | assert_match '<final_content>', facet_selecteds_html_for(environment, klass, params) |
113 | - end | |
113 | + end | |
114 | 114 | |
115 | 115 | should 'show select tag for order_by' do |
116 | 116 | [:products, :events, :articles, :enterprises, :people, :communities].each do |asset| | ... | ... |
plugins/solr/test/unit/text_article_test.rb
1 | -require 'test_helper' | |
2 | -require File.dirname(__FILE__) + '/../test_solr_helper' | |
1 | +require "#{File.dirname(__FILE__)}/../test_helper" | |
3 | 2 | |
4 | 3 | class TextArticleTest < ActiveSupport::TestCase |
5 | 4 | def setup |
... | ... | @@ -8,7 +7,7 @@ class TextArticleTest < ActiveSupport::TestCase |
8 | 7 | end |
9 | 8 | |
10 | 9 | attr_accessor :environment |
11 | - | |
10 | + | |
12 | 11 | should 'found TextileArticle by TextArticle indexes' do |
13 | 12 | TestSolr.enable |
14 | 13 | person = create_user('testuser').person | ... | ... |
plugins/solr/test/unit/textile_article_test.rb
1 | -require 'test_helper' | |
1 | +require "#{File.dirname(__FILE__)}/../test_helper" | |
2 | 2 | |
3 | 3 | class TextileArticleTest < ActiveSupport::TestCase |
4 | - | |
4 | + | |
5 | 5 | should 'define type facet' do |
6 | 6 | a = TextileArticle.new |
7 | 7 | assert_equal TextArticle.type_name, TextileArticle.send(:solr_plugin_f_type_proc, a.send(:solr_plugin_f_type)) | ... | ... |