Commit f131f71e authored by James Fargher's avatar James Fargher

Merge branch 'fix-specs-to-support-parent-strategy-in-factories-5' into 'master'

Refactor tests to support Parent Strategy in factories

See merge request gitlab-org/gitlab!41763
parents 96af7802 7a16ecfb
......@@ -3,7 +3,7 @@
FactoryBot.define do
factory :group_member do
access_level { GroupMember::OWNER }
group
source { association(:group) }
user
trait(:guest) { access_level { GroupMember::GUEST } }
......
......@@ -3,7 +3,7 @@
FactoryBot.define do
factory :project_member do
user
project
source { association(:project) }
maintainer
trait(:guest) { access_level { ProjectMember::GUEST } }
......
......@@ -23,7 +23,8 @@ RSpec.describe Member do
end
context "when an invite email is provided" do
let(:member) { build(:project_member, invite_email: "user@example.com", user: nil) }
let_it_be(:project) { create(:project) }
let(:member) { build(:project_member, source: project, invite_email: "user@example.com", user: nil) }
it "doesn't require a user" do
expect(member).to be_valid
......@@ -681,7 +682,7 @@ RSpec.describe Member do
describe 'create member' do
let!(:source) { create(source_type) }
subject { create(member_type, :guest, user: user, source_type => source) }
subject { create(member_type, :guest, user: user, source: source) }
include_examples 'update highest role with exclusive lease'
end
......
......@@ -8,17 +8,17 @@ RSpec.describe PersonalAccessTokenPolicy do
subject { described_class.new(current_user, token) }
context 'current_user is an administrator', :enable_admin_mode do
let_it_be(:current_user) { build(:admin) }
let_it_be(:current_user) { build_stubbed(:admin) }
context 'not the owner of the token' do
let_it_be(:token) { build(:personal_access_token) }
let_it_be(:token) { build_stubbed(:personal_access_token) }
it { is_expected.to be_allowed(:read_token) }
it { is_expected.to be_allowed(:revoke_token) }
end
context 'owner of the token' do
let_it_be(:token) { build(:personal_access_token, user: current_user) }
let_it_be(:token) { build_stubbed(:personal_access_token, user: current_user) }
it { is_expected.to be_allowed(:read_token) }
it { is_expected.to be_allowed(:revoke_token) }
......@@ -26,17 +26,17 @@ RSpec.describe PersonalAccessTokenPolicy do
end
context 'current_user is not an administrator' do
let_it_be(:current_user) { build(:user) }
let_it_be(:current_user) { build_stubbed(:user) }
context 'not the owner of the token' do
let_it_be(:token) { build(:personal_access_token) }
let_it_be(:token) { build_stubbed(:personal_access_token) }
it { is_expected.to be_disallowed(:read_token) }
it { is_expected.to be_disallowed(:revoke_token) }
end
context 'owner of the token' do
let_it_be(:token) { build(:personal_access_token, user: current_user) }
let_it_be(:token) { build_stubbed(:personal_access_token, user: current_user) }
it { is_expected.to be_allowed(:read_token) }
it { is_expected.to be_allowed(:revoke_token) }
......@@ -44,17 +44,17 @@ RSpec.describe PersonalAccessTokenPolicy do
end
context 'current_user is a blocked administrator', :enable_admin_mode do
let_it_be(:current_user) { build(:admin, :blocked) }
let_it_be(:current_user) { create(:admin, :blocked) }
context 'owner of the token' do
let_it_be(:token) { build(:personal_access_token, user: current_user) }
let_it_be(:token) { build_stubbed(:personal_access_token, user: current_user) }
it { is_expected.to be_disallowed(:read_token) }
it { is_expected.to be_disallowed(:revoke_token) }
end
context 'not the owner of the token' do
let_it_be(:token) { build(:personal_access_token) }
let_it_be(:token) { build_stubbed(:personal_access_token) }
it { is_expected.to be_disallowed(:read_token) }
it { is_expected.to be_disallowed(:revoke_token) }
......
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