Skip to content

Instantly share code, notes, and snippets.

@donrestarone
Last active March 14, 2020 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donrestarone/68584d8cf892c7e7cb79e890b1e2f0a9 to your computer and use it in GitHub Desktop.
Save donrestarone/68584d8cf892c7e7cb79e890b1e2f0a9 to your computer and use it in GitHub Desktop.
simple rspec test for a user model, testing a unique time-based token
require 'rails_helper'
RSpec.describe User, type: :model do
it 'can generate an expirable email confirmation link' do
user = create(:user)
link = user.generate_email_confirmation_link
token = link.split('/')[5].split('?')[0]
expect(CoreModules::JsonWebToken.decode(token)[:user_id]).to eql user.id
expiration_time = Time.now + 31.minutes
Timecop.travel(expiration_time) do
expect(CoreModules::JsonWebToken.decode(token)).to eql false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment