diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-10-16 23:20:21 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-10-16 23:20:21 -0300 |
commit | 8a80e3b6c446931330ad07130603712e8d0a2ff3 (patch) | |
tree | b9daeede0740a4a0f05707479adfd789776ea126 /activerecord/lib | |
parent | 056d06627af1c99647d88521557c65ddc476520f (diff) | |
parent | e01a46f1f0e21d9018906a6a8dcfdae2d92f32ae (diff) | |
download | rails-8a80e3b6c446931330ad07130603712e8d0a2ff3.tar.gz rails-8a80e3b6c446931330ad07130603712e8d0a2ff3.tar.bz2 rails-8a80e3b6c446931330ad07130603712e8d0a2ff3.zip |
Merge pull request #17296 from sgrif/sg-booleans-should-make-sense
Add a deprecation warning for abiguous boolean values
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/type/boolean.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/type/boolean.rb b/activerecord/lib/active_record/type/boolean.rb index 06dd17ed28..1311be3944 100644 --- a/activerecord/lib/active_record/type/boolean.rb +++ b/activerecord/lib/active_record/type/boolean.rb @@ -10,8 +10,15 @@ module ActiveRecord def cast_value(value) if value == '' nil + elsif ConnectionAdapters::Column::TRUE_VALUES.include?(value) + true else - ConnectionAdapters::Column::TRUE_VALUES.include?(value) + if !ConnectionAdapters::Column::FALSE_VALUES.include?(value) + ActiveSupport::Deprecation.warn(<<-EOM) + You attempted to assign a value which is not explicitly true or false to a boolean column. Currently this value casts to false. This will change to match Ruby's sematics, and will cast to true in Rails 5.0. If you would like to maintain the current behavior, you should explicitly handle the values you would like cast to false. + EOM + end + false end end end |