Skip to content

Commit

Permalink
633 Backend: Allow survey answers to be multiselect
Browse files Browse the repository at this point in the history
  • Loading branch information
lfilmeyer committed Oct 29, 2024
1 parent d22b87c commit 43bf6a8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion backend/app/controllers/survey_visits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def survey_visit_params
params.require(:survey_visit)
.permit(:surveyor_id, :home_id, :latitude, :longitude,
survey_response_attributes: [:survey_id,
{ survey_answers_attributes: %i[survey_question_id answer] }])
{ survey_answers_attributes: [:survey_question_id,
:answer, { answers: [] }] }])
end

def search_params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if survey_visit.survey_response.present?
json.id sa.id
json.survey_question_id sa.survey_question_id
json.answer sa.answer
json.answers sa.answers
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddAnswersToSurveyAnswers < ActiveRecord::Migration[7.1]
def change
add_column :survey_answers, :answers, :string, array: true, default: []
end
end
3 changes: 2 additions & 1 deletion backend/db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion backend/spec/requests/survey_visits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
survey_answers_attributes: [
{
survey_question_id: survey_question.id,
answer: 1
answer: 1,
answers: %w[Foo Bar]
}
]
}
Expand Down Expand Up @@ -88,6 +89,9 @@
expect(survey_response).to be_present
expect(survey_response.survey_id).to eq(survey.id)
expect(survey_response.survey_answers.count).to eq(1)

survey_answer = survey_response.survey_answers.first
expect(survey_answer.answers).to include('Foo', 'Bar')
end

it 'redirects to the created survey_visit' do
Expand Down

0 comments on commit 43bf6a8

Please sign in to comment.