Commit 27c95364 authored by blackst0ne's avatar blackst0ne

Replace '.team << [user, role]' with 'add_role(user)' in specs

parent 36f47103
Pipeline #15412271 passed with stages
in 81 minutes and 45 seconds
......@@ -226,7 +226,7 @@ class Project < ActiveRecord::Base
delegate :name, to: :owner, allow_nil: true, prefix: true
delegate :members, to: :team, prefix: true
delegate :add_user, :add_users, to: :team
delegate :add_guest, :add_reporter, :add_developer, :add_master, to: :team
delegate :add_guest, :add_reporter, :add_developer, :add_master, :add_role, to: :team
# Validations
validates :creator, presence: true, on: :create
......
......@@ -7,36 +7,24 @@ class ProjectTeam
@project = project
end
# Shortcut to add users
#
# Use:
# @team << [@user, :master]
# @team << [@users, :master]
#
def <<(args)
users, access, current_user = *args
if users.respond_to?(:each)
add_users(users, access, current_user: current_user)
else
add_user(users, access, current_user: current_user)
end
end
def add_guest(user, current_user: nil)
self << [user, :guest, current_user]
add_user(user, :guest, current_user: current_user)
end
def add_reporter(user, current_user: nil)
self << [user, :reporter, current_user]
add_user(user, :reporter, current_user: current_user)
end
def add_developer(user, current_user: nil)
self << [user, :developer, current_user]
add_user(user, :developer, current_user: current_user)
end
def add_master(user, current_user: nil)
self << [user, :master, current_user]
add_user(user, :master, current_user: current_user)
end
def add_role(user, role, current_user: nil)
send(:"add_#{role}", user, current_user: current_user) # rubocop:disable GitlabSecurity/PublicSend
end
def find_member(user_id)
......
---
title: Replace '.team << [user, role]' with 'add_role(user)' in specs
merge_request: 16069
author: "@blackst0ne"
type: other
......@@ -14,7 +14,7 @@ Sidekiq::Testing.inline! do
Project.all.each do |project|
User.all.sample(4).each do |user|
if project.team << [user, Gitlab::Access.values.sample]
if project.add_role(user, Gitlab::Access.values.sample)
print '.'
else
print 'F'
......
......@@ -165,7 +165,7 @@ class Spinach::Features::Profile < Spinach::FeatureSteps
@project = create(:project, :repository, namespace: @group)
@event = create(:closed_issue_event, project: @project)
@project.team << [current_user, :master]
@project.add_master(current_user)
end
step 'I should see groups I belong to' do
......
......@@ -48,11 +48,11 @@ class Spinach::Features::ProjectDeployKeys < Spinach::FeatureSteps
step 'other projects have deploy keys' do
@second_project = create(:project, namespace: create(:group))
@second_project.team << [current_user, :master]
@second_project.add_master(current_user)
create(:deploy_keys_project, project: @second_project)
@third_project = create(:project, namespace: create(:group))
@third_project.team << [current_user, :master]
@third_project.add_master(current_user)
create(:deploy_keys_project, project: @third_project, deploy_key: @second_project.deploy_keys.first)
end
......
......@@ -10,7 +10,7 @@ class Spinach::Features::ProjectFork < Spinach::FeatureSteps
step 'I am a member of project "Shop"' do
@project = create(:project, :repository, name: "Shop")
@project.team << [@user, :reporter]
@project.add_reporter(@user)
end
step 'I should see the forked project page' do
......@@ -71,7 +71,7 @@ class Spinach::Features::ProjectFork < Spinach::FeatureSteps
step 'There is an existent fork of the "Shop" project' do
user = create(:user, name: 'Mike')
@project.team << [user, :reporter]
@project.add_reporter(user)
@forked_project = Projects::ForkService.new(@project, user).execute
end
......
......@@ -10,7 +10,7 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps
step 'I am a member of project "Shop"' do
@project = ::Project.find_by(name: "Shop")
@project ||= create(:project, :repository, name: "Shop")
@project.team << [@user, :reporter]
@project.add_reporter(@user)
end
step 'I have a project forked off of "Shop" called "Forked Shop"' do
......
......@@ -8,7 +8,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
step "I don't have write access" do
@project = create(:project, :repository, name: "Other Project", path: "other-project")
@project.team << [@user, :reporter]
@project.add_reporter(@user)
visit project_tree_path(@project, root_ref)
end
......
......@@ -10,7 +10,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
step 'I own project "Delta"' do
@project = ::Project.find_by(name: "Delta")
@project ||= create(:project, :repository, name: "Delta", namespace: @user.namespace)
@project.team << [@user, :master]
@project.add_master(@user)
end
step 'I should see files from repository in markdown' do
......
......@@ -41,7 +41,7 @@ module SharedGroup
group.add_user(user, role)
project ||= create(:project, :repository, namespace: group)
create(:closed_issue_event, project: project)
project.team << [user, :master]
project.add_master(user)
end
def owned_group
......
......@@ -4,13 +4,13 @@ module SharedProject
# Create a project without caring about what it's called
step "I own a project" do
@project = create(:project, :repository, namespace: @user.namespace)
@project.team << [@user, :master]
@project.add_master(@user)
end
step "I own a project in some group namespace" do
@group = create(:group, name: 'some group')
@project = create(:project, namespace: @group)
@project.team << [@user, :master]
@project.add_master(@user)
end
step "project exists in some group namespace" do
......@@ -22,7 +22,7 @@ module SharedProject
step 'I own project "Shop"' do
@project = Project.find_by(name: "Shop")
@project ||= create(:project, :repository, name: "Shop", namespace: @user.namespace)
@project.team << [@user, :master]
@project.add_master(@user)
end
step 'I disable snippets in project' do
......@@ -40,7 +40,7 @@ module SharedProject
step 'I add a user to project "Shop"' do
@project = Project.find_by(name: "Shop")
other_user = create(:user, name: 'Alpha')
@project.team << [other_user, :master]
@project.add_master(other_user)
end
# Create another specific project called "Forum"
......@@ -49,14 +49,13 @@ module SharedProject
@project ||= create(:project, :repository, name: "Forum", namespace: @user.namespace, path: 'forum_project')
@project.build_project_feature
@project.project_feature.save
@project.team << [@user, :master]
@project.add_master(@user)
end
# Create an empty project without caring about the name
step 'I own an empty project' do
@project = create(:project,
name: 'Empty Project', namespace: @user.namespace)
@project.team << [@user, :master]
@project = create(:project, name: 'Empty Project', namespace: @user.namespace)
@project.add_master(@user)
end
step 'I visit my empty project page' do
......@@ -101,11 +100,11 @@ module SharedProject
# ----------------------------------------
step 'I am member of a project with a guest role' do
@project.team << [@user, Gitlab::Access::GUEST]
@project.add_guest(@user)
end
step 'I am member of a project with a reporter role' do
@project.team << [@user, Gitlab::Access::REPORTER]
@project.add_reporter(@user)
end
# ----------------------------------------
......@@ -245,6 +244,6 @@ module SharedProject
user = user_exists(user_name, username: user_name.gsub(/\s/, '').underscore)
project = Project.find_by(name: project_name)
project ||= create(:project, visibility, name: project_name, namespace: user.namespace)
project.team << [user, :master]
project.add_master(user)
end
end
......@@ -13,7 +13,7 @@ describe Admin::UsersController do
let!(:issue) { create(:issue, author: user) }
before do
project.team << [user, :developer]
project.add_developer(user)
end
it 'deletes user and ghosts their contributions' do
......
......@@ -13,8 +13,8 @@ describe Boards::IssuesController do
let!(:list2) { create(:list, board: board, label: development, position: 1) }
before do
project.team << [user, :master]
project.team << [guest, :guest]
project.add_master(user)
project.add_guest(guest)
end
describe 'GET index' do
......@@ -221,7 +221,7 @@ describe Boards::IssuesController do
let(:guest) { create(:user) }
before do
project.team << [guest, :guest]
project.add_guest(guest)
end
it 'returns a forbidden 403 response' do
......
......@@ -7,8 +7,8 @@ describe Boards::ListsController do
let(:guest) { create(:user) }
before do
project.team << [user, :master]
project.team << [guest, :guest]
project.add_master(user)
project.add_guest(guest)
end
describe 'GET index' do
......
......@@ -17,7 +17,7 @@ describe Dashboard::MilestonesController do
before do
sign_in(user)
project.team << [user, :master]
project.add_master(user)
end
it_behaves_like 'milestone tabs'
......
......@@ -8,7 +8,7 @@ describe Dashboard::TodosController do
before do
sign_in(user)
project.team << [user, :developer]
project.add_developer(user)
end
describe 'GET #index' do
......
......@@ -5,7 +5,7 @@ describe DashboardController do
let(:project) { create(:project) }
before do
project.team << [user, :master]
project.add_master(user)
sign_in(user)
end
......
......@@ -28,7 +28,7 @@ describe Groups::MilestonesController do
before do
sign_in(user)
group.add_owner(user)
project.team << [user, :master]
project.add_master(user)
end
describe '#index' do
......
......@@ -6,7 +6,7 @@ describe NotificationSettingsController do
let(:user) { create(:user) }
before do
project.team << [user, :developer]
project.add_developer(user)
end
describe '#create' do
......
......@@ -6,7 +6,7 @@ describe Projects::AvatarsController do
before do
sign_in(user)
project.team << [user, :master]
project.add_master(user)
controller.instance_variable_set(:@project, project)
end
......
......@@ -7,7 +7,7 @@ describe Projects::BlameController do
before do
sign_in(user)
project.team << [user, :master]
project.add_master(user)
controller.instance_variable_set(:@project, project)
end
......
......@@ -89,7 +89,7 @@ describe Projects::BlobController do
end
before do
project.team << [user, :master]
project.add_master(user)
sign_in(user)
end
......@@ -147,7 +147,7 @@ describe Projects::BlobController do
let(:developer) { create(:user) }
before do
project.team << [developer, :developer]
project.add_developer(developer)
sign_in(developer)
get :edit, default_params
end
......@@ -161,7 +161,7 @@ describe Projects::BlobController do
let(:master) { create(:user) }
before do
project.team << [master, :master]
project.add_master(master)
sign_in(master)
get :edit, default_params
end
......@@ -190,7 +190,7 @@ describe Projects::BlobController do
end
before do
project.team << [user, :master]
project.add_master(user)
sign_in(user)
end
......
......@@ -5,7 +5,7 @@ describe Projects::BoardsController do
let(:user) { create(:user) }
before do
project.team << [user, :master]
project.add_master(user)
sign_in(user)
end
......
......@@ -6,8 +6,8 @@ describe Projects::BranchesController do
let(:developer) { create(:user) }
before do
project.team << [user, :master]
project.team << [user, :developer]
project.add_master(user)
project.add_developer(user)
allow(project).to receive(:branches).and_return(['master', 'foo/bar/baz'])
allow(project).to receive(:tags).and_return(['v1.0.0', 'v2.0.0'])
......
......@@ -6,7 +6,7 @@ describe Projects::CommitsController do
before do
sign_in(user)
project.team << [user, :master]
project.add_master(user)
end
describe "GET show" do
......
......@@ -8,7 +8,7 @@ describe Projects::CompareController do
before do
sign_in(user)
project.team << [user, :master]
project.add_master(user)
end
it 'compare shows some diffs' do
......
......@@ -6,7 +6,7 @@ describe Projects::CycleAnalyticsController do
before do
sign_in(user)
project.team << [user, :master]
project.add_master(user)
end
describe 'cycle analytics not set up flag' do
......
......@@ -5,7 +5,7 @@ describe Projects::DeployKeysController do
let(:user) { create(:user) }
before do
project.team << [user, :master]
project.add_master(user)
sign_in(user)
end
......@@ -48,7 +48,7 @@ describe Projects::DeployKeysController do
end
before do
project2.team << [user, :developer]
project2.add_developer(user)
end
it 'returns json in a correct format' do
......
......@@ -8,7 +8,7 @@ describe Projects::DeploymentsController do
let(:environment) { create(:environment, name: 'production', project: project) }
before do
project.team << [user, :master]
project.add_master(user)
sign_in(user)
end
......
......@@ -31,7 +31,7 @@ describe Projects::DiscussionsController do
context "when the user is authorized to resolve the discussion" do
before do
project.team << [user, :developer]
project.add_developer(user)
end
context "when the discussion is not resolvable" do
......@@ -92,7 +92,7 @@ describe Projects::DiscussionsController do
context "when the user is authorized to resolve the discussion" do
before do
project.team << [user, :developer]
project.add_developer(user)
end
context "when the discussion is not resolvable" do
......
......@@ -7,7 +7,7 @@ describe Projects::FindFileController do
before do
sign_in(user)
project.team << [user, :master]
project.add_master(user)
controller.instance_variable_set(:@project, project)
end
......
......@@ -51,7 +51,7 @@ describe Projects::ForksController do
context 'when user is a member of the Project' do
before do
forked_project.team << [project.creator, :developer]
forked_project.add_developer(project.creator)
end
it 'sees the project listed' do
......
......@@ -6,7 +6,7 @@ describe Projects::GraphsController do
before do
sign_in(user)
project.team << [user, :master]
project.add_master(user)
end
describe 'GET languages' do
......
......@@ -7,7 +7,7 @@ describe Projects::GroupLinksController do
let(:user) { create(:user) }
before do
project.team << [user, :master]
project.add_master(user)
sign_in(user)
end
......
......@@ -5,7 +5,7 @@ describe Projects::HooksController do
let(:user) { create(:user) }
before do
project.team << [user, :master]