From a531986dc1d05a90fd2a1b43b406f7a427b83077 Mon Sep 17 00:00:00 2001 From: maebeale Date: Thu, 25 Jun 2026 22:18:36 -0400 Subject: [PATCH] Default new affiliations to first of month and unchecked primary contact Pre-filling today's date and a checked primary-contact box made admins accept defaults that were usually wrong: affiliations are tracked from the start of the month, and most people on an org are not its primary contact. Co-Authored-By: Claude Opus 4.8 --- app/views/affiliations/_fields.html.erb | 4 ++-- spec/views/organizations/edit.html.erb_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/views/affiliations/_fields.html.erb b/app/views/affiliations/_fields.html.erb index 7a585093f1..17073012a7 100644 --- a/app/views/affiliations/_fields.html.erb +++ b/app/views/affiliations/_fields.html.erb @@ -69,7 +69,7 @@ label_html: { class: "block text-sm font-medium text-gray-700 mb-1" }, input_html: { type: "date", - value: (f.object.start_date || (Date.current unless f.object.persisted?))&.strftime("%Y-%m-%d"), + value: (f.object.start_date || (Date.current.beginning_of_month unless f.object.persisted?))&.strftime("%Y-%m-%d"), class: "rounded-md border-gray-300 focus:ring-blue-500 focus:border-blue-500 text-sm", data: { action: "change->affiliation-dates#recalculate" } } %> @@ -94,7 +94,7 @@
<%= f.check_box :primary_contact, - checked: f.object.primary_contact? || !f.object.persisted?, + checked: f.object.primary_contact?, class: "h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500" %>
diff --git a/spec/views/organizations/edit.html.erb_spec.rb b/spec/views/organizations/edit.html.erb_spec.rb index 1b55b5b944..c706dd03a3 100644 --- a/spec/views/organizations/edit.html.erb_spec.rb +++ b/spec/views/organizations/edit.html.erb_spec.rb @@ -73,4 +73,15 @@ def org_with_status(name) assert_select "p.text-red-600", text: "Does not match affiliations status" end end + + describe "new affiliation defaults" do + it "defaults the start date to the first of the current month and leaves primary contact unchecked" do + organization.affiliations.build + render + assert_select "input[name*='start_date'][value=?]", + Date.current.beginning_of_month.strftime("%Y-%m-%d") + assert_select "input[type=checkbox][name*='primary_contact']" + assert_select "input[type=checkbox][name*='primary_contact'][checked]", false + end + end end