-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle DateTimes that come back from Sqlite as Strings
Upgrading to ruby 2.7.5-alpine3.14 has changed something in Sqlite or Sequel
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
spec/lib/pact_broker/api/decorators/format_date_time_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require "pact_broker/api/decorators/format_date_time" | ||
|
||
module PactBroker | ||
module Api | ||
module Decorators | ||
module FormatDateTime | ||
describe ".call" do | ||
context "with a Time object" do | ||
let(:date_time) { Time.parse("2022-02-14T15:18:00+14:00" )} | ||
|
||
it "converts the date to a string in utc" do | ||
expect(FormatDateTime.call(date_time)).to eq "2022-02-14T01:18:00+00:00" | ||
end | ||
end | ||
|
||
context "with a DateTime object" do | ||
let(:date_time) { DateTime.parse("2022-02-14T15:18:00+14:00" )} | ||
|
||
it "converts the date to a string in utc" do | ||
expect(FormatDateTime.call(date_time)).to eq "2022-02-14T01:18:00+00:00" | ||
end | ||
end | ||
|
||
context "with a String - MySQL and Sqlite (as of the upgrade to Ruby 2.7.5) return date columns as strings. Postgres returns them as dates." do | ||
let(:date_time) { "2022-02-14T15:18:00+14:00" } | ||
|
||
it "converts the date to a string in utc" do | ||
expect(FormatDateTime.call(date_time)).to eq "2022-02-14T01:18:00+00:00" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |