-
Notifications
You must be signed in to change notification settings - Fork 105
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
After upgrade from 4.0.1 to 5.3.1 option[:vague] raises error #126
Conversation
I think what we really want is a test calling ActionView So... first question first, how do we want it to work? |
On reading your comment about My PR had already skipped a step as to the cause of the problem. You're correct there are no tests for Our entry point for the error is Looking at the arguments to the method
But this is done after we have supposedly made use of the However, if the
My thoughts are that the argument handling that is done in the DOTIW method, should be moved/duplicated to the ActionView method. Failing that make the |
Ok I’m with you @mozcomp. Before we do this, … we inherited this mess … do you think it would be better to collapse these two arguments ( |
@dblock I'm torn, the non-intrusive fix is to copy the existing argument handling within the DOTIW method to the Actionview method, this would make it work as in the original version. However, as you say, the cleaner solution would be to collapse these arguments into a single argument My main problem with the latter - considering how long it has been since the change that broke the gem (about 12 months I think), there is obviously only a few people implementing the gem with the 3 argument I'm inclined to vote for the first option rather than the second. |
having collapsed arguments, pass options as single hash
@mozcomp Ok, I agree we should just fix the problem in the first place The code looks good. We also need specs for when Please also update https://github.com/radar/distance_of_time_in_words/blob/master/CHANGELOG.md |
Ok I’ll sort the spec tomorrow - away from the office at the moment
…On Mon, 21 Jun 2021 at 11:30 pm, Daniel Doubrovkine (dB.) < ***@***.***> wrote:
@mozcomp <https://github.com/mozcomp> Ok, I agree we should just fix the
problem in the first place
The code looks good. We also need specs for when include_seconds_or_options
= true/false here, right?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#126 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADSWVH5NYDRMZ6GEAL64MTTT5AX7ANCNFSM464XNYEA>
.
|
additional tests include/exclude seconds argument
Sorry so long getting back to this ... Added specs to cover all the permutations of the seconds & vague arguments Feel free to change all the above as these are all new for me to be contributing. |
I think you forgot to push the code up here ;) Thank you! |
That's a rookie error - done now. |
One more thing, please add a line to https://github.com/radar/distance_of_time_in_words/blob/master/CHANGELOG.md. I think this is good to go otherwise! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing I spotted.
if include_seconds_or_options.is_a?(Hash) | ||
options = include_seconds_or_options | ||
else | ||
options[:include_seconds] ||= !!include_seconds_or_options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This modifies the incoming hash, which is bad (TM). Do options = options.merge(...)
here.
I think I have the arguments handling right, but I didn't like that the same code was being repeated for the two calls to the actionview methods, so moved it to a private method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more nitpicks
CHANGELOG.md
Outdated
@@ -1,6 +1,6 @@ | |||
## 5.3.2 (Next) | |||
|
|||
* Your contribution here. | |||
* [#126](https://github.com/radar/distance_of_time_in_words/pull/126): Fixes `#distance_of_time_in_words_to_now` with `vague: true` when supplied without include_seconds argument - [@mozcomp](https://github.com/mozcomp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote include_seconds
|
||
private | ||
def merge_options(include_seconds_or_options, options) | ||
merged_options = options.dup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it's doing more work than needed in all cases, duping and merging. This is simpler:
def merge_options(include_seconds_or_options, options)
if include_seconds_or_options.is_a?(Hash)
options.merge(include_seconds_or_options)
else
options.merge(include_seconds: !!include_seconds_or_options)
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, newbie error, I thought you were making the change, not waiting for me to do it.
Change as suggested
Thank you. See comments above, please make the minor changes to CHANGELOG, and I think this will be good to merge! |
@@ -65,7 +65,8 @@ The third argument for this method is whether or not to include seconds. By defa | |||
=> "1 year, and 1 second" | |||
``` | |||
|
|||
Yes this could just be merged into the options hash but I'm leaving it here to ensure "backwards-compatibility", because that's just an insanely radical thing to do. \m/ | |||
Yes this could just be merged into the options hash but I'm leaving it here to ensure "backwards-compatibility", because that's just an insanely radical thing to do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should put back the original author's \m/
here, keep the spirit of the project alive.
CHANGELOG.md
Outdated
@@ -1,6 +1,7 @@ | |||
## 5.3.2 (Next) | |||
|
|||
- * Your contribution here. | |||
* Your contribution here. | |||
* [#126](https://github.com/radar/distance_of_time_in_words/pull/126): Fixes `#distance_of_time_in_words_to_now` with `vague: true` when supplied without `include_seconds` argument - [@mozcomp](https://github.com/mozcomp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're missing a period at the end. A bot will complain.
Release in 5.3.2 |
In relation to Issue: #125
Following further tests as to cause of the issue, it relates to the interaction between the optional 3rd argument for "include seconds" and the 4th argument "options". If the 3rd argument was supplied (true/false), then the code worked as expected.
This was included and passed in spec tests.
Adding same specs, but without the optional "include_seconds" argument, gave a series of fails as found in the Issue raised.
My solution may not be acceptable, as I'm changing the arguments supplied, but by testing for a valid true/false of the "include_seconds" argument, and if "options" are nil, then swap the contents.
Once this is done, with the minor tweak of excluding the vague option before passing to the ActiveSupport support version, the code now passes all tests.