Skip to content

Commit 2c89bf4

Browse files
committed
Add validations for transaction when the currency used a dot as a thousand separator
1 parent aa86548 commit 2c89bf4

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Diff for: spec/active_record/monetizable/monetize_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,20 @@ class SubProduct < Product
800800
transaction.amount = "$123"
801801
expect(transaction.valid?).to be_truthy
802802
end
803+
804+
it "is valid when the monetize field is set" do
805+
transaction.amount = 5_000
806+
transaction.currency = :eur
807+
808+
expect(transaction.valid?).to be_truthy
809+
end
810+
811+
it "is valid when the monetize field is not set" do
812+
transaction.update(amount: 5_000, currency: :eur)
813+
transaction.reload # reload to simulate the retrieved object
814+
815+
expect(transaction.valid?).to be_truthy
816+
end
803817
end
804818
end
805819
end

Diff for: spec/dummy/app/models/transaction.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
class Transaction < ActiveRecord::Base
2-
monetize :amount_cents, with_model_currency: :currency
2+
monetize :amount_cents, with_model_currency: :currency,
3+
subunit_numericality: {
4+
only_integer: true,
5+
greater_than: 0,
6+
less_than_or_equal_to: 2_000_000,
7+
},
8+
numericality: {
9+
greater_than: 0,
10+
less_than_or_equal_to: 20_000
11+
}
312

413
monetize :tax_cents, with_model_currency: :currency
514

0 commit comments

Comments
 (0)