X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/f1935b1c5786de8f27bee9b6b2da2f28f650468f..380027ffe0ca1b741148d8f66c6fcb4c450ce588:/test/controllers/users_controller_test.rb?ds=sidebyside diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index a73e48211..dda157f01 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -39,15 +39,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest { :controller => "users", :action => "show", :display_name => "username" } ) - assert_routing( - { :path => "/user/username/account", :method => :get }, - { :controller => "users", :action => "account", :display_name => "username" } - ) - assert_routing( - { :path => "/user/username/account", :method => :post }, - { :controller => "users", :action => "account", :display_name => "username" } - ) - assert_routing( { :path => "/user/username/set_status", :method => :post }, { :controller => "users", :action => "set_status", :display_name => "username" } @@ -78,7 +69,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # The user creation page loads def test_new_view get user_new_path - assert_response :redirect assert_redirected_to user_new_path(:cookie_test => "true") get user_new_path, :params => { :cookie_test => "true" } @@ -92,7 +82,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest 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 @@ -107,29 +96,19 @@ class UsersControllerTest < ActionDispatch::IntegrationTest session_for(create(:user)) get user_new_path - assert_response :redirect assert_redirected_to root_path get user_new_path, :params => { :referer => "/test" } - assert_response :redirect assert_redirected_to "/test" end def test_new_success user = build(:user, :pending) - assert_no_difference "User.count" do - assert_no_difference "ActionMailer::Base.deliveries.size" do - perform_enqueued_jobs do - post user_new_path, :params => { :user => user.attributes } - end - end - end - assert_difference "User.count", 1 do assert_difference "ActionMailer::Base.deliveries.size", 1 do perform_enqueued_jobs do - post user_save_path, :params => { :read_ct => 1, :read_tou => 1 } + post user_new_path, :params => { :user => user.attributes } end end end @@ -160,137 +139,63 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_template "new" - assert_select "form > div.form-group > input.is-invalid#user_email" - end - - def test_save_duplicate_email - user = build(:user, :pending) - - # Set up our user as being half-way through registration - assert_no_difference "User.count" do - assert_no_difference "ActionMailer::Base.deliveries.size" do - perform_enqueued_jobs do - post user_new_path, :params => { :user => user.attributes } - end - end - end - - # Now create another user with that email - create(:user, :email => user.email) - - # Check that the second half of registration fails - assert_no_difference "User.count" do - assert_no_difference "ActionMailer::Base.deliveries.size" do - perform_enqueued_jobs do - post user_save_path, :params => { :read_ct => 1, :read_tou => 1 } - end - end - end - - assert_response :success - assert_template "new" - assert_select "form > div.form-group > input.is-invalid#user_email" + assert_select "form > div > input.is-invalid#user_email" end - def test_save_duplicate_email_uppercase + def test_new_duplicate_email_uppercase user = build(:user, :pending) - - # Set up our user as being half-way through registration - assert_no_difference "User.count" do - assert_no_difference "ActionMailer::Base.deliveries.size" do - perform_enqueued_jobs do - post user_new_path, :params => { :user => user.attributes } - end - end - end - - # Now create another user with that email, but uppercased create(:user, :email => user.email.upcase) - # Check that the second half of registration fails assert_no_difference "User.count" do assert_no_difference "ActionMailer::Base.deliveries.size" do perform_enqueued_jobs do - post user_save_path, :params => { :read_ct => 1, :read_tou => 1 } + post user_new_path, :params => { :user => user.attributes } end end end assert_response :success assert_template "new" - assert_select "form > div.form-group > input.is-invalid#user_email" + assert_select "form > div > input.is-invalid#user_email" end - def test_save_duplicate_name + def test_new_duplicate_name user = build(:user, :pending) - - # Set up our user as being half-way through registration - assert_no_difference "User.count" do - assert_no_difference "ActionMailer::Base.deliveries.size" do - perform_enqueued_jobs do - post user_new_path, :params => { :user => user.attributes } - end - end - end - - # Now create another user with that display name create(:user, :display_name => user.display_name) - # Check that the second half of registration fails assert_no_difference "User.count" do assert_no_difference "ActionMailer::Base.deliveries.size" do perform_enqueued_jobs do - post user_save_path, :params => { :read_ct => 1, :read_tou => 1 } + post user_new_path, :params => { :user => user.attributes } end end end assert_response :success assert_template "new" - assert_select "form > div.form-group > input.is-invalid#user_display_name" + assert_select "form > div > input.is-invalid#user_display_name" end - def test_save_duplicate_name_uppercase + def test_new_duplicate_name_uppercase user = build(:user, :pending) - - # Set up our user as being half-way through registration - assert_no_difference "User.count" do - assert_no_difference "ActionMailer::Base.deliveries.size" do - perform_enqueued_jobs do - post user_new_path, :params => { :user => user.attributes } - end - end - end - - # Now create another user with that display_name, but uppercased create(:user, :display_name => user.display_name.upcase) - # Check that the second half of registration fails assert_no_difference "User.count" do assert_no_difference "ActionMailer::Base.deliveries.size" do perform_enqueued_jobs do - post user_save_path, :params => { :read_ct => 1, :read_tou => 1 } + post user_new_path, :params => { :user => user.attributes } end end end assert_response :success assert_template "new" - assert_select "form > div.form-group > input.is-invalid#user_display_name" + assert_select "form > div > input.is-invalid#user_display_name" end - def test_save_blocked_domain + def test_new_blocked_domain user = build(:user, :pending, :email => "user@example.net") - # Set up our user as being half-way through registration - assert_no_difference "User.count" do - assert_no_difference "ActionMailer::Base.deliveries.size" do - perform_enqueued_jobs do - post user_new_path, :params => { :user => user.attributes } - end - end - end - # Now block that domain create(:acl, :domain => "example.net", :k => "no_account_creation") @@ -298,7 +203,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_no_difference "User.count" do assert_no_difference "ActionMailer::Base.deliveries.size" do perform_enqueued_jobs do - post user_save_path, :params => { :read_ct => 1, :read_tou => 1 } + post user_new_path, :params => { :user => user.attributes } end end end @@ -310,55 +215,25 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_save_referer_params user = build(:user, :pending) - # Set up our user as being half-way through registration - assert_no_difference "User.count" do - assert_no_difference "ActionMailer::Base.deliveries.size" do - perform_enqueued_jobs do - post user_new_path, :params => { :user => user.attributes, :referer => "/edit?editor=id#map=1/2/3" } - end - end - end - assert_difference "User.count", 1 do assert_difference "ActionMailer::Base.deliveries.size", 1 do - perform_enqueued_jobs do - post user_save_path, :params => { :read_ct => 1, :read_tou => 1 } - end + post user_new_path, :params => { :user => user.attributes, :referer => "/edit?editor=id#map=1/2/3" } + assert_enqueued_with :job => ActionMailer::MailDeliveryJob, + :args => proc { |args| args[3][:args][2] == welcome_path(:editor => "id", :zoom => 1, :lat => 2, :lon => 3) } + perform_enqueued_jobs end end - assert_equal welcome_path(:editor => "id", :zoom => 1, :lat => 2, :lon => 3), - User.find_by(:email => user.email).tokens.order("id DESC").first.referer - ActionMailer::Base.deliveries.clear end - def test_terms_new_user - user = build(:user, :pending) - - # Set up our user as being half-way through registration - assert_no_difference "User.count" do - assert_no_difference "ActionMailer::Base.deliveries.size" do - perform_enqueued_jobs do - post user_new_path, :params => { :user => user.attributes } - end - end - end - - get user_terms_path - - assert_response :success - assert_template :terms - end - def test_terms_agreed user = create(:user, :terms_seen => true, :terms_agreed => Date.yesterday) session_for(user) get user_terms_path - assert_response :redirect - assert_redirected_to :action => :account, :display_name => user.display_name + assert_redirected_to edit_account_path end def test_terms_not_seen_without_referer @@ -371,8 +246,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_template :terms post user_save_path, :params => { :user => { :consider_pd => true }, :read_ct => 1, :read_tou => 1 } - assert_response :redirect - assert_redirected_to :action => :account, :display_name => user.display_name + assert_redirected_to edit_account_path assert_equal "Thanks for accepting the new contributor terms!", flash[:notice] user.reload @@ -392,7 +266,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_template :terms post user_save_path, :params => { :user => { :consider_pd => true }, :referer => "/test", :read_ct => 1, :read_tou => 1 } - assert_response :redirect assert_redirected_to "/test" assert_equal "Thanks for accepting the new contributor terms!", flash[:notice] @@ -409,9 +282,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest user = create(:user, :terms_seen => false, :terms_agreed => nil) session_for(user) - get user_account_path(user) - assert_response :redirect - assert_redirected_to :action => :terms, :referer => "/user/#{ERB::Util.u(user.display_name)}/account" + get edit_account_path + assert_redirected_to :controller => :users, :action => :terms, :referer => "/account/edit" + end + + def test_terms_not_logged_in + get user_terms_path + + assert_redirected_to login_path(:referer => "/user/terms") end def test_go_public @@ -420,144 +298,23 @@ class UsersControllerTest < ActionDispatch::IntegrationTest post user_go_public_path - assert_response :redirect - assert_redirected_to :action => :account, :display_name => user.display_name + assert_redirected_to edit_account_path assert User.find(user.id).data_public end - def test_account - # Get a user to work with - note that this user deliberately - # conflicts with uppercase_user in the email and display name - # fields to test that we can change other fields without any - # validation errors being reported - user = create(:user, :languages => []) - _uppercase_user = build(:user, :email => user.email.upcase, :display_name => user.display_name.upcase).tap { |u| u.save(:validate => false) } - - # Make sure that you are redirected to the login page when - # you are not logged in - get user_account_path(user) - assert_response :redirect - assert_redirected_to login_path(:referer => "/user/#{ERB::Util.u(user.display_name)}/account") - - # Make sure that you are blocked when not logged in as the right user - session_for(create(:user)) - get user_account_path(user) - assert_response :forbidden - - # Make sure we get the page when we are logged in as the right user - session_for(user) - get user_account_path(user) - assert_response :success - assert_template :account - assert_select "form#accountForm" do |form| - assert_equal "post", form.attr("method").to_s - assert_select "input[name='_method']", false - assert_equal "/user/#{ERB::Util.u(user.display_name)}/account", form.attr("action").to_s - end - - # Updating the description using GET should fail - user.description = "new description" - user.preferred_editor = "default" - get user_account_path(user), :params => { :user => user.attributes } - assert_response :success - assert_template :account - assert_not_equal user.description, User.find(user.id).description - - # Adding external authentication should redirect to the auth provider - post user_account_path(user), :params => { :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") } - assert_response :redirect - assert_redirected_to auth_path(:provider => "openid", :openid_url => "https://www.google.com/accounts/o8/id", :origin => "/user/#{ERB::Util.u(user.display_name)}/account") - - # Changing name to one that exists should fail - new_attributes = user.attributes.dup.merge(:display_name => create(:user).display_name) - post user_account_path(user), :params => { :user => new_attributes } - assert_response :success - assert_template :account - assert_select ".notice", false - assert_select "form#accountForm > div.form-group > input.is-invalid#user_display_name" - - # Changing name to one that exists should fail, regardless of case - new_attributes = user.attributes.dup.merge(:display_name => create(:user).display_name.upcase) - post user_account_path(user), :params => { :user => new_attributes } - assert_response :success - assert_template :account - assert_select ".notice", false - assert_select "form#accountForm > div.form-group > input.is-invalid#user_display_name" - - # Changing name to one that doesn't exist should work - new_attributes = user.attributes.dup.merge(:display_name => "new tester") - post user_account_path(user), :params => { :user => new_attributes } - assert_response :redirect - assert_redirected_to user_account_url(:display_name => "new tester") - get user_account_path(:display_name => "new tester") - assert_response :success - assert_template :account - assert_select ".notice", /^User information updated successfully/ - assert_select "form#accountForm > div.form-group > input#user_display_name[value=?]", "new tester" - - # Record the change of name - user.display_name = "new tester" - - # Changing email to one that exists should fail - user.new_email = create(:user).email - assert_no_difference "ActionMailer::Base.deliveries.size" do - perform_enqueued_jobs do - post user_account_path(user), :params => { :user => user.attributes } - end - end - assert_response :success - assert_template :account - assert_select ".notice", false - assert_select "form#accountForm > div.form-group > input.is-invalid#user_new_email" - - # Changing email to one that exists should fail, regardless of case - user.new_email = create(:user).email.upcase - assert_no_difference "ActionMailer::Base.deliveries.size" do - perform_enqueued_jobs do - post user_account_path(user), :params => { :user => user.attributes } - end - end - assert_response :success - assert_template :account - assert_select ".notice", false - assert_select "form#accountForm > div.form-group > input.is-invalid#user_new_email" - - # Changing email to one that doesn't exist should work - user.new_email = "new_tester@example.com" - assert_difference "ActionMailer::Base.deliveries.size", 1 do - perform_enqueued_jobs do - post user_account_path(user), :params => { :user => user.attributes } - end - end - assert_response :redirect - assert_redirected_to user_account_url(user) - get user_account_path(user) - assert_response :success - assert_template :account - assert_select ".notice", /^User information updated successfully/ - assert_select "form#accountForm > div.form-group > 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 # information for the user def test_show # Test a non-existent user - get user_path(:display_name => "unknown") + get user_path("unknown") assert_response :not_found # Test a normal user - user = create(:user, :home_lon => 1.1, :home_lat => 1.1) - friend_user = create(:user, :home_lon => 1.2, :home_lat => 1.2) - create(:friendship, :befriender => user, :befriendee => friend_user) - create(:changeset, :user => friend_user) + user = create(:user) get user_path(user) assert_response :success - assert_select "div#userinformation" do + assert_select "div.content-heading" do assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/traces']", 1 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary']", 1 @@ -568,15 +325,12 @@ class UsersControllerTest < ActionDispatch::IntegrationTest 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) get user_path(blocked_user) assert_response :success - assert_select "div#userinformation" do + assert_select "div.content-heading" do assert_select "a[href^='/user/#{ERB::Util.u(blocked_user.display_name)}/history']", 1 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/traces']", 1 assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/diary']", 1 @@ -592,7 +346,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest create(:user_block, :creator => moderator_user) get user_path(moderator_user) assert_response :success - assert_select "div#userinformation" do + assert_select "div.content-heading" do assert_select "a[href^='/user/#{ERB::Util.u(moderator_user.display_name)}/history']", 1 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/traces']", 1 assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/diary']", 1 @@ -609,20 +363,16 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # Test the normal user get user_path(user) assert_response :success - assert_select "div#userinformation" do + assert_select "div.content-heading" do assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1 assert_select "a[href='/traces/mine']", 1 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary']", 1 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary/comments']", 1 - assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/account']", 1 + assert_select "a[href='/account/edit']", 1 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks']", 0 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks_by']", 0 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 + assert_select "a[href='/api/0.6/user/#{ERB::Util.u(user.id)}']", 0 end # Login as a moderator @@ -631,15 +381,16 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # Test the normal user get user_path(user) assert_response :success - assert_select "div#userinformation" do + assert_select "div.content-heading" do assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/traces']", 1 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary']", 1 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary/comments']", 1 - assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/account']", 0 + assert_select "a[href='/account/edit']", 0 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks']", 0 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks_by']", 0 assert_select "a[href='/blocks/new/#{ERB::Util.u(user.display_name)}']", 1 + assert_select "a[href='/api/0.6/user/#{ERB::Util.u(user.id)}']", 1 end end @@ -651,23 +402,22 @@ class UsersControllerTest < ActionDispatch::IntegrationTest get user_path(agreed_user) assert_response :success - assert_select "div#userinformation" do - assert_select "p", :count => 0, :text => /Contributor terms/ + assert_select "div.content-heading" do + assert_select "dt", :count => 0, :text => /Contributor terms/ end get user_path(seen_user) assert_response :success - # put @response.body - assert_select "div#userinformation" do - assert_select "p", :count => 1, :text => /Contributor terms/ - assert_select "p", /Declined/ + assert_select "div.content-heading" do + assert_select "dt", :count => 1, :text => /Contributor terms/ + assert_select "dd", /Declined/ end get user_path(not_seen_user) assert_response :success - assert_select "div#userinformation" do - assert_select "p", :count => 1, :text => /Contributor terms/ - assert_select "p", /Undecided/ + assert_select "div.content-heading" do + assert_select "dt", :count => 1, :text => /Contributor terms/ + assert_select "dd", /Undecided/ end end @@ -675,40 +425,36 @@ class UsersControllerTest < ActionDispatch::IntegrationTest user = create(:user) # Try without logging in - post set_status_user_path(user), :params => { :status => "suspended" } + post set_status_user_path(user), :params => { :event => "confirm" } assert_response :forbidden # Now try as a normal user session_for(user) - post set_status_user_path(user), :params => { :status => "suspended" } - assert_response :redirect + post set_status_user_path(user), :params => { :event => "confirm" } assert_redirected_to :controller => :errors, :action => :forbidden # Finally try as an administrator session_for(create(:administrator_user)) - post set_status_user_path(user), :params => { :status => "suspended" } - assert_response :redirect + post set_status_user_path(user), :params => { :event => "confirm" } assert_redirected_to :action => :show, :display_name => user.display_name - assert_equal "suspended", User.find(user.id).status + assert_equal "confirmed", User.find(user.id).status end def test_destroy user = create(:user, :home_lat => 12.1, :home_lon => 12.1, :description => "test") # Try without logging in - delete user_path(user), :params => { :status => "suspended" } + delete user_path(user) assert_response :forbidden # Now try as a normal user session_for(user) - delete user_path(user), :params => { :status => "suspended" } - assert_response :redirect + delete user_path(user) assert_redirected_to :controller => :errors, :action => :forbidden # Finally try as an administrator session_for(create(:administrator_user)) - delete user_path(user), :params => { :status => "suspended" } - assert_response :redirect + delete user_path(user) assert_redirected_to :action => :show, :display_name => user.display_name # Check that the user was deleted properly @@ -730,7 +476,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest moderator_user = create(:moderator_user) administrator_user = create(:administrator_user) _suspended_user = create(:user, :suspended) - _ip_user = create(:user, :creation_ip => "1.2.3.4") + _ip_user = create(:user, :creation_address => "1.2.3.4") # There are now 7 users - the five above, plus two extra "granters" for the # moderator_user and administrator_user @@ -738,21 +484,18 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # Shouldn't work when not logged in get users_path - assert_response :redirect assert_redirected_to login_path(:referer => users_path) session_for(user) # Shouldn't work when logged in as a normal user get users_path - assert_response :redirect assert_redirected_to :controller => :errors, :action => :forbidden session_for(moderator_user) # Shouldn't work when logged in as a moderator get users_path - assert_response :redirect assert_redirected_to :controller => :errors, :action => :forbidden session_for(administrator_user) @@ -762,19 +505,19 @@ class UsersControllerTest < ActionDispatch::IntegrationTest get users_path assert_response :success assert_template :index - assert_select "table#user_list tr", :count => 7 + 1 + assert_select "table#user_list tbody tr", :count => 7 # Should be able to limit by status get users_path, :params => { :status => "suspended" } assert_response :success assert_template :index - assert_select "table#user_list tr", :count => 1 + 1 + assert_select "table#user_list tbody tr", :count => 1 # Should be able to limit by IP address get users_path, :params => { :ip => "1.2.3.4" } assert_response :success assert_template :index - assert_select "table#user_list tr", :count => 1 + 1 + assert_select "table#user_list tbody tr", :count => 1 end def test_index_get_paginated @@ -788,23 +531,56 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # 100 examples, an administrator, and a granter for the admin. assert_equal 102, User.count + next_path = users_path - get users_path + get next_path assert_response :success assert_template :index - assert_select "table#user_list tr", :count => 51 + assert_select "table#user_list tbody tr", :count => 50 + check_no_page_link "Newer Users" + next_path = check_page_link "Older Users" - get users_path, :params => { :page => 2 } + get next_path assert_response :success assert_template :index - assert_select "table#user_list tr", :count => 51 + assert_select "table#user_list tbody tr", :count => 50 + check_page_link "Newer Users" + next_path = check_page_link "Older Users" - get users_path, :params => { :page => 3 } + get next_path assert_response :success assert_template :index - assert_select "table#user_list tr", :count => 3 + assert_select "table#user_list tbody tr", :count => 2 + check_page_link "Newer Users" + check_no_page_link "Older Users" + end + + def test_index_get_invalid_paginated + session_for(create(:administrator_user)) + + %w[-1 0 fred].each do |id| + get users_path(:before => id) + assert_redirected_to :controller => :errors, :action => :bad_request + + get users_path(:after => id) + assert_redirected_to :controller => :errors, :action => :bad_request + end + end + + private + + def check_no_page_link(name) + assert_select "a.page-link", { :text => /#{Regexp.quote(name)}/, :count => 0 }, "unexpected #{name} page link" end + def check_page_link(name) + assert_select "a.page-link", { :text => /#{Regexp.quote(name)}/ }, "missing #{name} page link" do |buttons| + return buttons.first.attributes["href"].value + end + end + + public + def test_index_post_confirm inactive_user = create(:user, :pending) suspended_user = create(:user, :suspended) @@ -824,7 +600,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_no_difference "User.active.count" do post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } end - assert_response :redirect assert_redirected_to :controller => :errors, :action => :forbidden assert_equal "pending", inactive_user.reload.status assert_equal "suspended", suspended_user.reload.status @@ -835,7 +610,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_no_difference "User.active.count" do post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } end - assert_response :redirect assert_redirected_to :controller => :errors, :action => :forbidden assert_equal "pending", inactive_user.reload.status assert_equal "suspended", suspended_user.reload.status @@ -846,7 +620,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_difference "User.active.count", 2 do post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } end - assert_response :redirect assert_redirected_to :action => :index assert_equal "confirmed", inactive_user.reload.status assert_equal "confirmed", suspended_user.reload.status @@ -871,7 +644,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_no_difference "User.active.count" do post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } end - assert_response :redirect assert_redirected_to :controller => :errors, :action => :forbidden assert_equal "active", normal_user.reload.status assert_equal "confirmed", confirmed_user.reload.status @@ -882,7 +654,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_no_difference "User.active.count" do post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } end - assert_response :redirect assert_redirected_to :controller => :errors, :action => :forbidden assert_equal "active", normal_user.reload.status assert_equal "confirmed", confirmed_user.reload.status @@ -893,9 +664,19 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_difference "User.active.count", -2 do post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } end - assert_response :redirect assert_redirected_to :action => :index assert_equal "deleted", normal_user.reload.status assert_equal "deleted", confirmed_user.reload.status end + + def test_auth_failure_callback + get auth_failure_path + assert_redirected_to login_path + + get auth_failure_path, :params => { :origin => "/" } + assert_redirected_to root_path + + get auth_failure_path, :params => { :origin => "http://www.google.com" } + assert_redirected_to login_path + end end