Commit d4c822cdeb3207ee9138569f8786bfecb81b9635
1 parent
afeb5522
Add functionals testes for mention search
Showing
1 changed file
with
38 additions
and
0 deletions
Show diff stats
test/functional/search_controller_test.rb
| ... | ... | @@ -660,6 +660,44 @@ class SearchControllerTest < ActionController::TestCase |
| 660 | 660 | } |
| 661 | 661 | end |
| 662 | 662 | |
| 663 | + should 'search for friends and members render access denied if it is not an ajax call' do | |
| 664 | + get :search_for_friends_and_members | |
| 665 | + assert_template 'shared/access_denied' | |
| 666 | + end | |
| 667 | + | |
| 668 | + should 'search for friends and members' do | |
| 669 | + u1, u2, u3 = fast_create(User), fast_create(User), fast_create(User) | |
| 670 | + | |
| 671 | + p1 = fast_create(Person, name: 'fulano', user_id: u1.id) | |
| 672 | + p2 = fast_create(Person, name: 'ciclano', user_id: u2.id) | |
| 673 | + p3 = fast_create(Person, name: 'deltrano', user_id: u3.id) | |
| 674 | + | |
| 675 | + p1.add_friend(p2) | |
| 676 | + p1.save! | |
| 677 | + | |
| 678 | + c = fast_create(Community, name: 'sample test community') | |
| 679 | + c.add_member(p1) | |
| 680 | + c.add_member(p3) | |
| 681 | + c.save! | |
| 682 | + | |
| 683 | + @controller.stubs(:user).returns(p1) | |
| 684 | + | |
| 685 | + xhr :get, :search_for_friends_and_members, q: "ano", community: nil | |
| 686 | + | |
| 687 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
| 688 | + | |
| 689 | + assert_equal p2.name, json_response.first["name"] | |
| 690 | + | |
| 691 | + xhr :get, :search_for_friends_and_members, q: "del", community: c.identifier | |
| 692 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
| 693 | + assert_equal p3.name, json_response.first["name"] | |
| 694 | + | |
| 695 | + xhr :get, :search_for_friends_and_members, q: "ano", community: c.identifier | |
| 696 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
| 697 | + assert_equal p2.name, json_response.first["name"] | |
| 698 | + assert_equal p3.name, json_response.last["name"] | |
| 699 | + end | |
| 700 | + | |
| 663 | 701 | protected |
| 664 | 702 | |
| 665 | 703 | def create_event(profile, options) | ... | ... |