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
This commit is contained in:
Andrew Kvalheim 2022-03-11 11:44:48 -08:00
parent 3e7be52586
commit b565be2f46
2 changed files with 5 additions and 3 deletions

View file

@ -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

View file

@ -32,4 +32,8 @@ class Survey < ActiveRecord::Base
now <= end_date
end
end
def closed?
!active?
end
end