Skip to content
Snippets Groups Projects
Commit c10943d9 authored by Robert Speicher's avatar Robert Speicher
Browse files

Create guest users only when necessary rather than for every spec

These are two examples of a top-level `before` block doing too much.
Only specific specs cared about these guest users, but we were creating
them and their `ProjectMember` records for every single spec that ran.
parent f23d7434
No related branches found
No related tags found
No related merge requests found
require 'spec_helper'
 
feature 'Top Plus Menu', feature: true, js: true do
let(:user) { create :user }
let(:guest_user) { create :user}
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, :repository, creator: user, namespace: user.namespace) }
let(:public_project) { create(:project, :public) }
 
before do
group.add_owner(user)
group.add_guest(guest_user)
project.add_guest(guest_user)
end
 
context 'used by full user' do
Loading
Loading
@@ -39,7 +35,7 @@ feature 'Top Plus Menu', feature: true, js: true do
 
scenario 'click on New snippet shows new snippet page' do
visit root_dashboard_path
click_topmenuitem("New snippet")
 
expect(page).to have_content('New Snippet')
Loading
Loading
@@ -102,7 +98,12 @@ feature 'Top Plus Menu', feature: true, js: true do
end
 
context 'used by guest user' do
let(:guest_user) { create(:user) }
before do
group.add_guest(guest_user)
project.add_guest(guest_user)
sign_in(guest_user)
end
 
Loading
Loading
@@ -153,7 +154,7 @@ feature 'Top Plus Menu', feature: true, js: true do
 
scenario 'has no New project for group menu item' do
visit group_path(group)
expect(find('.header-new.dropdown')).not_to have_selector('.header-new-group-project')
end
end
Loading
Loading
@@ -168,5 +169,5 @@ feature 'Top Plus Menu', feature: true, js: true do
 
def hasnot_topmenuitem(item_name)
expect(find('.header-new.dropdown')).not_to have_content(item_name)
end
end
end
Loading
Loading
@@ -5,8 +5,6 @@ shared_examples 'issuable record that supports quick actions in its description
include QuickActionsHelpers
 
let(:master) { create(:user) }
let(:assignee) { create(:user, username: 'bob') }
let(:guest) { create(:user) }
let(:project) { create(:project, :public) }
let!(:milestone) { create(:milestone, project: project, title: 'ASAP') }
let!(:label_bug) { create(:label, project: project, title: 'bug') }
Loading
Loading
@@ -15,8 +13,6 @@ shared_examples 'issuable record that supports quick actions in its description
 
before do
project.team << [master, :master]
project.team << [assignee, :developer]
project.team << [guest, :guest]
 
sign_in(master)
end
Loading
Loading
@@ -57,6 +53,7 @@ shared_examples 'issuable record that supports quick actions in its description
 
context 'with a note containing commands' do
it 'creates a note without the commands and interpret the commands accordingly' do
assignee = create(:user, username: 'bob')
write_note("Awesome!\n/assign @bob\n/label ~bug\n/milestone %\"ASAP\"")
 
expect(page).to have_content 'Awesome!'
Loading
Loading
@@ -77,6 +74,7 @@ shared_examples 'issuable record that supports quick actions in its description
 
context 'with a note containing only commands' do
it 'does not create a note but interpret the commands accordingly' do
assignee = create(:user, username: 'bob')
write_note("/assign @bob\n/label ~bug\n/milestone %\"ASAP\"")
 
expect(page).not_to have_content '/assign @bob'
Loading
Loading
@@ -111,8 +109,12 @@ shared_examples 'issuable record that supports quick actions in its description
 
context "when current user cannot close #{issuable_type}" do
before do
guest = create(:user)
project.add_guest(guest)
sign_out(:user)
sign_in(guest)
visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
end
 
Loading
Loading
@@ -146,8 +148,12 @@ shared_examples 'issuable record that supports quick actions in its description
 
context "when current user cannot reopen #{issuable_type}" do
before do
guest = create(:user)
project.add_guest(guest)
sign_out(:user)
sign_in(guest)
visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
end
 
Loading
Loading
@@ -176,6 +182,9 @@ shared_examples 'issuable record that supports quick actions in its description
 
context "when current user cannot change title of #{issuable_type}" do
before do
guest = create(:user)
project.add_guest(guest)
sign_out(:user)
sign_in(guest)
visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
Loading
Loading
@@ -267,6 +276,8 @@ shared_examples 'issuable record that supports quick actions in its description
 
describe "preview of note on #{issuable_type}" do
it 'removes quick actions from note and explains them' do
create(:user, username: 'bob')
visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
 
page.within('.js-main-target-form') do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment