From 6be455e1afae857b9e479738791de320f5097f10 Mon Sep 17 00:00:00 2001 From: Ryan Vasios Date: Fri, 6 Feb 2026 13:59:27 -0500 Subject: [PATCH 1/3] Update turbo views to update partial --- .../registrations/create.turbo_stream.erb | 3 +- .../registrations/destroy.turbo_stream.erb | 3 +- app/views/events/show.html.erb | 32 +------------------ 3 files changed, 5 insertions(+), 33 deletions(-) diff --git a/app/views/events/registrations/create.turbo_stream.erb b/app/views/events/registrations/create.turbo_stream.erb index 66e116a29..a317c10c2 100644 --- a/app/views/events/registrations/create.turbo_stream.erb +++ b/app/views/events/registrations/create.turbo_stream.erb @@ -1,2 +1,3 @@ -<%= turbo_stream.replace dom_id(@event, :card), partial: "events/card", locals: {event: @event} %> +<%= turbo_stream.replace dom_id(@event, :card), partial: "events/card", locals: { event: @event } %> +<%= turbo_stream.replace dom_id(@event, :registration_section), partial: "events/registration_section", locals: { event: @event.decorate } %> <%= turbo_stream.replace "flash_now", partial: "shared/flash_messages" %> diff --git a/app/views/events/registrations/destroy.turbo_stream.erb b/app/views/events/registrations/destroy.turbo_stream.erb index 66e116a29..a317c10c2 100644 --- a/app/views/events/registrations/destroy.turbo_stream.erb +++ b/app/views/events/registrations/destroy.turbo_stream.erb @@ -1,2 +1,3 @@ -<%= turbo_stream.replace dom_id(@event, :card), partial: "events/card", locals: {event: @event} %> +<%= turbo_stream.replace dom_id(@event, :card), partial: "events/card", locals: { event: @event } %> +<%= turbo_stream.replace dom_id(@event, :registration_section), partial: "events/registration_section", locals: { event: @event.decorate } %> <%= turbo_stream.replace "flash_now", partial: "shared/flash_messages" %> diff --git a/app/views/events/show.html.erb b/app/views/events/show.html.erb index 926c7e233..d8669e839 100644 --- a/app/views/events/show.html.erb +++ b/app/views/events/show.html.erb @@ -30,37 +30,7 @@
<%= @event.labelled_cost %>
<% end %> -
- -
- <% registered = @event.event_registrations.exists?(registrant_id: current_user&.id) %> - - <% if registered %> - <%= button_to "De-register", - event_registrant_registration_path(event_id: @event), - method: :delete, - data: { turbo_confirm: "Are you sure?" }, - class: "btn btn-secondary-outline" %> - <% elsif @event.registerable? %> - <%= button_to "Register", - event_registrant_registration_path(event_id: @event), - class: "btn btn-primary-outline" %> - <% else %> - Registration closed - <% end %> - - <% if registered %> - - You are registered! - - <% end %> -
- - - <% if registered %> -
<%= @event.calendar_links %>
- <% end %> -
+ <%= render "events/registration_section", event: @event %> <% if @event.registration_close_date %>
From 2715d4b2fdae8b1952d9d343f3577e4aecd08449 Mon Sep 17 00:00:00 2001 From: Ryan Vasios Date: Fri, 6 Feb 2026 16:47:06 -0500 Subject: [PATCH 2/3] Add system spec --- spec/system/events_show_spec.rb | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/spec/system/events_show_spec.rb b/spec/system/events_show_spec.rb index ff0efefdf..2b4dcb424 100644 --- a/spec/system/events_show_spec.rb +++ b/spec/system/events_show_spec.rb @@ -130,6 +130,47 @@ end end + # -------------------------------------------------- + # REGISTRATION BUTTON UPDATES VIA TURBO + # -------------------------------------------------- + + describe "registration button updates via Turbo", js: true do + before { driven_by(:selenium_chrome_headless) } + + it "updates Register to De-register and shows badge without full page reload" do + sign_in(user) + visit event_path(event) + + expect(page).to have_button("Register") + expect(page).not_to have_text("You are registered!") + + click_button "Register" + + # Turbo stream replaces the registration section; we stay on the event page + expect(page).to have_current_path(event_path(event)) + expect(page).to have_button("De-register") + expect(page).to have_text("You are registered!") + expect(page).not_to have_button("Register") + end + + it "updates De-register back to Register after de-registering" do + create(:event_registration, event: event, registrant: user) + + sign_in(user) + visit event_path(event) + + expect(page).to have_button("De-register") + accept_confirm do + click_button "De-register" + end + + expect(page).to have_current_path(event_path(event)) + expect(page).to have_button("Register") + expect(page).not_to have_button("De-register") + expect(page).not_to have_text("You are registered!") + end + end + # -------------------------------------------------- # REGISTRATION CLOSE DATE SECTION # -------------------------------------------------- From c5ad8ae69a1fed93d92551f66cc57b7054e7175c Mon Sep 17 00:00:00 2001 From: Ryan Vasios Date: Fri, 6 Feb 2026 17:04:04 -0500 Subject: [PATCH 3/3] Add events/_registration_section partial for show page --- .../events/_registration_section.html.erb | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 app/views/events/_registration_section.html.erb diff --git a/app/views/events/_registration_section.html.erb b/app/views/events/_registration_section.html.erb new file mode 100644 index 000000000..75e4382bf --- /dev/null +++ b/app/views/events/_registration_section.html.erb @@ -0,0 +1,30 @@ +<% registered = event.event_registrations.exists?(registrant_id: current_user&.id) %> +<%= tag.div id: dom_id(event.object, :registration_section), class: "registration-section flex flex-col gap-4 mb-6" do %> + +
+ <% if registered %> + <%= button_to "De-register", + event_registrant_registration_path(event_id: event), + method: :delete, + data: { turbo_confirm: "Are you sure?" }, + class: "btn btn-secondary-outline" %> + <% elsif event.registerable? %> + <%= button_to "Register", + event_registrant_registration_path(event_id: event), + class: "btn btn-primary-outline" %> + <% else %> + Registration closed + <% end %> + + <% if registered %> + + You are registered! + + <% end %> +
+ + + <% if registered %> +
<%= event.calendar_links %>
+ <% end %> +<% end %>