diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-08-26 11:14:56 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-08-26 11:14:56 +0200 |
commit | 27dc4fa28ee098d70a11829ad5fa4af0c54e880b (patch) | |
tree | ed7b7d52308c9bb1c80199804bd74f4b615b4ff5 /activerecord/lib | |
parent | 078da2b22de765f368a4257bce67ab4370754ee2 (diff) | |
download | rails-27dc4fa28ee098d70a11829ad5fa4af0c54e880b.tar.gz rails-27dc4fa28ee098d70a11829ad5fa4af0c54e880b.tar.bz2 rails-27dc4fa28ee098d70a11829ad5fa4af0c54e880b.zip |
PG adapter deals with negative money values formatted with parenthesis.
Closes #11899.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb index 58c6235059..dab876af14 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb @@ -34,12 +34,17 @@ module ActiveRecord class Money < Type def type_cast(value) return if value.nil? + return value unless String === value # Because money output is formatted according to the locale, there are two # cases to consider (note the decimal separators): # (1) $12,345,678.12 # (2) $12.345.678,12 + # Negative values are represented as follows: + # (3) -$2.55 + # (4) ($2.55) + value.sub!(/^\((.+)\)$/, '-\1') # (4) case value when /^-?\D+[\d,]+\.\d{2}$/ # (1) value.gsub!(/[^-\d.]/, '') |