This project is archived and is in readonly mode.
Decimal attributes no longer work on Rails 3.0 edge
Reported by Sam Ruby | October 17th, 2009 @ 10:01 PM | in 3.0.2
Specifically, the following commit does not handle decimals: http://github.com/rails/rails/commit/f936a1f100e75082081e782e5cceb2...
More detail, in the Depot application in AWDwR3, price is defined as:
#<ActiveRecord::Type::Number:0x7fb12389fba8 @typecaster=#<ActiveRecord::ConnectionAdapters::SQLiteColumn:0x7fb1238b93a0 @sql_type="decimal(8,2)", @precision=8, @primary=false, @type=:decimal, @limit=8, @default=#<BigDecimal:7fb1238b90a8,'0.0',9(18)>, @null=true, @name="price", @scale=2>
Decimal is not handled in NumberTest or Type::Number.
The net result is that instead of this value begin converted to a BigDecimal, it is left as a String, resulting in errors like comparison of String with Float failed in validation routines such as:
def price_must_be_at_least_a_cent
errors.add(:price, 'should be at least 0.01') if price.nil? || price < 0.00
end
Comments and changes to this ticket
-
Yehuda Katz (wycats) October 17th, 2009 @ 10:05 PM
- State changed from new to open
- Milestone cleared.
-
Eric Chapweske October 17th, 2009 @ 10:59 PM
This was due to *before_typecast permanently disabling typecasting. Attached is the fix. Decimals not covered under the spec is a problem too. I'll go through all the basic types and see that they're handled more thoroughly.
-
Sam Ruby October 17th, 2009 @ 11:22 PM
I've verified that that does address the problem I've found. :-)
-
josh October 18th, 2009 @ 05:15 PM
- State changed from open to resolved
-
Repository January 21st, 2010 @ 09:52 PM
- State changed from resolved to open
(from [6d30002a52133bd105adb29084f4cc72b1ee847f]) Revert "Refactoring attributes/types" [#3348 state:open]
This reverts commit f936a1f100e75082081e782e5cceb272885c2df7.
Conflicts:
activerecord/lib/active_record.rb activerecord/lib/active_record/base.rb
Revert "Fixed: #without_typecast should only disable typecasting on the duplicated attributes" [#3387 state:open]
This reverts commit 2831996483c6a045f1f38d8030256eb58d9771c3.
Reason :
It's not generating attribute methods properly, making object.column 5x slower. http://github.com/rails/rails/commit/6d30002a52133bd105adb29084f4cc...
-
Pratik January 21st, 2010 @ 10:12 PM
- State changed from open to resolved
-
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 3348 Refactoring of attributes/typecasting behavior Revert "Fixed: #without_typecast should only disable type...
- 3387 Decimal attributes no longer work on Rails 3.0 edge Revert "Fixed: #without_typecast should only disable type...