Bergrebell / CyberCoach

1 stars 1 forks source link

[SportSession] Edit result exception #109

Closed lexruee closed 9 years ago

lexruee commented 9 years ago

Heroku log

T20:21:32.003522+00:00 app[web.1]:   Rendered cyclings/_table_attributes.erb (424.8ms)
2014-12-14T20:21:40.818439+00:00 app[web.1]:   app/models/sport_session.rb:264:in `result'
2014-12-14T20:21:40.818434+00:00 app[web.1]: F, [2014-12-14T20:21:40.818321 #2] FATAL -- : 
2014-12-14T20:21:40.818443+00:00 app[web.1]: 
2014-12-14T20:21:40.805879+00:00 app[web.1]: Processing by CyclingsController#edit_result as HTML
2014-12-14T20:21:40.805947+00:00 app[web.1]:   Parameters: {"id"=>"8"}
2014-12-14T20:21:40.816850+00:00 app[web.1]: Completed 404 Not Found in 11ms
2014-12-14T20:21:40.803583+00:00 app[web.1]: I, [2014-12-14T20:21:40.803487 #2]  INFO -- : Started GET "/cyclings/8/edit/result" for 81.62.83.171 at 2014-12-14 20:21:40 +0000
2014-12-14T20:21:40.820944+00:00 heroku[router]: at=info method=GET path="/cyclings/8/edit/result" host=radiant-depths-9885.herokuapp.com request_id=de5aa220-7064-4d18-ba2d-1ebc87d52286 fwd="81.62.83.171" dyno=web.1 connect=1ms service=20ms status=404 bytes=1829
2014-12-14T20:21:40.818437+00:00 app[web.1]: ActiveRecord::RecordNotFound (ActiveRecord::RecordNotFound):
2014-12-14T20:21:40.818442+00:00 app[web.1]: 
2014-12-14T20:21:40.818440+00:00 app[web.1]:   app/controllers/cyclings_controller.rb:35:in `edit_result'

Clicking on edit results on a sport session where a user is invited to join a passed sport session, results in an error.

screenshot from 2014-12-14 21 25 17

in SportSession#result(user):

def result(user)
    participant = SportSessionParticipant.where(:user_id => user.id, :sport_session_id => self.id, :confirmed => true).first! #  this line here raises an exception

    case self.type
      when 'Running'
        result = RunningParticipantResult.where(:sport_session_participant_id => participant.id).first_or_create
      when 'Boxing'
        result = BoxingParticipantResult.where(:sport_session_participant_id => participant.id).first_or_create
      when 'Cycling'
        result = CyclingParticipantResult.where(:sport_session_participant_id => participant.id).first_or_create
      else
        raise 'Unknown Type'
    end

    result
  end
lexruee commented 9 years ago

I'll add exception handling in the edit_result controller action.

lexruee commented 9 years ago

Fixed in commit: 53ed07a7e6d55795a92f8f7242f200b74f7fcc76