Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix renders after redirect

Oliver Günther47d62ba9df89
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 3d7f75cceeb..d909312f0d8 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -397,12 +397,15 @@ class AccountController < ApplicationController
show_user_name: true)
else
flash_and_log_invalid_credentials
+ render status: :unprocessable_entity
end
elsif user and user.invited?
invited_account_not_activated(user)
+ render status: :unprocessable_entity
else
# incorrect password
flash_and_log_invalid_credentials
+ render status: :unprocessable_entity
end
elsif user.new_record?
onthefly_creation_failed(user, login: user.login, ldap_auth_source_id: user.ldap_auth_source_id)
diff --git a/app/controllers/concerns/accounts/registration.rb b/app/controllers/concerns/accounts/registration.rb
index ca11d39edfc..655b185151f 100644
--- a/app/controllers/concerns/accounts/registration.rb
+++ b/app/controllers/concerns/accounts/registration.rb
@@ -118,7 +118,7 @@ module Accounts::Registration
def onthefly_creation_failed(user, auth_source_options = {})
@user = user
session[:auth_source_registration] = auth_source_options unless auth_source_options.empty?
- render action: "register"
+ render action: "register", status: :unprocessable_entity
end
def self_registration_disabled
diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rb
index 4753200c817..8cee30868d7 100644
--- a/spec/controllers/account_controller_spec.rb
+++ b/spec/controllers/account_controller_spec.rb
@@ -134,7 +134,7 @@ RSpec.describe AccountController, :skip_2fa_stage do
describe "wrong password" do
it "redirects back to login" do
post :login, params: { username: "admin", password: "bad" }
- expect(response).to be_successful
+ expect(response).to have_http_status :unprocessable_entity
expect(response).to render_template "login"
expect(flash[:error]).to include "Invalid user or password"
end
diff --git a/spec/controllers/my_controller_spec.rb b/spec/controllers/my_controller_spec.rb
index e2421ec60af..c7c8f0324ae 100644
--- a/spec/controllers/my_controller_spec.rb
+++ b/spec/controllers/my_controller_spec.rb
@@ -69,7 +69,7 @@ RSpec.describe MyController do
end
it "shows an error message" do
- assert_response :success
+ expect(response).to have_http_status :unprocessable_entity
assert_template "password"
expect(user.errors.attribute_names).to eq([:password_confirmation])
expect(user.errors.map(&:message).flatten)
@@ -90,7 +90,7 @@ RSpec.describe MyController do
end
it "shows an error message" do
- assert_response :success
+ expect(response).to have_http_status :unprocessable_entity
assert_template "password"
expect(flash[:error]).to eq("Wrong password")
end
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index 03e95140ee7..eacfa15a254 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -642,7 +642,7 @@ RSpec.describe UsersController do
end
it "redirects to the edit page" do
- expect(response).to render_template :edit
+ expect(response).to redirect_to(action: :edit)
end
it "is assigned their new values" do
@@ -689,12 +689,9 @@ RSpec.describe UsersController do
}
end
- it "is success" do
+ it "renders the edit template with errors", :aggregate_failures do
expect(response)
- .to have_http_status(:ok)
- end
-
- it "renders the edit template with errors" do
+ .to have_http_status(:unprocessable_entity)
expect(response)
.to have_rendered("edit")
expect(assigns(:user).errors.first)
diff --git a/spec/features/users/password_change_spec.rb b/spec/features/users/password_change_spec.rb
index e20bf315bb9..5207175054c 100644
--- a/spec/features/users/password_change_spec.rb
+++ b/spec/features/users/password_change_spec.rb
@@ -98,12 +98,15 @@ RSpec.describe "random password generation", :js, :with_cuprite do
# Logout and sign in with outdated password
visit signout_path
+
login_with user.login, password
+ wait_for_network_idle
expect(page).to have_content "Invalid user or password"
# Logout and sign in with new_passworwd
visit signout_path
login_with user.login, new_password
+ wait_for_network_idle
visit my_account_path
expect(page).to have_css(".account-menu-item.selected")