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

Make confirmable not dependant on trackable #1064

Merged
merged 1 commit into from
Jan 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def show
token_hash = BCrypt::Password.create(token)
expiry = (Time.now + @resource.token_lifespan).to_i

if @resource.sign_in_count > 0
if defined? @resource.sign_in_count && @resource.sign_in_count > 0

Choose a reason for hiding this comment

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

@zachfeldman, @lynndylanhurley Guys, there is a bug:
The parentheses are required here around the first @resource.sign_in_count, i.e.:

if defined?(@resource.sign_in_count) && @resource.sign_in_count > 0

Otherwise defined? is applied to the whole expression and returns string "expression", which results into assigning expiry to 1 second ahead of now even when sign_in_count equals 0.

Choose a reason for hiding this comment

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

There is a simple snippet to show the difference:

irb(main):001:0> defined? some_var
=> nil
irb(main):002:0> defined? some_var && some_var > 0
=> "expression"
irb(main):003:0> defined?(some_var) && some_var > 0
=> nil

Copy link
Contributor Author

@romankovt romankovt Jan 16, 2018

Choose a reason for hiding this comment

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

made a PR #1067 fixing this, thank you for the report

expiry = (Time.now + 1.second).to_i
end

Expand Down