Skip to content

Commit

Permalink
Fix admin form to actually show sponsor field (#72)
Browse files Browse the repository at this point in the history
* Fix admin form to actually show sponsor field

* Add integration spec to make sure form has all the expected fields

* Update comment
  • Loading branch information
crespire authored Nov 16, 2024
1 parent 6c9e829 commit 472a5bd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/views/admin/events/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<%= form_with(model: [:admin, event]) do |form| %>
<% if event.errors.any? %>
<div style="color: red">
<h2><%= pluralize(event.errors.count, "error") %> prohibited this event from being saved:</h2>
<h2><%= pluralize(event.errors.count, "error") %>
prohibited this event from being saved:</h2>

<ul>
<% event.errors.each do |error| %>
Expand All @@ -21,13 +22,22 @@
<%= form.label :description %>
<%= form.rich_text_area :description %>
<%= form.label :sponsor %>
<%= form.text_field :sponsor %>
<%= form.label :sponsor_link %>
<%= form.text_field :sponsor_link %>
<%= form.label :sponsor_logo %>
<%= form.text_field :sponsor_logo %>
<%= form.label :start_at %>
<%= form.datetime_field :start_at, include_seconds: false, value: event&.start_at&.in_time_zone("Eastern Time (US & Canada)").presence || Time.zone.now.in_time_zone("Eastern Time (US & Canada)") %>
<%= form.datetime_field :start_at,
include_seconds: false,
value:
event
&.start_at
&.in_time_zone("Eastern Time (US & Canada)")
.presence ||
Time.zone.now.in_time_zone("Eastern Time (US & Canada)") %>
<%= form.label :status %>
<%= form.select :status, options_for_select(Event.statuses_for_select, event.status) %>
<%= form.submit %>
</div>
<% end %>
<% end %>
29 changes: 29 additions & 0 deletions test/controllers/admin/events_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 472a5bd

Please sign in to comment.