Skip to content

Commit

Permalink
Merge pull request #15095 from opf/fix/53617/baseline-invisible-cfs
Browse files Browse the repository at this point in the history
Historic attributes: Fix accessing custom_field_id nil when eager loading
  • Loading branch information
ulferts committed Mar 25, 2024
2 parents a18e3aa + a0ad486 commit 374503f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def to_changes_format(references, key)
end

def merge_reference_journals_by_id(new_journals, old_journals, id_key, value)
all_associated_journal_ids = new_journals.pluck(id_key) | old_journals.pluck(id_key)
all_associated_journal_ids = (new_journals.pluck(id_key) | old_journals.pluck(id_key)).compact

all_associated_journal_ids.index_with do |id|
[select_and_combine_journals(old_journals, id, id_key, value),
Expand Down
26 changes: 26 additions & 0 deletions spec/lib/acts_as_journalized/journable_differ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,31 @@
)
end
end

context "with a default custom value" do
let(:original) do
build(:work_package,
custom_values: [
build_stubbed(:work_package_custom_value, custom_field_id: nil, value: nil),
build_stubbed(:work_package_custom_value, custom_field_id: nil, value: ""),
build_stubbed(:work_package_custom_value, custom_field_id: 2, value: 1)
])
end

let(:changed) do
build(:work_package,
custom_values: [
build_stubbed(:work_package_custom_value, custom_field_id: 1, value: "t"),
build_stubbed(:work_package_custom_value, custom_field_id: 2, value: 2)
])
end

it "returns the changes" do
params = [original, changed, "custom_values", "custom_field", :custom_field_id, :value]
expect(described_class.association_changes(*params))
.to eql("custom_field_1" => [nil, "t"],
"custom_field_2" => ["1", "2"])
end
end
end
end

0 comments on commit 374503f

Please sign in to comment.