From 148ffa5e1bd667d9ed11ef4dedf44096bc7d0d5b Mon Sep 17 00:00:00 2001 From: ChrisBAshton Date: Tue, 4 Jun 2024 10:52:54 +0100 Subject: [PATCH] Pre-select the current value for 'world location type' Prior to this commit, the selected value would always default to "World location", which meant it was easy to accidentally change the world location type when making an edit to a "international delegation". Trello: https://trello.com/c/GvXvAOvV/2655-fix-world-location-news-type-default-bug --- app/views/admin/world_location_news/edit.html.erb | 8 +++++++- .../admin/world_location_news_controller_test.rb | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/views/admin/world_location_news/edit.html.erb b/app/views/admin/world_location_news/edit.html.erb index e2ff831d377..2798764f2be 100644 --- a/app/views/admin/world_location_news/edit.html.erb +++ b/app/views/admin/world_location_news/edit.html.erb @@ -22,7 +22,13 @@ name: "world_location_news[world_location_attributes][world_location_type]", label: "Type (required)", heading_size: "l", - options: WorldLocation.world_location_types.keys.map { |location_type| { text: I18n.t("world_location.type.#{location_type}", count: 1), value: location_type } }, + options: WorldLocation.world_location_types.keys.map do |location_type| + { + text: I18n.t("world_location.type.#{location_type}", count: 1), + value: location_type, + selected: location_type == @world_location_news.world_location.world_location_type, + } + end, full_width: true, } %> diff --git a/test/functional/admin/world_location_news_controller_test.rb b/test/functional/admin/world_location_news_controller_test.rb index 78b6ae82811..a188de27782 100644 --- a/test/functional/admin/world_location_news_controller_test.rb +++ b/test/functional/admin/world_location_news_controller_test.rb @@ -24,11 +24,13 @@ class Admin::WorldLocationNewsControllerTest < ActionController::TestCase end view_test "should allow modification of existing world location data" do - world_location = create(:world_location) + world_location = create(:world_location, world_location_type: "international_delegation") get :edit, params: { id: world_location.world_location_news } assert_template "world_location_news/edit" + assert_select "select[name='world_location_news[world_location_attributes][world_location_type]']" + assert_select "option[value='international_delegation'][selected='selected']" assert_select "input[name='world_location_news[title]']" assert_select "textarea[name='world_location_news[mission_statement]']" assert_select "input[name='world_location_news[featured_links_attributes][0][title]']"