Commit 0c1d441e9a6a4034245dbe689ff3b83c2438bec3
1 parent
e705c4a8
Exists in
master
and in
29 other branches
Fixing some funcitonal tests and moving solr server start to plugin
Showing
8 changed files
with
28 additions
and
318 deletions
Show diff stats
app/controllers/admin/region_validators_controller.rb
@@ -33,7 +33,7 @@ class RegionValidatorsController < AdminController | @@ -33,7 +33,7 @@ class RegionValidatorsController < AdminController | ||
33 | def load_region_and_search | 33 | def load_region_and_search |
34 | @region = environment.regions.find(params[:id]) | 34 | @region = environment.regions.find(params[:id]) |
35 | if params[:search] | 35 | if params[:search] |
36 | - @search = find_by_contents(Organization, params[:search])[:results].reject {|item| @region.validator_ids.include?(item.id) } | 36 | + @search = find_by_contents(:organizations, Organization, params[:search])[:results].reject {|item| @region.validator_ids.include?(item.id) } |
37 | end | 37 | end |
38 | end | 38 | end |
39 | 39 |
app/controllers/my_profile/cms_controller.rb
@@ -270,7 +270,7 @@ class CmsController < MyProfileController | @@ -270,7 +270,7 @@ class CmsController < MyProfileController | ||
270 | 270 | ||
271 | def search | 271 | def search |
272 | query = params[:q] | 272 | query = params[:q] |
273 | - results = find_by_contents(profile.files.published, query)[:results] | 273 | + results = find_by_contents(:uploaded_files, profile.files.published, query)[:results] |
274 | render :text => article_list_to_json(results), :content_type => 'application/json' | 274 | render :text => article_list_to_json(results), :content_type => 'application/json' |
275 | end | 275 | end |
276 | 276 |
app/controllers/public/profile_search_controller.rb
@@ -11,7 +11,7 @@ class ProfileSearchController < PublicController | @@ -11,7 +11,7 @@ class ProfileSearchController < PublicController | ||
11 | if params[:where] == 'environment' | 11 | if params[:where] == 'environment' |
12 | redirect_to :controller => 'search', :query => @q | 12 | redirect_to :controller => 'search', :query => @q |
13 | else | 13 | else |
14 | - @results = find_by_contents(profile.articles.published, @q, {:per_page => 10, :page => params[:page]})[:results] | 14 | + @results = find_by_contents(:articles, profile.articles.published, @q, {:per_page => 10, :page => params[:page]})[:results] |
15 | end | 15 | end |
16 | end | 16 | end |
17 | end | 17 | end |
app/helpers/search_helper.rb
@@ -66,6 +66,7 @@ module SearchHelper | @@ -66,6 +66,7 @@ module SearchHelper | ||
66 | end | 66 | end |
67 | 67 | ||
68 | def display_filter(asset, display) | 68 | def display_filter(asset, display) |
69 | + asset = :articles if asset == :tag | ||
69 | if display?(asset, display) | 70 | if display?(asset, display) |
70 | display | 71 | display |
71 | else | 72 | else |
plugins/solr/test/test_solr_helper.rb
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 | + | ||
1 | class ActsAsSolr::Post | 9 | class ActsAsSolr::Post |
2 | class << self | 10 | class << self |
3 | alias_method :execute_orig, :execute | 11 | alias_method :execute_orig, :execute |
test/functional/cms_controller_test.rb
@@ -282,7 +282,6 @@ class CmsControllerTest < ActionController::TestCase | @@ -282,7 +282,6 @@ class CmsControllerTest < ActionController::TestCase | ||
282 | end | 282 | end |
283 | 283 | ||
284 | should 'display destination folder of files when uploading file' do | 284 | should 'display destination folder of files when uploading file' do |
285 | - TestSolr.enable | ||
286 | f = Folder.new(:name => 'f'); profile.articles << f; f.save! | 285 | f = Folder.new(:name => 'f'); profile.articles << f; f.save! |
287 | get :upload_files, :profile => profile.identifier, :parent_id => f.id | 286 | get :upload_files, :profile => profile.identifier, :parent_id => f.id |
288 | 287 | ||
@@ -1476,7 +1475,6 @@ class CmsControllerTest < ActionController::TestCase | @@ -1476,7 +1475,6 @@ class CmsControllerTest < ActionController::TestCase | ||
1476 | end | 1475 | end |
1477 | 1476 | ||
1478 | should 'search for content for inclusion in articles' do | 1477 | should 'search for content for inclusion in articles' do |
1479 | - TestSolr.enable | ||
1480 | file = UploadedFile.create!(:profile => @profile, :uploaded_data => fixture_file_upload('files/test.txt', 'text/plain')) | 1478 | file = UploadedFile.create!(:profile => @profile, :uploaded_data => fixture_file_upload('files/test.txt', 'text/plain')) |
1481 | get :search, :profile => @profile.identifier, :q => 'test.txt' | 1479 | get :search, :profile => @profile.identifier, :q => 'test.txt' |
1482 | assert_match /test.txt/, @response.body | 1480 | assert_match /test.txt/, @response.body |
test/functional/search_controller_test.rb
@@ -7,7 +7,6 @@ class SearchController; def rescue_action(e) raise e end; end | @@ -7,7 +7,6 @@ class SearchController; def rescue_action(e) raise e end; end | ||
7 | class SearchControllerTest < ActionController::TestCase | 7 | class SearchControllerTest < ActionController::TestCase |
8 | 8 | ||
9 | def setup | 9 | def setup |
10 | - TestSolr.enable | ||
11 | @controller = SearchController.new | 10 | @controller = SearchController.new |
12 | @request = ActionController::TestRequest.new | 11 | @request = ActionController::TestRequest.new |
13 | @request.stubs(:ssl?).returns(false) | 12 | @request.stubs(:ssl?).returns(false) |
@@ -34,8 +33,6 @@ class SearchControllerTest < ActionController::TestCase | @@ -34,8 +33,6 @@ class SearchControllerTest < ActionController::TestCase | ||
34 | user.stubs(:email).returns('some@test.com') | 33 | user.stubs(:email).returns('some@test.com') |
35 | user.stubs(:save!).returns(true) | 34 | user.stubs(:save!).returns(true) |
36 | Person.any_instance.stubs(:user).returns(user) | 35 | Person.any_instance.stubs(:user).returns(user) |
37 | - | ||
38 | - env.enable_plugin(SolrPlugin) | ||
39 | end | 36 | end |
40 | 37 | ||
41 | def create_article_with_optional_category(name, profile, category = nil) | 38 | def create_article_with_optional_category(name, profile, category = nil) |
@@ -77,23 +74,6 @@ class SearchControllerTest < ActionController::TestCase | @@ -77,23 +74,6 @@ class SearchControllerTest < ActionController::TestCase | ||
77 | assert_includes assigns(:searches)[:articles][:results], art | 74 | assert_includes assigns(:searches)[:articles][:results], art |
78 | end | 75 | end |
79 | 76 | ||
80 | -# should 'get facets with articles search results' do | ||
81 | -# cat1 = fast_create(Category, :name => 'cat1') | ||
82 | -# cat2 = fast_create(Category, :name => 'cat2') | ||
83 | -# person = fast_create(Person) | ||
84 | -# art = create_article_with_optional_category('an article to be found', person) | ||
85 | -# art.add_category cat1, false | ||
86 | -# art.add_category cat2, true | ||
87 | -# art.save! | ||
88 | -# | ||
89 | -# get 'articles', :query => 'article found' | ||
90 | -# assert !assigns(:searches)[:articles].facets.blank? | ||
91 | -# assert assigns(:searches)[:articles].facets['facet_fields']['f_type_facet'][0][0] == 'Article' | ||
92 | -# assert assigns(:searches)[:articles].facets['facet_fields']['f_profile_type_facet'][0][0] == 'Person' | ||
93 | -# assert assigns(:searches)[:articles].facets['facet_fields']['f_category_facet'][0][0] == 'cat1' | ||
94 | -# assert assigns(:searches)[:articles].facets['facet_fields']['f_category_facet'][1][0] == 'cat2' | ||
95 | -# end | ||
96 | - | ||
97 | should 'redirect contents to articles' do | 77 | should 'redirect contents to articles' do |
98 | person = fast_create(Person) | 78 | person = fast_create(Person) |
99 | art = create_article_with_optional_category('an article to be found', person) | 79 | art = create_article_with_optional_category('an article to be found', person) |
@@ -120,7 +100,6 @@ class SearchControllerTest < ActionController::TestCase | @@ -120,7 +100,6 @@ class SearchControllerTest < ActionController::TestCase | ||
120 | ent = create_profile_with_optional_category(Enterprise, 'teste') | 100 | ent = create_profile_with_optional_category(Enterprise, 'teste') |
121 | get :enterprises, :query => 'teste' | 101 | get :enterprises, :query => 'teste' |
122 | assert_includes assigns(:searches)[:enterprises][:results], ent | 102 | assert_includes assigns(:searches)[:enterprises][:results], ent |
123 | -# assert !assigns(:searches)[:enterprises].facets.nil? | ||
124 | end | 103 | end |
125 | 104 | ||
126 | should 'list enterprises in general' do | 105 | should 'list enterprises in general' do |
@@ -138,25 +117,6 @@ class SearchControllerTest < ActionController::TestCase | @@ -138,25 +117,6 @@ class SearchControllerTest < ActionController::TestCase | ||
138 | assert_includes assigns(:searches)[:people][:results], p1 | 117 | assert_includes assigns(:searches)[:people][:results], p1 |
139 | end | 118 | end |
140 | 119 | ||
141 | -# should 'get facets with people search results' do | ||
142 | -# state = fast_create(State, :name => 'Acre', :acronym => 'AC') | ||
143 | -# city = fast_create(City, :name => 'Rio Branco', :parent_id => state.id) | ||
144 | -# person = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :region_id => city.id) | ||
145 | -# cat1 = fast_create(Category, :name => 'cat1') | ||
146 | -# cat2 = fast_create(Category, :name => 'cat2') | ||
147 | -# person.add_category cat1 | ||
148 | -# person.add_category cat2 | ||
149 | -# | ||
150 | -# get 'people', :query => 'Hildebrando' | ||
151 | -# | ||
152 | -# assert !assigns(:searches)[:people].facets.blank? | ||
153 | -# assert assigns(:searches)[:people].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s | ||
154 | -# | ||
155 | -# categories_facet = assigns(:searches)[:people].facets['facet_fields']['f_categories_facet'] | ||
156 | -# assert_equal 2, categories_facet.count | ||
157 | -# assert_equivalent [cat1.id.to_s, cat2.id.to_s], [categories_facet[0][0], categories_facet[1][0]] | ||
158 | -# end | ||
159 | - | ||
160 | # 'assets' menu outside any category | 120 | # 'assets' menu outside any category |
161 | should 'list people in general' do | 121 | should 'list people in general' do |
162 | Profile.delete_all | 122 | Profile.delete_all |
@@ -173,7 +133,6 @@ class SearchControllerTest < ActionController::TestCase | @@ -173,7 +133,6 @@ class SearchControllerTest < ActionController::TestCase | ||
173 | c1 = create_profile_with_optional_category(Community, 'a beautiful community') | 133 | c1 = create_profile_with_optional_category(Community, 'a beautiful community') |
174 | get :communities, :query => 'beautiful' | 134 | get :communities, :query => 'beautiful' |
175 | assert_includes assigns(:searches)[:communities][:results], c1 | 135 | assert_includes assigns(:searches)[:communities][:results], c1 |
176 | -# assert !assigns(:searches)[:communities].facets.nil? | ||
177 | end | 136 | end |
178 | 137 | ||
179 | # 'assets' menu outside any category | 138 | # 'assets' menu outside any category |
@@ -192,40 +151,6 @@ class SearchControllerTest < ActionController::TestCase | @@ -192,40 +151,6 @@ class SearchControllerTest < ActionController::TestCase | ||
192 | assert_includes assigns(:searches)[:products][:results], prod | 151 | assert_includes assigns(:searches)[:products][:results], prod |
193 | end | 152 | end |
194 | 153 | ||
195 | -# should 'get facets with products search results' do | ||
196 | -# state = fast_create(State, :name => 'Acre', :acronym => 'AC') | ||
197 | -# city = fast_create(City, :name => 'Rio Branco', :parent_id => state.id) | ||
198 | -# ent = fast_create(Enterprise, :region_id => city.id) | ||
199 | -# prod = Product.create!(:name => 'Sound System', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
200 | -# qualifier1 = fast_create(Qualifier) | ||
201 | -# qualifier2 = fast_create(Qualifier) | ||
202 | -# prod.qualifiers_list = [[qualifier1.id, 0], [qualifier2.id, 0]] | ||
203 | -# prod.qualifiers.reload | ||
204 | -# prod.save! | ||
205 | -# | ||
206 | -# get 'products', :query => 'Sound' | ||
207 | -# assert !assigns(:searches)[:products].facets.blank? | ||
208 | -# assert assigns(:searches)[:products].facets['facet_fields']['f_category_facet'][0][0] == @product_category.name | ||
209 | -# assert assigns(:searches)[:products].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s | ||
210 | -# assert assigns(:searches)[:products].facets['facet_fields']['f_qualifier_facet'][0][0] == "#{qualifier1.id} 0" | ||
211 | -# assert assigns(:searches)[:products].facets['facet_fields']['f_qualifier_facet'][1][0] == "#{qualifier2.id} 0" | ||
212 | -# end | ||
213 | - | ||
214 | - # 'assets' menu outside any category | ||
215 | -# should 'list products in general without geosearch' do | ||
216 | -# Profile.delete_all | ||
217 | -# SearchController.stubs(:logged_in?).returns(false) | ||
218 | -# | ||
219 | -# ent1 = create_profile_with_optional_category(Enterprise, 'teste1') | ||
220 | -# ent2 = create_profile_with_optional_category(Enterprise, 'teste2') | ||
221 | -# prod1 = ent1.products.create!(:name => 'a beautiful product', :product_category => @product_category) | ||
222 | -# prod2 = ent2.products.create!(:name => 'another beautiful product', :product_category => @product_category) | ||
223 | -# | ||
224 | -# get :products | ||
225 | -# assert_equivalent [prod2, prod1], assigns(:searches)[:products].docs | ||
226 | -# assert_match 'Highlights', @response.body | ||
227 | -# end | ||
228 | - | ||
229 | should 'include extra content supplied by plugins on product asset' do | 154 | should 'include extra content supplied by plugins on product asset' do |
230 | class Plugin1 < Noosfero::Plugin | 155 | class Plugin1 < Noosfero::Plugin |
231 | def asset_product_extras(product) | 156 | def asset_product_extras(product) |
@@ -303,21 +228,21 @@ class SearchControllerTest < ActionController::TestCase | @@ -303,21 +228,21 @@ class SearchControllerTest < ActionController::TestCase | ||
303 | assert_no_tag :tag => 'div', :attributes => { :id => 'boxes', :class => 'boxes' } | 228 | assert_no_tag :tag => 'div', :attributes => { :id => 'boxes', :class => 'boxes' } |
304 | end | 229 | end |
305 | 230 | ||
306 | -# should 'offer text box to enter a new search in general context' do | ||
307 | -# get :index, :query => 'a sample search' | ||
308 | -# assert_tag :tag => 'form', :attributes => { :action => '/search' }, :descendant => { | ||
309 | -# :tag => 'input', | ||
310 | -# :attributes => { :name => 'query', :value => 'a sample search' } | ||
311 | -# } | ||
312 | -# end | ||
313 | -# | ||
314 | -# should 'offer text box to enter a new seach in specific context' do | ||
315 | -# get :index, :category_path => [ 'my-category'], :query => 'a sample search' | ||
316 | -# assert_tag :tag => 'form', :attributes => { :action => '/search/index/my-category' }, :descendant => { | ||
317 | -# :tag => 'input', | ||
318 | -# :attributes => { :name => 'query', :value => 'a sample search' } | ||
319 | -# } | ||
320 | -# end | 231 | + should 'offer text box to enter a new search in general context' do |
232 | + get :index, :query => 'a sample search' | ||
233 | + assert_tag :tag => 'form', :attributes => { :action => '/search' }, :descendant => { | ||
234 | + :tag => 'input', | ||
235 | + :attributes => { :name => 'query', :value => 'a sample search' } | ||
236 | + } | ||
237 | + end | ||
238 | + | ||
239 | + should 'offer text box to enter a new seach in specific context' do | ||
240 | + get :index, :category_path => [ 'my-category'], :query => 'a sample search' | ||
241 | + assert_tag :tag => 'form', :attributes => { :action => '/search/index/my-category' }, :descendant => { | ||
242 | + :tag => 'input', | ||
243 | + :attributes => { :name => 'query', :value => 'a sample search' } | ||
244 | + } | ||
245 | + end | ||
321 | 246 | ||
322 | should 'search in category hierachy' do | 247 | should 'search in category hierachy' do |
323 | parent = Category.create!(:name => 'Parent Category', :environment => Environment.default) | 248 | parent = Category.create!(:name => 'Parent Category', :environment => Environment.default) |
@@ -330,33 +255,6 @@ class SearchControllerTest < ActionController::TestCase | @@ -330,33 +255,6 @@ class SearchControllerTest < ActionController::TestCase | ||
330 | assert_includes assigns(:searches)[:people][:results], p | 255 | assert_includes assigns(:searches)[:people][:results], p |
331 | end | 256 | end |
332 | 257 | ||
333 | -# should 'find enterprise by product category' do | ||
334 | -# ent1 = create_profile_with_optional_category(Enterprise, 'test1') | ||
335 | -# prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) | ||
336 | -# prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat) | ||
337 | -# | ||
338 | -# ent2 = create_profile_with_optional_category(Enterprise, 'test2') | ||
339 | -# | ||
340 | -# get :index, :query => prod_cat.name | ||
341 | -# | ||
342 | -# assert_includes assigns(:searches)[:enterprises][:results], ent1 | ||
343 | -# assert_not_includes assigns(:searches)[:enterprises][:results], ent2 | ||
344 | -# end | ||
345 | - | ||
346 | -# should 'show only results in general search' do | ||
347 | -# ent1 = create_profile_with_optional_category(Enterprise, 'test1') | ||
348 | -# prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) | ||
349 | -# prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat) | ||
350 | -# | ||
351 | -# ent2 = create_profile_with_optional_category(Enterprise, 'test2') | ||
352 | -# | ||
353 | -# get :index, :query => prod_cat.name | ||
354 | -# | ||
355 | -# assert assigns(:facets).blank? | ||
356 | -# assert_nil assigns(:searches)[:enterprises].facets | ||
357 | -# assert_nil assigns(:searches)[:products].facets | ||
358 | -# end | ||
359 | - | ||
360 | should 'render specific action when only one asset is enabled' do | 258 | should 'render specific action when only one asset is enabled' do |
361 | environment = Environment.default | 259 | environment = Environment.default |
362 | # article is not disabled | 260 | # article is not disabled |
@@ -412,7 +310,6 @@ class SearchControllerTest < ActionController::TestCase | @@ -412,7 +310,6 @@ class SearchControllerTest < ActionController::TestCase | ||
412 | get :events, :query => 'event to be found' | 310 | get :events, :query => 'event to be found' |
413 | 311 | ||
414 | assert_includes assigns(:searches)[:events][:results], event | 312 | assert_includes assigns(:searches)[:events][:results], event |
415 | -# assert !assigns(:searches)[:events].facets.nil? | ||
416 | end | 313 | end |
417 | 314 | ||
418 | should 'return events of the day' do | 315 | should 'return events of the day' do |
@@ -491,47 +388,6 @@ class SearchControllerTest < ActionController::TestCase | @@ -491,47 +388,6 @@ class SearchControllerTest < ActionController::TestCase | ||
491 | assert_includes assigns(:searches)[:products][:results], p | 388 | assert_includes assigns(:searches)[:products][:results], p |
492 | end | 389 | end |
493 | 390 | ||
494 | - # Testing random sequences always have a small chance of failing | ||
495 | -# should 'randomize product display in empty search' do | ||
496 | -# prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default) | ||
497 | -# ent = create_profile_with_optional_category(Enterprise, 'test enterprise') | ||
498 | -# (1..SearchController::LIST_SEARCH_LIMIT+5).each do |n| | ||
499 | -# fast_create(Product, {:name => "produto #{n}", :enterprise_id => ent.id, :product_category_id => prod_cat.id}, :search => true) | ||
500 | -# end | ||
501 | -# | ||
502 | -# get :products | ||
503 | -# result1 = assigns(:searches)[:products][:results].map(&:id) | ||
504 | -# | ||
505 | -# (1..10).each do |n| | ||
506 | -# get :products | ||
507 | -# end | ||
508 | -# result2 = assigns(:searches)[:products][:results].map(&:id) | ||
509 | -# | ||
510 | -# assert_not_equal result1, result2 | ||
511 | -# end | ||
512 | - | ||
513 | -# should 'remove far products by geolocalization empty logged search' do | ||
514 | -# user = create_user('a_logged_user') | ||
515 | -# # trigger geosearch | ||
516 | -# user.person.lat = '1.0' | ||
517 | -# user.person.lng = '1.0' | ||
518 | -# SearchController.any_instance.stubs(:logged_in?).returns(true) | ||
519 | -# SearchController.any_instance.stubs(:current_user).returns(user) | ||
520 | -# | ||
521 | -# cat = fast_create(ProductCategory) | ||
522 | -# ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '1.3', :lng => '1.3') | ||
523 | -# prod1 = Product.create!(:name => 'produto 1', :enterprise_id => ent1.id, :product_category_id => cat.id) | ||
524 | -# ent2 = Enterprise.create!(:name => 'ent2', :identifier => 'ent2', :lat => '2.0', :lng => '2.0') | ||
525 | -# prod2 = Product.create!(:name => 'produto 2', :enterprise_id => ent2.id, :product_category_id => cat.id) | ||
526 | -# ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '1.6', :lng => '1.6') | ||
527 | -# prod3 = Product.create!(:name => 'produto 3', :enterprise_id => ent3.id, :product_category_id => cat.id) | ||
528 | -# ent4 = Enterprise.create!(:name => 'ent4', :identifier => 'ent4', :lat => '10', :lng => '10') | ||
529 | -# prod4 = Product.create!(:name => 'produto 4', :enterprise_id => ent4.id, :product_category_id => cat.id) | ||
530 | -# | ||
531 | -# get :products | ||
532 | -# assert_equivalent [prod1, prod3, prod2], assigns(:searches)[:products].docs | ||
533 | -# end | ||
534 | - | ||
535 | should 'display properly in conjuntion with a category' do | 391 | should 'display properly in conjuntion with a category' do |
536 | cat = Category.create(:name => 'cat', :environment => Environment.default) | 392 | cat = Category.create(:name => 'cat', :environment => Environment.default) |
537 | prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default) | 393 | prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default) |
@@ -714,25 +570,6 @@ class SearchControllerTest < ActionController::TestCase | @@ -714,25 +570,6 @@ class SearchControllerTest < ActionController::TestCase | ||
714 | assert_not_includes assigns(:searches)[:communities][:results], p1 | 570 | assert_not_includes assigns(:searches)[:communities][:results], p1 |
715 | end | 571 | end |
716 | 572 | ||
717 | -# should 'browse facets when query is not empty' do | ||
718 | -# get :articles, :query => 'something' | ||
719 | -# get :facets_browse, :asset => 'articles', :facet_id => 'f_type' | ||
720 | -# assert_equal assigns(:facet)[:id], 'f_type' | ||
721 | -# get :products, :query => 'something' | ||
722 | -# get :facets_browse, :asset => 'products', :facet_id => 'f_category' | ||
723 | -# assert_equal assigns(:facet)[:id], 'f_category' | ||
724 | -# get :people, :query => 'something' | ||
725 | -# get :facets_browse, :asset => 'people', :facet_id => 'f_region' | ||
726 | -# assert_equal assigns(:facet)[:id], 'f_region' | ||
727 | -# end | ||
728 | -# | ||
729 | -# should 'raise exception when facet is invalid' do | ||
730 | -# get :articles, :query => 'something' | ||
731 | -# assert_raise RuntimeError do | ||
732 | -# get :facets_browse, :asset => 'articles', :facet_id => 'f_whatever' | ||
733 | -# end | ||
734 | -# end | ||
735 | - | ||
736 | should 'keep old urls working' do | 573 | should 'keep old urls working' do |
737 | get :assets, :asset => 'articles' | 574 | get :assets, :asset => 'articles' |
738 | assert_redirected_to :controller => :search, :action => :articles | 575 | assert_redirected_to :controller => :search, :action => :articles |
@@ -790,92 +627,6 @@ class SearchControllerTest < ActionController::TestCase | @@ -790,92 +627,6 @@ class SearchControllerTest < ActionController::TestCase | ||
790 | assert_equal [art2], assigns(:searches)[:articles][:results] | 627 | assert_equal [art2], assigns(:searches)[:articles][:results] |
791 | end | 628 | end |
792 | 629 | ||
793 | -# should 'order product results by more recent when requested' do | ||
794 | -# ent = fast_create(Enterprise) | ||
795 | -# prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
796 | -# prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
797 | -# prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
798 | -# | ||
799 | -# # change others attrs will make updated_at = Time.now for all | ||
800 | -# Product.record_timestamps = false | ||
801 | -# prod3.update_attribute :updated_at, Time.now-2.days | ||
802 | -# prod1.update_attribute :updated_at, Time.now-1.days | ||
803 | -# prod2.update_attribute :updated_at, Time.now | ||
804 | -# Product.record_timestamps = true | ||
805 | -# | ||
806 | -# get :products, :query => 'product', :order_by => :more_recent | ||
807 | -# | ||
808 | -# assert_equal [prod2, prod1, prod3], assigns(:searches)[:products].docs | ||
809 | -# end | ||
810 | -# | ||
811 | -# should 'only list products from enabled enterprises' do | ||
812 | -# ent1 = fast_create(Enterprise, :enabled => true) | ||
813 | -# ent2 = fast_create(Enterprise, :enabled => false) | ||
814 | -# prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent1.id, :product_category_id => @product_category.id) | ||
815 | -# prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent2.id, :product_category_id => @product_category.id) | ||
816 | -# | ||
817 | -# get :products, :query => 'product' | ||
818 | -# | ||
819 | -# assert_includes assigns(:searches)[:products][:results], prod1 | ||
820 | -# assert_not_includes assigns(:searches)[:products][:results], prod2 | ||
821 | -# end | ||
822 | -# | ||
823 | -# should 'order product results by name when requested' do | ||
824 | -# ent = fast_create(Enterprise) | ||
825 | -# prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
826 | -# prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
827 | -# prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
828 | -# | ||
829 | -# prod3.update_attribute :name, 'product A' | ||
830 | -# prod2.update_attribute :name, 'product B' | ||
831 | -# prod1.update_attribute :name, 'product C' | ||
832 | -# | ||
833 | -# get :products, :query => 'product', :order_by => :name | ||
834 | -# | ||
835 | -# assert_equal [prod3, prod2, prod1], assigns(:searches)[:products].docs | ||
836 | -# end | ||
837 | -# | ||
838 | -# should 'order product results by closest when requested' do | ||
839 | -# user = create_user('a_logged_user') | ||
840 | -# user.person.lat = '1.0' | ||
841 | -# user.person.lng = '1.0' | ||
842 | -# # trigger geosearch | ||
843 | -# SearchController.any_instance.stubs(:logged_in?).returns(true) | ||
844 | -# SearchController.any_instance.stubs(:current_user).returns(user) | ||
845 | -# | ||
846 | -# cat = fast_create(ProductCategory) | ||
847 | -# ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '-5.0', :lng => '-5.0') | ||
848 | -# prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent1.id, :product_category_id => cat.id) | ||
849 | -# ent2 = Enterprise.create!(:name => 'ent2', :identifier => 'ent2', :lat => '2.0', :lng => '2.0') | ||
850 | -# prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent2.id, :product_category_id => cat.id) | ||
851 | -# ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '10.0', :lng => '10.0') | ||
852 | -# prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent3.id, :product_category_id => cat.id) | ||
853 | -# | ||
854 | -# get :products, :query => 'product', :order_by => :closest | ||
855 | -# assert_equal [prod2, prod1, prod3], assigns(:searches)[:products].docs | ||
856 | -# end | ||
857 | -# | ||
858 | -# | ||
859 | -# should 'order events by name when requested' do | ||
860 | -# person = create_user('someone').person | ||
861 | -# ev1 = create_event(person, :name => 'party B', :category_ids => [@category.id], :start_date => Date.today - 10.day) | ||
862 | -# ev2 = create_event(person, :name => 'party A', :category_ids => [@category.id], :start_date => Date.today - 2.month) | ||
863 | -# | ||
864 | -# get :events, :query => 'party', :order_by => :name | ||
865 | -# | ||
866 | -# assert_equal [ev2, ev1], assigns(:searches)[:events].docs | ||
867 | -# end | ||
868 | -# | ||
869 | -# should 'order articles by name when requested' do | ||
870 | -# art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id) | ||
871 | -# art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id) | ||
872 | -# art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id) | ||
873 | -# | ||
874 | -# get :articles, :query => 'review', :order_by => :name | ||
875 | -# | ||
876 | -# assert_equal [art2, art3, art1], assigns(:searches)[:articles].docs | ||
877 | -# end | ||
878 | - | ||
879 | should 'order articles by more recent' do | 630 | should 'order articles by more recent' do |
880 | Article.destroy_all | 631 | Article.destroy_all |
881 | art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id, :created_at => Time.now-1.days) | 632 | art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id, :created_at => Time.now-1.days) |
@@ -887,46 +638,6 @@ class SearchControllerTest < ActionController::TestCase | @@ -887,46 +638,6 @@ class SearchControllerTest < ActionController::TestCase | ||
887 | assert_equal [art2, art1, art3], assigns(:searches)[:articles][:results] | 638 | assert_equal [art2, art1, art3], assigns(:searches)[:articles][:results] |
888 | end | 639 | end |
889 | 640 | ||
890 | -# should 'order enterprise results by name when requested' do | ||
891 | -# ent1 = Enterprise.create!(:name => 'Company B', :identifier => 'com_b') | ||
892 | -# ent2 = Enterprise.create!(:name => 'Company A', :identifier => 'com_a') | ||
893 | -# ent3 = Enterprise.create!(:name => 'Company C', :identifier => 'com_c') | ||
894 | -# | ||
895 | -# get :enterprises, :query => 'Company', :order_by => :name | ||
896 | -# | ||
897 | -# assert_equal [ent2, ent1, ent3], assigns(:searches)[:enterprises].docs | ||
898 | -# end | ||
899 | -# | ||
900 | -# should 'order people results by name when requested' do | ||
901 | -# person1 = Person.create!(:name => 'Deodárbio Silva', :identifier => 'deod', :user_id => fast_create(User).id) | ||
902 | -# person2 = Person.create!(:name => 'Glislange Silva', :identifier => 'glis', :user_id => fast_create(User).id) | ||
903 | -# person3 = Person.create!(:name => 'Ausêncio Silva', :identifier => 'ause', :user_id => fast_create(User).id) | ||
904 | -# | ||
905 | -# get :people, :query => 'Silva', :order_by => :name | ||
906 | -# | ||
907 | -# assert_equal [person3, person1, person2], assigns(:searches)[:people].docs | ||
908 | -# end | ||
909 | -# | ||
910 | -# should 'order community results by name when requested' do | ||
911 | -# com1 = Community.create!(:name => 'Yellow Group') | ||
912 | -# com2 = Community.create!(:name => 'Red Group') | ||
913 | -# com3 = Community.create!(:name => 'Green Group') | ||
914 | -# | ||
915 | -# get :communities, :query => 'Group', :order_by => :name | ||
916 | -# | ||
917 | -# assert_equal [com3, com2, com1], assigns(:searches)[:communities].docs | ||
918 | -# end | ||
919 | -# | ||
920 | -# should 'raise error when requested to order by unknown filter' do | ||
921 | -# com1 = Community.create!(:name => 'Yellow Group') | ||
922 | -# com2 = Community.create!(:name => 'Red Group') | ||
923 | -# com3 = Community.create!(:name => 'Green Group') | ||
924 | -# | ||
925 | -# assert_raise RuntimeError do | ||
926 | -# get :communities, :query => 'Group', :order_by => :something | ||
927 | -# end | ||
928 | -# end | ||
929 | - | ||
930 | should 'add highlighted CSS class around a highlighted product' do | 641 | should 'add highlighted CSS class around a highlighted product' do |
931 | enterprise = fast_create(Enterprise) | 642 | enterprise = fast_create(Enterprise) |
932 | product = Product.create!(:name => 'Enter Sandman', :enterprise_id => enterprise.id, :product_category_id => @product_category.id, :highlighted => true) | 643 | product = Product.create!(:name => 'Enter Sandman', :enterprise_id => enterprise.id, :product_category_id => @product_category.id, :highlighted => true) |
@@ -941,8 +652,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -941,8 +652,7 @@ class SearchControllerTest < ActionController::TestCase | ||
941 | assert_no_tag :tag => 'li', :attributes => { :class => 'search-product-item highlighted' }, :content => /Holier Than Thou/ | 652 | assert_no_tag :tag => 'li', :attributes => { :class => 'search-product-item highlighted' }, :content => /Holier Than Thou/ |
942 | end | 653 | end |
943 | 654 | ||
944 | - ################################################################## | ||
945 | - ################################################################## | 655 | + protected |
946 | 656 | ||
947 | def create_event(profile, options) | 657 | def create_event(profile, options) |
948 | ev = Event.new({ :name => 'some event', :start_date => Date.new(2008,1,1) }.merge(options)) | 658 | ev = Event.new({ :name => 'some event', :start_date => Date.new(2008,1,1) }.merge(options)) |
test/test_helper.rb
1 | ENV["RAILS_ENV"] = "test" | 1 | ENV["RAILS_ENV"] = "test" |
2 | 2 | ||
3 | -# Start/stop Solr | ||
4 | -if not $test_helper_loaded | ||
5 | - abort unless system 'rake -s solr:start' | ||
6 | - at_exit { system 'rake -s solr:stop' } | ||
7 | - $test_helper_loaded = true | ||
8 | -end | ||
9 | - | ||
10 | require File.expand_path(File.dirname(__FILE__) + "/../config/environment") | 3 | require File.expand_path(File.dirname(__FILE__) + "/../config/environment") |
11 | require 'test_help' | 4 | require 'test_help' |
12 | require 'mocha' | 5 | require 'mocha' |