summaryrefslogtreecommitdiff
path: root/spec/finders
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2017-03-01 16:59:03 +0000
committerTiago Botelho <tiagonbotelho@hotmail.com>2017-03-06 19:18:26 +0000
commit005749a616c19b90d6ec0415df9ae5e35151e33c (patch)
treef1618dbe99a4ed60980dc94f831864f9e701c589 /spec/finders
parent2b474dc2b226460782413e634792cf83e791173b (diff)
downloadgitlab-ce-005749a616c19b90d6ec0415df9ae5e35151e33c.tar.gz
apply codestyle and implementation changes to the respective feature codepersonal_access_token_api_and_impersonation_token
Diffstat (limited to 'spec/finders')
-rw-r--r--spec/finders/personal_access_tokens_finder_spec.rb80
1 files changed, 42 insertions, 38 deletions
diff --git a/spec/finders/personal_access_tokens_finder_spec.rb b/spec/finders/personal_access_tokens_finder_spec.rb
index 91e746f295a..fd92664ca24 100644
--- a/spec/finders/personal_access_tokens_finder_spec.rb
+++ b/spec/finders/personal_access_tokens_finder_spec.rb
@@ -1,20 +1,23 @@
require 'spec_helper'
describe PersonalAccessTokensFinder do
+ def finder(options = {})
+ described_class.new(options)
+ end
+
describe '#execute' do
let(:user) { create(:user) }
+ let(:params) { {} }
let!(:active_personal_access_token) { create(:personal_access_token, user: user) }
- let!(:expired_personal_access_token) { create(:expired_personal_access_token, user: user) }
- let!(:revoked_personal_access_token) { create(:revoked_personal_access_token, user: user) }
- let!(:active_impersonation_token) { create(:impersonation_personal_access_token, user: user, impersonation: true) }
- let!(:expired_impersonation_token) { create(:expired_personal_access_token, user: user, impersonation: true) }
- let!(:revoked_impersonation_token) { create(:revoked_personal_access_token, user: user, impersonation: true) }
+ let!(:expired_personal_access_token) { create(:personal_access_token, :expired, user: user) }
+ let!(:revoked_personal_access_token) { create(:personal_access_token, :revoked, user: user) }
+ let!(:active_impersonation_token) { create(:personal_access_token, :impersonation, user: user) }
+ let!(:expired_impersonation_token) { create(:personal_access_token, :expired, :impersonation, user: user) }
+ let!(:revoked_impersonation_token) { create(:personal_access_token, :revoked, :impersonation, user: user) }
- subject { finder.execute }
+ subject { finder(params).execute }
describe 'without user' do
- let(:finder) { described_class.new }
-
it do
is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token,
revoked_personal_access_token, expired_personal_access_token,
@@ -22,49 +25,49 @@ describe PersonalAccessTokensFinder do
end
describe 'without impersonation' do
- before { finder.params.merge!(impersonation: false) }
+ before { params[:impersonation] = false }
it { is_expected.to contain_exactly(active_personal_access_token, revoked_personal_access_token, expired_personal_access_token) }
describe 'with active state' do
- before { finder.params.merge!(state: 'active') }
+ before { params[:state] = 'active' }
it { is_expected.to contain_exactly(active_personal_access_token) }
end
describe 'with inactive state' do
- before { finder.params.merge!(state: 'inactive') }
+ before { params[:state] = 'inactive' }
it { is_expected.to contain_exactly(revoked_personal_access_token, expired_personal_access_token) }
end
end
describe 'with impersonation' do
- before { finder.params.merge!(impersonation: true) }
+ before { params[:impersonation] = true }
it { is_expected.to contain_exactly(active_impersonation_token, revoked_impersonation_token, expired_impersonation_token) }
describe 'with active state' do
- before { finder.params.merge!(state: 'active') }
+ before { params[:state] = 'active' }
it { is_expected.to contain_exactly(active_impersonation_token) }
end
describe 'with inactive state' do
- before { finder.params.merge!(state: 'inactive') }
+ before { params[:state] = 'inactive' }
it { is_expected.to contain_exactly(revoked_impersonation_token, expired_impersonation_token) }
end
end
describe 'with active state' do
- before { finder.params.merge!(state: 'active') }
+ before { params[:state] = 'active' }
it { is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token) }
end
describe 'with inactive state' do
- before { finder.params.merge!(state: 'inactive') }
+ before { params[:state] = 'inactive' }
it do
is_expected.to contain_exactly(expired_personal_access_token, revoked_personal_access_token,
@@ -73,24 +76,24 @@ describe PersonalAccessTokensFinder do
end
describe 'with id' do
- subject { finder.execute(id: active_personal_access_token.id) }
+ subject { finder(params).find_by(id: active_personal_access_token.id) }
it { is_expected.to eq(active_personal_access_token) }
describe 'with impersonation' do
- before { finder.params.merge!(impersonation: true) }
+ before { params[:impersonation] = true }
it { is_expected.to be_nil }
end
end
describe 'with token' do
- subject { finder.execute(token: active_personal_access_token.token) }
+ subject { finder(params).find_by(token: active_personal_access_token.token) }
it { is_expected.to eq(active_personal_access_token) }
describe 'with impersonation' do
- before { finder.params.merge!(impersonation: true) }
+ before { params[:impersonation] = true }
it { is_expected.to be_nil }
end
@@ -99,13 +102,14 @@ describe PersonalAccessTokensFinder do
describe 'with user' do
let(:user2) { create(:user) }
- let(:finder) { described_class.new(user: user) }
let!(:other_user_active_personal_access_token) { create(:personal_access_token, user: user2) }
- let!(:other_user_expired_personal_access_token) { create(:expired_personal_access_token, user: user2) }
- let!(:other_user_revoked_personal_access_token) { create(:revoked_personal_access_token, user: user2) }
- let!(:other_user_active_impersonation_token) { create(:impersonation_personal_access_token, user: user2, impersonation: true) }
- let!(:other_user_expired_impersonation_token) { create(:expired_personal_access_token, user: user2, impersonation: true) }
- let!(:other_user_revoked_impersonation_token) { create(:revoked_personal_access_token, user: user2, impersonation: true) }
+ let!(:other_user_expired_personal_access_token) { create(:personal_access_token, :expired, user: user2) }
+ let!(:other_user_revoked_personal_access_token) { create(:personal_access_token, :revoked, user: user2) }
+ let!(:other_user_active_impersonation_token) { create(:personal_access_token, :impersonation, user: user2) }
+ let!(:other_user_expired_impersonation_token) { create(:personal_access_token, :expired, :impersonation, user: user2) }
+ let!(:other_user_revoked_impersonation_token) { create(:personal_access_token, :revoked, :impersonation, user: user2) }
+
+ before { params[:user] = user }
it do
is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token,
@@ -114,49 +118,49 @@ describe PersonalAccessTokensFinder do
end
describe 'without impersonation' do
- before { finder.params.merge!(impersonation: false) }
+ before { params[:impersonation] = false }
it { is_expected.to contain_exactly(active_personal_access_token, revoked_personal_access_token, expired_personal_access_token) }
describe 'with active state' do
- before { finder.params.merge!(state: 'active') }
+ before { params[:state] = 'active' }
it { is_expected.to contain_exactly(active_personal_access_token) }
end
describe 'with inactive state' do
- before { finder.params.merge!(state: 'inactive') }
+ before { params[:state] = 'inactive' }
it { is_expected.to contain_exactly(revoked_personal_access_token, expired_personal_access_token) }
end
end
describe 'with impersonation' do
- before { finder.params.merge!(impersonation: true) }
+ before { params[:impersonation] = true }
it { is_expected.to contain_exactly(active_impersonation_token, revoked_impersonation_token, expired_impersonation_token) }
describe 'with active state' do
- before { finder.params.merge!(state: 'active') }
+ before { params[:state] = 'active' }
it { is_expected.to contain_exactly(active_impersonation_token) }
end
describe 'with inactive state' do
- before { finder.params.merge!(state: 'inactive') }
+ before { params[:state] = 'inactive' }
it { is_expected.to contain_exactly(revoked_impersonation_token, expired_impersonation_token) }
end
end
describe 'with active state' do
- before { finder.params.merge!(state: 'active') }
+ before { params[:state] = 'active' }
it { is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token) }
end
describe 'with inactive state' do
- before { finder.params.merge!(state: 'inactive') }
+ before { params[:state] = 'inactive' }
it do
is_expected.to contain_exactly(expired_personal_access_token, revoked_personal_access_token,
@@ -165,24 +169,24 @@ describe PersonalAccessTokensFinder do
end
describe 'with id' do
- subject { finder.execute(id: active_personal_access_token.id) }
+ subject { finder(params).find_by(id: active_personal_access_token.id) }
it { is_expected.to eq(active_personal_access_token) }
describe 'with impersonation' do
- before { finder.params.merge!(impersonation: true) }
+ before { params[:impersonation] = true }
it { is_expected.to be_nil }
end
end
describe 'with token' do
- subject { finder.execute(token: active_personal_access_token.token) }
+ subject { finder(params).find_by(token: active_personal_access_token.token) }
it { is_expected.to eq(active_personal_access_token) }
describe 'with impersonation' do
- before { finder.params.merge!(impersonation: true) }
+ before { params[:impersonation] = true }
it { is_expected.to be_nil }
end