From 13994ca6caa0e253856126fc8029d0e3140f1bfd Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Thu, 2 Jan 2025 13:10:24 +0300 Subject: [PATCH] Use resourceful routes for user new/create actions --- app/views/layouts/_header.html.erb | 2 +- app/views/layouts/map.html.erb | 2 +- app/views/notes/new.html.erb | 2 +- app/views/site/fixthemap.html.erb | 2 +- config/routes.rb | 4 +- .../confirmations_controller_test.rb | 26 +++++------ test/controllers/users_controller_test.rb | 46 +++++++++---------- test/integration/user_creation_test.rb | 38 +++++++-------- 8 files changed, 60 insertions(+), 62 deletions(-) diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 322b738ec..45e23fc2b 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -111,7 +111,7 @@ <% else %>
<%= link_to t("layouts.log_in"), login_path(:referer => request.fullpath), :class => "geolink btn btn-outline-secondary" %> - <%= link_to t("layouts.sign_up"), user_new_path, :class => "btn btn-outline-secondary" %> + <%= link_to t("layouts.sign_up"), new_user_path, :class => "btn btn-outline-secondary" %>
<% end %> diff --git a/app/views/layouts/map.html.erb b/app/views/layouts/map.html.erb index 0630dace5..e17ea4ed8 100644 --- a/app/views/layouts/map.html.erb +++ b/app/views/layouts/map.html.erb @@ -51,7 +51,7 @@

<%= t("layouts.learn_more") %> - <%= t("layouts.start_mapping") %> + <%= t("layouts.start_mapping") %>
<% end %> diff --git a/app/views/notes/new.html.erb b/app/views/notes/new.html.erb index f461f60e2..4ae4a995d 100644 --- a/app/views/notes/new.html.erb +++ b/app/views/notes/new.html.erb @@ -7,7 +7,7 @@ <% if !current_user %>

<%= t ".anonymous_warning_html", :log_in => link_to(t(".anonymous_warning_log_in"), login_path(:referer => new_note_path)), - :sign_up => link_to(t(".anonymous_warning_sign_up"), user_new_path) %>

+ :sign_up => link_to(t(".anonymous_warning_sign_up"), new_user_path) %>

<% end %>
diff --git a/app/views/site/fixthemap.html.erb b/app/views/site/fixthemap.html.erb index 1e943c7cc..9d9ef9232 100644 --- a/app/views/site/fixthemap.html.erb +++ b/app/views/site/fixthemap.html.erb @@ -16,7 +16,7 @@

<%= t ".how_to_help.join_the_community.title" %>

<%= t ".how_to_help.join_the_community.explanation_html" %>

- <%= t("layouts.start_mapping") %> + <%= t("layouts.start_mapping") %>

diff --git a/config/routes.rb b/config/routes.rb index 4ab8f307b..e623a0738 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -182,8 +182,6 @@ OpenStreetMap::Application.routes.draw do get "/key" => "site#key" get "/id" => "site#id" get "/query" => "browse#query" - get "/user/new" => "users#new" - post "/user/new" => "users#create" get "/user/terms" => "users#terms" post "/user/save" => "users#save" post "/user/:display_name/confirm/resend" => "confirmations#confirm_resend", :as => :user_confirm_resend @@ -269,7 +267,7 @@ OpenStreetMap::Application.routes.draw do post "/diary_comments/:comment/unhide" => "diary_comments#unhide", :comment => /\d+/, :as => :unhide_diary_comment # user pages - resources :users, :path => "user", :param => :display_name, :only => [:show, :destroy] do + resources :users, :path => "user", :param => :display_name, :only => [:new, :create, :show, :destroy] do resource :role, :controller => "user_roles", :path => "roles/:role", :only => [:create, :destroy] scope :module => :users do resource :issued_blocks, :path => "blocks_by", :only => :show diff --git a/test/controllers/confirmations_controller_test.rb b/test/controllers/confirmations_controller_test.rb index c8926eb75..774efdb9c 100644 --- a/test/controllers/confirmations_controller_test.rb +++ b/test/controllers/confirmations_controller_test.rb @@ -37,7 +37,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_confirm_get user = build(:user, :pending) - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } confirm_string = User.find_by(:email => user.email).generate_token_for(:new_user) get user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string } @@ -48,7 +48,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_confirm_get_already_confirmed user = build(:user, :pending) stub_gravatar_request(user.email) - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } confirm_string = User.find_by(:email => user.email).generate_token_for(:new_user) # Get the confirmation page @@ -68,7 +68,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_confirm_success_no_token_no_referer user = build(:user, :pending) stub_gravatar_request(user.email) - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } confirm_string = User.find_by(:email => user.email).generate_token_for(:new_user) post logout_path @@ -81,7 +81,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_confirm_success_good_token_no_referer user = build(:user, :pending) stub_gravatar_request(user.email) - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } confirm_string = User.find_by(:email => user.email).generate_token_for(:new_user) post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string } @@ -91,7 +91,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_confirm_success_bad_token_no_referer user = build(:user, :pending) stub_gravatar_request(user.email) - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } confirm_string = User.find_by(:email => user.email).generate_token_for(:new_user) post logout_path @@ -105,7 +105,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_confirm_success_no_token_with_referer user = build(:user, :pending) stub_gravatar_request(user.email) - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } confirm_string = User.find_by(:email => user.email).generate_token_for(:new_user) post logout_path @@ -118,7 +118,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_confirm_success_good_token_with_referer user = build(:user, :pending) stub_gravatar_request(user.email) - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } confirm_string = User.find_by(:email => user.email).generate_token_for(:new_user) post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string, :referer => new_diary_entry_path } @@ -128,7 +128,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_confirm_success_bad_token_with_referer user = build(:user, :pending) stub_gravatar_request(user.email) - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } confirm_string = User.find_by(:email => user.email).generate_token_for(:new_user) post logout_path @@ -142,7 +142,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_confirm_expired_token user = build(:user, :pending) stub_gravatar_request(user.email) - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } confirm_string = User.find_by(:email => user.email).generate_token_for(:new_user) travel 2.weeks do @@ -155,7 +155,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_confirm_already_confirmed user = build(:user, :pending) stub_gravatar_request(user.email) - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } confirm_string = User.find_by(:email => user.email).generate_token_for(:new_user) post user_confirm_path, :params => { :display_name => user.display_name, :confirm_string => confirm_string, :referer => new_diary_entry_path } @@ -172,7 +172,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_confirm_deleted user = build(:user, :pending) stub_gravatar_request(user.email) - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } confirm_string = User.find_by(:email => user.email).generate_token_for(:new_user) User.find_by(:display_name => user.display_name).hide! @@ -189,7 +189,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_confirm_resend_success user = build(:user, :pending) - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } assert_difference "ActionMailer::Base.deliveries.size", 1 do perform_enqueued_jobs do @@ -210,7 +210,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest def test_confirm_resend_deleted user = build(:user, :pending) - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } User.find_by(:display_name => user.display_name).hide! diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index ba1af9509..10875b068 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -10,7 +10,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest ) assert_routing( - { :path => "/user/new", :method => :post }, + { :path => "/user", :method => :post }, { :controller => "users", :action => "create" } ) @@ -50,11 +50,11 @@ class UsersControllerTest < ActionDispatch::IntegrationTest end # The user creation page loads - def test_new_view - get user_new_path - assert_redirected_to user_new_path(:cookie_test => "true") + def test_new + get new_user_path + assert_redirected_to new_user_path(:cookie_test => "true") - get user_new_path, :params => { :cookie_test => "true" } + get new_user_path, :params => { :cookie_test => "true" } assert_response :success assert_select "html", :count => 1 do @@ -63,7 +63,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest 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 "form[action='/user'][method='post']", :count => 1 do assert_select "input[id='user_email']", :count => 1 assert_select "input[id='user_display_name']", :count => 1 assert_select "input[id='user_pass_crypt'][type='password']", :count => 1 @@ -75,23 +75,23 @@ class UsersControllerTest < ActionDispatch::IntegrationTest end end - def test_new_view_logged_in + def test_new_logged_in session_for(create(:user)) - get user_new_path + get new_user_path assert_redirected_to root_path - get user_new_path, :params => { :referer => "/test" } + get new_user_path, :params => { :referer => "/test" } assert_redirected_to "/test" end - def test_new_success + def test_create_success user = build(:user, :pending) assert_difference "User.count", 1 do assert_difference "ActionMailer::Base.deliveries.size", 1 do perform_enqueued_jobs do - post user_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } end end end @@ -108,14 +108,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest ActionMailer::Base.deliveries.clear end - def test_new_duplicate_email + def test_create_duplicate_email user = build(:user, :pending) create(:user, :email => user.email) 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 } + post users_path, :params => { :user => user.attributes } end end end @@ -125,14 +125,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_select "form > div > input.is-invalid#user_email" end - def test_new_duplicate_email_uppercase + def test_create_duplicate_email_uppercase user = build(:user, :pending) create(:user, :email => user.email.upcase) 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 } + post users_path, :params => { :user => user.attributes } end end end @@ -142,14 +142,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_select "form > div > input.is-invalid#user_email" end - def test_new_duplicate_name + def test_create_duplicate_name user = build(:user, :pending) create(:user, :display_name => user.display_name) 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 } + post users_path, :params => { :user => user.attributes } end end end @@ -159,14 +159,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_select "form > div > input.is-invalid#user_display_name" end - def test_new_duplicate_name_uppercase + def test_create_duplicate_name_uppercase user = build(:user, :pending) create(:user, :display_name => user.display_name.upcase) 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 } + post users_path, :params => { :user => user.attributes } end end end @@ -176,7 +176,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_select "form > div > input.is-invalid#user_display_name" end - def test_new_blocked_domain + def test_create_blocked_domain user = build(:user, :pending, :email => "user@example.net") # Now block that domain @@ -186,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_new_path, :params => { :user => user.attributes } + post users_path, :params => { :user => user.attributes } end end end @@ -195,12 +195,12 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_template "blocked" end - def test_save_referer_params + def test_create_referer_params user = build(:user, :pending) assert_difference "User.count", 1 do assert_difference "ActionMailer::Base.deliveries.size", 1 do - post user_new_path, :params => { :user => user.attributes, :referer => "/edit?editor=id#map=1/2/3" } + post users_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 diff --git a/test/integration/user_creation_test.rb b/test/integration/user_creation_test.rb index f75fde75e..1a53f62da 100644 --- a/test/integration/user_creation_test.rb +++ b/test/integration/user_creation_test.rb @@ -30,7 +30,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest assert_difference("User.count", 0) do assert_difference("ActionMailer::Base.deliveries.size", 0) do perform_enqueued_jobs do - post "/user/new", + post "/user", :params => { :user => { :email => dup_email, :display_name => display_name, :pass_crypt => "testtest", @@ -51,7 +51,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest assert_difference("User.count", 0) do assert_no_difference("ActionMailer::Base.deliveries.size") do perform_enqueued_jobs do - post "/user/new", + post "/user", :params => { :user => { :email => dup_email, :display_name => display_name, :pass_crypt => "testtest", @@ -74,7 +74,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest assert_difference("User.count", 0) do assert_difference("ActionMailer::Base.deliveries.size", 0) do perform_enqueued_jobs do - post "/user/new", + post "/user", :params => { :user => { :email => email, :display_name => dup_display_name, :pass_crypt => "testtest", @@ -93,7 +93,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest assert_difference("User.count", 0) do assert_difference("ActionMailer::Base.deliveries.size", 0) do perform_enqueued_jobs do - post "/user/new", + post "/user", :params => { :user => { :email => email, :display_name => display_name, :pass_crypt => "testtest", @@ -113,7 +113,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest assert_difference("User.count", 0) do assert_no_difference("ActionMailer::Base.deliveries.size") do perform_enqueued_jobs do - post "/user/new", + post "/user", :params => { :user => { :email => email, :display_name => dup_display_name, :auth_provider => "google", @@ -134,7 +134,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest assert_difference("User.count", 1) do assert_difference("ActionMailer::Base.deliveries.size", 1) do perform_enqueued_jobs do - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :display_name => display_name, :pass_crypt => "testtest", @@ -188,7 +188,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest assert_difference("User.count") do assert_difference("ActionMailer::Base.deliveries.size", 1) do perform_enqueued_jobs do - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :display_name => display_name, :pass_crypt => password, @@ -250,7 +250,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => new_email, :auth_provider => "openid", :auth_uid => auth_uid follow_redirect! - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :display_name => display_name, :auth_provider => "openid", @@ -326,7 +326,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest assert_redirected_to :controller => :users, :action => "new", :nickname => display_name, :email => new_email, :auth_provider => "openid", :auth_uid => auth_uid follow_redirect! - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :display_name => display_name, :auth_provider => "openid", @@ -388,7 +388,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest :auth_provider => "google", :auth_uid => auth_uid follow_redirect! - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :display_name => display_name, :auth_provider => "google", @@ -474,7 +474,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest :email => orig_email, :email_hmac => email_hmac, :auth_provider => "google", :auth_uid => auth_uid follow_redirect! - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :email_hmac => email_hmac, :display_name => display_name, @@ -537,7 +537,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest :auth_provider => "facebook", :auth_uid => auth_uid follow_redirect! - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :display_name => display_name, :auth_provider => "facebook", @@ -623,7 +623,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest :auth_provider => "facebook", :auth_uid => auth_uid follow_redirect! - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :email_hmac => email_hmac, :display_name => display_name, @@ -685,7 +685,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest :email => new_email, :email_hmac => email_hmac, :auth_provider => "microsoft", :auth_uid => auth_uid follow_redirect! - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :display_name => display_name, :auth_provider => "microsoft", @@ -770,7 +770,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest :auth_provider => "microsoft", :auth_uid => auth_uid follow_redirect! - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :email_hmac => email_hmac, :display_name => display_name, @@ -834,7 +834,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest :auth_provider => "github", :auth_uid => auth_uid follow_redirect! - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :display_name => display_name, :auth_provider => "github", @@ -921,7 +921,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest :email => orig_email, :email_hmac => email_hmac, :auth_provider => "github", :auth_uid => auth_uid follow_redirect! - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :email_hmac => email_hmac, :display_name => display_name, @@ -984,7 +984,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest :email => new_email, :email_hmac => email_hmac, :auth_provider => "wikipedia", :auth_uid => auth_uid follow_redirect! - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :display_name => display_name, :auth_provider => "wikipedia", @@ -1071,7 +1071,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest :auth_provider => "wikipedia", :auth_uid => auth_uid follow_redirect! - post "/user/new", + post "/user", :params => { :user => { :email => new_email, :email_hmac => email_hmac, :display_name => display_name, -- 2.39.5