Skip to content

Commit c3ce1af

Browse files
Improve method name for better clarity
The orignal `confirmation_token_has_not_expired?` is a negative sentence that might return false which makes you think twice. Issues ------ - Closes #33
1 parent f869e44 commit c3ce1af

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class User < ApplicationRecord
129129
confirmed_at.present?
130130
end
131131

132-
def confirmation_token_has_not_expired?
132+
def confirmation_token_is_valid?
133133
return false if confirmation_sent_at.nil?
134134
(Time.current - confirmation_sent_at) <= User::CONFIRMATION_TOKEN_EXPIRATION_IN_SECONDS
135135
end
@@ -152,7 +152,7 @@ end
152152
> - The `has_secure_token :confirmation_token` method is added to give us an [API](https://api.rubyonrails.org/classes/ActiveRecord/SecureToken/ClassMethods.html#method-i-has_secure_token) to work with the `confirmation_token` column.
153153
> - The `confirm!` method will be called when a user confirms their email address. We still need to build this feature.
154154
> - The `confirmed?` and `unconfirmed?` methods allow us to tell whether a user has confirmed their email address or not.
155-
> - The `confirmation_token_has_not_expired?` method tells us if the confirmation token is expired or not. This can be controlled by changing the value of the `CONFIRMATION_TOKEN_EXPIRATION_IN_SECONDS` constant. This will be useful when we build the confirmation mailer.
155+
> - The `confirmation_token_is_valid?` method tells us if the confirmation token is expired or not. This can be controlled by changing the value of the `CONFIRMATION_TOKEN_EXPIRATION_IN_SECONDS` constant. This will be useful when we build the confirmation mailer.
156156
157157
## Step 3: Create Sign Up Pages
158158

@@ -263,7 +263,7 @@ class ConfirmationsController < ApplicationController
263263
def edit
264264
@user = User.find_by(confirmation_token: params[:confirmation_token])
265265

266-
if @user.present? && @user.confirmation_token_has_not_expired?
266+
if @user.present? && @user.confirmation_token_is_valid?
267267
@user.confirm!
268268
redirect_to root_path, notice: "Your account has been confirmed."
269269
else
@@ -581,7 +581,7 @@ class ConfirmationsController < ApplicationController
581581

582582
def edit
583583
...
584-
if @user.present? && @user.confirmation_token_has_not_expired?
584+
if @user.present? && @user.confirmation_token_is_valid?
585585
@user.confirm!
586586
login @user
587587
...
@@ -886,7 +886,7 @@ class ConfirmationsController < ApplicationController
886886
...
887887
def edit
888888
...
889-
if @user.present? && @user.unconfirmed_or_reconfirming? && @user.confirmation_token_has_not_expired?
889+
if @user.present? && @user.unconfirmed_or_reconfirming? && @user.confirmation_token_is_valid?
890890
if @user.confirm!
891891
login @user
892892
redirect_to root_path, notice: "Your account has been confirmed."
@@ -1047,7 +1047,7 @@ class ConfirmationsController < ApplicationController
10471047
...
10481048
def edit
10491049
...
1050-
if @user.present? && @user.unconfirmed_or_reconfirming? && @user.confirmation_token_has_not_expired?
1050+
if @user.present? && @user.unconfirmed_or_reconfirming? && @user.confirmation_token_is_valid?
10511051
...
10521052
end
10531053
end

app/controllers/confirmations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def create
1414

1515
def edit
1616
@user = User.find_by(confirmation_token: params[:confirmation_token])
17-
if @user.present? && @user.unconfirmed_or_reconfirming? && @user.confirmation_token_has_not_expired?
17+
if @user.present? && @user.unconfirmed_or_reconfirming? && @user.confirmation_token_is_valid?
1818
if @user.confirm!
1919
login @user
2020
redirect_to root_path, notice: "Your account has been confirmed."

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def confirmable_email
5555
end
5656
end
5757

58-
def confirmation_token_has_not_expired?
58+
def confirmation_token_is_valid?
5959
return false if confirmation_sent_at.nil?
6060
(Time.current - confirmation_sent_at) <= User::CONFIRMATION_TOKEN_EXPIRATION_IN_SECONDS
6161
end

test/models/user_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ class UserTest < ActiveSupport::TestCase
107107
assert_equal @user.unconfirmed_email, ActionMailer::Base.deliveries.last.to[0]
108108
end
109109

110-
test "should respond to confirmation_token_has_not_expired?" do
111-
assert_not @user.confirmation_token_has_not_expired?
110+
test "should respond to confirmation_token_is_valid?" do
111+
assert_not @user.confirmation_token_is_valid?
112112

113113
@user.confirmation_sent_at = 1.minute.ago
114-
assert @user.confirmation_token_has_not_expired?
114+
assert @user.confirmation_token_is_valid?
115115

116116
@user.confirmation_sent_at = 601.seconds.ago
117-
assert_not @user.confirmation_token_has_not_expired?
117+
assert_not @user.confirmation_token_is_valid?
118118
end
119119

120120
test "should respond to send_password_reset_email!" do

0 commit comments

Comments
 (0)