Last active
February 2, 2016 15:35
-
-
Save pinzolo/37a8b724e51fadf682a1 to your computer and use it in GitHub Desktop.
Devise の confirmations_controller にて期間丁度に確認した場合、Mac, Linux での挙動が異なることの検証(デバッグコード)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Devise | |
module Models | |
module Confirmable | |
# some code | |
protected | |
# some code | |
def confirmation_period_expired? | |
t1, t2, t3 = Time.now, self.confirmation_sent_at, self.confirmation_sent_at + self.class.confirm_within | |
Rails.logger.debug("[devise][now] to_s: #{t1.to_s}, to_i: #{t1.to_i}, usec: #{t1.usec}, subsec: #{t1.subsec}") | |
Rails.logger.debug("[devise][sent_at] to_s: #{t2.to_s}, to_i: #{t2.to_i}, usec: #{t2.usec}, subsec: #{t2.subsec}") | |
Rails.logger.debug("[devise][added] to_s: #{t3.to_s}, to_i: #{t3.to_i}, usec: #{t3.usec}, subsec: #{t3.subsec}") | |
Rails.logger.debug("[devise] now > added: #{t1 > t3}") | |
Rails.logger.debug("[devise] now.subsec > added.subsec: #{t1.subsec > added.subsec}") | |
self.class.confirm_within && self.confirmation_sent_at && (Time.now > self.confirmation_sent_at + self.class.confirm_within) | |
end | |
# some code | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class ConfirmationsControllerTest < ActionController::TestCase | |
setup do | |
@request.env['devise.mapping'] = Devise.mappings[:user] | |
end | |
test '登録して10日以内なら確認可' do | |
user = create(:user) | |
Time.stub(:now, user.confirmation_sent_at + 10.days) do | |
t1, t2 = user.confirmation_sent_at, user.confirmation_sent_at + 30.days | |
Rails.logger.debug("[test-code][sent_at] to_s: #{t1.to_s}, to_i: #{t1.to_i}, usec: #{t1.usec}, subsec: #{t1.subsec}") | |
Rails.logger.debug("[test-code][added] to_s: #{t2.to_s}, to_i: #{t2.to_i}, usec: #{t2.usec}, subsec: #{t2.subsec}") | |
get :show, confirmation_token: user.confirmation_token | |
end | |
assert user.reload.confirmed? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment