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

spec for association_changes_multiple_attributes

Ivan Kuchind2c412efe8f9
diff --git a/spec/factories/journal/project_life_cycle_step_journal_factory.rb b/spec/factories/journal/project_life_cycle_step_journal_factory.rb
new file mode 100644
index 00000000000..a4449db3b10
--- /dev/null
+++ b/spec/factories/journal/project_life_cycle_step_journal_factory.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+FactoryBot.define do
+ factory :project_life_cycle_step_journal, class: "Journal::ProjectLifeCycleStepJournal"
+end
diff --git a/spec/lib/acts_as_journalized/journable_differ_spec.rb b/spec/lib/acts_as_journalized/journable_differ_spec.rb
index fee082cb791..2c655ff775c 100644
--- a/spec/lib/acts_as_journalized/journable_differ_spec.rb
+++ b/spec/lib/acts_as_journalized/journable_differ_spec.rb
@@ -166,4 +166,40 @@ RSpec.describe Acts::Journalized::JournableDiffer do
end
end
end
+
+ describe ".association_changes_multiple_attributes" do
+ let(:original) do
+ build(:journal, project_life_cycle_step_journals: [
+ build_stubbed(:project_life_cycle_step_journal, life_cycle_step_id: 1, active: false),
+ build_stubbed(:project_life_cycle_step_journal, life_cycle_step_id: 3, active: true),
+ build_stubbed(:project_life_cycle_step_journal, life_cycle_step_id: 4, active: true,
+ start_date: Date.new(2024, 1, 16),
+ end_date: Date.new(2024, 1, 17))
+ ])
+ end
+
+ let(:changed) do
+ build(:journal, project_life_cycle_step_journals: [
+ build_stubbed(:project_life_cycle_step_journal, life_cycle_step_id: 1, active: true),
+ build_stubbed(:project_life_cycle_step_journal, life_cycle_step_id: 2, active: true),
+ build_stubbed(:project_life_cycle_step_journal, life_cycle_step_id: 3, active: false),
+ build_stubbed(:project_life_cycle_step_journal, life_cycle_step_id: 4, active: true,
+ start_date: Date.new(2024, 1, 17),
+ end_date: Date.new(2024, 1, 18))
+ ])
+ end
+
+ it "returns the changes" do
+ params = [original, changed, "project_life_cycle_step_journals", "project_life_cycle_steps", :life_cycle_step_id,
+ %i[active start_date end_date]]
+ expect(described_class.association_changes_multiple_attributes(*params))
+ .to eq(
+ "project_life_cycle_steps_1_active" => ["false", "true"],
+ "project_life_cycle_steps_2_active" => [nil, "true"],
+ "project_life_cycle_steps_3_active" => ["true", "false"],
+ "project_life_cycle_steps_4_end_date" => ["2024-01-17", "2024-01-18"],
+ "project_life_cycle_steps_4_start_date" => ["2024-01-16", "2024-01-17"]
+ )
+ end
+ end
end