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:
parent
c5adf04cd6
commit
884fbf1d05
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue