Skip to content

Commit

Permalink
Use string filter instead of record for location_type
Browse files Browse the repository at this point in the history
`active_interaction` doesn't coerce an empty string value to the default
value on `record` filters[1]. This causes the form to break on any form
where `location_type` is optional (eg CommunityResources#create).

We hadn't run into this on the Ask|Offer form because we only show the
location_type input once the user provides an address, and then rely on
the browser to enforce that it's populated.

[1] AaronLasseigne/active_interaction#503
  • Loading branch information
solebared committed Apr 3, 2021
1 parent 7b1dca7 commit b68799a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/forms/location_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class LocationForm < BaseForm
with_options default: nil do
integer :id
record :location_type
integer :location_type
string :street_address
string :neighborhood
string :city
Expand All @@ -17,7 +17,14 @@ def execute
return nil if inputs.values.all?(&:blank?)

Location.find_or_new(id).tap do |location|
location.attributes = given_inputs
location.attributes = given_inputs_without_location_type
location.location_type_id = location_type if given?(:location_type)
end
end

private

def given_inputs_without_location_type
given_inputs.reject {|key| key == :location_type }
end
end
1 change: 1 addition & 0 deletions spec/forms/submission_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
before do
params[:location_attributes] = {
street_address: '',
location_type: '',
}
end

Expand Down

0 comments on commit b68799a

Please sign in to comment.