Commit 9eb00efa35aada9cea741f06528aa0b5e7bc6110
1 parent
be5eca41
Exists in
master
and in
29 other branches
Updated SearchControllerTest
Showing
1 changed file
with
332 additions
and
7 deletions
Show diff stats
test/functional/search_controller_test.rb
@@ -72,7 +72,23 @@ class SearchControllerTest < ActionController::TestCase | @@ -72,7 +72,23 @@ class SearchControllerTest < ActionController::TestCase | ||
72 | 72 | ||
73 | get 'articles', :query => 'article found' | 73 | get 'articles', :query => 'article found' |
74 | assert_includes assigns(:results)[:articles], art | 74 | assert_includes assigns(:results)[:articles], art |
75 | - assert !assigns(:results)[:articles].facets.nil? | 75 | + end |
76 | + | ||
77 | + should 'get facets with articles search results' do | ||
78 | + cat1 = fast_create(Category, :name => 'cat1') | ||
79 | + cat2 = fast_create(Category, :name => 'cat2') | ||
80 | + person = fast_create(Person) | ||
81 | + art = create_article_with_optional_category('an article to be found', person) | ||
82 | + art.add_category cat1, false | ||
83 | + art.add_category cat2, true | ||
84 | + art.save! | ||
85 | + | ||
86 | + get 'articles', :query => 'article found' | ||
87 | + assert !assigns(:results)[:articles].facets.blank? | ||
88 | + assert assigns(:results)[:articles].facets['facet_fields']['f_type_facet'][0][0] == 'Article' | ||
89 | + assert assigns(:results)[:articles].facets['facet_fields']['f_profile_type_facet'][0][0] == 'Person' | ||
90 | + assert assigns(:results)[:articles].facets['facet_fields']['f_category_facet'][0][0] == 'cat1' | ||
91 | + assert assigns(:results)[:articles].facets['facet_fields']['f_category_facet'][1][0] == 'cat2' | ||
76 | end | 92 | end |
77 | 93 | ||
78 | should 'redirect contents to articles' do | 94 | should 'redirect contents to articles' do |
@@ -113,11 +129,29 @@ class SearchControllerTest < ActionController::TestCase | @@ -113,11 +129,29 @@ class SearchControllerTest < ActionController::TestCase | ||
113 | assert_includes assigns(:results)[:enterprises], ent2 | 129 | assert_includes assigns(:results)[:enterprises], ent2 |
114 | end | 130 | end |
115 | 131 | ||
116 | - should 'find people' do | 132 | + should 'search for people' do |
117 | p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.save! | 133 | p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.save! |
118 | get :people, :query => 'beautiful' | 134 | get :people, :query => 'beautiful' |
119 | assert_includes assigns(:results)[:people], p1 | 135 | assert_includes assigns(:results)[:people], p1 |
120 | - assert !assigns(:results)[:people].facets.nil? | 136 | + end |
137 | + | ||
138 | + should 'get facets with people search results' do | ||
139 | + state = fast_create(State, :name => 'Acre', :acronym => 'AC') | ||
140 | + city = fast_create(City, :name => 'Rio Branco', :parent_id => state.id) | ||
141 | + person = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id) | ||
142 | + person.region = city | ||
143 | + cat1 = fast_create(Category, :name => 'cat1') | ||
144 | + cat2 = fast_create(Category, :name => 'cat2') | ||
145 | + person.add_category cat1, false | ||
146 | + person.add_category cat2, true | ||
147 | + person.save! | ||
148 | + | ||
149 | + get 'people', :query => 'Hildebrando' | ||
150 | + | ||
151 | + assert !assigns(:results)[:people].facets.blank? | ||
152 | + assert assigns(:results)[:people].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s | ||
153 | + assert assigns(:results)[:people].facets['facet_fields']['f_categories_facet'][0][0] == cat1.id.to_s | ||
154 | + assert assigns(:results)[:people].facets['facet_fields']['f_categories_facet'][1][0] == cat2.id.to_s | ||
121 | end | 155 | end |
122 | 156 | ||
123 | # 'assets' menu outside any category | 157 | # 'assets' menu outside any category |
@@ -148,12 +182,30 @@ class SearchControllerTest < ActionController::TestCase | @@ -148,12 +182,30 @@ class SearchControllerTest < ActionController::TestCase | ||
148 | assert_equivalent [c2, c1], assigns(:results)[:communities] | 182 | assert_equivalent [c2, c1], assigns(:results)[:communities] |
149 | end | 183 | end |
150 | 184 | ||
151 | - should 'find products' do | 185 | + should 'search for products' do |
152 | ent = create_profile_with_optional_category(Enterprise, 'teste') | 186 | ent = create_profile_with_optional_category(Enterprise, 'teste') |
153 | prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category) | 187 | prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category) |
154 | get :products, :query => 'beautiful' | 188 | get :products, :query => 'beautiful' |
155 | assert_includes assigns(:results)[:products], prod | 189 | assert_includes assigns(:results)[:products], prod |
156 | - assert !assigns(:results)[:products].facets.nil? | 190 | + end |
191 | + | ||
192 | + should 'get facets with products search results' do | ||
193 | + state = fast_create(State, :name => 'Acre', :acronym => 'AC') | ||
194 | + city = fast_create(City, :name => 'Rio Branco', :parent_id => state.id) | ||
195 | + ent = fast_create(Enterprise, :region_id => city.id) | ||
196 | + prod = Product.create!(:name => 'Sound System', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
197 | + qualifier1 = fast_create(Qualifier) | ||
198 | + qualifier2 = fast_create(Qualifier) | ||
199 | + prod.qualifiers_list = [[qualifier1.id, 0], [qualifier2.id, 0]] | ||
200 | + prod.qualifiers.reload | ||
201 | + prod.save! | ||
202 | + | ||
203 | + get 'products', :query => 'Sound' | ||
204 | + assert !assigns(:results)[:products].facets.blank? | ||
205 | + assert assigns(:results)[:products].facets['facet_fields']['f_category_facet'][0][0] == @product_category.name | ||
206 | + assert assigns(:results)[:products].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s | ||
207 | + assert assigns(:results)[:products].facets['facet_fields']['f_qualifier_facet'][0][0] == "#{qualifier1.id} 0" | ||
208 | + assert assigns(:results)[:products].facets['facet_fields']['f_qualifier_facet'][1][0] == "#{qualifier2.id} 0" | ||
157 | end | 209 | end |
158 | 210 | ||
159 | # 'assets' menu outside any category | 211 | # 'assets' menu outside any category |
@@ -168,6 +220,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -168,6 +220,7 @@ class SearchControllerTest < ActionController::TestCase | ||
168 | 220 | ||
169 | get :products | 221 | get :products |
170 | assert_equivalent [prod2, prod1], assigns(:results)[:products].docs | 222 | assert_equivalent [prod2, prod1], assigns(:results)[:products].docs |
223 | + assert_match 'Highlights', @response.body | ||
171 | end | 224 | end |
172 | 225 | ||
173 | should 'include extra content supplied by plugins on product asset' do | 226 | should 'include extra content supplied by plugins on product asset' do |
@@ -296,11 +349,25 @@ class SearchControllerTest < ActionController::TestCase | @@ -296,11 +349,25 @@ class SearchControllerTest < ActionController::TestCase | ||
296 | 349 | ||
297 | get :index, :query => prod_cat.name | 350 | get :index, :query => prod_cat.name |
298 | 351 | ||
299 | - assert assigns(:facets).empty? | 352 | + assert assigns(:facets).blank? |
300 | assert_nil assigns(:results)[:enterprises].facets | 353 | assert_nil assigns(:results)[:enterprises].facets |
301 | assert_nil assigns(:results)[:products].facets | 354 | assert_nil assigns(:results)[:products].facets |
302 | end | 355 | end |
303 | 356 | ||
357 | + should 'render specific action when only one asset is enabled' do | ||
358 | + # initialize @controller.environment | ||
359 | + get :index | ||
360 | + | ||
361 | + # article is not disabled | ||
362 | + [:enterprises, :people, :communities, :products, :events].select do |key, name| | ||
363 | + @controller.environment.enable('disable_asset_' + key.to_s) | ||
364 | + end | ||
365 | + | ||
366 | + @controller.expects(:articles) | ||
367 | + | ||
368 | + get :index, :query => 'something' | ||
369 | + end | ||
370 | + | ||
304 | should 'search all enabled assets in general search' do | 371 | should 'search all enabled assets in general search' do |
305 | ent1 = create_profile_with_optional_category(Enterprise, 'test enterprise') | 372 | ent1 = create_profile_with_optional_category(Enterprise, 'test enterprise') |
306 | prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) | 373 | prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) |
@@ -340,6 +407,50 @@ class SearchControllerTest < ActionController::TestCase | @@ -340,6 +407,50 @@ class SearchControllerTest < ActionController::TestCase | ||
340 | assert !assigns(:results)[:events].facets.nil? | 407 | assert !assigns(:results)[:events].facets.nil? |
341 | end | 408 | end |
342 | 409 | ||
410 | + should 'return events of the day' do | ||
411 | + person = create_user('someone').person | ||
412 | + ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => Date.today - 10.day) | ||
413 | + ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today - 2.month) | ||
414 | + | ||
415 | + get :events, :day => (Date.today - 10.day).day | ||
416 | + | ||
417 | + assert_equal [ev1], assigns(:events_of_the_day) | ||
418 | + end | ||
419 | + | ||
420 | + should 'return events of the day with category' do | ||
421 | + person = create_user('someone').person | ||
422 | + ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => Date.today - 10.day) | ||
423 | + ev2 = create_event(person, :name => 'event 2', :start_date => Date.today - 10.day) | ||
424 | + | ||
425 | + get :events, :day => (Date.today - 10.day).day, :category_path => @category.path.split('/') | ||
426 | + | ||
427 | + assert_equal [ev1], assigns(:events_of_the_day) | ||
428 | + end | ||
429 | + | ||
430 | + should 'return events of today when no date specified' do | ||
431 | + person = create_user('someone').person | ||
432 | + ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => Date.today) | ||
433 | + ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today - 2.month) | ||
434 | + | ||
435 | + get :events | ||
436 | + | ||
437 | + assert_equal [ev1], assigns(:events_of_the_day) | ||
438 | + end | ||
439 | + | ||
440 | + should 'show events for current month by default' do | ||
441 | + person = create_user('someone').person | ||
442 | + | ||
443 | + ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], | ||
444 | + :start_date => Date.today + 2.month) | ||
445 | + ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], | ||
446 | + :start_date => Date.today + 2.day) | ||
447 | + | ||
448 | + get :events | ||
449 | + | ||
450 | + assert_not_includes assigns(:results)[:events], ev1 | ||
451 | + assert_includes assigns(:results)[:events], ev2 | ||
452 | + end | ||
453 | + | ||
343 | should 'list events for a given month' do | 454 | should 'list events for a given month' do |
344 | person = create_user('testuser').person | 455 | person = create_user('testuser').person |
345 | 456 | ||
@@ -369,8 +480,46 @@ class SearchControllerTest < ActionController::TestCase | @@ -369,8 +480,46 @@ class SearchControllerTest < ActionController::TestCase | ||
369 | assert_includes assigns(:results)[:products], p | 480 | assert_includes assigns(:results)[:products], p |
370 | end | 481 | end |
371 | 482 | ||
372 | - should 'display properly in conjuntion with a category' do | 483 | + # Testing random sequences always have a small chance of failing |
484 | + should 'randomize product display in empty search' do | ||
485 | + prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default) | ||
486 | + ent = create_profile_with_optional_category(Enterprise, 'test enterprise') | ||
487 | + (1..SearchController::LIST_SEARCH_LIMIT+5).each do |n| | ||
488 | + fast_create(Product, {:name => "produto #{n}", :enterprise_id => ent.id, :product_category_id => prod_cat.id}, :search => true) | ||
489 | + end | ||
490 | + | ||
491 | + get :products | ||
492 | + result1 = assigns(:results)[:products].docs.map(&:id) | ||
493 | + | ||
494 | + (1..10).each do |n| | ||
495 | + get :products | ||
496 | + end | ||
497 | + result2 = assigns(:results)[:products].docs.map(&:id) | ||
498 | + | ||
499 | + assert_not_equal result1, result2 | ||
500 | + end | ||
501 | + | ||
502 | + should 'order products by geolocalization in empty search' do | ||
503 | + user = create_user('a_logged_user') | ||
504 | + user.person.lat = '1.0' | ||
505 | + user.person.lng = '1.0' | ||
506 | + # trigger geosearch | ||
507 | + SearchController.any_instance.stubs(:logged_in?).returns(true) | ||
508 | + SearchController.any_instance.stubs(:current_user).returns(user) | ||
509 | + | ||
510 | + cat = fast_create(ProductCategory) | ||
511 | + ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '-5.0', :lng => '-5.0') | ||
512 | + prod1 = Product.create!(:name => 'produto 1', :enterprise_id => ent1.id, :product_category_id => cat.id) | ||
513 | + ent2 = Enterprise.create!(:name => 'ent2', :identifier => 'ent2', :lat => '2.0', :lng => '2.0') | ||
514 | + prod2 = Product.create!(:name => 'produto 2', :enterprise_id => ent2.id, :product_category_id => cat.id) | ||
515 | + ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '10.0', :lng => '10.0') | ||
516 | + prod3 = Product.create!(:name => 'produto 3', :enterprise_id => ent3.id, :product_category_id => cat.id) | ||
517 | + | ||
518 | + get :products | ||
519 | + assert_equal [prod2, prod1, prod3], assigns(:results)[:products].docs | ||
520 | + end | ||
373 | 521 | ||
522 | + should 'display properly in conjuntion with a category' do | ||
374 | cat = Category.create(:name => 'cat', :environment => Environment.default) | 523 | cat = Category.create(:name => 'cat', :environment => Environment.default) |
375 | prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default) | 524 | prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default) |
376 | prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1) | 525 | prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1) |
@@ -586,6 +735,182 @@ class SearchControllerTest < ActionController::TestCase | @@ -586,6 +735,182 @@ class SearchControllerTest < ActionController::TestCase | ||
586 | assert_redirected_to :controller => :search, :action => :events | 735 | assert_redirected_to :controller => :search, :action => :events |
587 | end | 736 | end |
588 | 737 | ||
738 | + should 'show tag cloud' do | ||
739 | + @controller.stubs(:is_cache_expired?).returns(true) | ||
740 | + a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id) | ||
741 | + a.tag_list = ['one', 'two'] | ||
742 | + a.save_tags | ||
743 | + | ||
744 | + get :tags | ||
745 | + | ||
746 | + assert assigns(:tags)["two"] = 1 | ||
747 | + assert assigns(:tags)["one"] = 1 | ||
748 | + end | ||
749 | + | ||
750 | + should 'show tagged content' do | ||
751 | + @controller.stubs(:is_cache_expired?).returns(true) | ||
752 | + a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id) | ||
753 | + a2 = Article.create!(:name => 'my article 2', :profile_id => fast_create(Person).id) | ||
754 | + a.tag_list = ['one', 'two'] | ||
755 | + a2.tag_list = ['two', 'three'] | ||
756 | + a.save_tags | ||
757 | + a2.save_tags | ||
758 | + | ||
759 | + get :tag, :tag => 'two' | ||
760 | + | ||
761 | + assert_equal [a, a2], assigns(:results)[:tag] | ||
762 | + | ||
763 | + get :tag, :tag => 'one' | ||
764 | + | ||
765 | + assert_equal [a], assigns(:results)[:tag] | ||
766 | + end | ||
767 | + | ||
768 | + should 'not show assets from other environments' do | ||
769 | + other_env = Environment.create!(:name => 'Another environment') | ||
770 | + p1 = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :environment_id => other_env.id) | ||
771 | + p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id) | ||
772 | + art1 = Article.create!(:name => 'my article', :profile_id => p1.id) | ||
773 | + art2 = Article.create!(:name => 'my article', :profile_id => p2.id) | ||
774 | + | ||
775 | + get :articles, :query => 'my article' | ||
776 | + | ||
777 | + assert_equal [art2], assigns(:results)[:articles].docs | ||
778 | + end | ||
779 | + | ||
780 | + should 'order product results by more recent when requested' do | ||
781 | + ent = fast_create(Enterprise) | ||
782 | + prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
783 | + prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
784 | + prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
785 | + | ||
786 | + prod3.name = 'product 4' | ||
787 | + prod3.save! | ||
788 | + prod1.name = 'product 5' | ||
789 | + prod1.save! | ||
790 | + prod2.name = 'product 6' | ||
791 | + prod2.save! | ||
792 | + | ||
793 | + get :products, :query => 'product', :order_by => :more_recent | ||
794 | + | ||
795 | + assert_equal [prod2, prod1, prod3], assigns(:results)[:products].docs | ||
796 | + end | ||
797 | + | ||
798 | + should 'order product results by name when requested' do | ||
799 | + ent = fast_create(Enterprise) | ||
800 | + prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
801 | + prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
802 | + prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id) | ||
803 | + | ||
804 | + prod3.name = 'product A' | ||
805 | + prod3.save! | ||
806 | + prod1.name = 'product B' | ||
807 | + prod1.save! | ||
808 | + prod2.name = 'product C' | ||
809 | + prod2.save! | ||
810 | + | ||
811 | + get :products, :query => 'product', :order_by => :name | ||
812 | + | ||
813 | + assert_equal [prod3, prod1, prod2], assigns(:results)[:products].docs | ||
814 | + end | ||
815 | + | ||
816 | + should 'order product results by closest when requested' do | ||
817 | + user = create_user('a_logged_user') | ||
818 | + user.person.lat = '1.0' | ||
819 | + user.person.lng = '1.0' | ||
820 | + # trigger geosearch | ||
821 | + SearchController.any_instance.stubs(:logged_in?).returns(true) | ||
822 | + SearchController.any_instance.stubs(:current_user).returns(user) | ||
823 | + | ||
824 | + cat = fast_create(ProductCategory) | ||
825 | + ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '-5.0', :lng => '-5.0') | ||
826 | + prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent1.id, :product_category_id => cat.id) | ||
827 | + ent2 = Enterprise.create!(:name => 'ent2', :identifier => 'ent2', :lat => '2.0', :lng => '2.0') | ||
828 | + prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent2.id, :product_category_id => cat.id) | ||
829 | + ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '10.0', :lng => '10.0') | ||
830 | + prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent3.id, :product_category_id => cat.id) | ||
831 | + | ||
832 | + get :products, :query => 'product', :order_by => :closest | ||
833 | + assert_equal [prod2, prod1, prod3], assigns(:results)[:products].docs | ||
834 | + end | ||
835 | + | ||
836 | + | ||
837 | + should 'order events by name when requested' do | ||
838 | + person = create_user('someone').person | ||
839 | + ev1 = create_event(person, :name => 'party B', :category_ids => [@category.id], :start_date => Date.today - 10.day) | ||
840 | + ev2 = create_event(person, :name => 'party A', :category_ids => [@category.id], :start_date => Date.today - 2.month) | ||
841 | + | ||
842 | + get :events, :query => 'party', :order_by => :name | ||
843 | + | ||
844 | + assert_equal [ev2, ev1], assigns(:results)[:events].docs | ||
845 | + end | ||
846 | + | ||
847 | + should 'order articles by name when requested' do | ||
848 | + art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id) | ||
849 | + art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id) | ||
850 | + art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id) | ||
851 | + | ||
852 | + get :articles, :query => 'review', :order_by => :name | ||
853 | + | ||
854 | + assert_equal [art2, art3, art1], assigns(:results)[:articles].docs | ||
855 | + end | ||
856 | + | ||
857 | + should 'order articles by more recent' do | ||
858 | + art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id) | ||
859 | + art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id) | ||
860 | + art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id) | ||
861 | + | ||
862 | + art1.name = 'review 10' | ||
863 | + art1.save! | ||
864 | + art3.name = 'review 87' | ||
865 | + art3.save! | ||
866 | + art2.name = 'review 54' | ||
867 | + art2.save! | ||
868 | + | ||
869 | + get :articles, :query => 'review', :order_by => :more_recent | ||
870 | + | ||
871 | + assert_equal [art2, art3, art1], assigns(:results)[:articles].docs | ||
872 | + end | ||
873 | + | ||
874 | + should 'order enterprise results by name when requested' do | ||
875 | + ent1 = Enterprise.create!(:name => 'Company B', :identifier => 'com_b') | ||
876 | + ent2 = Enterprise.create!(:name => 'Company A', :identifier => 'com_a') | ||
877 | + ent3 = Enterprise.create!(:name => 'Company C', :identifier => 'com_c') | ||
878 | + | ||
879 | + get :enterprises, :query => 'Company', :order_by => :name | ||
880 | + | ||
881 | + assert_equal [ent2, ent1, ent3], assigns(:results)[:enterprises].docs | ||
882 | + end | ||
883 | + | ||
884 | + should 'order people results by name when requested' do | ||
885 | + person1 = Person.create!(:name => 'Deodárbio Silva', :identifier => 'deod', :user_id => fast_create(User).id) | ||
886 | + person2 = Person.create!(:name => 'Glislange Silva', :identifier => 'glis', :user_id => fast_create(User).id) | ||
887 | + person3 = Person.create!(:name => 'Ausêncio Silva', :identifier => 'ause', :user_id => fast_create(User).id) | ||
888 | + | ||
889 | + get :people, :query => 'Silva', :order_by => :name | ||
890 | + | ||
891 | + assert_equal [person3, person1, person2], assigns(:results)[:people].docs | ||
892 | + end | ||
893 | + | ||
894 | + should 'order community results by name when requested' do | ||
895 | + com1 = Community.create!(:name => 'Yellow Group') | ||
896 | + com2 = Community.create!(:name => 'Red Group') | ||
897 | + com3 = Community.create!(:name => 'Green Group') | ||
898 | + | ||
899 | + get :communities, :query => 'Group', :order_by => :name | ||
900 | + | ||
901 | + assert_equal [com3, com2, com1], assigns(:results)[:communities].docs | ||
902 | + end | ||
903 | + | ||
904 | + should 'raise error when requested to order by unknown filter' do | ||
905 | + com1 = Community.create!(:name => 'Yellow Group') | ||
906 | + com2 = Community.create!(:name => 'Red Group') | ||
907 | + com3 = Community.create!(:name => 'Green Group') | ||
908 | + | ||
909 | + assert_raise RuntimeError do | ||
910 | + get :communities, :query => 'Group', :order_by => :something | ||
911 | + end | ||
912 | + end | ||
913 | + | ||
589 | ################################################################## | 914 | ################################################################## |
590 | ################################################################## | 915 | ################################################################## |
591 | 916 |