Commit c10943d9 authored by Robert Speicher's avatar Robert Speicher

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
require 'spec_helper' require 'spec_helper'
feature 'Top Plus Menu', feature: true, js: true do feature 'Top Plus Menu', feature: true, js: true do
let(:user) { create :user } let(:user) { create(:user) }
let(:guest_user) { create :user}
let(:group) { create(:group) } let(:group) { create(:group) }
let(:project) { create(:project, :repository, creator: user, namespace: user.namespace) } let(:project) { create(:project, :repository, creator: user, namespace: user.namespace) }
let(:public_project) { create(:project, :public) } let(:public_project) { create(:project, :public) }
before do before do
group.add_owner(user) group.add_owner(user)
group.add_guest(guest_user)
project.add_guest(guest_user)
end end
context 'used by full user' do context 'used by full user' do
...@@ -39,7 +35,7 @@ feature 'Top Plus Menu', feature: true, js: true do ...@@ -39,7 +35,7 @@ feature 'Top Plus Menu', feature: true, js: true do
scenario 'click on New snippet shows new snippet page' do scenario 'click on New snippet shows new snippet page' do
visit root_dashboard_path visit root_dashboard_path
click_topmenuitem("New snippet") click_topmenuitem("New snippet")
expect(page).to have_content('New Snippet') expect(page).to have_content('New Snippet')
...@@ -102,7 +98,12 @@ feature 'Top Plus Menu', feature: true, js: true do ...@@ -102,7 +98,12 @@ feature 'Top Plus Menu', feature: true, js: true do
end end
context 'used by guest user' do context 'used by guest user' do
let(:guest_user) { create(:user) }
before do before do
group.add_guest(guest_user)
project.add_guest(guest_user)
sign_in(guest_user) sign_in(guest_user)
end end
...@@ -153,7 +154,7 @@ feature 'Top Plus Menu', feature: true, js: true do ...@@ -153,7 +154,7 @@ feature 'Top Plus Menu', feature: true, js: true do
scenario 'has no New project for group menu item' do scenario 'has no New project for group menu item' do
visit group_path(group) visit group_path(group)
expect(find('.header-new.dropdown')).not_to have_selector('.header-new-group-project') expect(find('.header-new.dropdown')).not_to have_selector('.header-new-group-project')
end end
end end
...@@ -168,5 +169,5 @@ feature 'Top Plus Menu', feature: true, js: true do ...@@ -168,5 +169,5 @@ feature 'Top Plus Menu', feature: true, js: true do
def hasnot_topmenuitem(item_name) def hasnot_topmenuitem(item_name)
expect(find('.header-new.dropdown')).not_to have_content(item_name) expect(find('.header-new.dropdown')).not_to have_content(item_name)
end end
end end
...@@ -5,8 +5,6 @@ shared_examples 'issuable record that supports quick actions in its description ...@@ -5,8 +5,6 @@ shared_examples 'issuable record that supports quick actions in its description
include QuickActionsHelpers include QuickActionsHelpers
let(:master) { create(:user) } let(:master) { create(:user) }
let(:assignee) { create(:user, username: 'bob') }
let(:guest) { create(:user) }
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
let!(:milestone) { create(:milestone, project: project, title: 'ASAP') } let!(:milestone) { create(:milestone, project: project, title: 'ASAP') }
let!(:label_bug) { create(:label, project: project, title: 'bug') } let!(:label_bug) { create(:label, project: project, title: 'bug') }
...@@ -15,8 +13,6 @@ shared_examples 'issuable record that supports quick actions in its description ...@@ -15,8 +13,6 @@ shared_examples 'issuable record that supports quick actions in its description
before do before do
project.team << [master, :master] project.team << [master, :master]
project.team << [assignee, :developer]
project.team << [guest, :guest]
sign_in(master) sign_in(master)
end end
...@@ -57,6 +53,7 @@ shared_examples 'issuable record that supports quick actions in its description ...@@ -57,6 +53,7 @@ shared_examples 'issuable record that supports quick actions in its description
context 'with a note containing commands' do context 'with a note containing commands' do
it 'creates a note without the commands and interpret the commands accordingly' 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\"") write_note("Awesome!\n/assign @bob\n/label ~bug\n/milestone %\"ASAP\"")
expect(page).to have_content 'Awesome!' expect(page).to have_content 'Awesome!'
...@@ -77,6 +74,7 @@ shared_examples 'issuable record that supports quick actions in its description ...@@ -77,6 +74,7 @@ shared_examples 'issuable record that supports quick actions in its description
context 'with a note containing only commands' do context 'with a note containing only commands' do
it 'does not create a note but interpret the commands accordingly' 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\"") write_note("/assign @bob\n/label ~bug\n/milestone %\"ASAP\"")
expect(page).not_to have_content '/assign @bob' expect(page).not_to have_content '/assign @bob'
...@@ -111,8 +109,12 @@ shared_examples 'issuable record that supports quick actions in its description ...@@ -111,8 +109,12 @@ shared_examples 'issuable record that supports quick actions in its description
context "when current user cannot close #{issuable_type}" do context "when current user cannot close #{issuable_type}" do
before do before do
guest = create(:user)
project.add_guest(guest)
sign_out(:user) sign_out(:user)
sign_in(guest) sign_in(guest)
visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable) visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
end end
...@@ -146,8 +148,12 @@ shared_examples 'issuable record that supports quick actions in its description ...@@ -146,8 +148,12 @@ shared_examples 'issuable record that supports quick actions in its description
context "when current user cannot reopen #{issuable_type}" do context "when current user cannot reopen #{issuable_type}" do
before do before do
guest = create(:user)
project.add_guest(guest)
sign_out(:user) sign_out(:user)
sign_in(guest) sign_in(guest)
visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable) visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
end end
...@@ -176,6 +182,9 @@ shared_examples 'issuable record that supports quick actions in its description ...@@ -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 context "when current user cannot change title of #{issuable_type}" do
before do before do
guest = create(:user)
project.add_guest(guest)
sign_out(:user) sign_out(:user)
sign_in(guest) sign_in(guest)
visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable) visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
...@@ -267,6 +276,8 @@ shared_examples 'issuable record that supports quick actions in its description ...@@ -267,6 +276,8 @@ shared_examples 'issuable record that supports quick actions in its description
describe "preview of note on #{issuable_type}" do describe "preview of note on #{issuable_type}" do
it 'removes quick actions from note and explains them' 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) visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
page.within('.js-main-target-form') do page.within('.js-main-target-form') do
......
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