Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Decimal attributes no longer work on Rails 3.0 edge

#3387

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

Reported by Sam Ruby · October 17th, 2009 @ 10:01 PM

State: resolved
Milestone: 3.0.2
Assigned to: josh josh
Importance: none

Activity

  1. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • State changed from new to open
    • Milestone cleared.

    October 17th, 2009 @ 10:05 PM

  2. Eric Chapweske
    Eric Chapweske

    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.

    October 17th, 2009 @ 10:59 PM

  3. Sam Ruby
    Sam Ruby

    I've verified that that does address the problem I've found. :-)

    October 17th, 2009 @ 11:22 PM

  4. josh
    josh
    • State changed from open to resolved

    October 18th, 2009 @ 05:15 PM

  5. Repository
    Repository
    • 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...

    January 21st, 2010 @ 09:52 PM

  6. Pratik
    Pratik
    • State changed from open to resolved

    January 21st, 2010 @ 10:12 PM

  7. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to

    October 15th, 2010 @ 11:01 PM