spec/dummy/app/models/product.rb in money-rails-1.2.0 vs spec/dummy/app/models/product.rb in money-rails-1.3.0
- old
+ new
@@ -3,10 +3,13 @@
register_currency :usd
# Use money-rails macros
monetize :price_cents
+ # Use money-rails macro with multiple fields
+ monetize :delivery_fee_cents, :restock_fee_cents, :allow_nil => true
+
# Use a custom name for the Money attribute
monetize :discount, :as => "discount_value"
# Allow nil
monetize :optional_price_cents, :allow_nil => true
@@ -27,20 +30,23 @@
:greater_than => 0,
:less_than_or_equal_to => 100,
:message => "Must be greater than zero and less than $100"
}
- attr_accessor :invalid_price_cents
- monetize :invalid_price_cents, disable_validation: true
+ attr_accessor :accessor_price_cents
+ monetize :accessor_price_cents, disable_validation: true
monetize :validates_method_amount_cents, allow_nil: true
validates :validates_method_amount, :money => {
:greater_than => 0,
- :less_than_or_equal_to => 100,
+ :less_than_or_equal_to => ->(product) { product.optional_price.to_f },
:message => 'Must be greater than zero and less than $100',
- }
+ }, allow_nil: true
alias_attribute :renamed_cents, :aliased_cents
monetize :renamed_cents, allow_nil: true
+
+ # Using postfix to determine currency column (reduced_price_currency)
+ monetize :reduced_price_cents, :allow_nil => true
end