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

633 allow survey answers to be multiselect #639

Merged
merged 2 commits into from
Oct 30, 2024
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
2 changes: 1 addition & 1 deletion backend/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gem 'pundit'
gem 'rack', '~> 2.0'
gem 'rack-cors', '~> 2.0'
gem 'rails', '~> 7.1.4'
gem 'rexml', '>= 3.3.3'
gem 'rexml', '>= 3.3.9'
gem 'sendgrid-actionmailer'
gem 'sprockets-rails'
gem 'sucker_punch', '~> 3.0'
Expand Down
6 changes: 2 additions & 4 deletions backend/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ GEM
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.3.6)
strscan
rexml (3.3.9)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.1)
Expand Down Expand Up @@ -296,7 +295,6 @@ GEM
activesupport (>= 6.1)
sprockets (>= 3.0.0)
stringio (3.1.1)
strscan (3.1.0)
sucker_punch (3.2.0)
concurrent-ruby (~> 1.0)
syntax_suggest (2.0.0)
Expand Down Expand Up @@ -347,7 +345,7 @@ DEPENDENCIES
rack (~> 2.0)
rack-cors (~> 2.0)
rails (~> 7.1.4)
rexml (>= 3.3.3)
rexml (>= 3.3.9)
rspec-rails (~> 6.0.0)
rubocop
rubocop-rails
Expand Down
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
Loading