-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #676 from airbrake/time-truncate-simplification
time_truncate: simplify conversion code and tests
- Loading branch information
Showing
2 changed files
with
23 additions
and
15 deletions.
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
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 |
---|---|---|
@@ -1,21 +1,30 @@ | ||
RSpec.describe Airbrake::TimeTruncate do | ||
time = Time.new(2018, 1, 1, 0, 0, 20, 0) | ||
time_with_zone = Time.new(2018, 1, 1, 0, 0, 20, '-05:00') | ||
|
||
describe "#utc_truncate_minutes" do | ||
it "truncates time to the floor minute and returns an RFC3339 timestamp" do | ||
time = Time.new(2018, 1, 1, 0, 0, 20, 0) | ||
expect(described_class.utc_truncate_minutes(time)) | ||
.to eq('2018-01-01T00:00:00+00:00') | ||
shared_examples 'time conversion' do |t| | ||
it "truncates the time to the floor minute and returns an RFC3339 timestamp" do | ||
expect(described_class.utc_truncate_minutes(t)) | ||
.to eq('2018-01-01T00:00:00+00:00') | ||
end | ||
|
||
it "converts time with zone to UTC" do | ||
expect(described_class.utc_truncate_minutes(time_with_zone)) | ||
.to eq('2018-01-01T05:00:00+00:00') | ||
end | ||
end | ||
|
||
context "when the time argument is a Time object" do | ||
include_examples 'time conversion', time | ||
end | ||
|
||
it "converts time with zone to UTC" do | ||
time = Time.new(2018, 1, 1, 0, 0, 20, '-05:00') | ||
expect(described_class.utc_truncate_minutes(time)) | ||
.to eq('2018-01-01T05:00:00+00:00') | ||
context "when the time argument is a Float" do | ||
include_examples 'time conversion', time.to_f | ||
end | ||
|
||
it "converts it well even if the argument is an instance of Float" do | ||
time = Time.new(2018, 1, 1, 0, 0, 20, '-05:00').to_f | ||
expect(described_class.utc_truncate_minutes(time)) | ||
.to eq('2018-01-01T05:00:00+00:00') | ||
context "when the time argument is an Integer" do | ||
include_examples 'time conversion', time.to_i | ||
end | ||
end | ||
end |