From 24453c936c308f0ced5dc4e13ede3e4f43b9403f Mon Sep 17 00:00:00 2001 From: "Chris Baudouin, Jr" Date: Sat, 15 Aug 2020 20:01:43 -0400 Subject: [PATCH 1/2] refactor: Cleans update method in rsvps_controller --- app/controllers/rsvps_controller.rb | 41 +++++++++++++++++------------ 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/app/controllers/rsvps_controller.rb b/app/controllers/rsvps_controller.rb index 82d9f0e2d..f50f48a51 100644 --- a/app/controllers/rsvps_controller.rb +++ b/app/controllers/rsvps_controller.rb @@ -55,10 +55,34 @@ def update return end + update_acc_status + update_bus_list + + unless @questionnaire.save + flash[:alert] = @questionnaire.errors.full_message.join(", ") + redirect_to rsvp_path + return + end + + if flash[:notice].blank? && flash[:alert].blank? + flash[:notice] = "Your RSVP has been updated." + flash[:notice] += " See below for additional bus information!" if @questionnaire.bus_list_id? + end + + redirect_to rsvp_path + end + # rubocop:enable CyclomaticComplexity + # rubocop:enable PerceivedComplexity + + private + + def update_acc_status @questionnaire.acc_status_date = Time.now if @questionnaire.acc_status != params[:questionnaire][:acc_status] @questionnaire.acc_status = params[:questionnaire][:acc_status] @questionnaire.acc_status_author_id = current_user.id + end + def update_bus_list new_bus_list_id = params[:questionnaire][:bus_list_id].presence new_bus_list = new_bus_list_id && BusList.find(new_bus_list_id) is_joining_bus = new_bus_list.present? && @questionnaire.bus_list != new_bus_list @@ -72,24 +96,7 @@ def update @questionnaire.bus_list = new_bus_list @questionnaire.bus_captain_interest = params[:questionnaire][:bus_captain_interest] end - - unless @questionnaire.save - flash[:alert] = @questionnaire.errors.full_message.join(", ") - redirect_to rsvp_path - return - end - - if flash[:notice].blank? && flash[:alert].blank? - flash[:notice] = "Your RSVP has been updated." - flash[:notice] += " See below for additional bus information!" if @questionnaire.bus_list_id? - end - - redirect_to rsvp_path end - # rubocop:enable CyclomaticComplexity - # rubocop:enable PerceivedComplexity - - private def rsvp_error_notice hackathon_name = HackathonConfig['name'] From f93e8ecf37c95a6364c69d090b095da884214c82 Mon Sep 17 00:00:00 2001 From: "Chris Baudouin, Jr" Date: Sat, 15 Aug 2020 20:18:08 -0400 Subject: [PATCH 2/2] refactor: Fixes whitespace issue for Hound --- app/controllers/rsvps_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/rsvps_controller.rb b/app/controllers/rsvps_controller.rb index f50f48a51..32cfc9881 100644 --- a/app/controllers/rsvps_controller.rb +++ b/app/controllers/rsvps_controller.rb @@ -57,7 +57,7 @@ def update update_acc_status update_bus_list - + unless @questionnaire.save flash[:alert] = @questionnaire.errors.full_message.join(", ") redirect_to rsvp_path