X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/276599d34fcbd7babc8e34b6859459cb44acabe7..8877427ab9e49f509414c2fa4d71ccc3e2ac8796:/test/controllers/user_controller_test.rb diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb index f2aaffb9b..ffae32d0c 100644 --- a/test/controllers/user_controller_test.rb +++ b/test/controllers/user_controller_test.rb @@ -245,7 +245,7 @@ class UserControllerTest < ActionController::TestCase register_email = ActionMailer::Base.deliveries.first assert_equal register_email.to[0], user.email - assert_match /#{@url}/, register_email.body.to_s + assert_match(/#{@url}/, register_email.body.to_s) # Check the page assert_redirected_to :action => "confirm", :display_name => user.display_name @@ -404,7 +404,7 @@ class UserControllerTest < ActionController::TestCase @request.cookies["_osm_session"] = user.display_name post :confirm, :params => { :display_name => user.display_name, :confirm_string => confirm_string } assert_redirected_to login_path - assert_match /Confirmed your account/, flash[:notice] + assert_match(/Confirmed your account/, flash[:notice]) end def test_confirm_success_good_token_no_referer @@ -427,7 +427,7 @@ class UserControllerTest < ActionController::TestCase @request.cookies["_osm_session"] = user.display_name post :confirm, :params => { :display_name => user.display_name, :confirm_string => confirm_string }, :session => { :token => token } assert_redirected_to login_path - assert_match /Confirmed your account/, flash[:notice] + assert_match(/Confirmed your account/, flash[:notice]) end def test_confirm_success_no_token_with_referer @@ -438,7 +438,7 @@ class UserControllerTest < ActionController::TestCase @request.cookies["_osm_session"] = user.display_name post :confirm, :params => { :display_name => user.display_name, :confirm_string => confirm_string } assert_redirected_to login_path(:referer => diary_new_path) - assert_match /Confirmed your account/, flash[:notice] + assert_match(/Confirmed your account/, flash[:notice]) end def test_confirm_success_good_token_with_referer @@ -461,7 +461,7 @@ class UserControllerTest < ActionController::TestCase @request.cookies["_osm_session"] = user.display_name post :confirm, :params => { :display_name => user.display_name, :confirm_string => confirm_string }, :session => { :token => token } assert_redirected_to login_path(:referer => diary_new_path) - assert_match /Confirmed your account/, flash[:notice] + assert_match(/Confirmed your account/, flash[:notice]) end def test_confirm_expired_token @@ -471,7 +471,7 @@ class UserControllerTest < ActionController::TestCase @request.cookies["_osm_session"] = user.display_name post :confirm, :params => { :display_name => user.display_name, :confirm_string => confirm_string } assert_redirected_to :action => "confirm" - assert_match /confirmation code has expired/, flash[:error] + assert_match(/confirmation code has expired/, flash[:error]) end def test_confirm_already_confirmed @@ -481,7 +481,7 @@ class UserControllerTest < ActionController::TestCase @request.cookies["_osm_session"] = user.display_name post :confirm, :params => { :display_name => user.display_name, :confirm_string => confirm_string } assert_redirected_to :action => "login" - assert_match /already been confirmed/, flash[:error] + assert_match(/already been confirmed/, flash[:error]) end def test_confirm_resend_success @@ -494,7 +494,7 @@ class UserControllerTest < ActionController::TestCase assert_response :redirect assert_redirected_to login_path - assert_match /sent a new confirmation/, flash[:notice] + assert_match(/sent a new confirmation/, flash[:notice]) email = ActionMailer::Base.deliveries.last @@ -541,7 +541,7 @@ class UserControllerTest < ActionController::TestCase post :confirm_email, :params => { :confirm_string => confirm_string } assert_response :redirect assert_redirected_to :action => :account, :display_name => user.display_name - assert_match /Confirmed your change of email address/, flash[:notice] + assert_match(/Confirmed your change of email address/, flash[:notice]) end def test_confirm_email_already_confirmed @@ -551,14 +551,14 @@ class UserControllerTest < ActionController::TestCase post :confirm_email, :params => { :confirm_string => confirm_string } assert_response :redirect assert_redirected_to :action => :account, :display_name => user.display_name - assert_match /already been confirmed/, flash[:error] + assert_match(/already been confirmed/, flash[:error]) end def test_confirm_email_bad_token post :confirm_email, :params => { :confirm_string => "XXXXX" } assert_response :success assert_template :confirm_email - assert_match /confirmation code has expired or does not exist/, flash[:error] + assert_match(/confirmation code has expired or does not exist/, flash[:error]) end ## @@ -575,7 +575,7 @@ class UserControllerTest < ActionController::TestCase post :confirm_email, :params => { :confirm_string => confirm_string } assert_response :redirect assert_redirected_to :action => :account, :display_name => user.display_name - assert_match /Confirmed your change of email address/, flash[:notice] + assert_match(/Confirmed your change of email address/, flash[:notice]) # gravatar use should now be enabled assert User.find(user.id).image_use_gravatar end @@ -590,7 +590,7 @@ class UserControllerTest < ActionController::TestCase post :confirm_email, :params => { :confirm_string => confirm_string } assert_response :redirect assert_redirected_to :action => :account, :display_name => user.display_name - assert_match /Confirmed your change of email address/, flash[:notice] + assert_match(/Confirmed your change of email address/, flash[:notice]) # gravatar use should now be disabled assert_not User.find(user.id).image_use_gravatar end @@ -678,7 +678,7 @@ class UserControllerTest < ActionController::TestCase end assert_response :redirect assert_redirected_to :action => :login - assert_match /^Sorry you lost it/, flash[:notice] + assert_match(/^Sorry you lost it/, flash[:notice]) email = ActionMailer::Base.deliveries.first assert_equal 1, email.to.count assert_equal user.email, email.to.first @@ -691,7 +691,7 @@ class UserControllerTest < ActionController::TestCase end assert_response :redirect assert_redirected_to :action => :login - assert_match /^Sorry you lost it/, flash[:notice] + assert_match(/^Sorry you lost it/, flash[:notice]) email = ActionMailer::Base.deliveries.first assert_equal 1, email.to.count assert_equal uppercase_user.email, email.to.first @@ -714,7 +714,7 @@ class UserControllerTest < ActionController::TestCase end assert_response :redirect assert_redirected_to :action => :login - assert_match /^Sorry you lost it/, flash[:notice] + assert_match(/^Sorry you lost it/, flash[:notice]) email = ActionMailer::Base.deliveries.first assert_equal 1, email.to.count assert_equal third_user.email, email.to.first @@ -727,7 +727,7 @@ class UserControllerTest < ActionController::TestCase end assert_response :redirect assert_redirected_to :action => :login - assert_match /^Sorry you lost it/, flash[:notice] + assert_match(/^Sorry you lost it/, flash[:notice]) email = ActionMailer::Base.deliveries.first assert_equal 1, email.to.count assert_equal third_user.email, email.to.first @@ -942,6 +942,7 @@ class UserControllerTest < ActionController::TestCase # Test a normal user user = create(:user) + create(:friend, :befriender => user) get :show, :params => { :display_name => user.display_name } assert_response :success assert_select "div#userinformation" do @@ -955,6 +956,9 @@ class UserControllerTest < ActionController::TestCase assert_select "a[href='/blocks/new/#{ERB::Util.u(user.display_name)}']", 0 end + # Friends shouldn't be visible as we're not logged in + assert_select "div#friends-container", :count => 0 + # Test a user who has been blocked blocked_user = create(:user) create(:user_block, :user => blocked_user) @@ -1004,6 +1008,11 @@ class UserControllerTest < ActionController::TestCase assert_select "a[href='/blocks/new/#{ERB::Util.u(user.display_name)}']", 0 end + # Friends should be visible as we're now logged in + assert_select "div#friends-container" do + assert_select "div.contact-activity", :count => 1 + end + # Login as a moderator session[:user] = create(:moderator_user).id @@ -1251,7 +1260,7 @@ class UserControllerTest < ActionController::TestCase post :make_friend, :params => { :display_name => friend.display_name }, :session => { :user => user } end assert_redirected_to user_path(friend) - assert_match /is now your friend/, flash[:notice] + assert_match(/is now your friend/, flash[:notice]) assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first email = ActionMailer::Base.deliveries.first assert_equal 1, email.to.count @@ -1263,7 +1272,7 @@ class UserControllerTest < ActionController::TestCase post :make_friend, :params => { :display_name => friend.display_name }, :session => { :user => user } end assert_redirected_to user_path(friend) - assert_match /You are already friends with/, flash[:warning] + assert_match(/You are already friends with/, flash[:warning]) assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first end @@ -1290,7 +1299,7 @@ class UserControllerTest < ActionController::TestCase post :make_friend, :params => { :display_name => friend.display_name, :referer => "/test" }, :session => { :user => user } end assert_redirected_to "/test" - assert_match /is now your friend/, flash[:notice] + assert_match(/is now your friend/, flash[:notice]) assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first email = ActionMailer::Base.deliveries.first assert_equal 1, email.to.count @@ -1336,13 +1345,13 @@ class UserControllerTest < ActionController::TestCase # When logged in a POST should remove the friendship post :remove_friend, :params => { :display_name => friend.display_name }, :session => { :user => user } assert_redirected_to user_path(friend) - assert_match /was removed from your friends/, flash[:notice] + assert_match(/was removed from your friends/, flash[:notice]) assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first # A second POST should report that the friendship does not exist post :remove_friend, :params => { :display_name => friend.display_name }, :session => { :user => user } assert_redirected_to user_path(friend) - assert_match /is not one of your friends/, flash[:error] + assert_match(/is not one of your friends/, flash[:error]) assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first end @@ -1368,7 +1377,7 @@ class UserControllerTest < ActionController::TestCase # When logged in a POST should remove the friendship and refer post :remove_friend, :params => { :display_name => friend.display_name, :referer => "/test" }, :session => { :user => user } assert_redirected_to "/test" - assert_match /was removed from your friends/, flash[:notice] + assert_match(/was removed from your friends/, flash[:notice]) assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first end