diff --git a/app/models/service/dialog_properties.rb b/app/models/service/dialog_properties.rb index 0611128ca92..65ef86a4eb7 100644 --- a/app/models/service/dialog_properties.rb +++ b/app/models/service/dialog_properties.rb @@ -17,8 +17,13 @@ def apply_dialog_settings retires_in_days retires_in_hours ).each do |field_name| - dialog_field_name = "dialog_service_#{field_name}" - send(dialog_field_name, dialog_options[dialog_field_name]) if dialog_options.key?(dialog_field_name) + begin + dialog_field_name = "dialog_service_#{field_name}" + dialog_field_value = dialog_options[dialog_field_name] + send(dialog_field_name, dialog_field_value) if dialog_options.key?(dialog_field_name) + rescue => err + _log.error("Error setting key [#{dialog_field_name}] with value [#{dialog_field_value.inspect}] error: [#{err}]") + end end end diff --git a/spec/models/service/dialog_properties_spec.rb b/spec/models/service/dialog_properties_spec.rb index aa180d5aed3..265b5d819d3 100644 --- a/spec/models/service/dialog_properties_spec.rb +++ b/spec/models/service/dialog_properties_spec.rb @@ -35,4 +35,28 @@ .to eq('test description from dialog') end end + + context 'service retires_on' do + it 'without empty options hash' do + expect(Service.create(:name => 'test').retires_on).to be_nil + end + + # it 'with empty dialog options' do + # expect(Service.create(:name => 'test', + # :description => 'test description', + # :options => {:dialog => {}}).description) + # .to eq('test description') + # end + + it 'with dialog option dialog_service_description' do + time = Time.new(2017, 12, 1, 0, 0, 0, 0) + Timecop.freeze(time) do + expect(Service.create(:name => 'test', + :options => { + :dialog => {'dialog_service_retires_on' => time.to_s} + }).retires_on) + .to eq(time) + end + end + end end