Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly support optional location_type on submission form #922

Merged
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
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_interaction (3.8.2)
activemodel (>= 4, < 7)
active_interaction (4.0.0)
activemodel (>= 5, < 7)
activejob (6.0.3.6)
activesupport (= 6.0.3.6)
globalid (>= 0.3.6)
Expand Down
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