Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

196 round json format #203

Merged
merged 2 commits into from
Sep 2, 2021
Merged

Conversation

fbuys
Copy link
Contributor

@fbuys fbuys commented Sep 2, 2021

What

  • Extracted with_rounding_on test helper into a separate WithAttributes module.
  • Fix JSON formatted output when -r is provided.

Notes

✅ Tests added.

Instead of outputting raw data to JSON we make use of model provided values for end and start time.

Extracted into a seprate WithAttributes module.

This helper could be useful in other test where we want to make sure
that rounding works as expected.

In a following commit I will make use of it to make sure JSON formatted
output is rounded correctly.
This commit fixes: samg#196

Instead of outputting raw data to JSON we make use of model provided
values for end and start time. This is convenient since the model
already outputs end and start time as rounded when the `-r` attribute is
set.

e.values.inject({}) do |h, (k,v)|
h[k] = v
h[k] = e.public_send(k) if %i[end start].include?(k)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥦 - Only start and end keys are forwarded onto the model.

@@ -33,8 +33,22 @@ def with_stubbed_config options = {}
end
end

module Timetrap::WithAttributes
def with_rounding_on
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥦 Extracted helper for other cases where we might want to test attributes and have them reverted/reset after the test.

@@ -740,17 +754,29 @@ def output

describe 'json' do
before do
create_entry(:start => local_time_cli('2008-10-03 12:00:00'), :end => local_time_cli('2008-10-03 14:00:00'))
create_entry(:start => local_time_cli('2008-10-03 12:07:00'), :end => local_time_cli('2008-10-03 14:08:00'))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥦 Rounding defaults to 900s (15min), so 7min goes to 0 and 8min goes to 15.

create_entry(:start => local_time_cli('2008-10-05 12:00:00'), :end => local_time_cli('2008-10-05 14:00:00'))
end

it "should export to json not including running items" do
invoke 'in'
invoke 'display -f json'
expect(JSON.parse($stdout.string)).to eq JSON.parse(<<-EOF)
[{\"sheet\":\"default\",\"end\":\"#{local_time('2008-10-03 14:00:00')}\",\"start\":\"#{local_time('2008-10-03 12:00:00')}\",\"note\":\"note\",\"id\":1},{\"sheet\":\"default\",\"end\":\"#{local_time('2008-10-05 14:00:00')}\",\"start\":\"#{local_time('2008-10-05 12:00:00')}\",\"note\":\"note\",\"id\":2}]
[{\"sheet\":\"default\",\"end\":\"#{local_time('2008-10-03 14:08:00')}\",\"start\":\"#{local_time('2008-10-03 12:07:00')}\",\"note\":\"note\",\"id\":1},{\"sheet\":\"default\",\"end\":\"#{local_time('2008-10-05 14:00:00')}\",\"start\":\"#{local_time('2008-10-05 12:00:00')}\",\"note\":\"note\",\"id\":2}]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥦 Still no rounding

# rounds to 900s by default
invoke 'display -r -f json'
expect(JSON.parse($stdout.string)).to eq JSON.parse(<<~EOF)
[{\"sheet\":\"default\",\"end\":\"#{local_time('2008-10-03 14:15:00')}\",\"start\":\"#{local_time('2008-10-03 12:00:00')}\",\"note\":\"note\",\"id\":1},{\"sheet\":\"default\",\"end\":\"#{local_time('2008-10-05 14:00:00')}\",\"start\":\"#{local_time('2008-10-05 12:00:00')}\",\"note\":\"note\",\"id\":2}]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥦 Uses default rounding (15min), so 7min goes to 0 and 8min goes to 15.

@categulario categulario merged commit 9706bd1 into samg:master Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants