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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Also skip FlashComponent turbo stream rendering
Alexander Brandon Coles8e18e3b1926f
diff --git a/app/components/op_primer/flash_component.rb b/app/components/op_primer/flash_component.rbindex 022a78245c8..98c24ccbd58 100644--- a/app/components/op_primer/flash_component.rb+++ b/app/components/op_primer/flash_component.rb@@ -46,6 +46,12 @@ module OpPrimersuperend+ def render_as_turbo_stream(...)+ return unless render?++ super+ end+privatedef render?diff --git a/spec/components/op_primer/flash_component_spec.rb b/spec/components/op_primer/flash_component_spec.rbindex 217f3ae6e65..c3999b298b1 100644--- a/spec/components/op_primer/flash_component_spec.rb+++ b/spec/components/op_primer/flash_component_spec.rb@@ -31,33 +31,82 @@require "rails_helper"RSpec.describe OpPrimer::FlashComponent, type: :component do- def render_component(content, ...)- render_inline(described_class.new(...).with_content(content))- end+ describe "#render" do+ def render_component(content, ...)+ render_inline(described_class.new(...).with_content(content))+ end- subject(:rendered_component) { render_component(content) }+ subject(:rendered_component) { render_component(content) }- context "with content" do- let(:content) { "Flash Text" }+ context "with content" do+ let(:content) { "Flash Text" }- it "renders an x-banner" do- expect(rendered_component).to have_element "x-banner"+ it "renders an x-banner" do+ expect(rendered_component).to have_element "x-banner"+ end++ it "renders the banner text" do+ expect(rendered_component).to have_css ".Banner-message .Banner-title", text: "Flash Text"+ endend- it "renders the banner text" do- expect(rendered_component).to have_css ".Banner-message .Banner-title", text: "Flash Text"+ context "with blank content" do+ let(:content) { " " }++ it "renders nothing" do+ expect(rendered_component.to_s).to be_empty+ end++ it "does not render an x-banner" do+ expect(rendered_component).to have_no_element "x-banner"+ end++ it "does not render the banner text" do+ expect(rendered_component).to have_no_css ".Banner-message .Banner-title"+ endendend- context "with blank content" do- let(:content) { " " }+ describe "#render_as_turbo_stream" do+ def render_component_as_turbo_stream(content, ...)+ component_class = described_class+ render_in_view_context do+ component_class.new(...)+ .with_content(content)+ .render_as_turbo_stream(view_context: self, action: :flash)+ end+ end++ subject(:rendered_component) { render_component_as_turbo_stream(content) }++ let(:rendered_template) { Nokogiri(rendered_component.to_s).css("turbo-stream template").first&.inner_html&.strip }++ context "with content" do+ let(:content) { "Flash Text" }++ it "renders a template" do+ expect(rendered_template).not_to be_blank+ end- it "does not render an x-banner" do- expect(rendered_component).to have_no_element "x-banner"+ it "renders an x-banner within the template" do+ expect(rendered_template).to have_element "x-banner"+ end++ it "renders the banner text within the template" do+ expect(rendered_template).to have_css ".Banner-message .Banner-title", text: "Flash Text"+ endend- it "does not render the banner text" do- expect(rendered_component).to have_no_css ".Banner-message .Banner-title"+ context "with blank content" do+ let(:content) { " " }++ it "renders nothing" do+ expect(rendered_component.to_s).to be_empty+ end++ it "does not render a template" do+ expect(rendered_template).to be_nil+ endendendenddiff --git a/spec/helpers/flash_messages_helper_spec.rb b/spec/helpers/flash_messages_helper_spec.rbindex cdf687e90f6..b5a7f677fed 100644--- a/spec/helpers/flash_messages_helper_spec.rb+++ b/spec/helpers/flash_messages_helper_spec.rb@@ -146,6 +146,22 @@ RSpec.describe FlashMessagesHelper doit_behaves_like "rendering nothing"end+ context "with an empty flash message" do+ before do+ flash[:info] = "" # rubocop:disable Rails/I18nLocaleTexts+ end++ it_behaves_like "rendering nothing"+ end++ context "with a nil flash message" do+ before do+ flash[:info] = nil+ end++ it_behaves_like "rendering nothing"+ end+context "with an :info flash message" dobefore doflash[:info] = "zu deiner Information" # rubocop:disable Rails/I18nLocaleTexts