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`.
This commit is contained in:
Jan Provaznik 2018-05-29 14:46:42 +02:00
parent c5adf04cd6
commit 884fbf1d05
1 changed files with 3 additions and 2 deletions

View File

@ -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
}