From 472a5bd9c1c2cd8c6155eaa0254187ecb24a4f52 Mon Sep 17 00:00:00 2001 From: Simmon Li Date: Sat, 16 Nov 2024 20:19:31 +0000 Subject: [PATCH] Fix admin form to actually show sponsor field (#72) * Fix admin form to actually show sponsor field * Add integration spec to make sure form has all the expected fields * Update comment --- app/views/admin/events/_form.html.erb | 16 ++++++++-- .../admin/events_controller_test.rb | 29 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/app/views/admin/events/_form.html.erb b/app/views/admin/events/_form.html.erb index b3961bc..b79d427 100644 --- a/app/views/admin/events/_form.html.erb +++ b/app/views/admin/events/_form.html.erb @@ -1,7 +1,8 @@ <%= form_with(model: [:admin, event]) do |form| %> <% if event.errors.any? %>
-

<%= pluralize(event.errors.count, "error") %> prohibited this event from being saved:

+

<%= pluralize(event.errors.count, "error") %> + prohibited this event from being saved:

-<% end %> +<% end %> diff --git a/test/controllers/admin/events_controller_test.rb b/test/controllers/admin/events_controller_test.rb index 2d7572a..4d0c89c 100644 --- a/test/controllers/admin/events_controller_test.rb +++ b/test/controllers/admin/events_controller_test.rb @@ -72,4 +72,33 @@ def setup assert_response :redirect assert_redirected_to admin_events_path end + + test 'edit form should show all fields for the event' do + # Also tests the form has all our model's attributes + get admin_event_path(Event.first.slug), + headers: { + Authorization: + ActionController::HttpAuthentication::Basic.encode_credentials( + 'admin', 'admin' + ) + } + + # Get all attributes and rich text associations + editable = Event.rich_text_association_names.map { |assoc| + assoc.to_s.gsub('rich_text', 'event') + } + Event.attribute_names.map do |attr| + "event_#{attr}" + end + # Remove meta attributes we don't edit via the form + editable -= %w[event_id event_slug event_city event_created_at event_updated_at] + + # Form fields we expect + want = %w[event_name event_location event_link event_description event_sponsor event_sponsor_link + event_sponsor_logo event_start_at event_status] + assert_equal(want.length, editable.length) + + want.each do |attr| + css_select "##{attr}" + end + end end