Commit 92d1163f140c7d900349b1eb17be194736420afc

Authored by Rafael Martins
1 parent f265ef22

More adaptations for the new SearchControllerTest

* Changed 'find_in' for the corresponding search action
* Updated google maps urls
Showing 1 changed file with 38 additions and 38 deletions   Show diff stats
test/functional/search_controller_test.rb
@@ -70,7 +70,7 @@ class SearchControllerTest < ActionController::TestCase @@ -70,7 +70,7 @@ class SearchControllerTest < ActionController::TestCase
70 person = fast_create(Person) 70 person = fast_create(Person)
71 art = create_article_with_optional_category('an article to be found', person) 71 art = create_article_with_optional_category('an article to be found', person)
72 72
73 - get 'index', :query => 'article found', :find_in => [ 'articles' ] 73 + get 'articles', :query => 'article found'
74 assert_includes assigns(:results)[:articles], art 74 assert_includes assigns(:results)[:articles], art
75 end 75 end
76 76
@@ -89,7 +89,7 @@ class SearchControllerTest < ActionController::TestCase @@ -89,7 +89,7 @@ class SearchControllerTest < ActionController::TestCase
89 89
90 should 'find enterprises' do 90 should 'find enterprises' do
91 ent = create_profile_with_optional_category(Enterprise, 'teste') 91 ent = create_profile_with_optional_category(Enterprise, 'teste')
92 - get 'index', :query => 'teste', :find_in => [ 'enterprises' ] 92 + get 'enterprises', :query => 'teste'
93 assert_includes assigns(:results)[:enterprises], ent 93 assert_includes assigns(:results)[:enterprises], ent
94 end 94 end
95 95
@@ -104,7 +104,7 @@ class SearchControllerTest < ActionController::TestCase @@ -104,7 +104,7 @@ class SearchControllerTest < ActionController::TestCase
104 104
105 should 'find people' do 105 should 'find people' do
106 p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.save! 106 p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.save!
107 - get :index, :query => 'beautiful', :find_in => [ 'people' ] 107 + get :people, :query => 'beautiful'
108 assert_includes assigns(:results)[:people], p1 108 assert_includes assigns(:results)[:people], p1
109 end 109 end
110 110
@@ -122,7 +122,7 @@ class SearchControllerTest < ActionController::TestCase @@ -122,7 +122,7 @@ class SearchControllerTest < ActionController::TestCase
122 122
123 should 'find communities' do 123 should 'find communities' do
124 c1 = create_profile_with_optional_category(Community, 'a beautiful community') 124 c1 = create_profile_with_optional_category(Community, 'a beautiful community')
125 - get :index, :query => 'beautiful', :find_in => [ 'communities' ] 125 + get :communities, :query => 'beautiful'
126 assert_includes assigns(:results)[:communities], c1 126 assert_includes assigns(:results)[:communities], c1
127 end 127 end
128 128
@@ -138,7 +138,7 @@ class SearchControllerTest < ActionController::TestCase @@ -138,7 +138,7 @@ class SearchControllerTest < ActionController::TestCase
138 should 'find products' do 138 should 'find products' do
139 ent = create_profile_with_optional_category(Enterprise, 'teste') 139 ent = create_profile_with_optional_category(Enterprise, 'teste')
140 prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category) 140 prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category)
141 - get 'index', :query => 'beautiful', :find_in => ['products'] 141 + get :products, :query => 'beautiful'
142 assert_includes assigns(:results)[:products], prod 142 assert_includes assigns(:results)[:products], prod
143 end 143 end
144 144
@@ -169,13 +169,13 @@ class SearchControllerTest < ActionController::TestCase @@ -169,13 +169,13 @@ class SearchControllerTest < ActionController::TestCase
169 end 169 end
170 170
171 enterprise = fast_create(Enterprise) 171 enterprise = fast_create(Enterprise)
172 - product = fast_create(Product, :enterprise_id => enterprise.id, :name => "produto1") 172 + product = fast_create(Product, {:enterprise_id => enterprise.id, :name => "produto1"}, :search => true)
173 173
174 e = Environment.default 174 e = Environment.default
175 e.enable_plugin(Plugin1.name) 175 e.enable_plugin(Plugin1.name)
176 e.enable_plugin(Plugin2.name) 176 e.enable_plugin(Plugin2.name)
177 177
178 - get :assets, {:asset => 'products', :query => 'produto1'} 178 + get :products, :query => 'produto1'
179 179
180 assert_tag :tag => 'span', :content => 'This is Plugin1 speaking!', :attributes => {:id => 'plugin1'} 180 assert_tag :tag => 'span', :content => 'This is Plugin1 speaking!', :attributes => {:id => 'plugin1'}
181 assert_tag :tag => 'span', :content => 'This is Plugin2 speaking!', :attributes => {:id => 'plugin2'} 181 assert_tag :tag => 'span', :content => 'This is Plugin2 speaking!', :attributes => {:id => 'plugin2'}
@@ -193,7 +193,7 @@ class SearchControllerTest < ActionController::TestCase @@ -193,7 +193,7 @@ class SearchControllerTest < ActionController::TestCase
193 end 193 end
194 end 194 end
195 enterprise = fast_create(Enterprise) 195 enterprise = fast_create(Enterprise)
196 - product = fast_create(Product, :enterprise_id => enterprise.id, :name => "produto1") 196 + product = fast_create(Product, {:enterprise_id => enterprise.id, :name => "produto1"}, :search => true)
197 197
198 environment = Environment.default 198 environment = Environment.default
199 environment.enable_plugin(Plugin1.name) 199 environment.enable_plugin(Plugin1.name)
@@ -201,8 +201,8 @@ class SearchControllerTest < ActionController::TestCase @@ -201,8 +201,8 @@ class SearchControllerTest < ActionController::TestCase
201 201
202 get :products, :query => "produto1" 202 get :products, :query => "produto1"
203 203
204 - assert_tag :tag => 'li', :content => /Property1/, :child => {:tag => 'a', :attributes => {:href => '/plugin1'}, :content => product.name}  
205 - assert_tag :tag => 'li', :content => /Property2/, :child => {:tag => 'a', :attributes => {:href => '/plugin2'}, :content => product.name} 204 + assert_tag :tag => 'div', :content => /Property1/, :child => {:tag => 'a', :attributes => {:href => '/plugin1'}, :content => product.name}
  205 + assert_tag :tag => 'div', :content => /Property2/, :child => {:tag => 'a', :attributes => {:href => '/plugin2'}, :content => product.name}
206 end 206 end
207 207
208 should 'paginate enterprise listing' do 208 should 'paginate enterprise listing' do
@@ -252,7 +252,7 @@ class SearchControllerTest < ActionController::TestCase @@ -252,7 +252,7 @@ class SearchControllerTest < ActionController::TestCase
252 252
253 p = create_profile_with_optional_category(Person, 'test_profile', child) 253 p = create_profile_with_optional_category(Person, 'test_profile', child)
254 254
255 - get :category_index, :category_path => ['parent-category'], :query => 'test_profile', :find_in => ['people'] 255 + get :category_index, :category_path => ['parent-category'], :query => 'test_profile'
256 256
257 assert_includes assigns(:results)[:people], p 257 assert_includes assigns(:results)[:people], p
258 end 258 end
@@ -285,7 +285,7 @@ class SearchControllerTest < ActionController::TestCase @@ -285,7 +285,7 @@ class SearchControllerTest < ActionController::TestCase
285 person = create_user('teste').person 285 person = create_user('teste').person
286 ev = create_event(person, :name => 'an event to be found') 286 ev = create_event(person, :name => 'an event to be found')
287 287
288 - get 'index', :query => 'event found', :find_in => [ 'events' ] 288 + get :events, :query => 'event found'
289 289
290 assert_includes assigns(:results)[:events], ev 290 assert_includes assigns(:results)[:events], ev
291 end 291 end
@@ -314,7 +314,7 @@ class SearchControllerTest < ActionController::TestCase @@ -314,7 +314,7 @@ class SearchControllerTest < ActionController::TestCase
314 314
315 p = prod_cat.products.create!(:name => 'prod test 1', :enterprise => ent) 315 p = prod_cat.products.create!(:name => 'prod test 1', :enterprise => ent)
316 316
317 - get :index, :find_in => 'products', :product_category => prod_cat.id 317 + get :products, :product_category => prod_cat.id
318 318
319 assert_includes assigns(:results)[:products], p 319 assert_includes assigns(:results)[:products], p
320 end 320 end
@@ -328,13 +328,13 @@ class SearchControllerTest < ActionController::TestCase @@ -328,13 +328,13 @@ class SearchControllerTest < ActionController::TestCase
328 328
329 product = prod_cat2.products.create!(:name => 'prod test 1', :enterprise_id => ent.id) 329 product = prod_cat2.products.create!(:name => 'prod test 1', :enterprise_id => ent.id)
330 330
331 - get :products, {:category_path => cat.path.split('/'), :product_category => prod_cat1.id} 331 + get :products, :category_path => cat.path.split('/'), :product_category => prod_cat1.id
332 332
333 assert_includes assigns(:results)[:products], product 333 assert_includes assigns(:results)[:products], product
334 end 334 end
335 335
336 should 'provide calendar for events' do 336 should 'provide calendar for events' do
337 - get :index, :find_in => [ 'events' ] 337 + get :events
338 assert_equal 0, assigns(:calendar).size % 7 338 assert_equal 0, assigns(:calendar).size % 7
339 end 339 end
340 340
@@ -349,14 +349,14 @@ class SearchControllerTest < ActionController::TestCase @@ -349,14 +349,14 @@ class SearchControllerTest < ActionController::TestCase
349 person = create_user('teste').person 349 person = create_user('teste').person
350 art = TextileArticle.create!(:name => 'an text_article article to be found', :profile => person) 350 art = TextileArticle.create!(:name => 'an text_article article to be found', :profile => person)
351 351
352 - get 'index', :query => 'article found', :find_in => [ 'articles' ] 352 + get 'articles', :query => 'article found'
353 353
354 assert_includes assigns(:results)[:articles], art 354 assert_includes assigns(:results)[:articles], art
355 end 355 end
356 356
357 should 'show link to article asset in the see all foot link of the articles block in the category page' do 357 should 'show link to article asset in the see all foot link of the articles block in the category page' do
358 a = create_user('test1').person.articles.create!(:name => 'an article to be found') 358 a = create_user('test1').person.articles.create!(:name => 'an article to be found')
359 - a.add_category @category 359 + a.categories << @category
360 360
361 get :category_index, :category_path => [ 'my-category' ] 361 get :category_index, :category_path => [ 'my-category' ]
362 assert_tag :tag => 'div', :attributes => {:class => /search-results-articles/} , :descendant => {:tag => 'a', :attributes => { :href => '/search/articles/my-category'}} 362 assert_tag :tag => 'div', :attributes => {:class => /search-results-articles/} , :descendant => {:tag => 'a', :attributes => { :href => '/search/articles/my-category'}}
@@ -382,40 +382,40 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -382,40 +382,40 @@ class SearchControllerTest &lt; ActionController::TestCase
382 ent = create_profile_with_optional_category(Enterprise, 'teste') 382 ent = create_profile_with_optional_category(Enterprise, 'teste')
383 ent.domains << Domain.new(:name => 'testent.com'); ent.save! 383 ent.domains << Domain.new(:name => 'testent.com'); ent.save!
384 prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category) 384 prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category)
385 - get 'index', :query => 'beautiful', :find_in => ['products'] 385 + get 'products', :query => 'beautiful'
386 assert_includes assigns(:results)[:products], prod 386 assert_includes assigns(:results)[:products], prod
387 end 387 end
388 388
389 should 'add script tag for google maps if searching products' do 389 should 'add script tag for google maps if searching products' do
390 - get 'index', :query => 'product', :display => 'map', :find_in => ['products'] 390 + get 'products', :query => 'product', :display => 'map'
391 391
392 - assert_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps?file=api&amp;v=2&amp;key=ENVIRONMENT_KEY'} 392 + assert_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps/api/js?sensor=true'}
393 end 393 end
394 394
395 should 'add script tag for google maps if searching enterprises' do 395 should 'add script tag for google maps if searching enterprises' do
396 ent = create_profile_with_optional_category(Enterprise, 'teste') 396 ent = create_profile_with_optional_category(Enterprise, 'teste')
397 - get 'index', :query => 'enterprise', :display => 'map', :find_in => ['enterprises'] 397 + get 'enterprises', :query => 'enterprise', :display => 'map'
398 398
399 - assert_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps?file=api&amp;v=2&amp;key=ENVIRONMENT_KEY'} 399 + assert_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps/api/js?sensor=true'}
400 end 400 end
401 401
402 should 'not add script tag for google maps if searching articles' do 402 should 'not add script tag for google maps if searching articles' do
403 ent = create_profile_with_optional_category(Enterprise, 'teste') 403 ent = create_profile_with_optional_category(Enterprise, 'teste')
404 - get 'index', :query => 'article', :display => 'map', :find_in => ['articles'] 404 + get 'articles', :query => 'article', :display => 'map'
405 405
406 - assert_no_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps?file=api&amp;v=2&amp;key=ENVIRONMENT_KEY'} 406 + assert_no_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps/api/js?sensor=true'}
407 end 407 end
408 408
409 should 'not add script tag for google maps if searching people' do 409 should 'not add script tag for google maps if searching people' do
410 - get 'index', :query => 'person', :display => 'map', :find_in => ['people'] 410 + get 'people', :query => 'person', :display => 'map'
411 411
412 - assert_no_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps?file=api&amp;v=2&amp;key=ENVIRONMENT_KEY'} 412 + assert_no_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps/api/js?sensor=true'}
413 end 413 end
414 414
415 should 'not add script tag for google maps if searching communities' do 415 should 'not add script tag for google maps if searching communities' do
416 - get 'index', :query => 'community', :display => 'map', :find_in => ['communities'] 416 + get 'communities', :query => 'community', :display => 'map'
417 417
418 - assert_no_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps?file=api&amp;v=2&amp;key=ENVIRONMENT_KEY'} 418 + assert_no_tag :tag => 'script', :attributes => { :src => 'http://maps.google.com/maps/api/js?sensor=true'}
419 end 419 end
420 420
421 should 'show events of specific day' do 421 should 'show events of specific day' do
@@ -440,16 +440,16 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -440,16 +440,16 @@ class SearchControllerTest &lt; ActionController::TestCase
440 assert_tag :tag => 'a', :content => /Maria Birthday/ 440 assert_tag :tag => 'a', :content => /Maria Birthday/
441 end 441 end
442 442
443 - should 'paginate search of people in groups of 27' do 443 + should "paginate search of people in groups of #{SearchController::BLOCKS_SEARCH_LIMIT}" do
444 Person.delete_all 444 Person.delete_all
445 445
446 - 1.upto(30).map do |n|  
447 - create(User) 446 + 1.upto(SearchController::BLOCKS_SEARCH_LIMIT+3).map do |n|
  447 + fast_create Person, {:name => 'Testing person'}
448 end 448 end
449 449
450 get :people 450 get :people
451 - assert_equal 30, Person.count  
452 - assert_equal 27, assigns(:results).count 451 + assert_equal SearchController::BLOCKS_SEARCH_LIMIT+3, Person.count
  452 + assert_equal SearchController::BLOCKS_SEARCH_LIMIT, assigns(:results)[:people].count
453 assert_tag :a, '', :attributes => {:class => 'next_page'} 453 assert_tag :a, '', :attributes => {:class => 'next_page'}
454 end 454 end
455 455
@@ -462,14 +462,14 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -462,14 +462,14 @@ class SearchControllerTest &lt; ActionController::TestCase
462 assert_equal [c3,c2,c1] , assigns(:results)[:communities] 462 assert_equal [c3,c2,c1] , assigns(:results)[:communities]
463 end 463 end
464 464
465 - should 'paginate search of communities in groups of 27' do  
466 - 1.upto(30).map do |n|  
467 - create(Community, :name => 'Testing community') 465 + should "paginate search of communities in groups of #{SearchController::BLOCKS_SEARCH_LIMIT}" do
  466 + 1.upto(SearchController::BLOCKS_SEARCH_LIMIT+3).map do |n|
  467 + fast_create Community, {:name => 'Testing community'}
468 end 468 end
469 469
470 get :communities 470 get :communities
471 - assert_equal 30 , Community.count  
472 - assert_equal 27 , assigns(:results).count 471 + assert_equal SearchController::BLOCKS_SEARCH_LIMIT+3, Community.count
  472 + assert_equal SearchController::BLOCKS_SEARCH_LIMIT, assigns(:results)[:communities].count
473 assert_tag :a, '', :attributes => {:class => 'next_page'} 473 assert_tag :a, '', :attributes => {:class => 'next_page'}
474 end 474 end
475 475