X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/98184dfb9cacc74ac5bcb91a41a2d5804b3f4f7d..250bb47cc2723c7af6fac0a6e9e900c1a50f9292:/test/controllers/user_controller_test.rb diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb index c068ee408..75d057b9f 100644 --- a/test/controllers/user_controller_test.rb +++ b/test/controllers/user_controller_test.rb @@ -195,13 +195,13 @@ class UserControllerTest < ActionController::TestCase end assert_select "body", :count => 1 do assert_select "div#content", :count => 1 do - assert_select "form[action='/user/new'][method=post]", :count => 1 do - assert_select "input[id=user_email]", :count => 1 - assert_select "input[id=user_email_confirmation]", :count => 1 - assert_select "input[id=user_display_name]", :count => 1 - assert_select "input[id=user_pass_crypt][type=password]", :count => 1 - assert_select "input[id=user_pass_crypt_confirmation][type=password]", :count => 1 - assert_select "input[type=submit][value=Sign Up]", :count => 1 + assert_select "form[action='/user/new'][method='post']", :count => 1 do + assert_select "input[id='user_email']", :count => 1 + assert_select "input[id='user_email_confirmation']", :count => 1 + assert_select "input[id='user_display_name']", :count => 1 + assert_select "input[id='user_pass_crypt'][type='password']", :count => 1 + assert_select "input[id='user_pass_crypt_confirmation'][type='password']", :count => 1 + assert_select "input[type='submit'][value='Sign Up']", :count => 1 end end end @@ -222,8 +222,8 @@ class UserControllerTest < ActionController::TestCase def test_user_create_success user = new_user - assert_difference('User.count') do - assert_difference('ActionMailer::Base.deliveries.size') do + assert_difference('User.count', 1) do + assert_difference('ActionMailer::Base.deliveries.size', 1) do post :save, {}, {:new_user => user} end end @@ -303,11 +303,17 @@ class UserControllerTest < ActionController::TestCase def test_user_save_referer_params user = new_user - post :save, {}, {:new_user => user, - :referer => '/edit?editor=id#map=1/2/3'} + assert_difference('User.count', 1) do + assert_difference('ActionMailer::Base.deliveries.size', 1) do + post :save, {}, {:new_user => user, + :referer => '/edit?editor=id#map=1/2/3'} + end + end assert_equal welcome_path(:editor => 'id', :zoom => 1, :lat => 2, :lon => 3), user.tokens.order("id DESC").first.referer + + ActionMailer::Base.deliveries.clear end def test_user_confirm_expired_token @@ -370,7 +376,10 @@ class UserControllerTest < ActionController::TestCase assert_response :redirect assert_redirected_to :action => :login assert_match /^Sorry you lost it/, flash[:notice] - assert_equal users(:normal_user).email, ActionMailer::Base.deliveries.last.to[0] + email = ActionMailer::Base.deliveries.first + assert_equal 1, email.to.count + assert_equal users(:normal_user).email, email.to.first + ActionMailer::Base.deliveries.clear # Test resetting using an address that matches a different user # that has the same address in a different case @@ -380,7 +389,10 @@ class UserControllerTest < ActionController::TestCase assert_response :redirect assert_redirected_to :action => :login assert_match /^Sorry you lost it/, flash[:notice] - assert_equal users(:uppercase_user).email, ActionMailer::Base.deliveries.last.to[0] + email = ActionMailer::Base.deliveries.first + assert_equal 1, email.to.count + assert_equal users(:uppercase_user).email, email.to.first + ActionMailer::Base.deliveries.clear # Test resetting using an address that is a case insensitive match # for more than one user but not an exact match for either @@ -399,7 +411,10 @@ class UserControllerTest < ActionController::TestCase assert_response :redirect assert_redirected_to :action => :login assert_match /^Sorry you lost it/, flash[:notice] - assert_equal users(:public_user).email, ActionMailer::Base.deliveries.last.to[0] + email = ActionMailer::Base.deliveries.first + assert_equal 1, email.to.count + assert_equal users(:public_user).email, email.to.first + ActionMailer::Base.deliveries.clear # Test resetting using an address that matches a user that has the # same (case insensitively unique) address in a different case @@ -409,7 +424,10 @@ class UserControllerTest < ActionController::TestCase assert_response :redirect assert_redirected_to :action => :login assert_match /^Sorry you lost it/, flash[:notice] - assert_equal users(:public_user).email, ActionMailer::Base.deliveries.last.to[0] + email = ActionMailer::Base.deliveries.first + assert_equal 1, email.to.count + assert_equal users(:public_user).email, email.to.first + ActionMailer::Base.deliveries.clear end def test_reset_password @@ -503,7 +521,9 @@ class UserControllerTest < ActionController::TestCase # Changing email to one that exists should fail user.new_email = users(:public_user).email - post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id } + assert_no_difference('ActionMailer::Base.deliveries.size') do + post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id } + end assert_response :success assert_template :account assert_select ".notice", false @@ -512,7 +532,9 @@ class UserControllerTest < ActionController::TestCase # Changing email to one that exists should fail, regardless of case user.new_email = users(:public_user).email.upcase - post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id } + assert_no_difference('ActionMailer::Base.deliveries.size') do + post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id } + end assert_response :success assert_template :account assert_select ".notice", false @@ -521,12 +543,18 @@ class UserControllerTest < ActionController::TestCase # Changing email to one that doesn't exist should work user.new_email = "new_tester@example.com" - post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id } + assert_difference('ActionMailer::Base.deliveries.size', 1) do + post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id } + end assert_response :success assert_template :account assert_select "div#errorExplanation", false assert_select ".notice", /^User information updated successfully/ assert_select "form#accountForm > fieldset > div.form-row > input#user_new_email[value=?]", user.new_email + email = ActionMailer::Base.deliveries.first + assert_equal 1, email.to.count + assert_equal user.new_email, email.to.first + ActionMailer::Base.deliveries.clear end # Check that the user account page will display and contains some relevant @@ -540,42 +568,42 @@ class UserControllerTest < ActionController::TestCase get :view, {:display_name => "test"} assert_response :success assert_select "div#userinformation" do - assert_select "a[href^=/user/test/history]", 1 - assert_select "a[href=/user/test/traces]", 1 - assert_select "a[href=/user/test/diary]", 1 - assert_select "a[href=/user/test/diary/comments]", 1 - assert_select "a[href=/user/test/account]", 0 - assert_select "a[href=/user/test/blocks]", 0 - assert_select "a[href=/user/test/blocks_by]", 0 - assert_select "a[href=/blocks/new/test]", 0 + assert_select "a[href^='/user/test/history']", 1 + assert_select "a[href='/user/test/traces']", 1 + assert_select "a[href='/user/test/diary']", 1 + assert_select "a[href='/user/test/diary/comments']", 1 + assert_select "a[href='/user/test/account']", 0 + assert_select "a[href='/user/test/blocks']", 0 + assert_select "a[href='/user/test/blocks_by']", 0 + assert_select "a[href='/blocks/new/test']", 0 end # Test a user who has been blocked get :view, {:display_name => "blocked"} assert_response :success assert_select "div#userinformation" do - assert_select "a[href^=/user/blocked/history]", 1 - assert_select "a[href=/user/blocked/traces]", 1 - assert_select "a[href=/user/blocked/diary]", 1 - assert_select "a[href=/user/blocked/diary/comments]", 1 - assert_select "a[href=/user/blocked/account]", 0 - assert_select "a[href=/user/blocked/blocks]", 1 - assert_select "a[href=/user/blocked/blocks_by]", 0 - assert_select "a[href=/blocks/new/blocked]", 0 + assert_select "a[href^='/user/blocked/history']", 1 + assert_select "a[href='/user/blocked/traces']", 1 + assert_select "a[href='/user/blocked/diary']", 1 + assert_select "a[href='/user/blocked/diary/comments']", 1 + assert_select "a[href='/user/blocked/account']", 0 + assert_select "a[href='/user/blocked/blocks']", 1 + assert_select "a[href='/user/blocked/blocks_by']", 0 + assert_select "a[href='/blocks/new/blocked']", 0 end # Test a moderator who has applied blocks get :view, {:display_name => "moderator"} assert_response :success assert_select "div#userinformation" do - assert_select "a[href^=/user/moderator/history]", 1 - assert_select "a[href=/user/moderator/traces]", 1 - assert_select "a[href=/user/moderator/diary]", 1 - assert_select "a[href=/user/moderator/diary/comments]", 1 - assert_select "a[href=/user/moderator/account]", 0 - assert_select "a[href=/user/moderator/blocks]", 0 - assert_select "a[href=/user/moderator/blocks_by]", 1 - assert_select "a[href=/blocks/new/moderator]", 0 + assert_select "a[href^='/user/moderator/history']", 1 + assert_select "a[href='/user/moderator/traces']", 1 + assert_select "a[href='/user/moderator/diary']", 1 + assert_select "a[href='/user/moderator/diary/comments']", 1 + assert_select "a[href='/user/moderator/account']", 0 + assert_select "a[href='/user/moderator/blocks']", 0 + assert_select "a[href='/user/moderator/blocks_by']", 1 + assert_select "a[href='/blocks/new/moderator']", 0 end # Login as a normal user @@ -585,14 +613,14 @@ class UserControllerTest < ActionController::TestCase get :view, {:display_name => "test"} assert_response :success assert_select "div#userinformation" do - assert_select "a[href^=/user/test/history]", 1 - assert_select "a[href=/traces/mine]", 1 - assert_select "a[href=/user/test/diary]", 1 - assert_select "a[href=/user/test/diary/comments]", 1 - assert_select "a[href=/user/test/account]", 1 - assert_select "a[href=/user/test/blocks]", 0 - assert_select "a[href=/user/test/blocks_by]", 0 - assert_select "a[href=/blocks/new/test]", 0 + assert_select "a[href^='/user/test/history']", 1 + assert_select "a[href='/traces/mine']", 1 + assert_select "a[href='/user/test/diary']", 1 + assert_select "a[href='/user/test/diary/comments']", 1 + assert_select "a[href='/user/test/account']", 1 + assert_select "a[href='/user/test/blocks']", 0 + assert_select "a[href='/user/test/blocks_by']", 0 + assert_select "a[href='/blocks/new/test']", 0 end # Login as a moderator @@ -602,14 +630,14 @@ class UserControllerTest < ActionController::TestCase get :view, {:display_name => "test"} assert_response :success assert_select "div#userinformation" do - assert_select "a[href^=/user/test/history]", 1 - assert_select "a[href=/user/test/traces]", 1 - assert_select "a[href=/user/test/diary]", 1 - assert_select "a[href=/user/test/diary/comments]", 1 - assert_select "a[href=/user/test/account]", 0 - assert_select "a[href=/user/test/blocks]", 0 - assert_select "a[href=/user/test/blocks_by]", 0 - assert_select "a[href=/blocks/new/test]", 1 + assert_select "a[href^='/user/test/history']", 1 + assert_select "a[href='/user/test/traces']", 1 + assert_select "a[href='/user/test/diary']", 1 + assert_select "a[href='/user/test/diary/comments']", 1 + assert_select "a[href='/user/test/account']", 0 + assert_select "a[href='/user/test/blocks']", 0 + assert_select "a[href='/user/test/blocks_by']", 0 + assert_select "a[href='/blocks/new/test']", 1 end end @@ -621,21 +649,21 @@ class UserControllerTest < ActionController::TestCase # check the data that is returned assert_select "description", :count => 1, :text => "test" assert_select "contributor-terms", :count => 1 do - assert_select "[agreed=true]" + assert_select "[agreed='true']" end assert_select "img", :count => 1 assert_select "roles", :count => 1 do assert_select "role", :count => 0 end assert_select "changesets", :count => 1 do - assert_select "[count=0]" + assert_select "[count='0']" end assert_select "traces", :count => 1 do - assert_select "[count=0]" + assert_select "[count='0']" end assert_select "blocks", :count => 1 do assert_select "received", :count => 1 do - assert_select "[count=0][active=0]" + assert_select "[count='0'][active='0']" end assert_select "issued", :count => 0 end @@ -672,36 +700,36 @@ class UserControllerTest < ActionController::TestCase # check the data that is returned assert_select "description", :count => 1, :text => "test" assert_select "contributor-terms", :count => 1 do - assert_select "[agreed=true][pd=false]" + assert_select "[agreed='true'][pd='false']" end assert_select "img", :count => 1 assert_select "roles", :count => 1 do assert_select "role", :count => 0 end assert_select "changesets", :count => 1 do - assert_select "[count=0]", :count => 1 + assert_select "[count='0']", :count => 1 end assert_select "traces", :count => 1 do - assert_select "[count=0]", :count => 1 + assert_select "[count='0']", :count => 1 end assert_select "blocks", :count => 1 do assert_select "received", :count => 1 do - assert_select "[count=0][active=0]" + assert_select "[count='0'][active='0']" end assert_select "issued", :count => 0 end assert_select "home", :count => 1 do - assert_select "[lat=12.1][lon=12.1][zoom=3]" + assert_select "[lat='12.1'][lon='12.1'][zoom='3']" end assert_select "languages", :count => 1 do assert_select "lang", :count => 1, :text => "en" end assert_select "messages", :count => 1 do assert_select "received", :count => 1 do - assert_select "[count=1][unread=0]" + assert_select "[count='1'][unread='0']" end assert_select "sent", :count => 1 do - assert_select "[count=1]" + assert_select "[count='1']" end end end @@ -728,8 +756,8 @@ class UserControllerTest < ActionController::TestCase assert_response :success assert_template :make_friend assert_select "form" do - assert_select "input[type=hidden][name=referer]", 0 - assert_select "input[type=submit]", 1 + assert_select "input[type='hidden'][name='referer']", 0 + assert_select "input[type='submit']", 1 end assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first @@ -738,19 +766,27 @@ class UserControllerTest < ActionController::TestCase assert_response :success assert_template :make_friend assert_select "form" do - assert_select "input[type=hidden][name=referer][value=/test]", 1 - assert_select "input[type=submit]", 1 + assert_select "input[type='hidden'][name='referer'][value='/test']", 1 + assert_select "input[type='submit']", 1 end assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first # When logged in a POST should add the friendship - post :make_friend, {:display_name => friend.display_name}, {"user" => user} + assert_difference('ActionMailer::Base.deliveries.size', 1) do + post :make_friend, {:display_name => friend.display_name}, {"user" => user} + end assert_redirected_to user_path(:display_name => friend.display_name) 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 + assert_equal friend.email, email.to.first + ActionMailer::Base.deliveries.clear # A second POST should report that the friendship already exists - post :make_friend, {:display_name => friend.display_name}, {"user" => user} + assert_no_difference('ActionMailer::Base.deliveries.size') do + post :make_friend, {:display_name => friend.display_name}, {"user" => user} + end assert_redirected_to user_path(:display_name => friend.display_name) assert_match /You are already friends with/, flash[:warning] assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first @@ -778,8 +814,8 @@ class UserControllerTest < ActionController::TestCase assert_response :success assert_template :remove_friend assert_select "form" do - assert_select "input[type=hidden][name=referer]", 0 - assert_select "input[type=submit]", 1 + assert_select "input[type='hidden'][name='referer']", 0 + assert_select "input[type='submit']", 1 end assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first @@ -788,8 +824,8 @@ class UserControllerTest < ActionController::TestCase assert_response :success assert_template :remove_friend assert_select "form" do - assert_select "input[type=hidden][name=referer][value=/test]", 1 - assert_select "input[type=submit]", 1 + assert_select "input[type='hidden'][name='referer'][value='/test']", 1 + assert_select "input[type='submit']", 1 end assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first