ref: master
test/functional/friends_controller_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
require_relative '../test_helper' class FriendsControllerTest < ActionController::TestCase self.default_params = {profile: 'testuser'} def setup @controller = FriendsController.new self.profile = create_user('testuser').person self.friend = create_user('thefriend').person login_as ('testuser') end attr_accessor :profile, :friend should 'list friends in alphabetical order' do profile.add_friend(create_user('angela').person) profile.add_friend(create_user('paula').person) profile.add_friend(create_user('jose').person) get :index assert_response :success assert_template 'index' assert_equal assigns(:friends).map(&:name), ['angela', 'jose', 'paula'] end should 'confirm removal of friend' do profile.add_friend(friend) get :remove, :id => friend.id assert_response :success assert_template 'remove' ok("must load the friend being removed") { friend == assigns(:friend) } end should 'actually remove friend' do profile.add_friend(friend) friend.add_friend(profile) assert_difference 'Friendship.count', -2 do post :remove, :id => friend.id, :confirmation => '1' assert_redirected_to :action => 'index' end end should 'display find people button' do get :index, :profile => 'testuser' assert_tag :tag => 'a', :content => 'Find people', :attributes => { :href => '/search/assets?asset=people'.html_safe } end should 'not display invite friends button if any plugin tells not to' do class Plugin1 < Noosfero::Plugin def remove_invite_friends_button true end end class Plugin2 < Noosfero::Plugin def remove_invite_friends_button false end end Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name]) e = profile.environment e.enable_plugin(Plugin1.name) e.enable_plugin(Plugin2.name) get :index, :profile => 'testuser' assert_no_tag :tag => 'a', :attributes => { :href => "/profile/testuser/invite/friends" } end should 'not display list suggestions button if there is no suggestion' do get :index, :profile => 'testuser' assert_no_tag :tag => 'a', :content => 'Suggest friends', :attributes => { :href => "/myprofile/testuser/friends/suggest" } end should 'display people suggestions' do profile.suggested_profiles.create(:suggestion => friend) get :suggest, :profile => 'testuser' assert_tag :tag => 'a', :content => "+ #{friend.name}", :attributes => { :href => "/profile/#{friend.identifier}/add" } end should 'display button to add friend suggestion' do profile.suggested_profiles.create(:suggestion => friend) get :suggest, :profile => 'testuser' assert_tag :tag => 'a', :attributes => { :href => "/profile/#{friend.identifier}/add" } end should 'display button to remove people suggestion' do profile.suggested_profiles.create(:suggestion => friend) get :suggest, :profile => 'testuser' assert_tag :tag => 'a', :attributes => { :href => /\/myprofile\/testuser\/friends\/remove_suggestion\/#{friend.identifier}/ } end should 'remove suggestion of friend' do suggestion = profile.suggested_profiles.create(:suggestion => friend) post :remove_suggestion, :profile => 'testuser', :id => friend.identifier assert_response :success assert_equal false, ProfileSuggestion.find(suggestion.id).enabled end end |