diff --git a/app/helpers/event_helper.rb b/app/helpers/event_helper.rb
index 17a4512c5..844a85f41 100644
--- a/app/helpers/event_helper.rb
+++ b/app/helpers/event_helper.rb
@@ -113,6 +113,14 @@ def event_profile_button(event, truncate_at: nil, subtitle: nil, data: {}, path:
end
end
+ # The question label to show next to a stored answer: the wording captured at
+ # submission time (so editing a question later doesn't rewrite history), falling
+ # back to the field's current name when there's no answer on file — e.g. a
+ # question added after this person submitted.
+ def display_question_label(field, response)
+ response&.question_name_when_answered.presence || field&.name
+ end
+
def display_response_text(field, response)
text = resolve_answer_text(field, response&.submitted_answer)
return tag.span("—", class: "text-gray-400") if text.blank?
diff --git a/app/views/events/public_registrations/show.html.erb b/app/views/events/public_registrations/show.html.erb
index 62b154feb..4e5c2fdce 100644
--- a/app/views/events/public_registrations/show.html.erb
+++ b/app/views/events/public_registrations/show.html.erb
@@ -50,7 +50,7 @@
<% else %>
<% response = @responses[field.id] %>
-
<%= form_label_html(field.name) %>
+
<%= form_label_html(display_question_label(field, response)) %>
<%= display_response_text(field, response) %>
diff --git a/app/views/events/recipients.html.erb b/app/views/events/recipients.html.erb
index 586139099..37afbe9de 100644
--- a/app/views/events/recipients.html.erb
+++ b/app/views/events/recipients.html.erb
@@ -174,7 +174,7 @@
<% answers.each do |answer| %>
-
- <%= answer.question_name_when_answered.presence || answer.form_field&.name %>
+ - <%= display_question_label(answer.form_field, answer) %>
- <%= resolve_answer_text(answer.form_field, answer.submitted_answer) %>
<% end %>
diff --git a/app/views/form_submissions/_submission.html.erb b/app/views/form_submissions/_submission.html.erb
index 681d8a09e..9ae5a765c 100644
--- a/app/views/form_submissions/_submission.html.erb
+++ b/app/views/form_submissions/_submission.html.erb
@@ -18,7 +18,7 @@
<% else %>
-
<%= field.name %>
+
<%= display_question_label(field, response) %>
<%= response&.submitted_answer.presence || tag.span("—", class: "text-gray-400") %>
diff --git a/app/views/scholarships/_form_submission.html.erb b/app/views/scholarships/_form_submission.html.erb
index c4f5a9919..992d69a52 100644
--- a/app/views/scholarships/_form_submission.html.erb
+++ b/app/views/scholarships/_form_submission.html.erb
@@ -24,7 +24,7 @@
<% @scholarship_answers.each do |field, response| %>
-
- <%= field.name %>
+ - <%= display_question_label(field, response) %>
- <%= display_response_text(field, response) %>
<% end %>
diff --git a/spec/helpers/event_helper_spec.rb b/spec/helpers/event_helper_spec.rb
index 944eb10f4..adb57c3a5 100644
--- a/spec/helpers/event_helper_spec.rb
+++ b/spec/helpers/event_helper_spec.rb
@@ -51,6 +51,28 @@
end
end
+ describe "#display_question_label" do
+ it "uses the question wording captured at submission time" do
+ field = build_stubbed(:form_field, name: "Current wording")
+ response = build_stubbed(:form_answer, question_name_when_answered: "Wording when answered")
+
+ expect(helper.display_question_label(field, response)).to eq("Wording when answered")
+ end
+
+ it "falls back to the field's current name when no answer is on file" do
+ field = build_stubbed(:form_field, name: "Current wording")
+
+ expect(helper.display_question_label(field, nil)).to eq("Current wording")
+ end
+
+ it "falls back to the field's current name when the snapshot is blank" do
+ field = build_stubbed(:form_field, name: "Current wording")
+ response = build_stubbed(:form_answer, question_name_when_answered: "")
+
+ expect(helper.display_question_label(field, response)).to eq("Current wording")
+ end
+ end
+
describe "#resolve_answer_text" do
it "maps category ids to names while preserving an 'Other: ' token" do
category_type = create(:category_type, name: "StoryPopulation")
diff --git a/spec/requests/events/public_registrations_spec.rb b/spec/requests/events/public_registrations_spec.rb
index 3d46433ff..a8b3b0674 100644
--- a/spec/requests/events/public_registrations_spec.rb
+++ b/spec/requests/events/public_registrations_spec.rb
@@ -489,5 +489,17 @@ def post_with_scholarship(scholarship_answer)
expect(response.body).to include("Your details")
expect(response.body).to include("Name")
end
+
+ it "shows the question wording captured at submission time, not the reworded label" do
+ submission = FormSubmission.find_by(person: person, form: form)
+ submission.form_answers.create!(form_field: essay_field, submitted_answer: "my reasons",
+ question_name_when_answered: "Why do you want to attend?")
+ essay_field.update!(name: "Reworded after submission")
+
+ get event_public_registration_path(event, person_id: person.id)
+
+ expect(response.body).to include("Why do you want to attend?")
+ expect(response.body).not_to include("Reworded after submission")
+ end
end
end