Skip to content

Commit

Permalink
Removed Timecop in favour of ActiveSupport::Testing::TimeHelpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
rjurado01 committed Feb 28, 2020
1 parent 583922d commit 51719b1
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 21 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ gem 'factory_bot'
gem 'mongoid'
gem 'rspec-rails'
gem 'sqlite3'
gem 'timecop'

group :development, :test do
gem 'pry-rails'
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ GEM
sqlite3 (1.3.13)
thor (0.20.3)
thread_safe (0.3.6)
timecop (0.9.1)
tzinfo (1.2.5)
thread_safe (~> 0.1)
websocket-driver (0.7.1)
Expand All @@ -163,7 +162,6 @@ DEPENDENCIES
rails_jwt_auth!
rspec-rails
sqlite3
timecop

BUNDLED WITH
1.17.2
1 change: 1 addition & 0 deletions app/models/concerns/rails_jwt_auth/confirmable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def skip_confirmation!

def validate_confirmation
return true unless confirmed_at

email_field = RailsJwtAuth.email_field_name!

if confirmed_at_was && !public_send("#{email_field}_changed?")
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/invitations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
let!(:invited_user) { RailsJwtAuth.model.invite! email: '[email protected]' }

it 'returns HTTP 422 Unprocessable Entity' do
Timecop.travel(3.days.from_now) do
travel_to(3.days.from_now) do
put :update, params: {
id: invited_user.invitation_token,
invitation: {password: 'abcdef', password_confirmation: 'abcdef'}
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module RailsJwtAuth
end

it 'unlock access when lock is expired' do
Timecop.freeze(Date.today - 30.days) { user.lock_access! }
travel_to(Date.today - 30.days) { user.lock_access! }
session = Session.new('email' => user.email, password: pass)
expect(session.valid?).to be_truthy
expect(user.reload.locked_at).to be_nil
Expand Down
5 changes: 3 additions & 2 deletions spec/models/concerns/authenticatable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@
password: current_password,
reset_password_token: '12345678',
reset_password_sent_at: Time.current)
Timecop.travel(Time.current + RailsJwtAuth.reset_password_expiration_time)

travel(RailsJwtAuth.reset_password_expiration_time)
end

after do
Timecop.return
travel_back
end

it 'reset recoverable fields' do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/concerns/confirmable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
user.email = '[email protected]'
user.save

Timecop.freeze(Date.today + 30) do
travel_to(Time.current + RailsJwtAuth.confirmation_expiration_time + 1.second) do
expect(user.confirm!).to be_falsey
expect(get_record_error(user, :confirmation_token)).to eq :expired
end
Expand Down Expand Up @@ -201,7 +201,7 @@ def deliver_later
it 'adds expiration error' do
unconfirmed_user.confirmed_at = Time.current

Timecop.freeze(Date.today + 30) do
travel_to(Time.current + RailsJwtAuth.confirmation_expiration_time + 1.second) do
expect(unconfirmed_user.save).to be_falsey
expect(get_record_error(unconfirmed_user, :confirmation_token)).to eq(:expired)
end
Expand Down
22 changes: 10 additions & 12 deletions spec/models/concerns/invitable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@

context 'when user already exists' do
context 'with pending invitation' do
after { Timecop.return }

it 'resets invitation' do
Timecop.freeze(Time.current)
first_invitation_date = Time.current.to_i
first_invitation_date = Time.current
second_invitation_date = nil

invited_user
travel_to(first_invitation_date) do
invited_user
end

Timecop.freeze(Time.current + 30.days) do
travel_to(Time.current + 30.days) do
RailsJwtAuth.model.invite! email: invited_user.email
second_invitation_date = Time.current.to_i
end
Expand Down Expand Up @@ -122,16 +121,15 @@
end

context 'when user has pending invitation' do
after { Timecop.return }

it 'resets invitation' do
Timecop.freeze(Time.current)
first_invitation_date = Time.current.to_i
first_invitation_date = Time.current
second_invitation_date = nil

invited_user
travel_to(first_invitation_date) do
invited_user
end

Timecop.freeze(Time.current + 30.days) do
travel_to(Time.current + 30.days) do
invited_user.invite!
second_invitation_date = Time.current.to_i
end
Expand Down

0 comments on commit 51719b1

Please sign in to comment.