X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/43db18ae911fef3ad7b36e9ed27e5eff469ef863..507c395f51c20c3c0d5375313ea1ca0ed4156c75:/test/controllers/users_controller_test.rb?ds=inline diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 62bb34279..732745539 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -47,23 +47,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest { :path => "/user/username", :method => :delete }, { :controller => "users", :action => "destroy", :display_name => "username" } ) - - assert_routing( - { :path => "/users", :method => :get }, - { :controller => "users", :action => "index" } - ) - assert_routing( - { :path => "/users", :method => :post }, - { :controller => "users", :action => "index" } - ) - assert_routing( - { :path => "/users/status", :method => :get }, - { :controller => "users", :action => "index", :status => "status" } - ) - assert_routing( - { :path => "/users/status", :method => :post }, - { :controller => "users", :action => "index", :status => "status" } - ) end # The user creation page loads @@ -82,7 +65,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 @@ -106,18 +88,10 @@ class UsersControllerTest < ActionDispatch::IntegrationTest 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 @@ -151,55 +125,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_select "form > div > input.is-invalid#user_email" end - def test_save_duplicate_email + 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 - 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 > input.is-invalid#user_email" - end - - def test_save_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 @@ -209,26 +142,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest 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 @@ -238,26 +159,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest 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 @@ -267,18 +176,9 @@ class UsersControllerTest < ActionDispatch::IntegrationTest 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") @@ -286,7 +186,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 @@ -298,18 +198,9 @@ 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 - post user_save_path, :params => { :read_ct => 1, :read_tou => 1 } + 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 @@ -319,24 +210,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest 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) @@ -435,9 +308,6 @@ 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) @@ -584,192 +454,6 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_equal "deleted", user.status end - def test_index_get - user = create(:user) - 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") - - # There are now 7 users - the five above, plus two extra "granters" for the - # moderator_user and administrator_user - assert_equal 7, User.count - - # Shouldn't work when not logged in - get users_path - 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_redirected_to :controller => :errors, :action => :forbidden - - session_for(moderator_user) - - # Shouldn't work when logged in as a moderator - get users_path - assert_redirected_to :controller => :errors, :action => :forbidden - - session_for(administrator_user) - - # Note there is a header row, so all row counts are users + 1 - # Should work when logged in as an administrator - get users_path - assert_response :success - assert_template :index - 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 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 tbody tr", :count => 1 - end - - def test_index_get_paginated - 1.upto(100).each do |n| - User.create(:display_name => "extra_#{n}", - :email => "extra#{n}@example.com", - :pass_crypt => "extraextra") - end - - session_for(create(:administrator_user)) - - # 100 examples, an administrator, and a granter for the admin. - assert_equal 102, User.count - next_path = users_path - - get next_path - assert_response :success - assert_template :index - assert_select "table#user_list tbody tr", :count => 50 - check_no_page_link "Newer Users" - next_path = check_page_link "Older Users" - - get next_path - assert_response :success - assert_template :index - assert_select "table#user_list tbody tr", :count => 50 - check_page_link "Newer Users" - next_path = check_page_link "Older Users" - - get next_path - assert_response :success - assert_template :index - assert_select "table#user_list tbody tr", :count => 2 - check_page_link "Newer Users" - check_no_page_link "Older Users" - 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) - - # Shouldn't work when not logged in - 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 :forbidden - - assert_equal "pending", inactive_user.reload.status - assert_equal "suspended", suspended_user.reload.status - - session_for(create(:user)) - - # Shouldn't work when logged in as a normal user - assert_no_difference "User.active.count" do - post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } - end - assert_redirected_to :controller => :errors, :action => :forbidden - assert_equal "pending", inactive_user.reload.status - assert_equal "suspended", suspended_user.reload.status - - session_for(create(:moderator_user)) - - # Shouldn't work when logged in as a moderator - assert_no_difference "User.active.count" do - post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } - end - assert_redirected_to :controller => :errors, :action => :forbidden - assert_equal "pending", inactive_user.reload.status - assert_equal "suspended", suspended_user.reload.status - - session_for(create(:administrator_user)) - - # Should work when logged in as an administrator - assert_difference "User.active.count", 2 do - post users_path, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } - end - assert_redirected_to :action => :index - assert_equal "confirmed", inactive_user.reload.status - assert_equal "confirmed", suspended_user.reload.status - end - - def test_index_post_hide - normal_user = create(:user) - confirmed_user = create(:user, :confirmed) - - # Shouldn't work when not logged in - 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 :forbidden - - assert_equal "active", normal_user.reload.status - assert_equal "confirmed", confirmed_user.reload.status - - session_for(create(:user)) - - # Shouldn't work when logged in as a normal user - assert_no_difference "User.active.count" do - post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } - end - assert_redirected_to :controller => :errors, :action => :forbidden - assert_equal "active", normal_user.reload.status - assert_equal "confirmed", confirmed_user.reload.status - - session_for(create(:moderator_user)) - - # Shouldn't work when logged in as a moderator - assert_no_difference "User.active.count" do - post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } - end - assert_redirected_to :controller => :errors, :action => :forbidden - assert_equal "active", normal_user.reload.status - assert_equal "confirmed", confirmed_user.reload.status - - session_for(create(:administrator_user)) - - # Should work when logged in as an administrator - assert_difference "User.active.count", -2 do - post users_path, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } - end - 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