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
move querying for phase to controller, use eager_load instead of joins+includes
Ivan Kuchinfcd6cf48ba35
diff --git a/app/components/projects/phases/hover_card_component.html.erb b/app/components/projects/phases/hover_card_component.html.erbindex 5598d0cb303..5b589aaa9e8 100644--- a/app/components/projects/phases/hover_card_component.html.erb+++ b/app/components/projects/phases/hover_card_component.html.erb@@ -28,7 +28,7 @@ See COPYRIGHT and LICENSE files for more details.++#%><%=- if @phase.present?+ if @phase&.active?flex_layout(classes: "op-phase-gate-hover-card", data: { test_selector: "phase-gate-hover-card-#{phase.id}" }) do |flex|flex.with_row doflex_layout(classes: "op-phase-gate-hover-card--info", justify_content: :space_between) do |f|diff --git a/app/components/projects/phases/hover_card_component.rb b/app/components/projects/phases/hover_card_component.rbindex 8175f832a04..ae61eb0b9e2 100644--- a/app/components/projects/phases/hover_card_component.rb+++ b/app/components/projects/phases/hover_card_component.rb@@ -35,17 +35,12 @@ module Projectsattr_reader :phase- def initialize(id:, gate:)+ def initialize(phase:, gate:)raise ArgumentError, "gate must be either 'start' or 'finish'" unless %w[start finish].include?(gate)super- @phase = Project::Phase- .joins(:definition)- .includes(:definition)- .where(active: true)- .find_by(id: id)-+ @phase = phase@gate = gate.to_symenddiff --git a/app/controllers/project_phases/hover_card_controller.rb b/app/controllers/project_phases/hover_card_controller.rbindex 6f78afcc1f9..4f995f9f37d 100644--- a/app/controllers/project_phases/hover_card_controller.rb+++ b/app/controllers/project_phases/hover_card_controller.rb@@ -39,7 +39,8 @@ module ProjectPhasesrender json: { error: "Invalid gate parameter" }, status: :unprocessable_entityend- @id = permitted_params[:id]+ id = permitted_params[:id]+ @phase = Project::Phase.eager_load(:definition).where(active: true).find_by(id:)@gate = permitted_params[:gate]render layout: nildiff --git a/app/views/project_phases/hover_card/show.html.erb b/app/views/project_phases/hover_card/show.html.erbindex 9175db13064..5edea1318e2 100644--- a/app/views/project_phases/hover_card/show.html.erb+++ b/app/views/project_phases/hover_card/show.html.erb@@ -1,3 +1,3 @@<turbo-frame id="op-hover-card-body">- <%= render Projects::Phases::HoverCardComponent.new(id: @id, gate: @gate) %>+ <%= render Projects::Phases::HoverCardComponent.new(phase: @phase, gate: @gate) %></turbo-frame>diff --git a/spec/components/projects/phases/hover_card_component_spec.rb b/spec/components/projects/phases/hover_card_component_spec.rbindex c124a628dd4..75486d1e814 100644--- a/spec/components/projects/phases/hover_card_component_spec.rb+++ b/spec/components/projects/phases/hover_card_component_spec.rb@@ -33,11 +33,10 @@ require "rails_helper"RSpec.describe Projects::Phases::HoverCardComponent, type: :component doinclude Rails.application.routes.url_helpers- let(:phase) { create(:project_phase, :with_gated_definition) }- let(:phase_id) { phase.id }+ let(:phase) { build_stubbed(:project_phase, :with_gated_definition) }let(:gate) { "start" }- subject { described_class.new(id: phase_id, gate:) }+ subject { described_class.new(phase:, gate:) }before dorender_inline(subject)@@ -79,7 +78,7 @@ RSpec.describe Projects::Phases::HoverCardComponent, type: :component doendcontext "when inactive" do- let(:phase) { create(:project_phase, active: false) }+ let(:phase) { build_stubbed(:project_phase, active: false) }it "renders a generic error message" doexpect(page).to have_text(I18n.t("http.response.unexpected"))@@ -87,7 +86,7 @@ RSpec.describe Projects::Phases::HoverCardComponent, type: :component doendcontext "when phase cannot be found in database" do- let(:phase_id) { :does_not_exist }+ let(:phase) { nil }it "renders a generic error message" doexpect(page).to have_text(I18n.t("http.response.unexpected"))