From 884fbf1d058ac00bc5c107f327475fa6eeda1f9f Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Tue, 29 May 2018 14:46:42 +0200 Subject: 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`. --- app/models/service.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/service.rb b/app/models/service.rb index 831c2ea1141..1d259bcfec7 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -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 } -- cgit v1.2.1