From f8c313e0efe71bceb3d39afb897728ea83ecae5e Mon Sep 17 00:00:00 2001 From: Ashrita Ramaswamy Date: Tue, 25 Oct 2022 16:27:41 -0400 Subject: [PATCH 1/2] @kkotak @aramasw : Fixed the error message displayed --- app/controllers/late_policies_controller.rb | 10 +++++----- spec/controllers/late_policies_controller_spec.rb | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) mode change 100644 => 100755 spec/controllers/late_policies_controller_spec.rb diff --git a/app/controllers/late_policies_controller.rb b/app/controllers/late_policies_controller.rb index dd011475e3f..271397812bf 100644 --- a/app/controllers/late_policies_controller.rb +++ b/app/controllers/late_policies_controller.rb @@ -137,7 +137,7 @@ def check_if_policy_name_exists_on_update(prefix) if existing_late_policy.policy_name != late_policy_params[:policy_name] return check_if_policy_name_exists(prefix) end - + return true, nil end @@ -145,7 +145,7 @@ def check_if_policy_name_exists_on_update(prefix) def check_if_policy_name_exists(prefix) error_message = nil if LatePolicy.check_policy_with_same_name(late_policy_params[:policy_name], instructor_id) - error_message = prefix + 'A policy with the same name ' + late_policy_params[:policy_name] + ' already exists.' + error_message = prefix + 'A policy with the same name ' + late_policy_params[:policy_name] + ' already exists. ' return false, error_message end return true, error_message @@ -167,19 +167,19 @@ def validate_input(is_update = false) # This check validates the maximum penalty. if max_penalty < penalty_per_unit - error_message = prefix + 'The maximum penalty cannot be less than penalty per unit.' + error_message = "#{error_message}" +prefix + 'The maximum penalty cannot be less than penalty per unit. ' valid_penalty = false end # This check validates the penalty per unit for a late policy. if penalty_per_unit < 0 - error_message = 'Penalty per unit cannot be negative.' + error_message = "#{error_message}Penalty per unit cannot be negative. " valid_penalty = false end # This checks maximum penalty does not exceed 100. if max_penalty >= 100 - error_message = prefix + 'Maximum penalty cannot be greater than or equal to 100' + error_message = "#{error_message}" + prefix + 'Maximum penalty cannot be greater than or equal to 100. ' valid_penalty = false end diff --git a/spec/controllers/late_policies_controller_spec.rb b/spec/controllers/late_policies_controller_spec.rb old mode 100644 new mode 100755 index 8074931a742..655c7619c5f --- a/spec/controllers/late_policies_controller_spec.rb +++ b/spec/controllers/late_policies_controller_spec.rb @@ -96,7 +96,7 @@ } } post :create, params: request_params - expect(flash[:error]).to eq('The maximum penalty cannot be less than penalty per unit.') + expect(flash[:error]).to eq('The maximum penalty cannot be less than penalty per unit. ') expect(response).to redirect_to('/late_policies/new') end end @@ -115,7 +115,7 @@ } } post :create, params: request_params - expect(flash[:error]).to eq('Maximum penalty cannot be greater than or equal to 100') + expect(flash[:error]).to eq('Maximum penalty cannot be greater than or equal to 100. ') expect(response).to redirect_to('/late_policies/new') end end @@ -133,7 +133,7 @@ } } post :create, params: request_params - expect(flash[:error]).to eq('Penalty per unit cannot be negative.') + expect(flash[:error]).to eq('Penalty per unit cannot be negative. ') end end @@ -151,7 +151,7 @@ } } post :create, params: request_params - expect(flash[:error]).to eq('A policy with the same name Policy1 already exists.') + expect(flash[:error]).to eq('A policy with the same name Policy1 already exists. ') end end @@ -201,7 +201,7 @@ id: 1 } post :update, params: request_params - expect(flash[:error]).to eq('Cannot edit the policy. The maximum penalty cannot be less than penalty per unit.') + expect(flash[:error]).to eq('Cannot edit the policy. The maximum penalty cannot be less than penalty per unit. ') expect(response).to redirect_to('/late_policies/1/edit') end end @@ -220,7 +220,7 @@ id: 1 } post :update, params: request_params - expect(flash[:error]).to eq('Cannot edit the policy. A policy with the same name Policy1 already exists.') + expect(flash[:error]).to eq('Cannot edit the policy. A policy with the same name Policy1 already exists. ') end end From 14baad5c2aa1693a8209fde9c3f799099738a366 Mon Sep 17 00:00:00 2001 From: Ashrita Ramaswamy Date: Tue, 25 Oct 2022 16:30:19 -0400 Subject: [PATCH 2/2] @kkotak @aramasw Fix build errors --- app/controllers/late_policies_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/late_policies_controller.rb b/app/controllers/late_policies_controller.rb index 271397812bf..f1f5196d25a 100644 --- a/app/controllers/late_policies_controller.rb +++ b/app/controllers/late_policies_controller.rb @@ -137,7 +137,7 @@ def check_if_policy_name_exists_on_update(prefix) if existing_late_policy.policy_name != late_policy_params[:policy_name] return check_if_policy_name_exists(prefix) end - + return true, nil end @@ -167,7 +167,7 @@ def validate_input(is_update = false) # This check validates the maximum penalty. if max_penalty < penalty_per_unit - error_message = "#{error_message}" +prefix + 'The maximum penalty cannot be less than penalty per unit. ' + error_message = "#{error_message}" + prefix + 'The maximum penalty cannot be less than penalty per unit. ' valid_penalty = false end