Commit ef18b18d authored by Robert Hunt's avatar Robert Hunt

Initial review feedback

Removed unnecessary render methods and updated to use let_it_be rather
than let
parent efc6600b
...@@ -5,13 +5,13 @@ require 'spec_helper' ...@@ -5,13 +5,13 @@ require 'spec_helper'
RSpec.describe('shared/credentials_inventory/_expiry_date.html.haml') do RSpec.describe('shared/credentials_inventory/_expiry_date.html.haml') do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
context 'when a non-expirable credential is used' do
let_it_be(:credential) { create(:deploy_key, user: user)}
before do before do
render 'shared/credentials_inventory/expiry_date', credential: credential render 'shared/credentials_inventory/expiry_date', credential: credential
end end
context 'when a non-expirable credential is used' do
let_it_be(:credential) { create(:deploy_key, user: user)}
it 'shows "Never" if expires? method does not exist' do it 'shows "Never" if expires? method does not exist' do
expect(rendered).to have_text('Never') expect(rendered).to have_text('Never')
end end
...@@ -20,10 +20,6 @@ RSpec.describe('shared/credentials_inventory/_expiry_date.html.haml') do ...@@ -20,10 +20,6 @@ RSpec.describe('shared/credentials_inventory/_expiry_date.html.haml') do
context 'when an expirable credential is used' do context 'when an expirable credential is used' do
let_it_be(:credential) { create(:personal_access_token, user: user, expires_at: nil)} let_it_be(:credential) { create(:personal_access_token, user: user, expires_at: nil)}
before do
render 'shared/credentials_inventory/expiry_date', credential: credential
end
it 'shows "Never" when not expirable' do it 'shows "Never" when not expirable' do
expect(rendered).to have_text('Never') expect(rendered).to have_text('Never')
end end
...@@ -32,10 +28,6 @@ RSpec.describe('shared/credentials_inventory/_expiry_date.html.haml') do ...@@ -32,10 +28,6 @@ RSpec.describe('shared/credentials_inventory/_expiry_date.html.haml') do
let_it_be(:expiry_date) { 20.days.since.to_date.to_s } let_it_be(:expiry_date) { 20.days.since.to_date.to_s }
let_it_be(:credential) { create(:personal_key, user: user, expires_at: expiry_date)} let_it_be(:credential) { create(:personal_key, user: user, expires_at: expiry_date)}
before do
render 'shared/credentials_inventory/expiry_date', credential: credential
end
it 'shows the correct date' do it 'shows the correct date' do
expect(rendered).to have_text(expiry_date) expect(rendered).to have_text(expiry_date)
end end
...@@ -49,10 +41,6 @@ RSpec.describe('shared/credentials_inventory/_expiry_date.html.haml') do ...@@ -49,10 +41,6 @@ RSpec.describe('shared/credentials_inventory/_expiry_date.html.haml') do
let_it_be(:expiry_date) { 1.day.since.to_date.to_s } let_it_be(:expiry_date) { 1.day.since.to_date.to_s }
let_it_be(:credential) { create(:personal_access_token, user: user, expires_at: expiry_date)} let_it_be(:credential) { create(:personal_access_token, user: user, expires_at: expiry_date)}
before do
render 'shared/credentials_inventory/expiry_date', credential: credential
end
it 'shows the correct date' do it 'shows the correct date' do
expect(rendered).to have_text(expiry_date) expect(rendered).to have_text(expiry_date)
end end
...@@ -66,10 +54,6 @@ RSpec.describe('shared/credentials_inventory/_expiry_date.html.haml') do ...@@ -66,10 +54,6 @@ RSpec.describe('shared/credentials_inventory/_expiry_date.html.haml') do
let_it_be(:expiry_date) { 2.days.ago.to_date.to_s } let_it_be(:expiry_date) { 2.days.ago.to_date.to_s }
let_it_be(:credential) { create(:personal_access_token, user: user, expires_at: expiry_date)} let_it_be(:credential) { create(:personal_access_token, user: user, expires_at: expiry_date)}
before do
render 'shared/credentials_inventory/expiry_date', credential: credential
end
it 'shows the correct date' do it 'shows the correct date' do
expect(rendered).to have_text(expiry_date) expect(rendered).to have_text(expiry_date)
end end
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe('shared/credentials_inventory/personal_access_tokens/_personal_access_token.html.haml') do RSpec.describe('shared/credentials_inventory/personal_access_tokens/_personal_access_token.html.haml') do
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:expiry_date) { 20.days.since } let_it_be(:expiry_date) { 20.days.since }
let(:personal_access_token) { create(:personal_access_token, user: user, expires_at: expiry_date)} let_it_be(:personal_access_token) { create(:personal_access_token, user: user, expires_at: expiry_date)}
before do before do
allow(view).to receive(:user_detail_path).and_return('abcd') allow(view).to receive(:user_detail_path).and_return('abcd')
...@@ -25,14 +25,10 @@ RSpec.describe('shared/credentials_inventory/personal_access_tokens/_personal_ac ...@@ -25,14 +25,10 @@ RSpec.describe('shared/credentials_inventory/personal_access_tokens/_personal_ac
end end
context 'revoked date' do context 'revoked date' do
let(:updated_at_date) { 10.days.ago } let_it_be(:updated_at_date) { 10.days.ago }
context 'when set' do context 'when set' do
let(:personal_access_token) { create(:personal_access_token, user: user, updated_at: updated_at_date, revoked: true)} let_it_be(:personal_access_token) { create(:personal_access_token, user: user, updated_at: updated_at_date, revoked: true)}
before do
render 'shared/credentials_inventory/personal_access_tokens/personal_access_token', personal_access_token: personal_access_token
end
it 'shows the last accessed on date' do it 'shows the last accessed on date' do
expect(rendered).to have_text(personal_access_token.updated_at.to_date.to_s) expect(rendered).to have_text(personal_access_token.updated_at.to_date.to_s)
...@@ -40,25 +36,18 @@ RSpec.describe('shared/credentials_inventory/personal_access_tokens/_personal_ac ...@@ -40,25 +36,18 @@ RSpec.describe('shared/credentials_inventory/personal_access_tokens/_personal_ac
end end
context 'when not set' do context 'when not set' do
let(:personal_access_token) { create(:personal_access_token, user: user, updated_at: updated_at_date)} let_it_be(:personal_access_token) { create(:personal_access_token, user: user, updated_at: updated_at_date)}
before do
render 'shared/credentials_inventory/personal_access_tokens/personal_access_token', personal_access_token: personal_access_token
end
it 'shows "Never" for the last accessed on date' do it 'shows "Never" for the last accessed on date' do
expect(rendered).not_to have_text(updated_at_date.to_date.to_s) expect(rendered).not_to have_text(updated_at_date.to_date.to_s)
end end
end end
end end
context 'scopes' do context 'scopes' do
context 'when set' do context 'when set' do
let(:scopes) { %w(api read_user read_api) } let_it_be(:scopes) { %w(api read_user read_api) }
let(:personal_access_token) { create(:personal_access_token, user: user, scopes: scopes)} let_it_be(:personal_access_token) { create(:personal_access_token, user: user, scopes: scopes)}
before do
render 'shared/credentials_inventory/personal_access_tokens/personal_access_token', personal_access_token: personal_access_token
end
it 'shows the scopes' do it 'shows the scopes' do
expect(rendered).to have_text(personal_access_token.scopes.join(', ')) expect(rendered).to have_text(personal_access_token.scopes.join(', '))
...@@ -66,7 +55,7 @@ RSpec.describe('shared/credentials_inventory/personal_access_tokens/_personal_ac ...@@ -66,7 +55,7 @@ RSpec.describe('shared/credentials_inventory/personal_access_tokens/_personal_ac
end end
context 'when not set' do context 'when not set' do
let(:personal_access_token) { create(:personal_access_token, user: user)} let_it_be(:personal_access_token) { create(:personal_access_token, user: user)}
before do before do
# Turns out on creation of a PersonalAccessToken we set some default scopes and you can't pass `nil` # Turns out on creation of a PersonalAccessToken we set some default scopes and you can't pass `nil`
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe('shared/credentials_inventory/ssh_keys/_ssh_key.html.haml') do RSpec.describe('shared/credentials_inventory/ssh_keys/_ssh_key.html.haml') do
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:expiry_date) { 20.days.since } let_it_be(:expiry_date) { 20.days.since }
let(:ssh_key) { create(:personal_key, user: user, expires_at: expiry_date)} let_it_be(:ssh_key) { create(:personal_key, user: user, expires_at: expiry_date)}
before do before do
allow(view).to receive(:user_detail_path).and_return('abcd') allow(view).to receive(:user_detail_path).and_return('abcd')
...@@ -26,12 +26,8 @@ RSpec.describe('shared/credentials_inventory/ssh_keys/_ssh_key.html.haml') do ...@@ -26,12 +26,8 @@ RSpec.describe('shared/credentials_inventory/ssh_keys/_ssh_key.html.haml') do
context 'last accessed date' do context 'last accessed date' do
context 'when set' do context 'when set' do
let(:last_used_date) { 10.days.ago } let_it_be(:last_used_date) { 10.days.ago }
let(:ssh_key) { create(:personal_key, user: user, last_used_at: last_used_date)} let_it_be(:ssh_key) { create(:personal_key, user: user, last_used_at: last_used_date)}
before do
render 'shared/credentials_inventory/ssh_keys/ssh_key', ssh_key: ssh_key
end
it 'shows the last accessed on date' do it 'shows the last accessed on date' do
expect(rendered).to have_text(ssh_key.last_used_at.to_date.to_s) expect(rendered).to have_text(ssh_key.last_used_at.to_date.to_s)
...@@ -39,11 +35,7 @@ RSpec.describe('shared/credentials_inventory/ssh_keys/_ssh_key.html.haml') do ...@@ -39,11 +35,7 @@ RSpec.describe('shared/credentials_inventory/ssh_keys/_ssh_key.html.haml') do
end end
context 'when not set' do context 'when not set' do
let(:ssh_key) { create(:personal_key, user: user)} let_it_be(:ssh_key) { create(:personal_key, user: user)}
before do
render 'shared/credentials_inventory/ssh_keys/ssh_key', ssh_key: ssh_key
end
it 'shows "Never" for the last accessed on date' do it 'shows "Never" for the last accessed on date' do
expect(rendered).to have_text('Last Accessed On Never') expect(rendered).to have_text('Last Accessed On Never')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment