File tree 2 files changed +24
-1
lines changed
active_record/monetizable
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -800,6 +800,20 @@ class SubProduct < Product
800
800
transaction . amount = "$123"
801
801
expect ( transaction . valid? ) . to be_truthy
802
802
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
803
817
end
804
818
end
805
819
end
Original file line number Diff line number Diff line change 1
1
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
+ }
3
12
4
13
monetize :tax_cents , with_model_currency : :currency
5
14
You can’t perform that action at this time.
0 commit comments