Skip to content
Merged
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
28 changes: 28 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,34 @@ def form_submission_link_path(submission)
form_submission_path(submission)
end

# A friendly type name for a noticeable record, e.g. "Registration" or "Bulk
# payment" rather than the raw model name ("EventRegistration").
def noticeable_type_label(record)
return "Registration" if record.is_a?(EventRegistration)

if record.is_a?(FormSubmission)
return record.role == "bulk_payment" ? "Bulk payment" : "Form submission"
end

record.class.name.underscore.humanize
end

# A human-friendly name for a noticeable record (the registrant and event for a

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: noticeable_label special-cases registrations/submissions (registrant · event, submitter · form) and otherwise falls back through title/name/full_name, so any future noticeable type gets a sensible label without changes here.

# registration, the submitter and form for a submission, otherwise the record's
# own title/name), so links read as the thing rather than its model class.
def noticeable_label(record)
label = case record
when EventRegistration
[ record.registrant&.name, record.event&.title ].compact_blank.join(" · ")
when FormSubmission
[ record.person&.name, record.form&.name ].compact_blank.join(" · ")
else
record.try(:title) || record.try(:name) || record.try(:full_name)
end

label.presence || "##{record.id}"
end

def search_page(params)
params[:search] ? params[:search][:page] : 1
end
Expand Down
19 changes: 11 additions & 8 deletions app/views/notifications/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@

<!-- Record -->
<td class="px-4 py-3 text-gray-700">
<% record_path = notification.noticeable.present? ? routable_path(notification.noticeable) : nil %>
<% if record_path %>
<%= link_to notification.noticeable.class.name,
record_path,
data: { turbo_frame: "_top" },
class: "btn btn-secondary-outline" %>
<% elsif notification.noticeable.present? %>
<span class="text-gray-700"><%= notification.noticeable.class.name %></span>
<% if notification.noticeable.present? %>
<% record_path = routable_path(notification.noticeable) %>
<div class="text-[10px] uppercase text-gray-400"><%= noticeable_type_label(notification.noticeable) %></div>
<% if record_path %>
<%= link_to noticeable_label(notification.noticeable),
record_path,
data: { turbo_frame: "_top" },
class: "font-medium text-blue-600 hover:underline" %>
<% else %>
<span class="font-medium text-gray-700"><%= noticeable_label(notification.noticeable) %></span>
<% end %>
<% else %>
<span class="text-gray-400">—</span>
<% end %>
Expand Down
12 changes: 9 additions & 3 deletions app/views/notifications/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,15 @@
<dt class="w-28 text-gray-500">Noticeable</dt>
<dd class="text-gray-900">
<% if @notification.noticeable.present? %>
<%= link_to @notification.noticeable.class.name,
polymorphic_path(@notification.noticeable),
class: "text-blue-600 hover:underline" %>
<% record_path = routable_path(@notification.noticeable) %>

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: This is the actual bug fix — #1656 only updated the index, leaving the detail page calling polymorphic_path unconditionally, which raised for FormSubmission noticeables (bulk payments). Reusing routable_path here makes it consistent and crash-safe.

<span class="text-xs uppercase text-gray-400 mr-2"><%= noticeable_type_label(@notification.noticeable) %></span>
<% if record_path %>
<%= link_to noticeable_label(@notification.noticeable),
record_path,
class: "font-medium text-blue-600 hover:underline" %>
<% else %>
<span class="font-medium"><%= noticeable_label(@notification.noticeable) %></span>
<% end %>
<% else %>
<% end %>
Expand Down
40 changes: 40 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,44 @@
expect(helper.routable_path(submission)).to eq(form_submission_path(submission))
end
end

describe "#noticeable_type_label" do
it "names registrations and bulk payments in plain language" do
registration = build(:event_registration)
bulk = build(:form_submission, role: "bulk_payment")
submission = build(:form_submission, role: "registration")

expect(helper.noticeable_type_label(registration)).to eq("Registration")
expect(helper.noticeable_type_label(bulk)).to eq("Bulk payment")
expect(helper.noticeable_type_label(submission)).to eq("Form submission")
end

it "humanizes other model names" do
expect(helper.noticeable_type_label(build(:user))).to eq("User")
end
end

describe "#noticeable_label" do
it "describes a registration by registrant and event" do
person = create(:person, first_name: "Jane", last_name: "Doe")
event = create(:event, title: "Summer Workshop")
registration = create(:event_registration, registrant: person, event: event)

expect(helper.noticeable_label(registration)).to eq("#{person.name} · Summer Workshop")
end

it "describes a form submission by submitter and form" do
person = create(:person, first_name: "Jane", last_name: "Doe")
form = create(:form, name: "Bulk Payment")
submission = create(:form_submission, person: person, form: form)

expect(helper.noticeable_label(submission)).to eq("#{person.name} · Bulk Payment")
end

it "uses the record's own name for other models" do
user = build(:user)

expect(helper.noticeable_label(user)).to eq(user.name)
end
end
end