Skip to content

Commit

Permalink
Allow for no custom questions on ask/offer form
Browse files Browse the repository at this point in the history
Fixes #621.
  • Loading branch information
solebared committed Aug 6, 2020
1 parent 36a6809 commit 15d30ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased
### Bugfixes
* Ask/Offer form breaks when no custom questions are configured #621, #622

## [0.2.8] - 2020-08-02
### Bugfixes
* Remove final & operator so all nils -> 0.0 #618
Expand Down
4 changes: 3 additions & 1 deletion app/forms/submission_form.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class SubmissionForm < BaseForm
hash :responses_attributes, strip: false, default: {}

with_options default: nil do
integer :id
record :service_area
hash :listing_attributes, strip: false
hash :location_attributes, strip: false
hash :person_attributes, strip: false
hash :responses_attributes, strip: false
string :form_name
string :privacy_level_requested # fixme: not submitted as yet
end
Expand Down Expand Up @@ -38,6 +39,7 @@ def build_listing

def build_submission
submission.tap do |submission|
# todo: this has to be smarter if we want to support partial updates
submission.attributes = submission_attributes
end
end
Expand Down
15 changes: 11 additions & 4 deletions spec/forms/submission_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
email: 'we@together.coop',
name: 'Harriet Tubman',
},
responses_attributes: {
questions.first.id.to_s => "answer 1",
questions.second.id.to_s => "answer 2"
},
responses_attributes: questions.map.with_index { |question, index|
[question.id.to_s, "answer #{index + 1}"]
}.to_h,
}}

subject(:submission) { SubmissionForm.build params }
Expand Down Expand Up @@ -129,6 +128,14 @@
expect(submission_responses.length).to eq(2)
expect(submission_responses.first.string_response).to eq("answer 1")
end

context 'when there are no custom questions' do
let(:questions) { [] }

it 'works without error' do
expect(submission_responses).to be_empty
end
end
end

describe 'submission capture' do
Expand Down

0 comments on commit 15d30ca

Please sign in to comment.