From b4f38edf74e376f6006def9bf9fc22db40586264 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Fri, 31 Mar 2023 07:33:17 +0200 Subject: Wrong type for user setting when default is defined by lambda (#24321) --- spec/models/user_settings/setting_spec.rb | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'spec/models') diff --git a/spec/models/user_settings/setting_spec.rb b/spec/models/user_settings/setting_spec.rb index 6e4ec6789..9884ae4f8 100644 --- a/spec/models/user_settings/setting_spec.rb +++ b/spec/models/user_settings/setting_spec.rb @@ -30,6 +30,38 @@ RSpec.describe UserSettings::Setting do it 'returns a type' do expect(subject.type).to be_a ActiveModel::Type::Value end + + context 'when default value is a boolean' do + let(:default) { false } + + it 'returns boolean' do + expect(subject.type).to be_a ActiveModel::Type::Boolean + end + end + + context 'when default value is a string' do + let(:default) { '' } + + it 'returns string' do + expect(subject.type).to be_a ActiveModel::Type::String + end + end + + context 'when default value is a lambda returning a boolean' do + let(:default) { -> { false } } + + it 'returns boolean' do + expect(subject.type).to be_a ActiveModel::Type::Boolean + end + end + + context 'when default value is a lambda returning a string' do + let(:default) { -> { '' } } + + it 'returns boolean' do + expect(subject.type).to be_a ActiveModel::Type::String + end + end end describe '#type_cast' do -- cgit