docs/survey_resubmission.md
The survey system now supports allowing users to resubmit surveys after they have completed them. This is controlled by a new allow_resubmission field on the Survey model.
allow_resubmissionbooleanfalsefalseThe Survey model now includes two new methods:
completed_by_user?(user)Returns true if the user has responded to all polls in the survey (either by voting, skipping, or providing text responses).
can_user_submit?(user)Returns true if the user is allowed to submit the survey:
true if allow_resubmission is truetrue if the user hasn't completed the survey yetfalse if the user has completed the survey and resubmission is not allowedallow_resubmission is false (default)allow_resubmission is true/surveys/:id/votes)The response now includes additional fields:
{
"votes": { "poll_id": "response" },
"can_submit": true,
"completed": false,
"allow_resubmission": false
}
can_submit: Whether the user can currently submit the surveycompleted: Whether the user has completed all polls in the surveyallow_resubmission: Whether the survey allows resubmissionWhen a poll belongs to a survey, the controller now checks if the user can submit the survey before allowing votes.
When a poll belongs to a survey, the controller now checks if the user can submit the survey before allowing text responses. Additionally, it now updates existing responses instead of creating duplicates.
The JavaScript in SurveyTag has been updated to handle resubmission scenarios:
To enable resubmission for a survey:
survey = Survey.find(id)
survey.update!(allow_resubmission: true)
Or when creating a new survey:
Survey.create!(
title: "My Survey",
allow_resubmission: true
)
Comprehensive tests have been added for:
Run the tests with:
bundle exec rspec spec/models/survey_spec.rb
bundle exec rspec spec/controllers/surveys_controller_spec.rb
bundle exec rspec spec/requests/poll_votes_spec.rb
bundle exec rspec spec/requests/poll_text_responses_spec.rb