diff --git a/app/models/dialog_field_date_control.rb b/app/models/dialog_field_date_control.rb index c5b97306ac0..a21a0e10f15 100644 --- a/app/models/dialog_field_date_control.rb +++ b/app/models/dialog_field_date_control.rb @@ -28,7 +28,7 @@ def normalize_automate_values(automate_hash) return default_time if automate_hash["value"].blank? begin - return DateTime.parse(automate_hash["value"]).iso8601 + return DateTime.parse(automate_hash["value"].to_s).iso8601 rescue return default_time end diff --git a/spec/models/dialog_field_date_control_spec.rb b/spec/models/dialog_field_date_control_spec.rb index 6f4555a2512..ffc67974b00 100644 --- a/spec/models/dialog_field_date_control_spec.rb +++ b/spec/models/dialog_field_date_control_spec.rb @@ -85,7 +85,7 @@ end context "when the automate hash has a value" do - context "when the value is a date format" do + context "when the value is a string" do let(:value) { "01/02/2015" } it_behaves_like "DialogFieldDateControl#normalize_automate_values" @@ -95,6 +95,16 @@ end end + context "when the value is a date object" do + let(:value) { Time.utc(2015, 1, 2) } + + it_behaves_like "DialogFieldDateControl#normalize_automate_values" + + it "returns the value in iso format" do + expect(dialog_field.normalize_automate_values(automate_hash)).to eq("2015-01-02T00:00:00+00:00") + end + end + context "when the value is not a proper date format" do let(:value) { "not a date" }