Skip to content

Commit

Permalink
Merge pull request #8920 from alphagov/editionable-ww-org-case-studies
Browse files Browse the repository at this point in the history
Editionable ww org case studies
  • Loading branch information
jkempster34 authored Mar 27, 2024
2 parents 01e8c01 + d43adfb commit 3b0f12e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/case_study.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class CaseStudy < Edition
include Edition::TaggableOrganisations
include Edition::WorldLocations
include Edition::WorldwideOrganisations
include Edition::EditionableWorldwideOrganisations
include Edition::LeadImage

def rendering_app
Expand Down
7 changes: 6 additions & 1 deletion app/views/admin/case_studies/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
id: "associations",
} do %>
<div class="govuk-!-margin-bottom-4">
<%= render "worldwide_organisation_fields", form: form, edition: edition %>
<% if Flipflop.editionable_worldwide_organisations? %>
<%= render "editionable_worldwide_organisation_fields", form: form, edition: edition %>
<% else %>
<%= render "worldwide_organisation_fields", form: form, edition: edition %>
<% end %>
<%= render "world_location_fields", form: form, edition: edition %>
<%= render "organisation_fields", form: form, edition: edition %>
</div>
Expand Down
1 change: 1 addition & 0 deletions test/functional/admin/case_studies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Admin::CaseStudiesControllerTest < ActionController::TestCase
should_have_summary :case_study
should_allow_scheduled_publication_of :case_study
should_allow_association_with_worldwide_organisations :case_study
should_allow_association_with_editionable_worldwide_organisations :case_study
should_allow_association_between_world_locations_and :case_study
should_send_drafts_to_content_preview_environment_for :case_study
should_render_govspeak_history_and_fact_checking_tabs_for :case_study
Expand Down
1 change: 1 addition & 0 deletions test/functional/admin/news_articles_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Admin::NewsArticlesControllerTest < ActionController::TestCase
should_allow_lead_and_supporting_organisations_for :news_article
should_allow_role_appointments_for :news_article
should_allow_association_between_world_locations_and :news_article
should_allow_association_with_editionable_worldwide_organisations :news_article, required: true
should_prevent_modification_of_unmodifiable :news_article
should_allow_overriding_of_first_published_at_for :news_article
should_have_summary :news_article
Expand Down
61 changes: 61 additions & 0 deletions test/support/admin_edition_controller_test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,67 @@ def should_allow_association_with_worldwide_organisations(edition_type)
end
end

def should_allow_association_with_editionable_worldwide_organisations(edition_type, required: false)
edition_class = class_for(edition_type)

view_test "new should display editionable worldwide organisations field" do
feature_flags.switch! :editionable_worldwide_organisations, true

get :new

assert_select "form#new_edition" do
text = required ? "Worldwide organisations (required)" : "Worldwide organisations"
assert_select("label[for=edition_editionable_worldwide_organisation_document_ids]", text:)

assert_select "#edition_editionable_worldwide_organisation_document_ids" do |elements|
assert_equal 1, elements.length
assert_data_attributes_for_worldwide_organisations(
element: elements.first,
track_label: new_edition_path(edition_type),
)
end
end
end

view_test "edit should display editionable worldwide organisations field" do
feature_flags.switch! :editionable_worldwide_organisations, true

edition = create(edition_type) # rubocop:disable Rails/SaveBang
get :edit, params: { id: edition }

assert_select "form#edit_edition" do
text = required ? "Worldwide organisations (required)" : "Worldwide organisations"
assert_select("label[for=edition_editionable_worldwide_organisation_document_ids]", text:)

assert_select "#edition_editionable_worldwide_organisation_document_ids" do |elements|
assert_equal 1, elements.length
assert_data_attributes_for_worldwide_organisations(
element: elements.first,
track_label: edit_edition_path(edition_type),
)
end
end
end

test "create should associate editionable worldwide organisations with the edition" do
feature_flags.switch! :editionable_worldwide_organisations, true

first_world_organisation = create(:editionable_worldwide_organisation, document: create(:document))
second_world_organisation = create(:editionable_worldwide_organisation, document: create(:document))
attributes = controller_attributes_for(edition_type)

post :create,
params: {
edition: attributes.merge(
editionable_worldwide_organisation_document_ids: [first_world_organisation.document.id, second_world_organisation.document.id],
),
}

edition = edition_class.last!
assert_equal [first_world_organisation, second_world_organisation], edition.editionable_worldwide_organisations
end
end

def should_render_govspeak_history_and_fact_checking_tabs_for(edition_type)
view_test "GET :show renders a side nav bar with history and fact checking" do
edition = create(edition_type) # rubocop:disable Rails/SaveBang
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ def present(edition)
assert_equal [wworg.content_id], presented_item.links[:worldwide_organisations]
end

test "includes editionable worldwide organisations as worldwide organisation links when the editionable_worldwide_organisations is enabled" do
worldwide_organisation = create(:editionable_worldwide_organisation)
case_study = create(
:published_case_study,
editionable_worldwide_organisations: [worldwide_organisation],
)

presented_item = present(case_study)

assert_valid_against_links_schema({ links: presented_item.links }, "case_study")
assert_equal [worldwide_organisation.content_id], presented_item.links[:worldwide_organisations]
end

test "an unpublished document has a first_public_at of the document creation time" do
case_study = create(:draft_case_study)
presented_item = present(case_study)
Expand Down

0 comments on commit 3b0f12e

Please sign in to comment.