Commit 884fbf1d authored by Jan Provaznik's avatar Jan Provaznik

Fix boolean casting for nil value

`nil` value is not included in
`ActiveModel::Type::Boolean::FALSE_VALUES` which caused that in Rails 5
the boolean_accessor converted `nil` to `true` instead of `false`.
parent c5adf04c
......@@ -206,10 +206,11 @@ class Service < ActiveRecord::Base
args.each do |arg|
class_eval %{
def #{arg}?
# '!!' is used because nil or empty string is converted to nil
if Gitlab.rails5?
!ActiveModel::Type::Boolean::FALSE_VALUES.include?(#{arg})
!!ActiveRecord::Type::Boolean.new.cast(#{arg})
else
ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(#{arg})
!!ActiveRecord::Type::Boolean.new.type_cast_from_database(#{arg})
end
end
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment