Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/helpers/event_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 From Claude: Fallback to the live field.name is intentional but means answers predating the question_name_when_answered column (blank snapshot) still show the current wording — there's no backfill, only forward capture.

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?
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/public_registrations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<% else %>
<% response = @responses[field.id] %>
<div class="<%= field.grid_span_class %> py-2">
<dt class="rich-label text-xs font-medium text-gray-500 uppercase tracking-wide"><%= form_label_html(field.name) %></dt>
<dt class="rich-label text-xs font-medium text-gray-500 uppercase tracking-wide"><%= form_label_html(display_question_label(field, response)) %></dt>
<dd class="mt-1 text-sm text-gray-900">
<%= display_response_text(field, response) %>
</dd>
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/recipients.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
<dl class="space-y-4">
<% answers.each do |answer| %>
<div>
<dt class="text-sm font-semibold text-gray-800"><%= answer.question_name_when_answered.presence || answer.form_field&.name %></dt>
<dt class="text-sm font-semibold text-gray-800"><%= display_question_label(answer.form_field, answer) %></dt>
<dd class="mt-1 text-sm text-gray-700 whitespace-pre-line"><%= resolve_answer_text(answer.form_field, answer.submitted_answer) %></dd>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/form_submissions/_submission.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</div>
<% else %>
<div class="py-2">
<dt class="text-xs font-medium text-gray-500 uppercase tracking-wide"><%= field.name %></dt>
<dt class="text-xs font-medium text-gray-500 uppercase tracking-wide"><%= display_question_label(field, response) %></dt>
<dd class="mt-1 text-sm text-gray-900">
<%= response&.submitted_answer.presence || tag.span("—", class: "text-gray-400") %>
</dd>
Expand Down
2 changes: 1 addition & 1 deletion app/views/scholarships/_form_submission.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dl class="space-y-3">
<% @scholarship_answers.each do |field, response| %>
<div>
<dt class="text-xs font-medium uppercase tracking-wide text-gray-400"><%= field.name %></dt>
<dt class="text-xs font-medium uppercase tracking-wide text-gray-400"><%= display_question_label(field, response) %></dt>
<dd class="mt-0.5 text-sm text-gray-900 whitespace-pre-line"><%= display_response_text(field, response) %></dd>
</div>
<% end %>
Expand Down
22 changes: 22 additions & 0 deletions spec/helpers/event_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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: <text>' token" do
category_type = create(:category_type, name: "StoryPopulation")
Expand Down
12 changes: 12 additions & 0 deletions spec/requests/events/public_registrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,5 +423,17 @@ def post_with_scholarship(scholarship_answer)
expect(response.body).to include("<strong>Your details</strong>")
expect(response.body).to include("<em>Name</em>")
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