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

[56168] Fixed MyController specs

Andreas Pfohl169f4b46662a
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb
index 662daef9417..368fff61f5f 100644
--- a/app/controllers/my_controller.rb
+++ b/app/controllers/my_controller.rb
@@ -31,6 +31,7 @@ class MyController < ApplicationController
include Accounts::UserPasswordChange
include ActionView::Helpers::TagHelper
include OpTurbo::ComponentStream
+ include FlashMessagesOutputSafetyHelper
layout "my"
@@ -163,9 +164,16 @@ class MyController < ApplicationController
result = APITokens::CreateService.new(user: current_user).call(token_name: params[:token_api][:token_name])
result.on_success do |r|
- token = Primer::Beta::Text.new(font_weight: :bold).render_in(view_context) { r.result.plain_value }
- message = "#{t('my.access_token.notice_reset_token', type: 'API')} #{token} #{t('my.access_token.token_value_warning')}"
- flash[:primer_banner] = { message:, scheme: :success }
+ flash[:primer_banner] = {
+ scheme: :success,
+ message: join_flash_messages(
+ [
+ t("my.access_token.notice_reset_token", type: "API"),
+ Primer::Beta::Text.new(font_weight: :bold).render_in(view_context) { r.result.plain_value },
+ t("my.access_token.token_value_warning")
+ ]
+ )
+ }
redirect_to action: "access_token"
end
diff --git a/spec/controllers/my_controller_spec.rb b/spec/controllers/my_controller_spec.rb
index 2f39f345cf6..3e82458cc57 100644
--- a/spec/controllers/my_controller_spec.rb
+++ b/spec/controllers/my_controller_spec.rb
@@ -309,8 +309,8 @@ RSpec.describe MyController do
new_token = user.reload.api_tokens.last
expect(new_token).to be_present
- expect(flash[:info]).to be_present
- expect(flash[:error]).not_to be_present
+ expect(flash[:primer_banner]).to be_present
+ expect(flash[:primer_banner]).to include(scheme: :success)
expect(response).to redirect_to action: :access_token
end
@@ -327,8 +327,8 @@ RSpec.describe MyController do
new_token = user.reload.api_tokens.last
expect(new_token).not_to eq(key)
expect(new_token.value).not_to eq(key.value)
- expect(flash[:info]).to be_present
- expect(flash[:error]).not_to be_present
+ expect(flash[:primer_banner]).to be_present
+ expect(flash[:primer_banner]).to include(scheme: :success)
expect(response).to redirect_to action: :access_token
end