aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-01-04 11:31:58 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-01-04 11:58:44 -0300
commita502703c3d2151d4d3b421b29fefdac5ad05df61 (patch)
tree26d2062847b25b296ca753f71fef38e217e0de26 /activerecord/lib
parent07d3d402341e81ada0214f2cb2be1da69eadfe72 (diff)
downloadrails-a502703c3d2151d4d3b421b29fefdac5ad05df61.tar.gz
rails-a502703c3d2151d4d3b421b29fefdac5ad05df61.tar.bz2
rails-a502703c3d2151d4d3b421b29fefdac5ad05df61.zip
Change the behavior of boolean columns to be closer to Ruby's semantics.
Before this change we had a small set of "truthy", and all others are "falsy". Now, we have a small set of "falsy" values and all others are "truthy" matching Ruby's semantics.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/column.rb1
-rw-r--r--activerecord/lib/active_record/type/boolean.rb15
2 files changed, 3 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index d7f999c3c6..e74de60a83 100644
--- a/activerecord/lib/active_record/connection_adapters/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/column.rb
@@ -5,7 +5,6 @@ module ActiveRecord
module ConnectionAdapters
# An abstract definition of a column in a table.
class Column
- TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].to_set
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'].to_set
module Format
diff --git a/activerecord/lib/active_record/type/boolean.rb b/activerecord/lib/active_record/type/boolean.rb
index 978d16d524..2e24afc7c0 100644
--- a/activerecord/lib/active_record/type/boolean.rb
+++ b/activerecord/lib/active_record/type/boolean.rb
@@ -10,19 +10,10 @@ module ActiveRecord
def cast_value(value)
if value == ''
nil
- elsif ConnectionAdapters::Column::TRUE_VALUES.include?(value)
- true
- else
- if !ConnectionAdapters::Column::FALSE_VALUES.include?(value)
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- 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 semantics, and will cast to `true` in Rails 5.
- If you would like to maintain the current behavior, you should
- explicitly handle the values you would like cast to `false`.
- MSG
- end
+ elsif ConnectionAdapters::Column::FALSE_VALUES.include?(value)
false
+ else
+ true
end
end
end