access_token_spec.rb revision 9dd500e3acdc343dbefcaf88b7663db25be0ef46
490da89281b7ee019c87406fb8ce7359aff0932cEugen Kuksarequire 'spec_helper'
490da89281b7ee019c87406fb8ce7359aff0932cEugen Kuksa
490da89281b7ee019c87406fb8ce7359aff0932cEugen Kuksadescribe AccessToken do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa let(:access_token) { create :access_token }
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa let(:repository) { create :repository, access_token: access_token }
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa context 'expired?' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should not be expired when the expiration date is in the future' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa expect(access_token.expired?).to be_falsy
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should be expired when the expiration date is in the past' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa access_token.expiration = (-1).minutes.from_now
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa expect(access_token.expired?).to be_truthy
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa context 'refresh' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa let!(:old_access_token) { access_token.dup }
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa before do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa access_token.expiration = (-1).minutes.from_now
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should be expired before refresh' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa expect(access_token.expired?).to be_truthy
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa context 'after refresh' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa before do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa access_token.refresh!
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should not be expired' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa expect(access_token.expired?).to be_falsy
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should have the same token' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa expect(access_token.token).to eq(old_access_token.token)
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa context 'replacement' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa let!(:replacement) { access_token.replace }
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should delete the old token' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa expect(access_token.persisted?).to be_falsy
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should generate another token' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa expect(replacement.token).not_to eq(access_token.token)
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
490da89281b7ee019c87406fb8ce7359aff0932cEugen Kuksaend