Commit b47d43ac9671c3697d23821a95e6e5a0aae636a5
Exists in
master
and in
29 other branches
Merge branch 'rails235' into AI3031-community_track_embed_block
Showing
1 changed file
with
51 additions
and
50 deletions
Show diff stats
test/functional/search_controller_test.rb
@@ -74,14 +74,14 @@ class SearchControllerTest < ActionController::TestCase | @@ -74,14 +74,14 @@ class SearchControllerTest < ActionController::TestCase | ||
74 | assert_includes assigns(:searches)[:articles][:results], art | 74 | assert_includes assigns(:searches)[:articles][:results], art |
75 | end | 75 | end |
76 | 76 | ||
77 | - should 'redirect contents to articles' do | 77 | + should 'redirect contents to articles' do |
78 | person = fast_create(Person) | 78 | person = fast_create(Person) |
79 | 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) |
80 | 80 | ||
81 | get 'contents', :query => 'article found' | 81 | get 'contents', :query => 'article found' |
82 | - # full description to avoid deprecation warning | 82 | + # full description to avoid deprecation warning |
83 | assert_redirected_to :controller => :search, :action => :articles, :query => 'article found' | 83 | assert_redirected_to :controller => :search, :action => :articles, :query => 'article found' |
84 | - end | 84 | + end |
85 | 85 | ||
86 | # 'assets' outside any category | 86 | # 'assets' outside any category |
87 | should 'list articles in general' do | 87 | should 'list articles in general' do |
@@ -259,10 +259,10 @@ class SearchControllerTest < ActionController::TestCase | @@ -259,10 +259,10 @@ class SearchControllerTest < ActionController::TestCase | ||
259 | 259 | ||
260 | should 'render specific action when only one asset is enabled' do | 260 | should 'render specific action when only one asset is enabled' do |
261 | environment = Environment.default | 261 | environment = Environment.default |
262 | - # article is not disabled | 262 | + # article is not disabled |
263 | [:enterprises, :people, :communities, :products, :events].select do |key, name| | 263 | [:enterprises, :people, :communities, :products, :events].select do |key, name| |
264 | - environment.enable('disable_asset_' + key.to_s) | ||
265 | - end | 264 | + environment.enable('disable_asset_' + key.to_s) |
265 | + end | ||
266 | environment.save! | 266 | environment.save! |
267 | @controller.stubs(:environment).returns(environment) | 267 | @controller.stubs(:environment).returns(environment) |
268 | 268 | ||
@@ -274,25 +274,25 @@ class SearchControllerTest < ActionController::TestCase | @@ -274,25 +274,25 @@ class SearchControllerTest < ActionController::TestCase | ||
274 | assert !assigns(:searches).has_key?(:communities) | 274 | assert !assigns(:searches).has_key?(:communities) |
275 | assert !assigns(:searches).has_key?(:products) | 275 | assert !assigns(:searches).has_key?(:products) |
276 | assert !assigns(:searches).has_key?(:events) | 276 | assert !assigns(:searches).has_key?(:events) |
277 | - end | 277 | + end |
278 | 278 | ||
279 | should 'search all enabled assets in general search' do | 279 | should 'search all enabled assets in general search' do |
280 | ent1 = create_profile_with_optional_category(Enterprise, 'test enterprise') | 280 | ent1 = create_profile_with_optional_category(Enterprise, 'test enterprise') |
281 | prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) | 281 | prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) |
282 | prod = ent1.products.create!(:name => 'test product', :product_category => prod_cat) | 282 | prod = ent1.products.create!(:name => 'test product', :product_category => prod_cat) |
283 | - art = Article.create!(:name => 'test article', :profile_id => fast_create(Person).id) | ||
284 | - per = Person.create!(:name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id) | ||
285 | - com = Community.create!(:name => 'test community') | ||
286 | - eve = Event.create!(:name => 'test event', :profile_id => fast_create(Person).id) | 283 | + art = Article.create!(:name => 'test article', :profile_id => fast_create(Person).id) |
284 | + per = Person.create!(:name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id) | ||
285 | + com = Community.create!(:name => 'test community') | ||
286 | + eve = Event.create!(:name => 'test event', :profile_id => fast_create(Person).id) | ||
287 | 287 | ||
288 | get :index, :query => 'test' | 288 | get :index, :query => 'test' |
289 | 289 | ||
290 | [:articles, :enterprises, :people, :communities, :products, :events].select do |key, name| | 290 | [:articles, :enterprises, :people, :communities, :products, :events].select do |key, name| |
291 | - !assigns(:environment).enabled?('disable_asset_' + key.to_s) | ||
292 | - end.each do |asset| | ||
293 | - assert !assigns(:searches)[asset][:results].empty? | ||
294 | - end | ||
295 | - end | 291 | + !assigns(:environment).enabled?('disable_asset_' + key.to_s) |
292 | + end.each do |asset| | ||
293 | + assert !assigns(:searches)[asset][:results].empty? | ||
294 | + end | ||
295 | + end | ||
296 | 296 | ||
297 | should 'display category image while in directory' do | 297 | should 'display category image while in directory' do |
298 | parent = Category.create!(:name => 'category1', :environment => Environment.default) | 298 | parent = Category.create!(:name => 'category1', :environment => Environment.default) |
@@ -318,8 +318,8 @@ class SearchControllerTest < ActionController::TestCase | @@ -318,8 +318,8 @@ class SearchControllerTest < ActionController::TestCase | ||
318 | person = create_user('someone').person | 318 | person = create_user('someone').person |
319 | ten_days_ago = Date.today - 10.day | 319 | ten_days_ago = Date.today - 10.day |
320 | 320 | ||
321 | - ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => ten_days_ago) | ||
322 | - ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today - 2.month) | 321 | + ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => ten_days_ago) |
322 | + ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today - 2.month) | ||
323 | 323 | ||
324 | get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year | 324 | get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year |
325 | assert_equal [ev1], assigns(:events) | 325 | assert_equal [ev1], assigns(:events) |
@@ -329,7 +329,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -329,7 +329,7 @@ class SearchControllerTest < ActionController::TestCase | ||
329 | person = create_user('someone').person | 329 | person = create_user('someone').person |
330 | ten_days_ago = Date.today - 10.day | 330 | ten_days_ago = Date.today - 10.day |
331 | 331 | ||
332 | - ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => ten_days_ago) | 332 | + ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => ten_days_ago) |
333 | ev2 = create_event(person, :name => 'event 2', :start_date => ten_days_ago) | 333 | ev2 = create_event(person, :name => 'event 2', :start_date => ten_days_ago) |
334 | 334 | ||
335 | get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year, :category_path => @category.path.split('/') | 335 | get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year, :category_path => @category.path.split('/') |
@@ -339,8 +339,8 @@ class SearchControllerTest < ActionController::TestCase | @@ -339,8 +339,8 @@ class SearchControllerTest < ActionController::TestCase | ||
339 | 339 | ||
340 | should 'return events of today when no date specified' do | 340 | should 'return events of today when no date specified' do |
341 | person = create_user('someone').person | 341 | person = create_user('someone').person |
342 | - ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => Date.today) | ||
343 | - ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today - 2.month) | 342 | + ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => Date.today) |
343 | + ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today - 2.month) | ||
344 | 344 | ||
345 | get :events | 345 | get :events |
346 | 346 | ||
@@ -351,9 +351,9 @@ class SearchControllerTest < ActionController::TestCase | @@ -351,9 +351,9 @@ class SearchControllerTest < ActionController::TestCase | ||
351 | person = create_user('someone').person | 351 | person = create_user('someone').person |
352 | 352 | ||
353 | ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], | 353 | ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], |
354 | - :start_date => Date.today + 2.month) | 354 | + :start_date => Date.today + 2.month) |
355 | ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], | 355 | ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], |
356 | - :start_date => Date.today + 2.day) | 356 | + :start_date => Date.today + 2.day) |
357 | 357 | ||
358 | get :events | 358 | get :events |
359 | 359 | ||
@@ -373,8 +373,9 @@ class SearchControllerTest < ActionController::TestCase | @@ -373,8 +373,9 @@ class SearchControllerTest < ActionController::TestCase | ||
373 | end | 373 | end |
374 | 374 | ||
375 | should 'see the events paginated' do | 375 | should 'see the events paginated' do |
376 | + person = create_user('pagination').person | ||
376 | 30.times do |i| | 377 | 30.times do |i| |
377 | - create_event(person, :name => "Event #{i}", :start_date => Date.today) | 378 | + create_event(person, :name => "Event #{i}", :start_date => Date.today) |
378 | end | 379 | end |
379 | get :events | 380 | get :events |
380 | assert_equal 20, assigns(:events).count | 381 | assert_equal 20, assigns(:events).count |
@@ -433,8 +434,8 @@ class SearchControllerTest < ActionController::TestCase | @@ -433,8 +434,8 @@ class SearchControllerTest < ActionController::TestCase | ||
433 | end | 434 | end |
434 | 435 | ||
435 | should 'show link to article asset in the see all foot link of the articles block in the category page' do | 436 | should 'show link to article asset in the see all foot link of the articles block in the category page' do |
436 | - (1..SearchController::MULTIPLE_SEARCH_LIMIT+1).each do |i| | ||
437 | - a = create_user("test#{i}").person.articles.create!(:name => "article #{i} to be found") | 437 | + (1..SearchController::MULTIPLE_SEARCH_LIMIT+1).each do |i| |
438 | + a = create_user("test#{i}").person.articles.create!(:name => "article #{i} to be found") | ||
438 | ArticleCategorization.add_category_to_article(@category, a) | 439 | ArticleCategorization.add_category_to_article(@category, a) |
439 | end | 440 | end |
440 | 441 | ||
@@ -580,55 +581,55 @@ class SearchControllerTest < ActionController::TestCase | @@ -580,55 +581,55 @@ class SearchControllerTest < ActionController::TestCase | ||
580 | assert_not_includes assigns(:searches)[:communities][:results], p1 | 581 | assert_not_includes assigns(:searches)[:communities][:results], p1 |
581 | end | 582 | end |
582 | 583 | ||
583 | - should 'keep old urls working' do | ||
584 | - get :assets, :asset => 'articles' | 584 | + should 'keep old urls working' do |
585 | + get :assets, :asset => 'articles' | ||
585 | assert_redirected_to :controller => :search, :action => :articles | 586 | assert_redirected_to :controller => :search, :action => :articles |
586 | - get :assets, :asset => 'people' | 587 | + get :assets, :asset => 'people' |
587 | assert_redirected_to :controller => :search, :action => :people | 588 | assert_redirected_to :controller => :search, :action => :people |
588 | - get :assets, :asset => 'communities' | 589 | + get :assets, :asset => 'communities' |
589 | assert_redirected_to :controller => :search, :action => :communities | 590 | assert_redirected_to :controller => :search, :action => :communities |
590 | - get :assets, :asset => 'products' | 591 | + get :assets, :asset => 'products' |
591 | assert_redirected_to :controller => :search, :action => :products | 592 | assert_redirected_to :controller => :search, :action => :products |
592 | - get :assets, :asset => 'enterprises' | 593 | + get :assets, :asset => 'enterprises' |
593 | assert_redirected_to :controller => :search, :action => :enterprises | 594 | assert_redirected_to :controller => :search, :action => :enterprises |
594 | - get :assets, :asset => 'events' | 595 | + get :assets, :asset => 'events' |
595 | assert_redirected_to :controller => :search, :action => :events | 596 | assert_redirected_to :controller => :search, :action => :events |
596 | - end | 597 | + end |
597 | 598 | ||
598 | - should 'show tag cloud' do | ||
599 | - @controller.stubs(:is_cache_expired?).returns(true) | 599 | + should 'show tag cloud' do |
600 | + @controller.stubs(:is_cache_expired?).returns(true) | ||
600 | a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id) | 601 | a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id) |
601 | a.tag_list = ['one', 'two'] | 602 | a.tag_list = ['one', 'two'] |
602 | - a.save_tags | 603 | + a.save_tags |
603 | 604 | ||
604 | - get :tags | 605 | + get :tags |
605 | 606 | ||
606 | - assert assigns(:tags)["two"] = 1 | ||
607 | - assert assigns(:tags)["one"] = 1 | ||
608 | - end | 607 | + assert assigns(:tags)["two"] = 1 |
608 | + assert assigns(:tags)["one"] = 1 | ||
609 | + end | ||
609 | 610 | ||
610 | should 'show tagged content' do | 611 | should 'show tagged content' do |
611 | - @controller.stubs(:is_cache_expired?).returns(true) | 612 | + @controller.stubs(:is_cache_expired?).returns(true) |
612 | a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id) | 613 | a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id) |
613 | a2 = Article.create!(:name => 'my article 2', :profile_id => fast_create(Person).id) | 614 | a2 = Article.create!(:name => 'my article 2', :profile_id => fast_create(Person).id) |
614 | a.tag_list = ['one', 'two'] | 615 | a.tag_list = ['one', 'two'] |
615 | a2.tag_list = ['two', 'three'] | 616 | a2.tag_list = ['two', 'three'] |
616 | - a.save_tags | 617 | + a.save_tags |
617 | a2.save_tags | 618 | a2.save_tags |
618 | 619 | ||
619 | - get :tag, :tag => 'two' | 620 | + get :tag, :tag => 'two' |
620 | 621 | ||
621 | assert_equivalent [a, a2], assigns(:searches)[:tag][:results] | 622 | assert_equivalent [a, a2], assigns(:searches)[:tag][:results] |
622 | 623 | ||
623 | - get :tag, :tag => 'one' | 624 | + get :tag, :tag => 'one' |
624 | 625 | ||
625 | assert_equivalent [a], assigns(:searches)[:tag][:results] | 626 | assert_equivalent [a], assigns(:searches)[:tag][:results] |
626 | end | 627 | end |
627 | 628 | ||
628 | should 'not show assets from other environments' do | 629 | should 'not show assets from other environments' do |
629 | other_env = Environment.create!(:name => 'Another environment') | 630 | other_env = Environment.create!(:name => 'Another environment') |
630 | - p1 = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :environment_id => other_env.id) | ||
631 | - p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id) | 631 | + p1 = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :environment_id => other_env.id) |
632 | + p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id) | ||
632 | art1 = Article.create!(:name => 'my article', :profile_id => p1.id) | 633 | art1 = Article.create!(:name => 'my article', :profile_id => p1.id) |
633 | art2 = Article.create!(:name => 'my article', :profile_id => p2.id) | 634 | art2 = Article.create!(:name => 'my article', :profile_id => p2.id) |
634 | 635 | ||
@@ -639,9 +640,9 @@ class SearchControllerTest < ActionController::TestCase | @@ -639,9 +640,9 @@ class SearchControllerTest < ActionController::TestCase | ||
639 | 640 | ||
640 | should 'order articles by more recent' do | 641 | should 'order articles by more recent' do |
641 | Article.destroy_all | 642 | Article.destroy_all |
642 | - art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id, :created_at => Time.now-1.days) | ||
643 | - art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id, :created_at => Time.now) | ||
644 | - art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id, :created_at => Time.now-2.days) | 643 | + art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id, :created_at => Time.now-1.days) |
644 | + art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id, :created_at => Time.now) | ||
645 | + art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id, :created_at => Time.now-2.days) | ||
645 | 646 | ||
646 | get :articles, :filter => :more_recent | 647 | get :articles, :filter => :more_recent |
647 | 648 |