Skip to content

Commit

Permalink
add restriction non negative partner quota
Browse files Browse the repository at this point in the history
  • Loading branch information
italomatos committed Sep 20, 2024
1 parent 51ed96b commit 8930b4f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Partner < ApplicationRecord
validates :email, presence: true, uniqueness: { case_sensitive: false },
format: { with: URI::MailTo::EMAIL_REGEXP, on: :create }

validates :quota, numericality: true, allow_blank: true
validates :quota, numericality: { greater_than_or_equal_to: 0 }, allow_blank: true

validate :correct_document_mime_type

Expand Down
6 changes: 6 additions & 0 deletions spec/models/partner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
end

it { should validate_numericality_of(:quota).allow_nil }

it "validates that the quota is greater than or equal to 0" do
expect(build(:partner, quota: -1)).not_to be_valid
expect(build(:partner, quota: 0)).to be_valid
expect(build(:partner, quota: 1)).to be_valid
end
end

context "callbacks" do
Expand Down

0 comments on commit 8930b4f

Please sign in to comment.