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

After upgrading from 4.0.1 to 5.3.1, time_ago_in_words(b.updated_at, vague: true) no longer works #125

Closed
MSCAU opened this issue Jun 15, 2021 · 8 comments
Labels

Comments

@MSCAU
Copy link

MSCAU commented Jun 15, 2021

I had to upgrade to Rails 5.2.6 yesterday to get around the MimeMagic license issue (see https://dev.to/cseeman/what-s-up-with-mimemagic-breaking-everything-he1). As the same time, dotiw got switched from 4.0.1 to 5.3.1. I now get this error which wan't present before:

Unknown key: :vague. Valid keys are: :words_connector, :two_words_connector, :last_word_connector, :locale

The line where this breaks reads:

time_ago_in_words(b.updated_at, vague: true)

Has something broken with this version change? I can't see anything in your docs or issues. If I amend the Gemfile to use 4.0.1 and bundle update again, the problem goes away.

@dblock
Copy link
Collaborator

dblock commented Jun 15, 2021

This sounds vaguely (no pun intended) familiar. I suspect that you're no longer calling this library, but the original Rails time_ago_in_words method. In which class is this call made?

  1. Check that https://github.com/radar/distance_of_time_in_words/blob/master/lib/dotiw/action_view/helpers/date_helper.rb gets included in the location of the call. This should be automatic for wherever the method is available in Rails.
  2. Check that it's calling the wrapped method,
    def time_ago_in_words(from_time, include_seconds_or_options = {})

@dblock dblock added the bug? label Jun 15, 2021
@mozcomp
Copy link
Contributor

mozcomp commented Jun 16, 2021

I'm getting a similar issue, though still with Rails 4.2.11, between DOTIW 4.0.1 -> 5.3.1

From the console ...

>
 helper.distance_of_time_in_words(Time.current, contract.expires_on, vague: true)
Traceback (most recent call last):
       15: from bin/rails:4:in `<main>'
       14: from bin/rails:4:in `require'
       13: from /usr/local/var/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/railties-4.2.11.1/lib/rails/commands.rb:17:in `<top (required)>'
       12: from /usr/local/var/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/railties-4.2.11.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
       11: from /usr/local/var/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/railties-4.2.11.1/lib/rails/commands/commands_tasks.rb:68:in `console'
       10: from /usr/local/var/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/railties-4.2.11.1/lib/rails/commands/console.rb:9:in `start'
        9: from /usr/local/var/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/railties-4.2.11.1/lib/rails/commands/console.rb:110:in `start'
        8: from (irb):7
        7: from /usr/local/var/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/dotiw-5.3.1/lib/dotiw/action_view/helpers/date_helper.rb:14:in `distance_of_time_in_words'
        6: from /usr/local/var/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/dotiw-5.3.1/lib/dotiw/methods.rb:35:in `distance_of_time_in_words'
        5: from /usr/local/var/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/dotiw-5.3.1/lib/dotiw/methods.rb:105:in `_display_time_in_words'
        4: from /usr/local/var/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/activesupport-4.2.11.1/lib/active_support/core_ext/array/conversions.rb:60:in `to_sentence'
        3: from /usr/local/var/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/state_machines-0.5.0/lib/state_machines/assertions.rb:16:in `assert_valid_keys'
        2: from /usr/local/var/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/state_machines-0.5.0/lib/state_machines/assertions.rb:16:in `each_key'
        1: from /usr/local/var/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/state_machines-0.5.0/lib/state_machines/assertions.rb:18:in `block in assert_valid_keys'
ArgumentError (Unknown key: :vague. Valid keys are: :words_connector, :two_words_connector, :last_word_connector, :locale)

though error appears downstream in activesupport/to_sentence

@mozcomp
Copy link
Contributor

mozcomp commented Jun 16, 2021

I think the issue has arisen from commit 20/11/2020 by joshuapinter ...

where previous code called the activesupport method with if options.delete(:vague}
the new version calls it without removing the vague option if options[:vague] so it's the activesupport code that throw the error

old ..

return _distance_of_time_in_words(from_time, to_time, options) if options.delete(:vague) DOTIW::Methods.distance_of_time_in_words(from_time, to_time, include_seconds_or_options, options)

new ..

return _distance_of_time_in_words(from_time, to_time, options) if options[:vague] DOTIW::Methods.distance_of_time_in_words(from_time, to_time, include_seconds_or_options, options.except(:vague))

I'd create a pull request but it's beyond my pay grade!!

@dblock
Copy link
Collaborator

dblock commented Jun 16, 2021

That's correct @mozcomp. Making a pull request is definitely not above your pay grade though, we pay you enough :)

Maybe try to write a spec that reproduces this here? The code fix is trivial, we need to do , options.except(:vague) in this code, but I'd want a spec to merge.

@MSCAU
Copy link
Author

MSCAU commented Jun 20, 2021

This sounds vaguely (no pun intended) familiar. I suspect that you're no longer calling this library, but the original Rails time_ago_in_words method. In which class is this call made?

  1. Check that https://github.com/radar/distance_of_time_in_words/blob/master/lib/dotiw/action_view/helpers/date_helper.rb gets included in the location of the call. This should be automatic for wherever the method is available in Rails.
  2. Check that it's calling the wrapped method,
    def time_ago_in_words(from_time, include_seconds_or_options = {})

Sorry, my Rails is very rusty and I don't remember enough to understand your questions.

I am making the call thus, in a file called app/views/budgets/browse.jb, which uses https://github.com/amatsuda/jb:

def budget(b)

	json = {
		id: b.id,
		name: b.name,
		time: time_ago_in_words(b.updated_at, vague: true),
		owner: {
                   ...

@matt-whiteley
Copy link

Would it be possible to get a new release now that a fix has been merged? The latest on RubyGems is the version with this bug present.

I don't like tracking master in production deployed code!

Thanks!

@dblock
Copy link
Collaborator

dblock commented Nov 8, 2021

This was fixed in #126

@dblock dblock closed this as completed Nov 8, 2021
@dblock
Copy link
Collaborator

dblock commented Nov 8, 2021

@matt-whiteley Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants