Skip to content

Commit

Permalink
normalize_automate_vals gets called with ActiveSupport::TimeWithZone,…
Browse files Browse the repository at this point in the history
… not string
  • Loading branch information
d-m-u committed Mar 6, 2019
1 parent 5307629 commit 764e1e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/dialog_field_date_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion spec/models/dialog_field_date_control_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" }

Expand Down

0 comments on commit 764e1e3

Please sign in to comment.