Skip to content

Commit

Permalink
Merge pull request #9038 from alphagov/fix-ww-org-social
Browse files Browse the repository at this point in the history
Fix bug with social media accounts on new editions
  • Loading branch information
brucebolt committed May 15, 2024
2 parents e8067b8 + 7f3725b commit 77a230e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/concerns/edition/social_media_accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Edition::SocialMediaAccounts
class Trait < Edition::Traits::Trait
def process_associations_after_save(edition)
@edition.social_media_accounts.each do |association|
new_social_media_account = edition.social_media_accounts.build(association.attributes.except("id", "socialable_id", "socialable_type"))
new_social_media_account = edition.social_media_accounts.create!(association.attributes.except("id", "socialable_id", "socialable_type"))

@edition.non_english_translated_locales.map(&:code).each do |locale|
I18n.with_locale(locale) do
Expand Down
16 changes: 16 additions & 0 deletions test/unit/app/models/editionable_worldwide_organisation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ class EditionableWorldwideOrganisationTest < ActiveSupport::TestCase
assert_equal [c], worldwide_organisation.office_staff_roles
end

test "should clone social media associations which don't have translations when new draft of published edition is created" do
published_worldwide_organisation = create(
:editionable_worldwide_organisation,
:published,
:with_social_media_account,
)
draft_worldwide_organisation = published_worldwide_organisation.create_draft(create(:writer))

draft_worldwide_organisation.reload

assert_equal published_worldwide_organisation.social_media_accounts.first.title, draft_worldwide_organisation.social_media_accounts.first.title
assert_equal published_worldwide_organisation.social_media_accounts.first.url, draft_worldwide_organisation.social_media_accounts.first.url
end

test "should clone social media associations and their translations when new draft of published edition is created" do
published_worldwide_organisation = create(
:editionable_worldwide_organisation,
Expand All @@ -152,6 +166,8 @@ class EditionableWorldwideOrganisationTest < ActiveSupport::TestCase

draft_worldwide_organisation = published_worldwide_organisation.create_draft(create(:writer))

draft_worldwide_organisation.reload

assert_equal published_worldwide_organisation.social_media_accounts.first.title, draft_worldwide_organisation.social_media_accounts.first.title
assert_equal published_worldwide_organisation.social_media_accounts.first.url, draft_worldwide_organisation.social_media_accounts.first.url

Expand Down

0 comments on commit 77a230e

Please sign in to comment.