Skip to content

Commit f0476d1

Browse files
Handle association with different label in type change summary
1 parent 3215205 commit f0476d1

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

app/components/admin/editions/document_type_change_summary.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ class Admin::Editions::DocumentTypeChangeSummary < ViewComponent::Base
22
attr_reader :lost_property_items,
33
:new_property_items,
44
:lost_association_items,
5-
:new_association_items,
6-
:common_association_items
5+
:new_association_items
76

87
def initialize(edition:, old_type:, new_type:)
98
@edition = edition
@@ -20,7 +19,6 @@ def compute_diffs
2019
added_prop_keys = @new_type.properties.keys - @old_type.properties.keys # will need populating
2120
removed_assoc_keys = @old_type.associations.map { |a| a["key"] } - @new_type.associations.map { |a| a["key"] }
2221
added_assoc_keys = @new_type.associations.map { |a| a["key"] } - @old_type.associations.map { |a| a["key"] }
23-
common_assoc_keys = @old_type.associations.map { |a| a["key"] } & @new_type.associations.map { |a| a["key"] } # are present in both
2422

2523
@lost_property_items = removed_prop_keys.map do |key|
2624
schema = @old_type.properties[key]
@@ -64,12 +62,5 @@ def compute_diffs
6462
value: "These associations will be carried over, you will not have to fill them in again.",
6563
}
6664
end
67-
68-
@common_association_items = common_assoc_keys.map do |key|
69-
{
70-
field: key.humanize,
71-
value: "These associations will be carried over, you will not have to fill them in again.",
72-
}
73-
end
7465
end
7566
end

test/components/admin/editions/document_type_change_summary_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def build_type(label:, properties: {}, associations: [])
1919
associations: [
2020
{ "key" => "organisations" },
2121
{ "key" => "world_locations" },
22+
{ "key" => "ministerial_role_appointments" },
2223
],
2324
)
2425

@@ -64,6 +65,10 @@ def build_type(label:, properties: {}, associations: [])
6465
assert_text "Ministers"
6566
assert_text "Will be deleted. A ‘New type’ does not have a ‘Ministers’ association."
6667

68+
# Association with a different label to name
69+
assert_text "Ministers"
70+
assert_text "Will be deleted. A 'New type' does not have a 'Ministers' association."
71+
6772
# New association (topical_events)
6873
assert_text "Topical events"
6974
assert_text "Will need to be added. A ‘New type’ has a ‘Topical events’ association. This field will be blank after the change."

0 commit comments

Comments
 (0)