Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the Error message displayed #3

Merged
merged 2 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/controllers/late_policies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
12 changes: 6 additions & 6 deletions spec/controllers/late_policies_controller_spec.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down