Skip to content

Commit 20cf220

Browse files
authored
Merge pull request #4784 from McEileen/4673/improve-client-share-error-message
Improve client share error message
2 parents ca8ccd8 + beec1c8 commit 20cf220

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

app/models/partners/served_area.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ class ServedArea < ApplicationRecord
1616
belongs_to :partner_profile, class_name: "Partners::Profile"
1717
belongs_to :county
1818
validates :client_share, numericality: {only_integer: true}
19-
validates :client_share, inclusion: {in: 1..100}
19+
validates :client_share, inclusion: {in: 1..100, message: "Client share must be between 1 and 100 inclusive"}
2020
end
2121
end

spec/models/partners/served_area_spec.rb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,27 @@
1111
#
1212

1313
RSpec.describe Partners::ServedArea, type: :model do
14-
it { should belong_to(:partner_profile) }
15-
it { should belong_to(:county) }
14+
describe "validations" do
15+
let(:served_area_nil_client_share) { build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: nil) }
16+
it { should belong_to(:partner_profile) }
17+
it { should belong_to(:county) }
1618

17-
it "must only allow integer client shares" do
18-
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 50)).to be_valid
19-
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 50.5)).not_to be_valid
20-
end
19+
it "displays a user friendly error message for nil client shares" do
20+
expect(served_area_nil_client_share).not_to be_valid
21+
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"])
22+
end
23+
24+
it "must only allow integer client shares" do
25+
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 50)).to be_valid
26+
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 50.5)).not_to be_valid
27+
end
2128

22-
it "must only allow valid client share values" do
23-
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 0)).not_to be_valid
24-
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 101)).not_to be_valid
25-
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 1)).to be_valid
26-
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 100)).to be_valid
29+
it "must only allow valid client share values" do
30+
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 0)).not_to be_valid
31+
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 101)).not_to be_valid
32+
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 1)).to be_valid
33+
expect(build(:partners_served_area, partner_profile: create(:partner_profile), county: create(:county), client_share: 100)).to be_valid
34+
end
2735
end
2836

2937
describe "versioning" do

spec/services/partner_profile_update_service_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
expect(profile.served_areas.size).to eq(2)
8989
result = PartnerProfileUpdateService.new(profile.partner, partner_params, incorrect_attributes_missing_client_share).call
9090
expect(result.success?).to eq(false)
91-
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")
91+
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")
9292
profile.reload
9393
expect(profile.served_areas.size).to eq(2)
9494
end

0 commit comments

Comments
 (0)