mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make currency symbols optional for money column type in PostgreSQL
This commit is contained in:
parent
727da1d8cd
commit
ddd0e9b026
3 changed files with 10 additions and 2 deletions
|
@ -1,3 +1,7 @@
|
|||
* Make currency symbols optional for money column type in PostgreSQL
|
||||
|
||||
*Joel Schneider*
|
||||
|
||||
* Add database_exists? method to connection adapters to check if a database exists.
|
||||
|
||||
*Guilherme Mansur*
|
||||
|
|
|
@ -26,9 +26,9 @@ module ActiveRecord
|
|||
|
||||
value = value.sub(/^\((.+)\)$/, '-\1') # (4)
|
||||
case value
|
||||
when /^-?\D+[\d,]+\.\d{2}$/ # (1)
|
||||
when /^-?\D*[\d,]+\.\d{2}$/ # (1)
|
||||
value.gsub!(/[^-\d.]/, "")
|
||||
when /^-?\D+[\d.]+,\d{2}$/ # (2)
|
||||
when /^-?\D*[\d.]+,\d{2}$/ # (2)
|
||||
value.gsub!(/[^-\d,]/, "").sub!(/,/, ".")
|
||||
end
|
||||
|
||||
|
|
|
@ -54,8 +54,12 @@ class PostgresqlMoneyTest < ActiveRecord::PostgreSQLTestCase
|
|||
type = PostgresqlMoney.type_for_attribute("wealth")
|
||||
assert_equal(12345678.12, type.cast(+"$12,345,678.12"))
|
||||
assert_equal(12345678.12, type.cast(+"$12.345.678,12"))
|
||||
assert_equal(12345678.12, type.cast(+"12,345,678.12"))
|
||||
assert_equal(12345678.12, type.cast(+"12.345.678,12"))
|
||||
assert_equal(-1.15, type.cast(+"-$1.15"))
|
||||
assert_equal(-2.25, type.cast(+"($2.25)"))
|
||||
assert_equal(-1.15, type.cast(+"-1.15"))
|
||||
assert_equal(-2.25, type.cast(+"(2.25)"))
|
||||
end
|
||||
|
||||
def test_schema_dumping
|
||||
|
|
Loading…
Reference in a new issue