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

Improve client share error message #4784

Merged
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
2 changes: 1 addition & 1 deletion app/models/partners/served_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class ServedArea < ApplicationRecord
belongs_to :partner_profile, class_name: "Partners::Profile"
belongs_to :county
validates :client_share, numericality: {only_integer: true}
validates :client_share, inclusion: {in: 1..100}
validates :client_share, inclusion: {in: 1..100, message: "Client share must be between 1 and 100 inclusive"}
end
end
30 changes: 19 additions & 11 deletions spec/models/partners/served_area_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,27 @@
#

RSpec.describe Partners::ServedArea, type: :model do
it { should belong_to(:partner_profile) }
it { should belong_to(:county) }
describe "validations" do
let(:served_area_nil_client_share) { build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: nil) }
it { should belong_to(:partner_profile) }
it { should belong_to(:county) }

it "must only allow integer client shares" do
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 50)).to be_valid
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 50.5)).not_to be_valid
end
it "displays a user friendly error message for nil client shares" do
expect(served_area_nil_client_share).not_to be_valid
expect(served_area_nil_client_share.errors.messages[:client_share]).to match_array(["Client share must be between 1 and 100 inclusive", "is not a number"])
end

it "must only allow integer client shares" do
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 50)).to be_valid
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 50.5)).not_to be_valid
end

it "must only allow valid client share values" do
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 0)).not_to be_valid
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 101)).not_to be_valid
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 1)).to be_valid
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 100)).to be_valid
it "must only allow valid client share values" do
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 0)).not_to be_valid
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 101)).not_to be_valid
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 1)).to be_valid
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 100)).to be_valid
end
end

describe "versioning" do
Expand Down
2 changes: 1 addition & 1 deletion spec/services/partner_profile_update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
expect(profile.served_areas.size).to eq(2)
result = PartnerProfileUpdateService.new(profile.partner, partner_params, incorrect_attributes_missing_client_share).call
expect(result.success?).to eq(false)
expect(result.error.to_s).to include("Validation failed: Served areas client share is not a number, Served areas client share is not included in the list")
expect(result.error.to_s).to include("Validation failed: Served areas client share is not a number, Served areas client share Client share must be between 1 and 100 inclusive")
profile.reload
expect(profile.served_areas.size).to eq(2)
end
Expand Down