Skip to content

Commit b27ef92

Browse files
authored
Merge pull request #622 from maebeale/fix-form-when-no-responses
Allow for no custom questions on ask/offer form
2 parents 36a6809 + 15d30ca commit b27ef92

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
### Bugfixes
5+
* Ask/Offer form breaks when no custom questions are configured #621, #622
6+
37
## [0.2.8] - 2020-08-02
48
### Bugfixes
59
* Remove final & operator so all nils -> 0.0 #618

app/forms/submission_form.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
class SubmissionForm < BaseForm
2+
hash :responses_attributes, strip: false, default: {}
3+
24
with_options default: nil do
35
integer :id
46
record :service_area
57
hash :listing_attributes, strip: false
68
hash :location_attributes, strip: false
79
hash :person_attributes, strip: false
8-
hash :responses_attributes, strip: false
910
string :form_name
1011
string :privacy_level_requested # fixme: not submitted as yet
1112
end
@@ -38,6 +39,7 @@ def build_listing
3839

3940
def build_submission
4041
submission.tap do |submission|
42+
# todo: this has to be smarter if we want to support partial updates
4143
submission.attributes = submission_attributes
4244
end
4345
end

spec/forms/submission_form_spec.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828
2929
name: 'Harriet Tubman',
3030
},
31-
responses_attributes: {
32-
questions.first.id.to_s => "answer 1",
33-
questions.second.id.to_s => "answer 2"
34-
},
31+
responses_attributes: questions.map.with_index { |question, index|
32+
[question.id.to_s, "answer #{index + 1}"]
33+
}.to_h,
3534
}}
3635

3736
subject(:submission) { SubmissionForm.build params }
@@ -129,6 +128,14 @@
129128
expect(submission_responses.length).to eq(2)
130129
expect(submission_responses.first.string_response).to eq("answer 1")
131130
end
131+
132+
context 'when there are no custom questions' do
133+
let(:questions) { [] }
134+
135+
it 'works without error' do
136+
expect(submission_responses).to be_empty
137+
end
138+
end
132139
end
133140

134141
describe 'submission capture' do

0 commit comments

Comments
 (0)