From b565be2f46763e72e34ba02ba59fe74b339c4692 Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Fri, 11 Mar 2022 11:44:48 -0800 Subject: [PATCH] Correct assumption of survey start and end dates The logic used for the `:reply` ability incompletely duplicated that of `Survey#active?` and incorrectly assumed that surveys always have start and end dates. Resolves: Failures: 1) Survey as an attendee respond to a survey during registration Failure/Error: survey.start_date > Time.current || survey.end_date < Time.current ActionView::Template::Error: undefined method `>' for nil:NilClass survey.start_date > Time.current || survey.end_date < Time.current ^ # ./app/models/ability.rb:126:in `block in signed_in' # ./app/views/surveys/show.html.haml:28:in `block in _app_views_surveys_show_html_haml___3404959267043700678_138180' # ./app/views/surveys/show.html.haml:19:in `_app_views_surveys_show_html_haml___3404959267043700678_138180' Failed examples: rspec ./spec/features/surveys_spec.rb:37 # Survey as an attendee respond to a survey during registration --- app/models/ability.rb | 4 +--- app/models/survey.rb | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index caf8f2a4..4fc5ae34 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -122,9 +122,7 @@ class Ability # if not, do not allow replies. # do not allow replies before the start_date or after the end_date of survey - cannot :reply, Survey do |survey| - survey.start_date > Time.current || survey.end_date < Time.current - end + cannot :reply, Survey, &:closed? can [:destroy], Openid diff --git a/app/models/survey.rb b/app/models/survey.rb index 50e251a7..66783e90 100644 --- a/app/models/survey.rb +++ b/app/models/survey.rb @@ -32,4 +32,8 @@ class Survey < ActiveRecord::Base now <= end_date end end + + def closed? + !active? + end end