diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2018-07-13 17:34:27 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2018-07-13 17:34:27 +0800 |
commit | d9f26586b4ec00c00fb470e55af3dc5c1f4ce33a (patch) | |
tree | 1a16bb35e6b103042ed405dcb37227c4dc44244f /spec | |
parent | 99c80156ae6058f70fde77baabd5f007f0246e6d (diff) | |
parent | a3c8525dc9a69d0e1048c114fd27317dcffc4221 (diff) | |
download | gitlab-ce-d9f26586b4ec00c00fb470e55af3dc5c1f4ce33a.tar.gz |
Merge remote-tracking branch 'upstream/master' into 14995-custom_wiki_sidebar
* upstream/master: (467 commits)
Update docs board features tier
Upgrade grape-path-helpers to 1.0.6
Remove healthchecks from prometheus endpoint
Fix find_branch call sites
Ensure Encoding.default_external is set to UTF-8 when running QA scenarios
i18n: externalize strings from 'app/views/admin/groups'
Backport mr widget changes from EE
Allow to toggle notifications for issues due soon
Vuex test helper improvements
whitespace
Make more ref RPC's mandatory
Resolve "Improve performance of MR Changes tab: reduce event listeners on scroll event"
Remove old service architecture from Vue docs
Adding spec to test basic forking functionalities
Fix performance problem of accessing tag list for projects api endpoints
typo
Add sleep to QA test before installing tiller
Include Vue files that are not covered by tests in test coverage
Remove Repository#path memoization
Resolve "do not set updated_at when creating note"
...
Diffstat (limited to 'spec')
833 files changed, 10446 insertions, 6250 deletions
diff --git a/spec/bin/changelog_spec.rb b/spec/bin/changelog_spec.rb index f278043028f..9dc4edf97d1 100644 --- a/spec/bin/changelog_spec.rb +++ b/spec/bin/changelog_spec.rb @@ -3,6 +3,20 @@ require 'spec_helper' load File.expand_path('../../bin/changelog', __dir__) describe 'bin/changelog' do + let(:options) { OpenStruct.new(title: 'Test title', type: 'fixed', dry_run: true) } + + describe ChangelogEntry do + it 'truncates the file path' do + entry = described_class.new(options) + + allow(entry).to receive(:ee?).and_return(false) + allow(entry).to receive(:branch_name).and_return('long-branch-' * 100) + + file_path = entry.send(:file_path) + expect(file_path.length).to eq(140) + end + end + describe ChangelogOptionParser do describe '.parse' do it 'parses --amend' do diff --git a/spec/controllers/autocomplete_controller_spec.rb b/spec/controllers/autocomplete_controller_spec.rb index fb6d82d7de3..2c59d1929a1 100644 --- a/spec/controllers/autocomplete_controller_spec.rb +++ b/spec/controllers/autocomplete_controller_spec.rb @@ -228,12 +228,12 @@ describe AutocompleteController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end context 'authorized projects' do before do - authorized_project.add_master(user) + authorized_project.add_maintainer(user) end describe 'GET #projects with project ID' do @@ -253,8 +253,8 @@ describe AutocompleteController do context 'authorized projects and search' do before do - authorized_project.add_master(user) - authorized_search_project.add_master(user) + authorized_project.add_maintainer(user) + authorized_search_project.add_maintainer(user) end describe 'GET #projects with project ID and search' do @@ -277,9 +277,9 @@ describe AutocompleteController do authorized_project2 = create(:project) authorized_project3 = create(:project) - authorized_project.add_master(user) - authorized_project2.add_master(user) - authorized_project3.add_master(user) + authorized_project.add_maintainer(user) + authorized_project2.add_maintainer(user) + authorized_project3.add_maintainer(user) stub_const 'MoveToProjectFinder::PAGE_SIZE', 2 end @@ -301,9 +301,9 @@ describe AutocompleteController do authorized_project2 = create(:project) authorized_project3 = create(:project) - authorized_project.add_master(user) - authorized_project2.add_master(user) - authorized_project3.add_master(user) + authorized_project.add_maintainer(user) + authorized_project2.add_maintainer(user) + authorized_project3.add_maintainer(user) end describe 'GET #projects with project ID and offset_id' do diff --git a/spec/controllers/boards/issues_controller_spec.rb b/spec/controllers/boards/issues_controller_spec.rb index e47ff8661a2..ce7762691c9 100644 --- a/spec/controllers/boards/issues_controller_spec.rb +++ b/spec/controllers/boards/issues_controller_spec.rb @@ -13,7 +13,7 @@ describe Boards::IssuesController do let!(:list2) { create(:list, board: board, label: development, position: 1) } before do - project.add_master(user) + project.add_maintainer(user) project.add_guest(guest) end diff --git a/spec/controllers/boards/lists_controller_spec.rb b/spec/controllers/boards/lists_controller_spec.rb index 57ccbf1d6b5..80631d2efb0 100644 --- a/spec/controllers/boards/lists_controller_spec.rb +++ b/spec/controllers/boards/lists_controller_spec.rb @@ -7,7 +7,7 @@ describe Boards::ListsController do let(:guest) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) project.add_guest(guest) end diff --git a/spec/controllers/concerns/group_tree_spec.rb b/spec/controllers/concerns/group_tree_spec.rb index ba84fbf8564..503eb416962 100644 --- a/spec/controllers/concerns/group_tree_spec.rb +++ b/spec/controllers/concerns/group_tree_spec.rb @@ -63,6 +63,17 @@ describe GroupTree do expect(assigns(:groups)).to contain_exactly(parent, subgroup) end + + it 'preloads parents regardless of pagination' do + allow(Kaminari.config).to receive(:default_per_page).and_return(1) + group = create(:group, :public) + subgroup = create(:group, :public, parent: group) + search_result = create(:group, :public, name: 'result', parent: subgroup) + + get :index, filter: 'resu', format: :json + + expect(assigns(:groups)).to contain_exactly(group, subgroup, search_result) + end end context 'json content' do diff --git a/spec/controllers/dashboard/groups_controller_spec.rb b/spec/controllers/dashboard/groups_controller_spec.rb index 7f2eaf95165..9068c1a792e 100644 --- a/spec/controllers/dashboard/groups_controller_spec.rb +++ b/spec/controllers/dashboard/groups_controller_spec.rb @@ -28,8 +28,8 @@ describe Dashboard::GroupsController do let!(:other_group) { create(:group, name: 'other') } before do - top_level_result.add_master(user) - top_level_a.add_master(user) + top_level_result.add_maintainer(user) + top_level_a.add_maintainer(user) end it 'renders only groups the user is a member of when searching hierarchy correctly' do diff --git a/spec/controllers/dashboard/milestones_controller_spec.rb b/spec/controllers/dashboard/milestones_controller_spec.rb index 60547db82b6..ba2669a5ea7 100644 --- a/spec/controllers/dashboard/milestones_controller_spec.rb +++ b/spec/controllers/dashboard/milestones_controller_spec.rb @@ -17,7 +17,7 @@ describe Dashboard::MilestonesController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'milestone tabs' diff --git a/spec/controllers/dashboard_controller_spec.rb b/spec/controllers/dashboard_controller_spec.rb index 3458d679107..187542ba30c 100644 --- a/spec/controllers/dashboard_controller_spec.rb +++ b/spec/controllers/dashboard_controller_spec.rb @@ -5,7 +5,7 @@ describe DashboardController do let(:project) { create(:project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/groups/boards_controller_spec.rb b/spec/controllers/groups/boards_controller_spec.rb index 0f5bde62006..bf41aa0706f 100644 --- a/spec/controllers/groups/boards_controller_spec.rb +++ b/spec/controllers/groups/boards_controller_spec.rb @@ -5,7 +5,7 @@ describe Groups::BoardsController do let(:user) { create(:user) } before do - group.add_master(user) + group.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/groups/milestones_controller_spec.rb b/spec/controllers/groups/milestones_controller_spec.rb index 733386500ca..f7068546093 100644 --- a/spec/controllers/groups/milestones_controller_spec.rb +++ b/spec/controllers/groups/milestones_controller_spec.rb @@ -28,7 +28,7 @@ describe Groups::MilestonesController do before do sign_in(user) group.add_owner(user) - project.add_master(user) + project.add_maintainer(user) end describe '#index' do diff --git a/spec/controllers/groups/runners_controller_spec.rb b/spec/controllers/groups/runners_controller_spec.rb index 5770d15557c..598fb84552f 100644 --- a/spec/controllers/groups/runners_controller_spec.rb +++ b/spec/controllers/groups/runners_controller_spec.rb @@ -14,7 +14,7 @@ describe Groups::RunnersController do before do sign_in(user) - group.add_master(user) + group.add_maintainer(user) end describe '#update' do diff --git a/spec/controllers/groups/settings/ci_cd_controller_spec.rb b/spec/controllers/groups/settings/ci_cd_controller_spec.rb index e9f0924caba..ea18122e0c3 100644 --- a/spec/controllers/groups/settings/ci_cd_controller_spec.rb +++ b/spec/controllers/groups/settings/ci_cd_controller_spec.rb @@ -5,7 +5,7 @@ describe Groups::Settings::CiCdController do let(:user) { create(:user) } before do - group.add_master(user) + group.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/groups/uploads_controller_spec.rb b/spec/controllers/groups/uploads_controller_spec.rb index 6a1869d1a48..5a7281ed704 100644 --- a/spec/controllers/groups/uploads_controller_spec.rb +++ b/spec/controllers/groups/uploads_controller_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe Groups::UploadsController do + include WorkhorseHelpers + let(:model) { create(:group, :public) } let(:params) do { group_id: model } @@ -9,4 +11,10 @@ describe Groups::UploadsController do it_behaves_like 'handle uploads' do let(:uploader_class) { NamespaceFileUploader } end + + def post_authorize(verified: true) + request.headers.merge!(workhorse_internal_api_request_header) if verified + + post :authorize, group_id: model.full_path, format: :json + end end diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index 39a36b92bb4..e5ac5634f95 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -6,7 +6,7 @@ describe Groups::VariablesController do before do sign_in(user) - group.add_master(user) + group.add_maintainer(user) end describe 'GET #show' do diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 8688fb33f0d..7a037828035 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -7,7 +7,7 @@ describe GroupsController do let(:project) { create(:project, namespace: group) } let!(:group_member) { create(:group_member, group: group, user: user) } let!(:owner) { group.add_owner(create(:user)).user } - let!(:master) { group.add_master(create(:user)).user } + let!(:maintainer) { group.add_maintainer(create(:user)).user } let!(:developer) { group.add_developer(create(:user)).user } let!(:guest) { group.add_guest(create(:user)).user } @@ -62,7 +62,7 @@ describe GroupsController do [true, false].each do |can_create_group_status| context "and can_create_group is #{can_create_group_status}" do before do - User.where(id: [admin, owner, master, developer, guest]).update_all(can_create_group: can_create_group_status) + User.where(id: [admin, owner, maintainer, developer, guest]).update_all(can_create_group: can_create_group_status) end [:admin, :owner].each do |member_type| @@ -73,7 +73,7 @@ describe GroupsController do end end - [:guest, :developer, :master].each do |member_type| + [:guest, :developer, :maintainer].each do |member_type| context "and logged in as #{member_type.capitalize}" do it_behaves_like 'member without ability to create subgroups' do let(:member) { send(member_type) } diff --git a/spec/controllers/metrics_controller_spec.rb b/spec/controllers/metrics_controller_spec.rb index 7376841fac8..c7c83369d7c 100644 --- a/spec/controllers/metrics_controller_spec.rb +++ b/spec/controllers/metrics_controller_spec.rb @@ -15,55 +15,16 @@ describe MetricsController do allow(Prometheus::Client.configuration).to receive(:multiprocess_files_dir).and_return(metrics_multiproc_dir) allow(Gitlab::Metrics).to receive(:prometheus_metrics_enabled?).and_return(true) allow(Settings.monitoring).to receive(:ip_whitelist).and_return([whitelisted_ip, whitelisted_ip_range]) + allow_any_instance_of(MetricsService).to receive(:metrics_text).and_return("prometheus_counter 1") end describe '#index' do shared_examples_for 'endpoint providing metrics' do - it 'returns DB ping metrics' do + it 'returns prometheus metrics' do get :index - expect(response.body).to match(/^db_ping_timeout 0$/) - expect(response.body).to match(/^db_ping_success 1$/) - expect(response.body).to match(/^db_ping_latency_seconds [0-9\.]+$/) - end - - it 'returns Redis ping metrics' do - get :index - - expect(response.body).to match(/^redis_ping_timeout 0$/) - expect(response.body).to match(/^redis_ping_success 1$/) - expect(response.body).to match(/^redis_ping_latency_seconds [0-9\.]+$/) - end - - it 'returns Caching ping metrics' do - get :index - - expect(response.body).to match(/^redis_cache_ping_timeout 0$/) - expect(response.body).to match(/^redis_cache_ping_success 1$/) - expect(response.body).to match(/^redis_cache_ping_latency_seconds [0-9\.]+$/) - end - - it 'returns Queues ping metrics' do - get :index - - expect(response.body).to match(/^redis_queues_ping_timeout 0$/) - expect(response.body).to match(/^redis_queues_ping_success 1$/) - expect(response.body).to match(/^redis_queues_ping_latency_seconds [0-9\.]+$/) - end - - it 'returns SharedState ping metrics' do - get :index - - expect(response.body).to match(/^redis_shared_state_ping_timeout 0$/) - expect(response.body).to match(/^redis_shared_state_ping_success 1$/) - expect(response.body).to match(/^redis_shared_state_ping_latency_seconds [0-9\.]+$/) - end - - it 'returns Gitaly metrics' do - get :index - - expect(response.body).to match(/^gitaly_health_check_success{shard="default"} 1$/) - expect(response.body).to match(/^gitaly_health_check_latency_seconds{shard="default"} [0-9\.]+$/) + expect(response.status).to eq(200) + expect(response.body).to match(/^prometheus_counter 1$/) end context 'prometheus metrics are disabled' do @@ -101,7 +62,7 @@ describe MetricsController do allow(Gitlab::RequestContext).to receive(:client_ip).and_return(not_whitelisted_ip) end - it 'returns proper response' do + it 'returns the expected error response' do get :index expect(response.status).to eq(404) diff --git a/spec/controllers/projects/avatars_controller_spec.rb b/spec/controllers/projects/avatars_controller_spec.rb index acfa2730d94..17c9a61f339 100644 --- a/spec/controllers/projects/avatars_controller_spec.rb +++ b/spec/controllers/projects/avatars_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::AvatarsController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) controller.instance_variable_set(:@project, project) end diff --git a/spec/controllers/projects/badges_controller_spec.rb b/spec/controllers/projects/badges_controller_spec.rb index e7cddf8cfbf..dfe34171b55 100644 --- a/spec/controllers/projects/badges_controller_spec.rb +++ b/spec/controllers/projects/badges_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::BadgesController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/blame_controller_spec.rb b/spec/controllers/projects/blame_controller_spec.rb index 88d4f4e9cd0..fe4c4863717 100644 --- a/spec/controllers/projects/blame_controller_spec.rb +++ b/spec/controllers/projects/blame_controller_spec.rb @@ -7,7 +7,7 @@ describe Projects::BlameController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) controller.instance_variable_set(:@project, project) end diff --git a/spec/controllers/projects/blob_controller_spec.rb b/spec/controllers/projects/blob_controller_spec.rb index 4dcb7dc6c87..32cd7c6e70a 100644 --- a/spec/controllers/projects/blob_controller_spec.rb +++ b/spec/controllers/projects/blob_controller_spec.rb @@ -108,7 +108,7 @@ describe Projects::BlobController do end before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -230,12 +230,12 @@ describe Projects::BlobController do end end - context 'as master' do - let(:master) { create(:user) } + context 'as maintainer' do + let(:maintainer) { create(:user) } before do - project.add_master(master) - sign_in(master) + project.add_maintainer(maintainer) + sign_in(maintainer) get :edit, default_params end @@ -263,7 +263,7 @@ describe Projects::BlobController do end before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/boards_controller_spec.rb b/spec/controllers/projects/boards_controller_spec.rb index 509f19ed030..096efc1c7b2 100644 --- a/spec/controllers/projects/boards_controller_spec.rb +++ b/spec/controllers/projects/boards_controller_spec.rb @@ -5,7 +5,7 @@ describe Projects::BoardsController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index 4860ea5dcce..31471cde420 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::BranchesController do let(:developer) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(user) allow(project).to receive(:branches).and_return(['master', 'foo/bar/baz']) diff --git a/spec/controllers/projects/clusters/applications_controller_spec.rb b/spec/controllers/projects/clusters/applications_controller_spec.rb index 99fdff5f846..9e17e392d3d 100644 --- a/spec/controllers/projects/clusters/applications_controller_spec.rb +++ b/spec/controllers/projects/clusters/applications_controller_spec.rb @@ -17,7 +17,7 @@ describe Projects::Clusters::ApplicationsController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -70,7 +70,7 @@ describe Projects::Clusters::ApplicationsController do it { expect { go }.to be_allowed_for(:admin) } it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } it { expect { go }.to be_denied_for(:developer).of(project) } it { expect { go }.to be_denied_for(:reporter).of(project) } it { expect { go }.to be_denied_for(:guest).of(project) } diff --git a/spec/controllers/projects/clusters/gcp_controller_spec.rb b/spec/controllers/projects/clusters/gcp_controller_spec.rb deleted file mode 100644 index 271ba37aed4..00000000000 --- a/spec/controllers/projects/clusters/gcp_controller_spec.rb +++ /dev/null @@ -1,182 +0,0 @@ -require 'spec_helper' - -describe Projects::Clusters::GcpController do - include AccessMatchersForController - include GoogleApi::CloudPlatformHelpers - - set(:project) { create(:project) } - - describe 'GET login' do - describe 'functionality' do - let(:user) { create(:user) } - - before do - project.add_master(user) - sign_in(user) - end - - context 'when omniauth has been configured' do - let(:key) { 'secret-key' } - let(:session_key_for_redirect_uri) do - GoogleApi::CloudPlatform::Client.session_key_for_redirect_uri(key) - end - - before do - allow(SecureRandom).to receive(:hex).and_return(key) - end - - it 'has authorize_url' do - go - - expect(assigns(:authorize_url)).to include(key) - expect(session[session_key_for_redirect_uri]).to eq(gcp_new_project_clusters_path(project)) - end - end - - context 'when omniauth has not configured' do - before do - stub_omniauth_setting(providers: []) - end - - it 'does not have authorize_url' do - go - - expect(assigns(:authorize_url)).to be_nil - end - end - end - - describe 'security' do - it { expect { go }.to be_allowed_for(:admin) } - it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } - it { expect { go }.to be_denied_for(:developer).of(project) } - it { expect { go }.to be_denied_for(:reporter).of(project) } - it { expect { go }.to be_denied_for(:guest).of(project) } - it { expect { go }.to be_denied_for(:user) } - it { expect { go }.to be_denied_for(:external) } - end - - def go - get :login, namespace_id: project.namespace, project_id: project - end - end - - describe 'GET new' do - describe 'functionality' do - let(:user) { create(:user) } - - before do - project.add_master(user) - sign_in(user) - end - - context 'when access token is valid' do - before do - stub_google_api_validate_token - end - - it 'has new object' do - go - - expect(assigns(:cluster)).to be_an_instance_of(Clusters::Cluster) - end - end - - context 'when access token is expired' do - before do - stub_google_api_expired_token - end - - it { expect(go).to redirect_to(gcp_login_project_clusters_path(project)) } - end - - context 'when access token is not stored in session' do - it { expect(go).to redirect_to(gcp_login_project_clusters_path(project)) } - end - end - - describe 'security' do - it { expect { go }.to be_allowed_for(:admin) } - it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } - it { expect { go }.to be_denied_for(:developer).of(project) } - it { expect { go }.to be_denied_for(:reporter).of(project) } - it { expect { go }.to be_denied_for(:guest).of(project) } - it { expect { go }.to be_denied_for(:user) } - it { expect { go }.to be_denied_for(:external) } - end - - def go - get :new, namespace_id: project.namespace, project_id: project - end - end - - describe 'POST create' do - let(:params) do - { - cluster: { - name: 'new-cluster', - provider_gcp_attributes: { - gcp_project_id: '111' - } - } - } - end - - describe 'functionality' do - let(:user) { create(:user) } - - before do - project.add_master(user) - sign_in(user) - end - - context 'when access token is valid' do - before do - stub_google_api_validate_token - end - - it 'creates a new cluster' do - expect(ClusterProvisionWorker).to receive(:perform_async) - expect { go }.to change { Clusters::Cluster.count } - .and change { Clusters::Providers::Gcp.count } - expect(response).to redirect_to(project_cluster_path(project, project.clusters.first)) - expect(project.clusters.first).to be_gcp - expect(project.clusters.first).to be_kubernetes - end - end - - context 'when access token is expired' do - before do - stub_google_api_expired_token - end - - it 'redirects to login page' do - expect(go).to redirect_to(gcp_login_project_clusters_path(project)) - end - end - - context 'when access token is not stored in session' do - it 'redirects to login page' do - expect(go).to redirect_to(gcp_login_project_clusters_path(project)) - end - end - end - - describe 'security' do - it { expect { go }.to be_allowed_for(:admin) } - it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } - it { expect { go }.to be_denied_for(:developer).of(project) } - it { expect { go }.to be_denied_for(:reporter).of(project) } - it { expect { go }.to be_denied_for(:guest).of(project) } - it { expect { go }.to be_denied_for(:user) } - it { expect { go }.to be_denied_for(:external) } - end - - def go - post :create, params.merge(namespace_id: project.namespace, project_id: project) - end - end -end diff --git a/spec/controllers/projects/clusters/user_controller_spec.rb b/spec/controllers/projects/clusters/user_controller_spec.rb deleted file mode 100644 index 913976d187f..00000000000 --- a/spec/controllers/projects/clusters/user_controller_spec.rb +++ /dev/null @@ -1,89 +0,0 @@ -require 'spec_helper' - -describe Projects::Clusters::UserController do - include AccessMatchersForController - - set(:project) { create(:project) } - - describe 'GET new' do - describe 'functionality' do - let(:user) { create(:user) } - - before do - project.add_master(user) - sign_in(user) - end - - it 'has new object' do - go - - expect(assigns(:cluster)).to be_an_instance_of(Clusters::Cluster) - end - end - - describe 'security' do - it { expect { go }.to be_allowed_for(:admin) } - it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } - it { expect { go }.to be_denied_for(:developer).of(project) } - it { expect { go }.to be_denied_for(:reporter).of(project) } - it { expect { go }.to be_denied_for(:guest).of(project) } - it { expect { go }.to be_denied_for(:user) } - it { expect { go }.to be_denied_for(:external) } - end - - def go - get :new, namespace_id: project.namespace, project_id: project - end - end - - describe 'POST create' do - let(:params) do - { - cluster: { - name: 'new-cluster', - platform_kubernetes_attributes: { - api_url: 'http://my-url', - token: 'test', - namespace: 'aaa' - } - } - } - end - - describe 'functionality' do - let(:user) { create(:user) } - - before do - project.add_master(user) - sign_in(user) - end - - context 'when creates a cluster' do - it 'creates a new cluster' do - expect(ClusterProvisionWorker).to receive(:perform_async) - expect { go }.to change { Clusters::Cluster.count } - .and change { Clusters::Platforms::Kubernetes.count } - expect(response).to redirect_to(project_cluster_path(project, project.clusters.first)) - expect(project.clusters.first).to be_user - expect(project.clusters.first).to be_kubernetes - end - end - end - - describe 'security' do - it { expect { go }.to be_allowed_for(:admin) } - it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } - it { expect { go }.to be_denied_for(:developer).of(project) } - it { expect { go }.to be_denied_for(:reporter).of(project) } - it { expect { go }.to be_denied_for(:guest).of(project) } - it { expect { go }.to be_denied_for(:user) } - it { expect { go }.to be_denied_for(:external) } - end - - def go - post :create, params.merge(namespace_id: project.namespace, project_id: project) - end - end -end diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb index 380e50c8cac..42917d0d505 100644 --- a/spec/controllers/projects/clusters_controller_spec.rb +++ b/spec/controllers/projects/clusters_controller_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe Projects::ClustersController do include AccessMatchersForController + include GoogleApi::CloudPlatformHelpers set(:project) { create(:project) } @@ -10,7 +11,7 @@ describe Projects::ClustersController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -60,7 +61,7 @@ describe Projects::ClustersController do it { expect { go }.to be_allowed_for(:admin) } it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } it { expect { go }.to be_denied_for(:developer).of(project) } it { expect { go }.to be_denied_for(:reporter).of(project) } it { expect { go }.to be_denied_for(:guest).of(project) } @@ -73,6 +74,231 @@ describe Projects::ClustersController do end end + describe 'GET new' do + describe 'functionality for new cluster' do + let(:user) { create(:user) } + + before do + project.add_maintainer(user) + sign_in(user) + end + + context 'when omniauth has been configured' do + let(:key) { 'secret-key' } + let(:session_key_for_redirect_uri) do + GoogleApi::CloudPlatform::Client.session_key_for_redirect_uri(key) + end + + before do + allow(SecureRandom).to receive(:hex).and_return(key) + end + + it 'has authorize_url' do + go + + expect(assigns(:authorize_url)).to include(key) + expect(session[session_key_for_redirect_uri]).to eq(new_project_cluster_path(project)) + end + end + + context 'when omniauth has not configured' do + before do + stub_omniauth_setting(providers: []) + end + + it 'does not have authorize_url' do + go + + expect(assigns(:authorize_url)).to be_nil + end + end + + context 'when access token is valid' do + before do + stub_google_api_validate_token + end + + it 'has new object' do + go + + expect(assigns(:gcp_cluster)).to be_an_instance_of(Clusters::Cluster) + end + end + + context 'when access token is expired' do + before do + stub_google_api_expired_token + end + + it { expect(@valid_gcp_token).to be_falsey } + end + + context 'when access token is not stored in session' do + it { expect(@valid_gcp_token).to be_falsey } + end + end + + describe 'functionality for existing cluster' do + let(:user) { create(:user) } + + before do + project.add_maintainer(user) + sign_in(user) + end + + it 'has new object' do + go + + expect(assigns(:user_cluster)).to be_an_instance_of(Clusters::Cluster) + end + end + + describe 'security' do + it { expect { go }.to be_allowed_for(:admin) } + it { expect { go }.to be_allowed_for(:owner).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } + it { expect { go }.to be_denied_for(:developer).of(project) } + it { expect { go }.to be_denied_for(:reporter).of(project) } + it { expect { go }.to be_denied_for(:guest).of(project) } + it { expect { go }.to be_denied_for(:user) } + it { expect { go }.to be_denied_for(:external) } + end + + def go + get :new, namespace_id: project.namespace, project_id: project + end + end + + describe 'POST create for new cluster' do + let(:params) do + { + cluster: { + name: 'new-cluster', + provider_gcp_attributes: { + gcp_project_id: 'gcp-project-12345' + } + } + } + end + + describe 'functionality' do + let(:user) { create(:user) } + + before do + project.add_maintainer(user) + sign_in(user) + end + + context 'when access token is valid' do + before do + stub_google_api_validate_token + end + + it 'creates a new cluster' do + expect(ClusterProvisionWorker).to receive(:perform_async) + expect { go }.to change { Clusters::Cluster.count } + .and change { Clusters::Providers::Gcp.count } + expect(response).to redirect_to(project_cluster_path(project, project.clusters.first)) + expect(project.clusters.first).to be_gcp + expect(project.clusters.first).to be_kubernetes + end + end + + context 'when access token is expired' do + before do + stub_google_api_expired_token + end + + it { expect(@valid_gcp_token).to be_falsey } + end + + context 'when access token is not stored in session' do + it { expect(@valid_gcp_token).to be_falsey } + end + end + + describe 'security' do + before do + allow_any_instance_of(described_class) + .to receive(:token_in_session).and_return('token') + allow_any_instance_of(described_class) + .to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s) + allow_any_instance_of(GoogleApi::CloudPlatform::Client) + .to receive(:projects_zones_clusters_create) do + OpenStruct.new( + self_link: 'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123', + status: 'RUNNING' + ) + end + + allow(WaitForClusterCreationWorker).to receive(:perform_in).and_return(nil) + end + + it { expect { go }.to be_allowed_for(:admin) } + it { expect { go }.to be_allowed_for(:owner).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } + it { expect { go }.to be_denied_for(:developer).of(project) } + it { expect { go }.to be_denied_for(:reporter).of(project) } + it { expect { go }.to be_denied_for(:guest).of(project) } + it { expect { go }.to be_denied_for(:user) } + it { expect { go }.to be_denied_for(:external) } + end + + def go + post :create_gcp, params.merge(namespace_id: project.namespace, project_id: project) + end + end + + describe 'POST create for existing cluster' do + let(:params) do + { + cluster: { + name: 'new-cluster', + platform_kubernetes_attributes: { + api_url: 'http://my-url', + token: 'test', + namespace: 'aaa' + } + } + } + end + + describe 'functionality' do + let(:user) { create(:user) } + + before do + project.add_maintainer(user) + sign_in(user) + end + + context 'when creates a cluster' do + it 'creates a new cluster' do + expect(ClusterProvisionWorker).to receive(:perform_async) + expect { go }.to change { Clusters::Cluster.count } + .and change { Clusters::Platforms::Kubernetes.count } + expect(response).to redirect_to(project_cluster_path(project, project.clusters.first)) + expect(project.clusters.first).to be_user + expect(project.clusters.first).to be_kubernetes + end + end + end + + describe 'security' do + it { expect { go }.to be_allowed_for(:admin) } + it { expect { go }.to be_allowed_for(:owner).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } + it { expect { go }.to be_denied_for(:developer).of(project) } + it { expect { go }.to be_denied_for(:reporter).of(project) } + it { expect { go }.to be_denied_for(:guest).of(project) } + it { expect { go }.to be_denied_for(:user) } + it { expect { go }.to be_denied_for(:external) } + end + + def go + post :create_user, params.merge(namespace_id: project.namespace, project_id: project) + end + end + describe 'GET status' do let(:cluster) { create(:cluster, :providing_by_gcp, projects: [project]) } @@ -80,7 +306,7 @@ describe Projects::ClustersController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -101,7 +327,7 @@ describe Projects::ClustersController do describe 'security' do it { expect { go }.to be_allowed_for(:admin) } it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } it { expect { go }.to be_denied_for(:developer).of(project) } it { expect { go }.to be_denied_for(:reporter).of(project) } it { expect { go }.to be_denied_for(:guest).of(project) } @@ -124,7 +350,7 @@ describe Projects::ClustersController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -139,7 +365,7 @@ describe Projects::ClustersController do describe 'security' do it { expect { go }.to be_allowed_for(:admin) } it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } it { expect { go }.to be_denied_for(:developer).of(project) } it { expect { go }.to be_denied_for(:reporter).of(project) } it { expect { go }.to be_denied_for(:guest).of(project) } @@ -160,7 +386,7 @@ describe Projects::ClustersController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -211,7 +437,7 @@ describe Projects::ClustersController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -299,7 +525,7 @@ describe Projects::ClustersController do it { expect { go }.to be_allowed_for(:admin) } it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } it { expect { go }.to be_denied_for(:developer).of(project) } it { expect { go }.to be_denied_for(:reporter).of(project) } it { expect { go }.to be_denied_for(:guest).of(project) } @@ -326,7 +552,7 @@ describe Projects::ClustersController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -379,7 +605,7 @@ describe Projects::ClustersController do it { expect { go }.to be_allowed_for(:admin) } it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } it { expect { go }.to be_denied_for(:developer).of(project) } it { expect { go }.to be_denied_for(:reporter).of(project) } it { expect { go }.to be_denied_for(:guest).of(project) } diff --git a/spec/controllers/projects/commit_controller_spec.rb b/spec/controllers/projects/commit_controller_spec.rb index 003fec8ac68..916a4be2567 100644 --- a/spec/controllers/projects/commit_controller_spec.rb +++ b/spec/controllers/projects/commit_controller_spec.rb @@ -9,7 +9,7 @@ describe Projects::CommitController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end describe 'GET show' do diff --git a/spec/controllers/projects/commits_controller_spec.rb b/spec/controllers/projects/commits_controller_spec.rb index 55ed276f96b..d44048fdf55 100644 --- a/spec/controllers/projects/commits_controller_spec.rb +++ b/spec/controllers/projects/commits_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::CommitsController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end describe "GET show" do diff --git a/spec/controllers/projects/compare_controller_spec.rb b/spec/controllers/projects/compare_controller_spec.rb index b15cde4314e..8695aa826bb 100644 --- a/spec/controllers/projects/compare_controller_spec.rb +++ b/spec/controllers/projects/compare_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::CompareController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end describe 'GET index' do diff --git a/spec/controllers/projects/cycle_analytics_controller_spec.rb b/spec/controllers/projects/cycle_analytics_controller_spec.rb index 5516c95d044..5c79269e8f1 100644 --- a/spec/controllers/projects/cycle_analytics_controller_spec.rb +++ b/spec/controllers/projects/cycle_analytics_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::CycleAnalyticsController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end describe 'cycle analytics not set up flag' do diff --git a/spec/controllers/projects/deploy_keys_controller_spec.rb b/spec/controllers/projects/deploy_keys_controller_spec.rb index 97db69427e9..d2f133f972a 100644 --- a/spec/controllers/projects/deploy_keys_controller_spec.rb +++ b/spec/controllers/projects/deploy_keys_controller_spec.rb @@ -5,7 +5,7 @@ describe Projects::DeployKeysController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/deployments_controller_spec.rb b/spec/controllers/projects/deployments_controller_spec.rb index 6c67dfde63a..d1c960e895d 100644 --- a/spec/controllers/projects/deployments_controller_spec.rb +++ b/spec/controllers/projects/deployments_controller_spec.rb @@ -8,7 +8,7 @@ describe Projects::DeploymentsController do let(:environment) { create(:environment, name: 'production', project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb index 47d4942acbd..b86029a4baf 100644 --- a/spec/controllers/projects/environments_controller_spec.rb +++ b/spec/controllers/projects/environments_controller_spec.rb @@ -9,7 +9,7 @@ describe Projects::EnvironmentsController do end before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -277,6 +277,25 @@ describe Projects::EnvironmentsController do end end + describe 'GET #metrics_redirect' do + let(:project) { create(:project) } + + it 'redirects to environment if it exists' do + environment = create(:environment, name: 'production', project: project) + + get :metrics_redirect, namespace_id: project.namespace, project_id: project + + expect(response).to redirect_to(environment_metrics_path(environment)) + end + + it 'redirects to empty page if no environment exists' do + get :metrics_redirect, namespace_id: project.namespace, project_id: project + + expect(response).to be_ok + expect(response).to render_template 'empty' + end + end + describe 'GET #metrics' do before do allow(controller).to receive(:environment).and_return(environment) diff --git a/spec/controllers/projects/find_file_controller_spec.rb b/spec/controllers/projects/find_file_controller_spec.rb index 505fe82851a..66fe41108e2 100644 --- a/spec/controllers/projects/find_file_controller_spec.rb +++ b/spec/controllers/projects/find_file_controller_spec.rb @@ -7,7 +7,7 @@ describe Projects::FindFileController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) controller.instance_variable_set(:@project, project) end diff --git a/spec/controllers/projects/forks_controller_spec.rb b/spec/controllers/projects/forks_controller_spec.rb index e20623c0ac1..945b6142abf 100644 --- a/spec/controllers/projects/forks_controller_spec.rb +++ b/spec/controllers/projects/forks_controller_spec.rb @@ -31,7 +31,7 @@ describe Projects::ForksController do context 'when fork is private' do before do - forked_project.update_attributes(visibility_level: Project::PRIVATE, group: group) + forked_project.update(visibility_level: Project::PRIVATE, group: group) end it 'is not be visible for non logged in users' do diff --git a/spec/controllers/projects/graphs_controller_spec.rb b/spec/controllers/projects/graphs_controller_spec.rb index c3605555fe7..da78592a6f6 100644 --- a/spec/controllers/projects/graphs_controller_spec.rb +++ b/spec/controllers/projects/graphs_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::GraphsController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end describe 'GET languages' do diff --git a/spec/controllers/projects/group_links_controller_spec.rb b/spec/controllers/projects/group_links_controller_spec.rb index 72f6af112b3..879aff26deb 100644 --- a/spec/controllers/projects/group_links_controller_spec.rb +++ b/spec/controllers/projects/group_links_controller_spec.rb @@ -7,7 +7,7 @@ describe Projects::GroupLinksController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -23,7 +23,7 @@ describe Projects::GroupLinksController do context 'when project is not allowed to be shared with a group' do before do - group.update_attributes(share_with_group_lock: false) + group.update(share_with_group_lock: false) end include_context 'link project to group' diff --git a/spec/controllers/projects/hooks_controller_spec.rb b/spec/controllers/projects/hooks_controller_spec.rb index 2d473d5bf52..0f3033b0933 100644 --- a/spec/controllers/projects/hooks_controller_spec.rb +++ b/spec/controllers/projects/hooks_controller_spec.rb @@ -5,7 +5,7 @@ describe Projects::HooksController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/imports_controller_spec.rb b/spec/controllers/projects/imports_controller_spec.rb index 812833cc86b..adf3c78ae51 100644 --- a/spec/controllers/projects/imports_controller_spec.rb +++ b/spec/controllers/projects/imports_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::ImportsController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end describe 'GET #show' do @@ -29,7 +29,7 @@ describe Projects::ImportsController do context 'when import is in progress' do before do - project.update_attributes(import_status: :started) + project.update(import_status: :started) end it 'renders template' do @@ -47,7 +47,7 @@ describe Projects::ImportsController do context 'when import failed' do before do - project.update_attributes(import_status: :failed) + project.update(import_status: :failed) end it 'redirects to new_namespace_project_import_path' do @@ -59,7 +59,7 @@ describe Projects::ImportsController do context 'when import finished' do before do - project.update_attributes(import_status: :finished) + project.update(import_status: :finished) end context 'when project is a fork' do @@ -108,7 +108,7 @@ describe Projects::ImportsController do context 'when import never happened' do before do - project.update_attributes(import_status: :none) + project.update(import_status: :none) end it 'redirects to namespace_project_path' do diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index 3a41f0fc07a..ff1835a34c2 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -695,7 +695,7 @@ describe Projects::IssuesController do let(:project) { merge_request.source_project } before do - project.add_master(user) + project.add_maintainer(user) sign_in user end @@ -869,7 +869,7 @@ describe Projects::IssuesController do def post_spam admin = create(:admin) create(:user_agent_detail, subject: issue) - project.add_master(admin) + project.add_maintainer(admin) sign_in(admin) post :mark_as_spam, { namespace_id: project.namespace, diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb index 06c8a432561..1aca44c6e74 100644 --- a/spec/controllers/projects/jobs_controller_spec.rb +++ b/spec/controllers/projects/jobs_controller_spec.rb @@ -102,6 +102,8 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do describe 'GET show' do let!(:job) { create(:ci_build, :failed, pipeline: pipeline) } + let!(:second_job) { create(:ci_build, :failed, pipeline: pipeline) } + let!(:third_job) { create(:ci_build, :failed) } context 'when requesting HTML' do context 'when job exists' do @@ -113,6 +115,13 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do expect(response).to have_gitlab_http_status(:ok) expect(assigns(:build).id).to eq(job.id) end + + it 'has the correct build collection' do + builds = assigns(:builds).map(&:id) + + expect(builds).to include(job.id, second_job.id) + expect(builds).not_to include(third_job.id) + end end context 'when job does not exist' do @@ -207,17 +216,19 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do end context 'when trace artifact is in ObjectStorage' do + let(:url) { 'http://object-storage/trace' } + let(:file_path) { expand_fixture_path('trace/sample_trace') } let!(:job) { create(:ci_build, :success, :trace_artifact, pipeline: pipeline) } before do allow_any_instance_of(JobArtifactUploader).to receive(:file_storage?) { false } - allow_any_instance_of(JobArtifactUploader).to receive(:url) { remote_trace_url } - allow_any_instance_of(JobArtifactUploader).to receive(:size) { remote_trace_size } + allow_any_instance_of(JobArtifactUploader).to receive(:url) { url } + allow_any_instance_of(JobArtifactUploader).to receive(:size) { File.size(file_path) } end context 'when there are no network issues' do before do - stub_remote_trace_206 + stub_remote_url_206(url, file_path) get_trace end @@ -232,11 +243,11 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do context 'when there is a network issue' do before do - stub_remote_trace_500 + stub_remote_url_500(url) end it 'returns a trace' do - expect { get_trace }.to raise_error(Gitlab::Ci::Trace::HttpIO::FailedToGetChunkError) + expect { get_trace }.to raise_error(Gitlab::HttpIO::FailedToGetChunkError) end end end @@ -420,7 +431,7 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do end describe 'POST erase' do - let(:role) { :master } + let(:role) { :maintainer } before do project.add_role(user, role) @@ -553,4 +564,105 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do end end end + + describe 'GET #terminal' do + before do + project.add_developer(user) + sign_in(user) + end + + context 'when job exists' do + context 'and it has a terminal' do + let!(:job) { create(:ci_build, :running, :with_runner_session, pipeline: pipeline) } + + it 'has a job' do + get_terminal(id: job.id) + + expect(response).to have_gitlab_http_status(:ok) + expect(assigns(:build).id).to eq(job.id) + end + end + + context 'and does not have a terminal' do + let!(:job) { create(:ci_build, :running, pipeline: pipeline) } + + it 'returns not_found' do + get_terminal(id: job.id) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + context 'when job does not exist' do + it 'renders not_found' do + get_terminal(id: 1234) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + def get_terminal(**extra_params) + params = { + namespace_id: project.namespace.to_param, + project_id: project + } + + get :terminal, params.merge(extra_params) + end + end + + describe 'GET #terminal_websocket_authorize' do + let!(:job) { create(:ci_build, :running, :with_runner_session, pipeline: pipeline) } + + before do + project.add_developer(user) + sign_in(user) + end + + context 'with valid workhorse signature' do + before do + allow(Gitlab::Workhorse).to receive(:verify_api_request!).and_return(nil) + end + + context 'and valid id' do + it 'returns the terminal for the job' do + expect(Gitlab::Workhorse) + .to receive(:terminal_websocket) + .and_return(workhorse: :response) + + get_terminal_websocket(id: job.id) + + expect(response).to have_gitlab_http_status(200) + expect(response.headers["Content-Type"]).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) + expect(response.body).to eq('{"workhorse":"response"}') + end + end + + context 'and invalid id' do + it 'returns 404' do + get_terminal_websocket(id: 1234) + + expect(response).to have_gitlab_http_status(404) + end + end + end + + context 'with invalid workhorse signature' do + it 'aborts with an exception' do + allow(Gitlab::Workhorse).to receive(:verify_api_request!).and_raise(JWT::DecodeError) + + expect { get_terminal_websocket(id: job.id) }.to raise_error(JWT::DecodeError) + end + end + + def get_terminal_websocket(**extra_params) + params = { + namespace_id: project.namespace.to_param, + project_id: project + } + + get :terminal_websocket_authorize, params.merge(extra_params) + end + end end diff --git a/spec/controllers/projects/labels_controller_spec.rb b/spec/controllers/projects/labels_controller_spec.rb index 452d7e23983..273702e6d21 100644 --- a/spec/controllers/projects/labels_controller_spec.rb +++ b/spec/controllers/projects/labels_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::LabelsController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/mattermosts_controller_spec.rb b/spec/controllers/projects/mattermosts_controller_spec.rb index c5ac0be27bb..c2a334a849c 100644 --- a/spec/controllers/projects/mattermosts_controller_spec.rb +++ b/spec/controllers/projects/mattermosts_controller_spec.rb @@ -5,7 +5,7 @@ describe Projects::MattermostsController do let!(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/merge_requests/creations_controller_spec.rb b/spec/controllers/projects/merge_requests/creations_controller_spec.rb index 00d76f3c39a..d8995f98575 100644 --- a/spec/controllers/projects/merge_requests/creations_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/creations_controller_spec.rb @@ -16,7 +16,7 @@ describe Projects::MergeRequests::CreationsController do end before do - fork_project.add_master(user) + fork_project.add_maintainer(user) Projects::ForkService.new(project, user).execute(fork_project) sign_in(user) end @@ -94,7 +94,7 @@ describe Projects::MergeRequests::CreationsController do let(:other_project) { create(:project, :repository) } before do - other_project.add_master(user) + other_project.add_maintainer(user) end context 'when the path exists in the diff' do diff --git a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb index ec82b35f227..9dc06436c72 100644 --- a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb @@ -140,7 +140,7 @@ describe Projects::MergeRequests::DiffsController do let(:other_project) { create(:project) } before do - other_project.add_master(user) + other_project.add_maintainer(user) diff_for_path(old_path: existing_path, new_path: existing_path, project_id: other_project) end diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index 7f5f0b76c51..444415011a9 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -315,7 +315,7 @@ describe Projects::MergeRequestsController do context 'when the merge request is not mergeable' do before do - merge_request.update_attributes(title: "WIP: #{merge_request.title}") + merge_request.update(title: "WIP: #{merge_request.title}") post :merge, base_params end diff --git a/spec/controllers/projects/milestones_controller_spec.rb b/spec/controllers/projects/milestones_controller_spec.rb index b1d83246238..ea906cf7f32 100644 --- a/spec/controllers/projects/milestones_controller_spec.rb +++ b/spec/controllers/projects/milestones_controller_spec.rb @@ -11,7 +11,7 @@ describe Projects::MilestonesController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) controller.instance_variable_set(:@project, project) end diff --git a/spec/controllers/projects/pages_controller_spec.rb b/spec/controllers/projects/pages_controller_spec.rb index 8d2fa6a1740..927b6e0c473 100644 --- a/spec/controllers/projects/pages_controller_spec.rb +++ b/spec/controllers/projects/pages_controller_spec.rb @@ -14,7 +14,7 @@ describe Projects::PagesController do before do allow(Gitlab.config.pages).to receive(:enabled).and_return(true) sign_in(user) - project.add_master(user) + project.add_maintainer(user) end describe 'GET show' do diff --git a/spec/controllers/projects/pages_domains_controller_spec.rb b/spec/controllers/projects/pages_domains_controller_spec.rb index d4058a5c515..75871eab1ab 100644 --- a/spec/controllers/projects/pages_domains_controller_spec.rb +++ b/spec/controllers/projects/pages_domains_controller_spec.rb @@ -19,7 +19,7 @@ describe Projects::PagesDomainsController do before do allow(Gitlab.config.pages).to receive(:enabled).and_return(true) sign_in(user) - project.add_master(user) + project.add_maintainer(user) end describe 'GET show' do diff --git a/spec/controllers/projects/pipeline_schedules_controller_spec.rb b/spec/controllers/projects/pipeline_schedules_controller_spec.rb index 4cdaa54e0bc..7179423dde2 100644 --- a/spec/controllers/projects/pipeline_schedules_controller_spec.rb +++ b/spec/controllers/projects/pipeline_schedules_controller_spec.rb @@ -121,7 +121,7 @@ describe Projects::PipelineSchedulesController do it { expect { go }.to be_allowed_for(:admin) } it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } it { expect { go }.to be_allowed_for(:developer).of(project) } it { expect { go }.to be_denied_for(:reporter).of(project) } it { expect { go }.to be_denied_for(:guest).of(project) } @@ -274,7 +274,7 @@ describe Projects::PipelineSchedulesController do it { expect { go }.to be_allowed_for(:admin) } it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } it { expect { go }.to be_allowed_for(:developer).of(project).own(pipeline_schedule) } it { expect { go }.to be_denied_for(:reporter).of(project) } it { expect { go }.to be_denied_for(:guest).of(project) } @@ -292,19 +292,19 @@ describe Projects::PipelineSchedulesController do it { expect { go }.to be_allowed_for(developer_1) } it { expect { go }.to be_denied_for(:developer).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } end - context 'when a master created a pipeline schedule' do - let(:master_1) { create(:user) } - let!(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: master_1) } + context 'when a maintainer created a pipeline schedule' do + let(:maintainer_1) { create(:user) } + let!(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: maintainer_1) } before do - project.add_master(master_1) + project.add_maintainer(maintainer_1) end - it { expect { go }.to be_allowed_for(master_1) } - it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_allowed_for(maintainer_1) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } it { expect { go }.to be_denied_for(:developer).of(project) } end end @@ -331,7 +331,7 @@ describe Projects::PipelineSchedulesController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -346,7 +346,7 @@ describe Projects::PipelineSchedulesController do describe 'security' do it { expect { go }.to be_allowed_for(:admin) } it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } it { expect { go }.to be_allowed_for(:developer).of(project).own(pipeline_schedule) } it { expect { go }.to be_denied_for(:reporter).of(project) } it { expect { go }.to be_denied_for(:guest).of(project) } @@ -364,7 +364,7 @@ describe Projects::PipelineSchedulesController do describe 'security' do it { expect { go }.to be_allowed_for(:admin) } it { expect { go }.to be_allowed_for(:owner).of(project) } - it { expect { go }.to be_allowed_for(:master).of(project) } + it { expect { go }.to be_allowed_for(:maintainer).of(project) } it { expect { go }.to be_allowed_for(:developer).of(project).own(pipeline_schedule) } it { expect { go }.to be_denied_for(:reporter).of(project) } it { expect { go }.to be_denied_for(:guest).of(project) } @@ -453,9 +453,9 @@ describe Projects::PipelineSchedulesController do end end - context 'when a master makes the request' do + context 'when a maintainer makes the request' do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index 9618a8417ec..290fcd4f8e6 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -4,7 +4,7 @@ describe Projects::PipelinesController do include ApiHelpers set(:user) { create(:user) } - set(:project) { create(:project, :public, :repository) } + let(:project) { create(:project, :public, :repository) } let(:feature) { ProjectFeature::DISABLED } before do @@ -74,7 +74,7 @@ describe Projects::PipelinesController do expect(stages.count).to eq 3 end - expect(queries.count).to be_within(3).of(30) + expect(queries.count).to be_within(5).of(30) end end @@ -91,6 +91,24 @@ describe Projects::PipelinesController do end end + context 'when the project is private' do + let(:project) { create(:project, :private, :repository) } + + it 'returns `not_found` when the user does not have access' do + sign_in(create(:user)) + + get_pipelines_index_json + + expect(response).to have_gitlab_http_status(:not_found) + end + + it 'returns the pipelines when the user has access' do + get_pipelines_index_json + + expect(json_response['pipelines'].size).to eq(5) + end + end + def get_pipelines_index_json get :index, namespace_id: project.namespace, project_id: project, diff --git a/spec/controllers/projects/pipelines_settings_controller_spec.rb b/spec/controllers/projects/pipelines_settings_controller_spec.rb index 694896b6bcf..b1ba9f74e38 100644 --- a/spec/controllers/projects/pipelines_settings_controller_spec.rb +++ b/spec/controllers/projects/pipelines_settings_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::PipelinesSettingsController do let(:project) { project_auto_devops.project } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/project_members_controller_spec.rb b/spec/controllers/projects/project_members_controller_spec.rb index d84b31ad978..519af10d78c 100644 --- a/spec/controllers/projects/project_members_controller_spec.rb +++ b/spec/controllers/projects/project_members_controller_spec.rb @@ -37,7 +37,7 @@ describe Projects::ProjectMembersController do context 'when user has enough rights' do before do - project.add_master(user) + project.add_maintainer(user) end it 'adds user to members' do @@ -70,7 +70,7 @@ describe Projects::ProjectMembersController do let(:requester) { create(:project_member, :access_request, project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -121,7 +121,7 @@ describe Projects::ProjectMembersController do context 'when user has enough rights' do before do - project.add_master(user) + project.add_maintainer(user) end it '[HTML] removes user from members' do @@ -181,7 +181,7 @@ describe Projects::ProjectMembersController do let(:project) { create(:project, namespace: user.namespace) } before do - project.add_master(user) + project.add_maintainer(user) end it 'cannot remove themselves from the project' do @@ -263,7 +263,7 @@ describe Projects::ProjectMembersController do context 'when user has enough rights' do before do - project.add_master(user) + project.add_maintainer(user) end it 'adds user to members' do @@ -285,7 +285,7 @@ describe Projects::ProjectMembersController do let(:member) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) another_project.add_guest(member) sign_in(user) end @@ -332,7 +332,7 @@ describe Projects::ProjectMembersController do context 'when creating owner' do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -346,9 +346,9 @@ describe Projects::ProjectMembersController do end end - context 'when create master' do + context 'when create maintainer' do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -356,7 +356,7 @@ describe Projects::ProjectMembersController do expect do post :create, user_ids: stranger.id, namespace_id: project.namespace, - access_level: Member::MASTER, + access_level: Member::MAINTAINER, project_id: project end.to change { project.members.count }.by(1) end diff --git a/spec/controllers/projects/prometheus/metrics_controller_spec.rb b/spec/controllers/projects/prometheus/metrics_controller_spec.rb index 871dcf5c796..5c56a712245 100644 --- a/spec/controllers/projects/prometheus/metrics_controller_spec.rb +++ b/spec/controllers/projects/prometheus/metrics_controller_spec.rb @@ -7,7 +7,7 @@ describe Projects::Prometheus::MetricsController do let(:prometheus_adapter) { double('prometheus_adapter', can_query?: true) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/protected_branches_controller_spec.rb b/spec/controllers/projects/protected_branches_controller_spec.rb index 096e29bc39f..ac812707e74 100644 --- a/spec/controllers/projects/protected_branches_controller_spec.rb +++ b/spec/controllers/projects/protected_branches_controller_spec.rb @@ -8,7 +8,7 @@ describe Projects::ProtectedBranchesController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) end describe "GET #index" do @@ -20,10 +20,10 @@ describe Projects::ProtectedBranchesController do end describe "POST #create" do - let(:master_access_level) { [{ access_level: Gitlab::Access::MASTER }] } + let(:maintainer_access_level) { [{ access_level: Gitlab::Access::MAINTAINER }] } let(:access_level_params) do - { merge_access_levels_attributes: master_access_level, - push_access_levels_attributes: master_access_level } + { merge_access_levels_attributes: maintainer_access_level, + push_access_levels_attributes: maintainer_access_level } end let(:create_params) { attributes_for(:protected_branch).merge(access_level_params) } diff --git a/spec/controllers/projects/protected_tags_controller_spec.rb b/spec/controllers/projects/protected_tags_controller_spec.rb index b6de90039f3..20440c5a5d5 100644 --- a/spec/controllers/projects/protected_tags_controller_spec.rb +++ b/spec/controllers/projects/protected_tags_controller_spec.rb @@ -15,7 +15,7 @@ describe Projects::ProtectedTagsController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/runners_controller_spec.rb b/spec/controllers/projects/runners_controller_spec.rb index 2082dd2cff0..b1e0b496ede 100644 --- a/spec/controllers/projects/runners_controller_spec.rb +++ b/spec/controllers/projects/runners_controller_spec.rb @@ -15,7 +15,7 @@ describe Projects::RunnersController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end describe '#update' do diff --git a/spec/controllers/projects/services_controller_spec.rb b/spec/controllers/projects/services_controller_spec.rb index 61f35cf325b..45cea8c1351 100644 --- a/spec/controllers/projects/services_controller_spec.rb +++ b/spec/controllers/projects/services_controller_spec.rb @@ -9,7 +9,7 @@ describe Projects::ServicesController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end describe '#test' do diff --git a/spec/controllers/projects/settings/ci_cd_controller_spec.rb b/spec/controllers/projects/settings/ci_cd_controller_spec.rb index d53fe9bf734..1f14a0cc381 100644 --- a/spec/controllers/projects/settings/ci_cd_controller_spec.rb +++ b/spec/controllers/projects/settings/ci_cd_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::Settings::CiCdController do let(:project) { project_auto_devops.project } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -27,7 +27,7 @@ describe Projects::Settings::CiCdController do let!(:shared_runner) { create(:ci_runner, :instance) } it 'sets assignable project runners only' do - group.add_master(user) + group.add_maintainer(user) get :show, namespace_id: project.namespace, project_id: project @@ -40,7 +40,7 @@ describe Projects::Settings::CiCdController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) allow(ResetProjectCacheService).to receive_message_chain(:new, :execute).and_return(true) end diff --git a/spec/controllers/projects/settings/integrations_controller_spec.rb b/spec/controllers/projects/settings/integrations_controller_spec.rb index 77df9a6f567..a2484c04c7a 100644 --- a/spec/controllers/projects/settings/integrations_controller_spec.rb +++ b/spec/controllers/projects/settings/integrations_controller_spec.rb @@ -5,7 +5,7 @@ describe Projects::Settings::IntegrationsController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/settings/repository_controller_spec.rb b/spec/controllers/projects/settings/repository_controller_spec.rb index 3a4014b7768..9cee40b7553 100644 --- a/spec/controllers/projects/settings/repository_controller_spec.rb +++ b/spec/controllers/projects/settings/repository_controller_spec.rb @@ -5,7 +5,7 @@ describe Projects::Settings::RepositoryController do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/snippets_controller_spec.rb b/spec/controllers/projects/snippets_controller_spec.rb index e7c0b484ede..9c383bd7628 100644 --- a/spec/controllers/projects/snippets_controller_spec.rb +++ b/spec/controllers/projects/snippets_controller_spec.rb @@ -6,8 +6,8 @@ describe Projects::SnippetsController do let(:user2) { create(:user) } before do - project.add_master(user) - project.add_master(user2) + project.add_maintainer(user) + project.add_maintainer(user2) end describe 'GET #index' do @@ -291,7 +291,7 @@ describe Projects::SnippetsController do def mark_as_spam admin = create(:admin) create(:user_agent_detail, subject: snippet) - project.add_master(admin) + project.add_maintainer(admin) sign_in(admin) post :mark_as_spam, diff --git a/spec/controllers/projects/templates_controller_spec.rb b/spec/controllers/projects/templates_controller_spec.rb index 8fcfa3c9ecd..d7f07aa2b01 100644 --- a/spec/controllers/projects/templates_controller_spec.rb +++ b/spec/controllers/projects/templates_controller_spec.rb @@ -13,7 +13,7 @@ describe Projects::TemplatesController do end before do - project.add_user(user, Gitlab::Access::MASTER) + project.add_user(user, Gitlab::Access::MAINTAINER) project.repository.create_file(user, file_path_1, 'something valid', message: 'test 3', branch_name: 'master') end diff --git a/spec/controllers/projects/tree_controller_spec.rb b/spec/controllers/projects/tree_controller_spec.rb index d3188f054cf..9982b49eebb 100644 --- a/spec/controllers/projects/tree_controller_spec.rb +++ b/spec/controllers/projects/tree_controller_spec.rb @@ -7,7 +7,7 @@ describe Projects::TreeController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) controller.instance_variable_set(:@project, project) end diff --git a/spec/controllers/projects/uploads_controller_spec.rb b/spec/controllers/projects/uploads_controller_spec.rb index eca9baed9c9..325ee53aafb 100644 --- a/spec/controllers/projects/uploads_controller_spec.rb +++ b/spec/controllers/projects/uploads_controller_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe Projects::UploadsController do + include WorkhorseHelpers + let(:model) { create(:project, :public) } let(:params) do { namespace_id: model.namespace.to_param, project_id: model } @@ -15,4 +17,10 @@ describe Projects::UploadsController do expect(response).to redirect_to(new_user_session_path) end end + + def post_authorize(verified: true) + request.headers.merge!(workhorse_internal_api_request_header) if verified + + post :authorize, namespace_id: model.namespace, project_id: model.path, format: :json + end end diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index 68019743be0..9afd1f751c6 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -6,7 +6,7 @@ describe Projects::VariablesController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end describe 'GET #show' do diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 27f04be3fdf..94644b1f9fd 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -166,7 +166,7 @@ describe ProjectsController do User.project_views.keys.each do |project_view| context "with #{project_view} view set" do before do - user.update_attributes(project_view: project_view) + user.update(project_view: project_view) get :show, namespace_id: empty_project.namespace, id: empty_project end @@ -188,7 +188,7 @@ describe ProjectsController do User.project_views.keys.each do |project_view| context "with #{project_view} view set" do before do - user.update_attributes(project_view: project_view) + user.update(project_view: project_view) get :show, namespace_id: empty_project.namespace, id: empty_project end @@ -616,13 +616,40 @@ describe ProjectsController do end describe 'POST #preview_markdown' do - it 'renders json in a correct format' do + before do sign_in(user) + end + it 'renders json in a correct format' do post :preview_markdown, namespace_id: public_project.namespace, id: public_project, text: '*Markdown* text' expect(JSON.parse(response.body).keys).to match_array(%w(body references)) end + + context 'state filter on references' do + let(:issue) { create(:issue, :closed, project: public_project) } + let(:merge_request) { create(:merge_request, :closed, target_project: public_project) } + + it 'renders JSON body with state filter for issues' do + post :preview_markdown, namespace_id: public_project.namespace, + id: public_project, + text: issue.to_reference + + json_response = JSON.parse(response.body) + + expect(json_response['body']).to match(/\##{issue.iid} \(closed\)/) + end + + it 'renders JSON body with state filter for MRs' do + post :preview_markdown, namespace_id: public_project.namespace, + id: public_project, + text: merge_request.to_reference + + json_response = JSON.parse(response.body) + + expect(json_response['body']).to match(/\!#{merge_request.iid} \(closed\)/) + end + end end describe '#ensure_canonical_path' do @@ -732,7 +759,7 @@ describe ProjectsController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end context 'when project export is enabled' do @@ -760,26 +787,58 @@ describe ProjectsController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end - context 'when project export is enabled' do - it 'returns 302' do - get :download_export, namespace_id: project.namespace, id: project + context 'object storage disabled' do + before do + stub_feature_flags(import_export_object_storage: false) + end - expect(response).to have_gitlab_http_status(302) + context 'when project export is enabled' do + it 'returns 302' do + get :download_export, namespace_id: project.namespace, id: project + + expect(response).to have_gitlab_http_status(302) + end + end + + context 'when project export is disabled' do + before do + stub_application_setting(project_export_enabled?: false) + end + + it 'returns 404' do + get :download_export, namespace_id: project.namespace, id: project + + expect(response).to have_gitlab_http_status(404) + end end end - context 'when project export is disabled' do + context 'object storage enabled' do before do - stub_application_setting(project_export_enabled?: false) + stub_feature_flags(import_export_object_storage: true) end - it 'returns 404' do - get :download_export, namespace_id: project.namespace, id: project + context 'when project export is enabled' do + it 'returns 302' do + get :download_export, namespace_id: project.namespace, id: project - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(302) + end + end + + context 'when project export is disabled' do + before do + stub_application_setting(project_export_enabled?: false) + end + + it 'returns 404' do + get :download_export, namespace_id: project.namespace, id: project + + expect(response).to have_gitlab_http_status(404) + end end end end @@ -788,7 +847,7 @@ describe ProjectsController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end context 'when project export is enabled' do @@ -816,7 +875,7 @@ describe ProjectsController do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end context 'when project export is enabled' do diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index cdec26bd421..7c00652317b 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -93,6 +93,12 @@ describe SessionsController do it 'displays an error when the reCAPTCHA is not solved' do # Without this, `verify_recaptcha` arbitraily returns true in test env Recaptcha.configuration.skip_verify_env.delete('test') + counter = double(:counter) + + expect(counter).to receive(:increment) + expect(Gitlab::Metrics).to receive(:counter) + .with(:failed_login_captcha_total, anything) + .and_return(counter) post(:create, user: user_params) @@ -104,6 +110,13 @@ describe SessionsController do it 'successfully logs in a user when reCAPTCHA is solved' do # Avoid test ordering issue and ensure `verify_recaptcha` returns true Recaptcha.configuration.skip_verify_env << 'test' + counter = double(:counter) + + expect(counter).to receive(:increment) + expect(Gitlab::Metrics).to receive(:counter) + .with(:successful_login_captcha_total, anything) + .and_return(counter) + expect(Gitlab::Metrics).to receive(:counter).and_call_original post(:create, user: user_params) diff --git a/spec/controllers/uploads_controller_spec.rb b/spec/controllers/uploads_controller_spec.rb index eb94d395a9e..bcf289f36a9 100644 --- a/spec/controllers/uploads_controller_spec.rb +++ b/spec/controllers/uploads_controller_spec.rb @@ -269,13 +269,13 @@ describe UploadsController do context "when the user has access to the project" do before do - project.add_master(user) + project.add_maintainer(user) end context "when the user is blocked" do before do user.block - project.add_master(user) + project.add_maintainer(user) end it "redirects to the sign in page" do @@ -475,13 +475,13 @@ describe UploadsController do context "when the user has access to the project" do before do - project.add_master(user) + project.add_maintainer(user) end context "when the user is blocked" do before do user.block - project.add_master(user) + project.add_maintainer(user) end it "redirects to the sign in page" do diff --git a/spec/factories/ci/build_trace_chunks.rb b/spec/factories/ci/build_trace_chunks.rb index c0b9a25bfe8..3e8e2736423 100644 --- a/spec/factories/ci/build_trace_chunks.rb +++ b/spec/factories/ci/build_trace_chunks.rb @@ -3,5 +3,53 @@ FactoryBot.define do build factory: :ci_build chunk_index 0 data_store :redis + + trait :redis_with_data do + data_store :redis + + transient do + initial_data 'test data' + end + + after(:create) do |build_trace_chunk, evaluator| + Ci::BuildTraceChunks::Redis.new.set_data(build_trace_chunk, evaluator.initial_data) + end + end + + trait :redis_without_data do + data_store :redis + end + + trait :database_with_data do + data_store :database + + transient do + initial_data 'test data' + end + + after(:build) do |build_trace_chunk, evaluator| + Ci::BuildTraceChunks::Database.new.set_data(build_trace_chunk, evaluator.initial_data) + end + end + + trait :database_without_data do + data_store :database + end + + trait :fog_with_data do + data_store :fog + + transient do + initial_data 'test data' + end + + after(:create) do |build_trace_chunk, evaluator| + Ci::BuildTraceChunks::Fog.new.set_data(build_trace_chunk, evaluator.initial_data) + end + end + + trait :fog_without_data do + data_store :fog + end end end diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 4acc008ed38..83cb4750741 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -248,5 +248,11 @@ FactoryBot.define do failed failure_reason 2 end + + trait :with_runner_session do + after(:build) do |build| + build.build_runner_session(url: 'ws://localhost') + end + end end end diff --git a/spec/factories/ci/runners.rb b/spec/factories/ci/runners.rb index 6fb621b5e51..347e4f433e2 100644 --- a/spec/factories/ci/runners.rb +++ b/spec/factories/ci/runners.rb @@ -6,7 +6,6 @@ FactoryBot.define do active true access_level :not_protected - is_shared true runner_type :instance_type trait :online do @@ -14,12 +13,10 @@ FactoryBot.define do end trait :instance do - is_shared true runner_type :instance_type end trait :group do - is_shared false runner_type :group_type after(:build) do |runner, evaluator| @@ -28,7 +25,6 @@ FactoryBot.define do end trait :project do - is_shared false runner_type :project_type after(:build) do |runner, evaluator| diff --git a/spec/factories/group_members.rb b/spec/factories/group_members.rb index 1c2214e9481..47036560b9d 100644 --- a/spec/factories/group_members.rb +++ b/spec/factories/group_members.rb @@ -7,7 +7,7 @@ FactoryBot.define do trait(:guest) { access_level GroupMember::GUEST } trait(:reporter) { access_level GroupMember::REPORTER } trait(:developer) { access_level GroupMember::DEVELOPER } - trait(:master) { access_level GroupMember::MASTER } + trait(:maintainer) { access_level GroupMember::MAINTAINER } trait(:owner) { access_level GroupMember::OWNER } trait(:access_request) { requested_at Time.now } diff --git a/spec/factories/import_export_uploads.rb b/spec/factories/import_export_uploads.rb new file mode 100644 index 00000000000..7750d49b1d0 --- /dev/null +++ b/spec/factories/import_export_uploads.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :import_export_upload do + project { create(:project) } + end +end diff --git a/spec/factories/issues.rb b/spec/factories/issues.rb index 3a35bdd25de..4d4f74e101e 100644 --- a/spec/factories/issues.rb +++ b/spec/factories/issues.rb @@ -27,7 +27,7 @@ FactoryBot.define do end after(:create) do |issue, evaluator| - issue.update_attributes(labels: evaluator.labels) + issue.update(labels: evaluator.labels) end end end diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index 3441ce1b8cb..f722bb9cb0d 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -117,7 +117,7 @@ FactoryBot.define do end after(:create) do |merge_request, evaluator| - merge_request.update_attributes(labels: evaluator.labels) + merge_request.update(labels: evaluator.labels) end end end diff --git a/spec/factories/project_members.rb b/spec/factories/project_members.rb index 4260f52498d..22a8085ea45 100644 --- a/spec/factories/project_members.rb +++ b/spec/factories/project_members.rb @@ -2,12 +2,12 @@ FactoryBot.define do factory :project_member do user project - master + maintainer trait(:guest) { access_level ProjectMember::GUEST } trait(:reporter) { access_level ProjectMember::REPORTER } trait(:developer) { access_level ProjectMember::DEVELOPER } - trait(:master) { access_level ProjectMember::MASTER } + trait(:maintainer) { access_level ProjectMember::MAINTAINER } trait(:access_request) { requested_at Time.now } trait(:invited) do diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index f6b05bac0e8..fec1bea2751 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -47,7 +47,7 @@ FactoryBot.define do # user have access to the project. Our specs don't use said service class, # thus we must manually refresh things here. unless project.group || project.pending_delete - project.add_master(project.owner) + project.add_maintainer(project.owner) end project.group&.refresh_members_authorized_projects @@ -103,6 +103,22 @@ FactoryBot.define do end trait :with_export do + before(:create) do |_project, _evaluator| + allow(Feature).to receive(:enabled?).with(:import_export_object_storage) { false } + allow(Feature).to receive(:enabled?).with('import_export_object_storage') { false } + end + + after(:create) do |project, _evaluator| + ProjectExportWorker.new.perform(project.creator.id, project.id) + end + end + + trait :with_object_export do + before(:create) do |_project, _evaluator| + allow(Feature).to receive(:enabled?).with(:import_export_object_storage) { true } + allow(Feature).to receive(:enabled?).with('import_export_object_storage') { true } + end + after(:create) do |project, evaluator| ProjectExportWorker.new.perform(project.creator.id, project.id) end diff --git a/spec/factories/protected_branches.rb b/spec/factories/protected_branches.rb index 60956511834..5457c0d2a8f 100644 --- a/spec/factories/protected_branches.rb +++ b/spec/factories/protected_branches.rb @@ -39,23 +39,23 @@ FactoryBot.define do end end - trait :masters_can_push do + trait :maintainers_can_push do transient do default_push_level false end after(:build) do |protected_branch| - protected_branch.push_access_levels.new(access_level: Gitlab::Access::MASTER) + protected_branch.push_access_levels.new(access_level: Gitlab::Access::MAINTAINER) end end after(:build) do |protected_branch, evaluator| if evaluator.default_access_level && evaluator.default_push_level - protected_branch.push_access_levels.new(access_level: Gitlab::Access::MASTER) + protected_branch.push_access_levels.new(access_level: Gitlab::Access::MAINTAINER) end if evaluator.default_access_level && evaluator.default_merge_level - protected_branch.merge_access_levels.new(access_level: Gitlab::Access::MASTER) + protected_branch.merge_access_levels.new(access_level: Gitlab::Access::MAINTAINER) end end diff --git a/spec/factories/protected_tags.rb b/spec/factories/protected_tags.rb index df9c8b3cb63..2b81d089549 100644 --- a/spec/factories/protected_tags.rb +++ b/spec/factories/protected_tags.rb @@ -27,19 +27,19 @@ FactoryBot.define do end end - trait :masters_can_create do + trait :maintainers_can_create do transient do default_access_level false end after(:build) do |protected_tag| - protected_tag.create_access_levels.new(access_level: Gitlab::Access::MASTER) + protected_tag.create_access_levels.new(access_level: Gitlab::Access::MAINTAINER) end end after(:build) do |protected_tag, evaluator| if evaluator.default_access_level - protected_tag.create_access_levels.new(access_level: Gitlab::Access::MASTER) + protected_tag.create_access_levels.new(access_level: Gitlab::Access::MAINTAINER) end end end diff --git a/spec/features/abuse_report_spec.rb b/spec/features/abuse_report_spec.rb index 091fdcec3db..eb12eebe8e6 100644 --- a/spec/features/abuse_report_spec.rb +++ b/spec/features/abuse_report_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -feature 'Abuse reports' do +describe 'Abuse reports' do let(:another_user) { create(:user) } before do sign_in(create(:user)) end - scenario 'Report abuse' do + it 'Report abuse' do visit user_path(another_user) click_link 'Report abuse' diff --git a/spec/features/admin/admin_appearance_spec.rb b/spec/features/admin/admin_appearance_spec.rb index a5e0ac592b9..3c2ae5b3c6a 100644 --- a/spec/features/admin/admin_appearance_spec.rb +++ b/spec/features/admin/admin_appearance_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -feature 'Admin Appearance' do +describe 'Admin Appearance' do let!(:appearance) { create(:appearance) } - scenario 'Create new appearance' do + it 'Create new appearance' do sign_in(create(:admin)) visit admin_appearances_path @@ -21,7 +21,7 @@ feature 'Admin Appearance' do expect(page).to have_content 'Last edit' end - scenario 'Preview sign-in page appearance' do + it 'Preview sign-in page appearance' do sign_in(create(:admin)) visit admin_appearances_path @@ -30,7 +30,7 @@ feature 'Admin Appearance' do expect_custom_sign_in_appearance(appearance) end - scenario 'Preview new project page appearance' do + it 'Preview new project page appearance' do sign_in(create(:admin)) visit admin_appearances_path @@ -39,20 +39,20 @@ feature 'Admin Appearance' do expect_custom_new_project_appearance(appearance) end - scenario 'Custom sign-in page' do + it 'Custom sign-in page' do visit new_user_session_path expect_custom_sign_in_appearance(appearance) end - scenario 'Custom new project page' do + it 'Custom new project page' do sign_in create(:user) visit new_project_path expect_custom_new_project_appearance(appearance) end - scenario 'Appearance logo' do + it 'Appearance logo' do sign_in(create(:admin)) visit admin_appearances_path @@ -64,7 +64,7 @@ feature 'Admin Appearance' do expect(page).not_to have_css(logo_selector) end - scenario 'Header logos' do + it 'Header logos' do sign_in(create(:admin)) visit admin_appearances_path @@ -76,7 +76,7 @@ feature 'Admin Appearance' do expect(page).not_to have_css(header_logo_selector) end - scenario 'Favicon' do + it 'Favicon' do sign_in(create(:admin)) visit admin_appearances_path diff --git a/spec/features/admin/admin_broadcast_messages_spec.rb b/spec/features/admin/admin_broadcast_messages_spec.rb index 430a8d22b0f..f6dc499df29 100644 --- a/spec/features/admin/admin_broadcast_messages_spec.rb +++ b/spec/features/admin/admin_broadcast_messages_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' -feature 'Admin Broadcast Messages' do +describe 'Admin Broadcast Messages' do before do sign_in(create(:admin)) create(:broadcast_message, :expired, message: 'Migration to new server') visit admin_broadcast_messages_path end - scenario 'See broadcast messages list' do + it 'See broadcast messages list' do expect(page).to have_content 'Migration to new server' end - scenario 'Create a customized broadcast message' do + it 'Create a customized broadcast message' do fill_in 'broadcast_message_message', with: 'Application update from **4:00 CST to 5:00 CST**' fill_in 'broadcast_message_color', with: '#f2dede' fill_in 'broadcast_message_font', with: '#b94a48' @@ -24,7 +24,7 @@ feature 'Admin Broadcast Messages' do expect(page).to have_selector %(div[style="background-color: #f2dede; color: #b94a48"]) end - scenario 'Edit an existing broadcast message' do + it 'Edit an existing broadcast message' do click_link 'Edit' fill_in 'broadcast_message_message', with: 'Application update RIGHT NOW' click_button 'Update broadcast message' @@ -33,14 +33,14 @@ feature 'Admin Broadcast Messages' do expect(page).to have_content 'Application update RIGHT NOW' end - scenario 'Remove an existing broadcast message' do + it 'Remove an existing broadcast message' do click_link 'Remove' expect(current_path).to eq admin_broadcast_messages_path expect(page).not_to have_content 'Migration to new server' end - scenario 'Live preview a customized broadcast message', :js do + it 'Live preview a customized broadcast message', :js do fill_in 'broadcast_message_message', with: "Live **Markdown** previews. :tada:" page.within('.broadcast-message-preview') do diff --git a/spec/features/admin/admin_browse_spam_logs_spec.rb b/spec/features/admin/admin_browse_spam_logs_spec.rb index 31d4142a8e9..4645fde7522 100644 --- a/spec/features/admin/admin_browse_spam_logs_spec.rb +++ b/spec/features/admin/admin_browse_spam_logs_spec.rb @@ -7,7 +7,7 @@ describe 'Admin browse spam logs' do sign_in(create(:admin)) end - scenario 'Browse spam logs' do + it 'Browse spam logs' do visit admin_spam_logs_path expect(page).to have_content('Spam Logs') diff --git a/spec/features/admin/admin_cohorts_spec.rb b/spec/features/admin/admin_cohorts_spec.rb index bca52bf674c..9dce9494b97 100644 --- a/spec/features/admin/admin_cohorts_spec.rb +++ b/spec/features/admin/admin_cohorts_spec.rb @@ -1,11 +1,11 @@ require 'rails_helper' -feature 'Admin cohorts page' do +describe 'Admin cohorts page' do before do sign_in(create(:admin)) end - scenario 'See users count per month' do + it 'See users count per month' do 2.times { create(:user) } visit admin_cohorts_path diff --git a/spec/features/admin/admin_disables_git_access_protocol_spec.rb b/spec/features/admin/admin_disables_git_access_protocol_spec.rb index 9946cc77d1d..91c22e7ad82 100644 --- a/spec/features/admin/admin_disables_git_access_protocol_spec.rb +++ b/spec/features/admin/admin_disables_git_access_protocol_spec.rb @@ -1,22 +1,22 @@ require 'rails_helper' -feature 'Admin disables Git access protocol' do +describe 'Admin disables Git access protocol' do include StubENV let(:project) { create(:project, :empty_repo) } let(:admin) { create(:admin) } - background do + before do stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') sign_in(admin) end context 'with HTTP disabled' do - background do + before do disable_http_protocol end - scenario 'shows only SSH url' do + it 'shows only SSH url' do visit_project expect(page).to have_content("git clone #{project.ssh_url_to_repo}") @@ -25,11 +25,11 @@ feature 'Admin disables Git access protocol' do end context 'with SSH disabled' do - background do + before do disable_ssh_protocol end - scenario 'shows only HTTP url' do + it 'shows only HTTP url' do visit_project expect(page).to have_content("git clone #{project.http_url_to_repo}") @@ -38,11 +38,11 @@ feature 'Admin disables Git access protocol' do end context 'with nothing disabled' do - background do + before do create(:personal_key, user: admin) end - scenario 'shows default SSH url and protocol selection dropdown' do + it 'shows default SSH url and protocol selection dropdown' do visit_project expect(page).to have_content("git clone #{project.ssh_url_to_repo}") diff --git a/spec/features/admin/admin_disables_two_factor_spec.rb b/spec/features/admin/admin_disables_two_factor_spec.rb index 2abdd3c9ef2..e41835b4f24 100644 --- a/spec/features/admin/admin_disables_two_factor_spec.rb +++ b/spec/features/admin/admin_disables_two_factor_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' -feature 'Admin disables 2FA for a user' do - scenario 'successfully', :js do +describe 'Admin disables 2FA for a user' do + it 'successfully', :js do sign_in(create(:admin)) user = create(:user, :two_factor) @@ -16,7 +16,7 @@ feature 'Admin disables 2FA for a user' do end end - scenario 'for a user without 2FA enabled' do + it 'for a user without 2FA enabled' do sign_in(create(:admin)) user = create(:user) diff --git a/spec/features/admin/admin_groups_spec.rb b/spec/features/admin/admin_groups_spec.rb index a4226d7a682..96dfde2e08c 100644 --- a/spec/features/admin/admin_groups_spec.rb +++ b/spec/features/admin/admin_groups_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Admin Groups' do +describe 'Admin Groups' do include Select2Helper let(:internal) { Gitlab::VisibilityLevel::INTERNAL } @@ -47,13 +47,13 @@ feature 'Admin Groups' do expect(li_texts).to match group_description end - scenario 'shows the visibility level radio populated with the default value' do + it 'shows the visibility level radio populated with the default value' do visit new_admin_group_path expect_selected_visibility(internal) end - scenario 'when entered in group path, it auto filled the group name', :js do + it 'when entered in group path, it auto filled the group name', :js do visit admin_groups_path click_link "New group" group_path = 'gitlab' @@ -64,7 +64,7 @@ feature 'Admin Groups' do end describe 'show a group' do - scenario 'shows the group' do + it 'shows the group' do group = create(:group, :private) visit admin_group_path(group) @@ -74,7 +74,7 @@ feature 'Admin Groups' do end describe 'group edit' do - scenario 'shows the visibility level radio populated with the group visibility_level value' do + it 'shows the visibility level radio populated with the group visibility_level value' do group = create(:group, :private) visit admin_group_edit_path(group) @@ -82,7 +82,7 @@ feature 'Admin Groups' do expect_selected_visibility(group.visibility_level) end - scenario 'edit group path does not change group name', :js do + it 'edit group path does not change group name', :js do group = create(:group, :private) visit admin_group_edit_path(group) @@ -168,7 +168,7 @@ feature 'Admin Groups' do it 'renders shared project' do empty_project = create(:project) empty_project.project_group_links.create!( - group_access: Gitlab::Access::MASTER, + group_access: Gitlab::Access::MAINTAINER, group: group ) diff --git a/spec/features/admin/admin_health_check_spec.rb b/spec/features/admin/admin_health_check_spec.rb index 3693e5882f9..aaa3e8dc821 100644 --- a/spec/features/admin/admin_health_check_spec.rb +++ b/spec/features/admin/admin_health_check_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature "Admin Health Check", :feature do +describe "Admin Health Check", :feature do include StubENV before do diff --git a/spec/features/admin/admin_hook_logs_spec.rb b/spec/features/admin/admin_hook_logs_spec.rb index 710822ac042..928f97b6d29 100644 --- a/spec/features/admin/admin_hook_logs_spec.rb +++ b/spec/features/admin/admin_hook_logs_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Admin::HookLogs' do +describe 'Admin::HookLogs' do let(:project) { create(:project) } let(:system_hook) { create(:system_hook) } let(:hook_log) { create(:web_hook_log, web_hook: system_hook, internal_error_message: 'some error') } @@ -9,7 +9,7 @@ feature 'Admin::HookLogs' do sign_in(create(:admin)) end - scenario 'show list of hook logs' do + it 'show list of hook logs' do hook_log visit edit_admin_hook_path(system_hook) @@ -17,7 +17,7 @@ feature 'Admin::HookLogs' do expect(page).to have_content(hook_log.url) end - scenario 'show hook log details' do + it 'show hook log details' do hook_log visit edit_admin_hook_path(system_hook) click_link 'View details' @@ -27,7 +27,7 @@ feature 'Admin::HookLogs' do expect(page).to have_content('Resend Request') end - scenario 'retry hook log' do + it 'retry hook log' do WebMock.stub_request(:post, system_hook.url) hook_log diff --git a/spec/features/admin/admin_projects_spec.rb b/spec/features/admin/admin_projects_spec.rb index 328e8f25f89..d6ee256f5b5 100644 --- a/spec/features/admin/admin_projects_spec.rb +++ b/spec/features/admin/admin_projects_spec.rb @@ -88,7 +88,7 @@ describe "Admin::Projects" do describe 'add admin himself to a project' do before do - project.add_master(user) + project.add_maintainer(user) end it 'adds admin a to a project as developer', :js do @@ -110,7 +110,7 @@ describe "Admin::Projects" do describe 'admin remove himself from a project' do before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(current_user) end diff --git a/spec/features/admin/admin_settings_spec.rb b/spec/features/admin/admin_settings_spec.rb index f3ab4ff771a..a852ca689e7 100644 --- a/spec/features/admin/admin_settings_spec.rb +++ b/spec/features/admin/admin_settings_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Admin updates settings' do +describe 'Admin updates settings' do include StubENV include TermsHelper @@ -12,7 +12,7 @@ feature 'Admin updates settings' do visit admin_application_settings_path end - scenario 'Change visibility settings' do + it 'Change visibility settings' do page.within('.as-visibility-access') do choose "application_setting_default_project_visibility_20" click_button 'Save changes' @@ -21,7 +21,7 @@ feature 'Admin updates settings' do expect(page).to have_content "Application settings saved successfully" end - scenario 'Uncheck all restricted visibility levels' do + it 'Uncheck all restricted visibility levels' do page.within('.as-visibility-access') do find('#application_setting_visibility_level_0').set(false) find('#application_setting_visibility_level_10').set(false) @@ -35,7 +35,7 @@ feature 'Admin updates settings' do expect(find('#application_setting_visibility_level_20')).not_to be_checked end - scenario 'Modify import sources' do + it 'Modify import sources' do expect(Gitlab::CurrentSettings.import_sources).not_to be_empty page.within('.as-visibility-access') do @@ -58,7 +58,7 @@ feature 'Admin updates settings' do expect(Gitlab::CurrentSettings.import_sources).to eq(['git']) end - scenario 'Change Visibility and Access Controls' do + it 'Change Visibility and Access Controls' do page.within('.as-visibility-access') do uncheck 'Project export enabled' click_button 'Save changes' @@ -68,7 +68,7 @@ feature 'Admin updates settings' do expect(page).to have_content "Application settings saved successfully" end - scenario 'Change Account and Limit Settings' do + it 'Change Account and Limit Settings' do page.within('.as-account-limit') do uncheck 'Gravatar enabled' click_button 'Save changes' @@ -78,7 +78,7 @@ feature 'Admin updates settings' do expect(page).to have_content "Application settings saved successfully" end - scenario 'Change Sign-in restrictions' do + it 'Change Sign-in restrictions' do page.within('.as-signin') do fill_in 'Home page URL', with: 'https://about.gitlab.com/' click_button 'Save changes' @@ -88,7 +88,7 @@ feature 'Admin updates settings' do expect(page).to have_content "Application settings saved successfully" end - scenario 'Terms of Service' do + it 'Terms of Service' do # Already have the admin accept terms, so they don't need to accept in this spec. _existing_terms = create(:term) accept_terms(admin) @@ -104,7 +104,7 @@ feature 'Admin updates settings' do expect(page).to have_content 'Application settings saved successfully' end - scenario 'Modify oauth providers' do + it 'Modify oauth providers' do expect(Gitlab::CurrentSettings.disabled_oauth_sign_in_sources).to be_empty page.within('.as-signin') do @@ -124,7 +124,7 @@ feature 'Admin updates settings' do expect(Gitlab::CurrentSettings.disabled_oauth_sign_in_sources).not_to include('google_oauth2') end - scenario 'Oauth providers do not raise validation errors when saving unrelated changes' do + it 'Oauth providers do not raise validation errors when saving unrelated changes' do expect(Gitlab::CurrentSettings.disabled_oauth_sign_in_sources).to be_empty page.within('.as-signin') do @@ -147,7 +147,7 @@ feature 'Admin updates settings' do expect(Gitlab::CurrentSettings.disabled_oauth_sign_in_sources).to include('google_oauth2') end - scenario 'Change Help page' do + it 'Change Help page' do page.within('.as-help-page') do fill_in 'Help page text', with: 'Example text' check 'Hide marketing-related entries from help' @@ -161,7 +161,7 @@ feature 'Admin updates settings' do expect(page).to have_content "Application settings saved successfully" end - scenario 'Change Pages settings' do + it 'Change Pages settings' do page.within('.as-pages') do fill_in 'Maximum size of pages (MB)', with: 15 check 'Require users to prove ownership of custom domains' @@ -173,7 +173,7 @@ feature 'Admin updates settings' do expect(page).to have_content "Application settings saved successfully" end - scenario 'Change CI/CD settings' do + it 'Change CI/CD settings' do page.within('.as-ci-cd') do check 'Enabled Auto DevOps for projects by default' fill_in 'Auto devops domain', with: 'domain.com' @@ -185,7 +185,7 @@ feature 'Admin updates settings' do expect(page).to have_content "Application settings saved successfully" end - scenario 'Change Influx settings' do + it 'Change Influx settings' do page.within('.as-influx') do check 'Enable InfluxDB Metrics' click_button 'Save changes' @@ -195,7 +195,7 @@ feature 'Admin updates settings' do expect(page).to have_content "Application settings saved successfully" end - scenario 'Change Prometheus settings' do + it 'Change Prometheus settings' do page.within('.as-prometheus') do check 'Enable Prometheus Metrics' click_button 'Save changes' @@ -205,7 +205,7 @@ feature 'Admin updates settings' do expect(page).to have_content "Application settings saved successfully" end - scenario 'Change Performance bar settings' do + it 'Change Performance bar settings' do group = create(:group) page.within('.as-performance-bar') do @@ -228,7 +228,7 @@ feature 'Admin updates settings' do expect(find_field('Allowed group').value).to be_nil end - scenario 'Change Background jobs settings' do + it 'Change Background jobs settings' do page.within('.as-background') do fill_in 'Throttling Factor', with: 1 click_button 'Save changes' @@ -238,7 +238,7 @@ feature 'Admin updates settings' do expect(page).to have_content "Application settings saved successfully" end - scenario 'Change Spam settings' do + it 'Change Spam settings' do page.within('.as-spam') do check 'Enable reCAPTCHA' fill_in 'reCAPTCHA Site Key', with: 'key' @@ -252,7 +252,7 @@ feature 'Admin updates settings' do expect(Gitlab::CurrentSettings.unique_ips_limit_per_user).to eq(15) end - scenario 'Configure web terminal' do + it 'Configure web terminal' do page.within('.as-terminal') do fill_in 'Max session time', with: 15 click_button 'Save changes' @@ -262,7 +262,7 @@ feature 'Admin updates settings' do expect(Gitlab::CurrentSettings.terminal_max_session_time).to eq(15) end - scenario 'Enable outbound requests' do + it 'Enable outbound requests' do page.within('.as-outbound') do check 'Allow requests to the local network from hooks and services' click_button 'Save changes' @@ -272,7 +272,17 @@ feature 'Admin updates settings' do expect(Gitlab::CurrentSettings.allow_local_requests_from_hooks_and_services).to be true end - scenario 'Change Slack Notifications Service template settings' do + it 'Enable hiding third party offers' do + page.within('.as-third-party-offers') do + check 'Do not display offers from third parties within GitLab' + click_button 'Save changes' + end + + expect(page).to have_content "Application settings saved successfully" + expect(Gitlab::CurrentSettings.hide_third_party_offers).to be true + end + + it 'Change Slack Notifications Service template settings' do first(:link, 'Service Templates').click click_link 'Slack notifications' fill_in 'Webhook', with: 'http://localhost' @@ -296,7 +306,7 @@ feature 'Admin updates settings' do expect(find('#service_push_channel').value).to eq '#test_channel' end - scenario 'Change Keys settings' do + it 'Change Keys settings' do page.within('.as-visibility-access') do select 'Are forbidden', from: 'RSA SSH keys' select 'Are allowed', from: 'DSA SSH keys' diff --git a/spec/features/admin/admin_uses_repository_checks_spec.rb b/spec/features/admin/admin_uses_repository_checks_spec.rb index 7371a494d36..e658f1b6738 100644 --- a/spec/features/admin/admin_uses_repository_checks_spec.rb +++ b/spec/features/admin/admin_uses_repository_checks_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Admin uses repository checks' do +describe 'Admin uses repository checks' do include StubENV before do @@ -8,7 +8,7 @@ feature 'Admin uses repository checks' do sign_in(create(:admin)) end - scenario 'to trigger a single check' do + it 'to trigger a single check' do project = create(:project) visit_admin_project_page(project) @@ -19,7 +19,7 @@ feature 'Admin uses repository checks' do expect(page).to have_content('Repository check was triggered') end - scenario 'to see a single failed repository check', :js do + it 'to see a single failed repository check', :js do project = create(:project) project.update_columns( last_repository_check_failed: true, @@ -32,7 +32,7 @@ feature 'Admin uses repository checks' do end end - scenario 'to clear all repository checks', :js do + it 'to clear all repository checks', :js do visit admin_application_settings_path expect(RepositoryCheck::ClearWorker).to receive(:perform_async) diff --git a/spec/features/atom/dashboard_issues_spec.rb b/spec/features/atom/dashboard_issues_spec.rb index da7749b42d2..bd4c00d97b1 100644 --- a/spec/features/atom/dashboard_issues_spec.rb +++ b/spec/features/atom/dashboard_issues_spec.rb @@ -8,8 +8,8 @@ describe "Dashboard Issues Feed" do let!(:project2) { create(:project) } before do - project1.add_master(user) - project2.add_master(user) + project1.add_maintainer(user) + project2.add_maintainer(user) end describe "atom feed" do diff --git a/spec/features/atom/dashboard_spec.rb b/spec/features/atom/dashboard_spec.rb index 462eab07a75..86b3f88298f 100644 --- a/spec/features/atom/dashboard_spec.rb +++ b/spec/features/atom/dashboard_spec.rb @@ -26,7 +26,7 @@ describe "Dashboard Feed" do let(:note) { create(:note, noteable: issue, author: user, note: 'Bug confirmed', project: project) } before do - project.add_master(user) + project.add_maintainer(user) issue_event(issue, user) note_event(note, user) visit dashboard_projects_path(:atom, feed_token: user.feed_token) diff --git a/spec/features/atom/users_spec.rb b/spec/features/atom/users_spec.rb index eeaaa40fe21..8d7df346abb 100644 --- a/spec/features/atom/users_spec.rb +++ b/spec/features/atom/users_spec.rb @@ -47,7 +47,7 @@ describe "User Feed" do let!(:push_event_payload) { create(:push_event_payload, event: push_event) } before do - project.add_master(user) + project.add_maintainer(user) issue_event(issue, user) note_event(note, user) merge_request_event(merge_request, user) diff --git a/spec/features/boards/add_issues_modal_spec.rb b/spec/features/boards/add_issues_modal_spec.rb index 7a14a441088..eebc987499d 100644 --- a/spec/features/boards/add_issues_modal_spec.rb +++ b/spec/features/boards/add_issues_modal_spec.rb @@ -12,7 +12,7 @@ describe 'Issue Boards add issue modal', :js do let!(:issue2) { create(:issue, project: project, title: 'hij', description: 'klm') } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) diff --git a/spec/features/boards/boards_spec.rb b/spec/features/boards/boards_spec.rb index f6e0dee28c6..a0af2dea3ad 100644 --- a/spec/features/boards/boards_spec.rb +++ b/spec/features/boards/boards_spec.rb @@ -11,8 +11,8 @@ describe 'Issue Boards', :js do let!(:user2) { create(:user) } before do - project.add_master(user) - project.add_master(user2) + project.add_maintainer(user) + project.add_maintainer(user2) set_cookie('sidebar_collapsed', 'true') diff --git a/spec/features/boards/issue_ordering_spec.rb b/spec/features/boards/issue_ordering_spec.rb index 32bd7b88840..ec0ca21450a 100644 --- a/spec/features/boards/issue_ordering_spec.rb +++ b/spec/features/boards/issue_ordering_spec.rb @@ -13,7 +13,7 @@ describe 'Issue Boards', :js do let!(:issue3) { create(:labeled_issue, project: project, title: 'testing 3', labels: [label], relative_position: 1) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/boards/modal_filter_spec.rb b/spec/features/boards/modal_filter_spec.rb index be9c6a51c29..615223a2a88 100644 --- a/spec/features/boards/modal_filter_spec.rb +++ b/spec/features/boards/modal_filter_spec.rb @@ -10,7 +10,7 @@ describe 'Issue Boards add issue modal filtering', :js do let!(:issue1) { create(:issue, project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/boards/new_issue_spec.rb b/spec/features/boards/new_issue_spec.rb index 7a95f5cf871..0bf1ecbc433 100644 --- a/spec/features/boards/new_issue_spec.rb +++ b/spec/features/boards/new_issue_spec.rb @@ -8,7 +8,7 @@ describe 'Issue Boards new issue', :js do context 'authorized user' do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) diff --git a/spec/features/boards/sidebar_spec.rb b/spec/features/boards/sidebar_spec.rb index a03aa681827..ee38e756f9e 100644 --- a/spec/features/boards/sidebar_spec.rb +++ b/spec/features/boards/sidebar_spec.rb @@ -22,7 +22,7 @@ describe 'Issue Boards', :js do end before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) diff --git a/spec/features/boards/sub_group_project_spec.rb b/spec/features/boards/sub_group_project_spec.rb index 271c610dcc8..de2cb4c335e 100644 --- a/spec/features/boards/sub_group_project_spec.rb +++ b/spec/features/boards/sub_group_project_spec.rb @@ -11,7 +11,7 @@ describe 'Sub-group project issue boards', :js do let!(:issue) { create(:labeled_issue, project: project, labels: [label]) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) diff --git a/spec/features/calendar_spec.rb b/spec/features/calendar_spec.rb index 70faf28e09d..f08946b0593 100644 --- a/spec/features/calendar_spec.rb +++ b/spec/features/calendar_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Contributions Calendar', :js do +describe 'Contributions Calendar', :js do let(:user) { create(:user) } let(:contributed_project) { create(:project, :public, :repository) } let(:issue_note) { create(:note, project: contributed_project) } diff --git a/spec/features/commits_spec.rb b/spec/features/commits_spec.rb index 87fa3f60826..8989b2051bb 100644 --- a/spec/features/commits_spec.rb +++ b/spec/features/commits_spec.rb @@ -89,7 +89,7 @@ describe 'Commits' do context 'Download artifacts' do before do - build.update_attributes(legacy_artifacts_file: artifacts_file) + build.update(legacy_artifacts_file: artifacts_file) end it do @@ -146,7 +146,7 @@ describe 'Commits' do context "when logged as reporter" do before do project.add_reporter(user) - build.update_attributes(legacy_artifacts_file: artifacts_file) + build.update(legacy_artifacts_file: artifacts_file) visit pipeline_path(pipeline) end @@ -168,7 +168,7 @@ describe 'Commits' do project.update( visibility_level: Gitlab::VisibilityLevel::INTERNAL, public_builds: false) - build.update_attributes(legacy_artifacts_file: artifacts_file) + build.update(legacy_artifacts_file: artifacts_file) visit pipeline_path(pipeline) end @@ -188,7 +188,7 @@ describe 'Commits' do let(:branch_name) { 'master' } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_commits_path(project, branch_name) end diff --git a/spec/features/container_registry_spec.rb b/spec/features/container_registry_spec.rb index bef2aa9e0e5..9986206f619 100644 --- a/spec/features/container_registry_spec.rb +++ b/spec/features/container_registry_spec.rb @@ -16,7 +16,7 @@ describe "Container Registry", :js do end context 'when there are no image repositories' do - scenario 'user visits container registry main page' do + it 'user visits container registry main page' do visit_container_registry expect(page).to have_content 'No container images' @@ -29,13 +29,13 @@ describe "Container Registry", :js do project.container_repositories << container_repository end - scenario 'user wants to see multi-level container repository' do + it 'user wants to see multi-level container repository' do visit_container_registry expect(page).to have_content('my/image') end - scenario 'user removes entire container repository' do + it 'user removes entire container repository' do visit_container_registry expect_any_instance_of(ContainerRepository) @@ -44,7 +44,7 @@ describe "Container Registry", :js do click_on(class: 'js-remove-repo') end - scenario 'user removes a specific tag from container repository' do + it 'user removes a specific tag from container repository' do visit_container_registry find('.js-toggle-repo').click diff --git a/spec/features/cycle_analytics_spec.rb b/spec/features/cycle_analytics_spec.rb index ef493db3f11..32c75cae0a1 100644 --- a/spec/features/cycle_analytics_spec.rb +++ b/spec/features/cycle_analytics_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Cycle Analytics', :js do +describe 'Cycle Analytics', :js do let(:user) { create(:user) } let(:guest) { create(:user) } let(:project) { create(:project, :repository) } @@ -12,7 +12,7 @@ feature 'Cycle Analytics', :js do context 'as an allowed user' do context 'when project is new' do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) @@ -39,7 +39,7 @@ feature 'Cycle Analytics', :js do context "when there's cycle analytics data" do before do allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return([issue]) - project.add_master(user) + project.add_maintainer(user) @build = create_cycle(user, project, issue, mr, milestone, pipeline) deploy_master(user, project) @@ -95,7 +95,7 @@ feature 'Cycle Analytics', :js do before do user.update_attribute(:preferred_language, 'es') - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_cycle_analytics_path(project) wait_for_requests diff --git a/spec/features/dashboard/activity_spec.rb b/spec/features/dashboard/activity_spec.rb index 941208fa244..bf91dc121d8 100644 --- a/spec/features/dashboard/activity_spec.rb +++ b/spec/features/dashboard/activity_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Dashboard > Activity' do +describe 'Dashboard > Activity' do let(:user) { create(:user) } before do @@ -60,13 +60,13 @@ feature 'Dashboard > Activity' do end before do - project.add_master(user) + project.add_maintainer(user) visit activity_dashboard_path wait_for_requests end - scenario 'user should see all events' do + it 'user should see all events' do within '.content_list' do expect(page).to have_content('pushed new branch') expect(page).to have_content('joined') @@ -77,7 +77,7 @@ feature 'Dashboard > Activity' do end end - scenario 'user should see only pushed events' do + it 'user should see only pushed events' do click_link('Push events') wait_for_requests @@ -90,7 +90,7 @@ feature 'Dashboard > Activity' do end end - scenario 'user should see only merged events' do + it 'user should see only merged events' do click_link('Merge events') wait_for_requests @@ -103,7 +103,7 @@ feature 'Dashboard > Activity' do end end - scenario 'user should see only issues events' do + it 'user should see only issues events' do click_link('Issue events') wait_for_requests @@ -117,7 +117,7 @@ feature 'Dashboard > Activity' do end end - scenario 'user should see only comments events' do + it 'user should see only comments events' do click_link('Comments') wait_for_requests @@ -130,7 +130,7 @@ feature 'Dashboard > Activity' do end end - scenario 'user should see only joined events' do + it 'user should see only joined events' do click_link('Team') wait_for_requests @@ -143,7 +143,7 @@ feature 'Dashboard > Activity' do end end - scenario 'user see selected event after page reloading' do + it 'user see selected event after page reloading' do click_link('Push events') wait_for_requests visit activity_dashboard_path diff --git a/spec/features/dashboard/archived_projects_spec.rb b/spec/features/dashboard/archived_projects_spec.rb index b36231fd78b..6a0cd848345 100644 --- a/spec/features/dashboard/archived_projects_spec.rb +++ b/spec/features/dashboard/archived_projects_spec.rb @@ -6,8 +6,8 @@ RSpec.describe 'Dashboard Archived Project' do let(:archived_project) { create(:project, :archived) } before do - project.add_master(user) - archived_project.add_master(user) + project.add_maintainer(user) + archived_project.add_maintainer(user) sign_in(user) diff --git a/spec/features/dashboard/datetime_on_tooltips_spec.rb b/spec/features/dashboard/datetime_on_tooltips_spec.rb index 089c388636d..d7234158fa1 100644 --- a/spec/features/dashboard/datetime_on_tooltips_spec.rb +++ b/spec/features/dashboard/datetime_on_tooltips_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Tooltips on .timeago dates', :js do +describe 'Tooltips on .timeago dates', :js do let(:user) { create(:user) } let(:project) { create(:project, name: 'test', namespace: user.namespace) } let(:created_date) { Date.yesterday.to_time } @@ -8,7 +8,7 @@ feature 'Tooltips on .timeago dates', :js do context 'on the activity tab' do before do - project.add_master(user) + project.add_maintainer(user) Event.create( project: project, author_id: user.id, action: Event::JOINED, updated_at: created_date, created_at: created_date) @@ -27,7 +27,7 @@ feature 'Tooltips on .timeago dates', :js do context 'on the snippets tab' do before do - project.add_master(user) + project.add_maintainer(user) create(:snippet, author: user, updated_at: created_date, created_at: created_date) sign_in user diff --git a/spec/features/dashboard/groups_list_spec.rb b/spec/features/dashboard/groups_list_spec.rb index 29280bd6e06..eceb12e91cd 100644 --- a/spec/features/dashboard/groups_list_spec.rb +++ b/spec/features/dashboard/groups_list_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Dashboard Groups page', :js do +describe 'Dashboard Groups page', :js do let(:user) { create :user } let(:group) { create(:group) } let(:nested_group) { create(:group, :nested) } diff --git a/spec/features/dashboard/issues_filter_spec.rb b/spec/features/dashboard/issues_filter_spec.rb index 8d0b0be1bd4..95e2610dd4a 100644 --- a/spec/features/dashboard/issues_filter_spec.rb +++ b/spec/features/dashboard/issues_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Dashboard Issues filtering', :js do +describe 'Dashboard Issues filtering', :js do include Spec::Support::Helpers::Features::SortingHelpers let(:user) { create(:user) } @@ -11,7 +11,7 @@ feature 'Dashboard Issues filtering', :js do let!(:issue2) { create(:issue, project: project, author: user, assignees: [user], milestone: milestone) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit_issues diff --git a/spec/features/dashboard/issues_spec.rb b/spec/features/dashboard/issues_spec.rb index 3cc7b38550d..4ae062f242a 100644 --- a/spec/features/dashboard/issues_spec.rb +++ b/spec/features/dashboard/issues_spec.rb @@ -12,7 +12,7 @@ RSpec.describe 'Dashboard Issues' do let!(:other_issue) { create :issue, project: project } before do - [project, project_with_issues_disabled].each { |project| project.add_master(current_user) } + [project, project_with_issues_disabled].each { |project| project.add_maintainer(current_user) } sign_in(current_user) visit issues_dashboard_path(assignee_id: current_user.id) end diff --git a/spec/features/dashboard/merge_requests_spec.rb b/spec/features/dashboard/merge_requests_spec.rb index 0965b745c03..f51142f5790 100644 --- a/spec/features/dashboard/merge_requests_spec.rb +++ b/spec/features/dashboard/merge_requests_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Dashboard Merge Requests' do +describe 'Dashboard Merge Requests' do include Spec::Support::Helpers::Features::SortingHelpers include FilterItemSelectHelper include ProjectForksHelper @@ -12,7 +12,7 @@ feature 'Dashboard Merge Requests' do let(:forked_project) { fork_project(public_project, current_user, repository: true) } before do - project.add_master(current_user) + project.add_maintainer(current_user) sign_in(current_user) end @@ -20,7 +20,7 @@ feature 'Dashboard Merge Requests' do let(:project_with_disabled_merge_requests) { create(:project, :merge_requests_disabled) } before do - project_with_disabled_merge_requests.add_master(current_user) + project_with_disabled_merge_requests.add_maintainer(current_user) visit merge_requests_dashboard_path end diff --git a/spec/features/dashboard/milestone_filter_spec.rb b/spec/features/dashboard/milestone_filter_spec.rb index 8cd57f4f327..00373050aeb 100644 --- a/spec/features/dashboard/milestone_filter_spec.rb +++ b/spec/features/dashboard/milestone_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Dashboard > milestone filter', :js do +describe 'Dashboard > milestone filter', :js do include FilterItemSelectHelper let(:user) { create(:user) } diff --git a/spec/features/dashboard/milestone_tabs_spec.rb b/spec/features/dashboard/milestone_tabs_spec.rb index 6fcde35f541..21de7c2f06f 100644 --- a/spec/features/dashboard/milestone_tabs_spec.rb +++ b/spec/features/dashboard/milestone_tabs_spec.rb @@ -14,7 +14,7 @@ describe 'Dashboard milestone tabs', :js do let!(:merge_request) { create(:labeled_merge_request, source_project: project, target_project: project, milestone: project_milestone, labels: [label]) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit dashboard_milestone_path(milestone.safe_title, title: milestone.title) diff --git a/spec/features/dashboard/milestones_spec.rb b/spec/features/dashboard/milestones_spec.rb index 7787772a958..0db69432702 100644 --- a/spec/features/dashboard/milestones_spec.rb +++ b/spec/features/dashboard/milestones_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Dashboard > Milestones' do +describe 'Dashboard > Milestones' do describe 'as anonymous user' do before do visit dashboard_milestones_path @@ -16,7 +16,7 @@ feature 'Dashboard > Milestones' do let(:project) { create(:project, namespace: user.namespace) } let!(:milestone) { create(:milestone, project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit dashboard_milestones_path end diff --git a/spec/features/dashboard/project_member_activity_index_spec.rb b/spec/features/dashboard/project_member_activity_index_spec.rb index 6c3093607b0..498775acff3 100644 --- a/spec/features/dashboard/project_member_activity_index_spec.rb +++ b/spec/features/dashboard/project_member_activity_index_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -feature 'Project member activity', :js do +describe 'Project member activity', :js do let(:user) { create(:user) } let(:project) { create(:project, :public, name: 'x', namespace: user.namespace) } before do - project.add_master(user) + project.add_maintainer(user) end def visit_activities_and_wait_with_event(event_type) diff --git a/spec/features/dashboard/projects_spec.rb b/spec/features/dashboard/projects_spec.rb index ef2f0b5b31a..4daacc61d85 100644 --- a/spec/features/dashboard/projects_spec.rb +++ b/spec/features/dashboard/projects_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Dashboard Projects' do +describe 'Dashboard Projects' do let(:user) { create(:user) } let(:project) { create(:project, :repository, name: 'awesome stuff') } let(:project2) { create(:project, :public, name: 'Community project') } @@ -29,9 +29,37 @@ feature 'Dashboard Projects' do end end + context 'when user has access to the project' do + it 'shows role badge' do + visit dashboard_projects_path + + page.within '.user-access-role' do + expect(page).to have_content('Developer') + end + end + + context 'when role changes', :use_clean_rails_memory_store_fragment_caching do + it 'displays the right role' do + visit dashboard_projects_path + + page.within '.user-access-role' do + expect(page).to have_content('Developer') + end + + project.members.last.update(access_level: 40) + + visit dashboard_projects_path + + page.within '.user-access-role' do + expect(page).to have_content('Maintainer') + end + end + end + end + context 'when last_repository_updated_at, last_activity_at and update_at are present' do it 'shows the last_repository_updated_at attribute as the update date' do - project.update_attributes!(last_repository_updated_at: Time.now, last_activity_at: 1.hour.ago) + project.update!(last_repository_updated_at: Time.now, last_activity_at: 1.hour.ago) visit dashboard_projects_path @@ -39,7 +67,7 @@ feature 'Dashboard Projects' do end it 'shows the last_activity_at attribute as the update date' do - project.update_attributes!(last_repository_updated_at: 1.hour.ago, last_activity_at: Time.now) + project.update!(last_repository_updated_at: 1.hour.ago, last_activity_at: Time.now) visit dashboard_projects_path @@ -49,7 +77,7 @@ feature 'Dashboard Projects' do context 'when last_repository_updated_at and last_activity_at are missing' do it 'shows the updated_at attribute as the update date' do - project.update_attributes!(last_repository_updated_at: nil, last_activity_at: nil) + project.update!(last_repository_updated_at: nil, last_activity_at: nil) project.touch visit dashboard_projects_path @@ -121,7 +149,7 @@ feature 'Dashboard Projects' do visit dashboard_projects_path end - scenario 'shows "Create merge request" button' do + it 'shows "Create merge request" button' do expect(page).to have_content 'You pushed to feature' within('#content-body') do diff --git a/spec/features/dashboard/shortcuts_spec.rb b/spec/features/dashboard/shortcuts_spec.rb index e41bd7a8419..e5c5ab9c039 100644 --- a/spec/features/dashboard/shortcuts_spec.rb +++ b/spec/features/dashboard/shortcuts_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -feature 'Dashboard shortcuts', :js do +describe 'Dashboard shortcuts', :js do context 'logged in' do before do sign_in(create(:user)) visit root_dashboard_path end - scenario 'Navigate to tabs' do + it 'Navigate to tabs' do find('body').send_keys([:shift, 'I']) check_page_title('Issues') @@ -31,7 +31,7 @@ feature 'Dashboard shortcuts', :js do visit explore_root_path end - scenario 'Navigate to tabs' do + it 'Navigate to tabs' do find('body').send_keys([:shift, 'G']) find('.nothing-here-block') diff --git a/spec/features/dashboard/todos/target_state_spec.rb b/spec/features/dashboard/todos/target_state_spec.rb index 030a86d1c01..d55c32b3082 100644 --- a/spec/features/dashboard/todos/target_state_spec.rb +++ b/spec/features/dashboard/todos/target_state_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Dashboard > Todo target states' do +describe 'Dashboard > Todo target states' do let(:user) { create(:user) } let(:author) { create(:user) } let(:project) { create(:project, :public) } @@ -9,7 +9,7 @@ feature 'Dashboard > Todo target states' do sign_in(user) end - scenario 'on a closed issue todo has closed label' do + it 'on a closed issue todo has closed label' do issue_closed = create(:issue, state: 'closed') create_todo issue_closed visit dashboard_todos_path @@ -19,7 +19,7 @@ feature 'Dashboard > Todo target states' do end end - scenario 'on an open issue todo does not have an open label' do + it 'on an open issue todo does not have an open label' do issue_open = create(:issue) create_todo issue_open visit dashboard_todos_path @@ -29,7 +29,7 @@ feature 'Dashboard > Todo target states' do end end - scenario 'on a merged merge request todo has merged label' do + it 'on a merged merge request todo has merged label' do mr_merged = create(:merge_request, :simple, :merged, author: user) create_todo mr_merged visit dashboard_todos_path @@ -39,7 +39,7 @@ feature 'Dashboard > Todo target states' do end end - scenario 'on a closed merge request todo has closed label' do + it 'on a closed merge request todo has closed label' do mr_closed = create(:merge_request, :simple, :closed, author: user) create_todo mr_closed visit dashboard_todos_path @@ -49,7 +49,7 @@ feature 'Dashboard > Todo target states' do end end - scenario 'on an open merge request todo does not have an open label' do + it 'on an open merge request todo does not have an open label' do mr_open = create(:merge_request, :simple, author: user) create_todo mr_open visit dashboard_todos_path diff --git a/spec/features/dashboard/todos/todos_filtering_spec.rb b/spec/features/dashboard/todos/todos_filtering_spec.rb index 7b359b0c651..85f865321cf 100644 --- a/spec/features/dashboard/todos/todos_filtering_spec.rb +++ b/spec/features/dashboard/todos/todos_filtering_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Dashboard > User filters todos', :js do +describe 'Dashboard > User filters todos', :js do let(:user_1) { create(:user, username: 'user_1', name: 'user_1') } let(:user_2) { create(:user, username: 'user_2', name: 'user_2') } diff --git a/spec/features/dashboard/todos/todos_sorting_spec.rb b/spec/features/dashboard/todos/todos_sorting_spec.rb index 10e3ad843fd..b87caaa1c07 100644 --- a/spec/features/dashboard/todos/todos_sorting_spec.rb +++ b/spec/features/dashboard/todos/todos_sorting_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Dashboard > User sorts todos' do +describe 'Dashboard > User sorts todos' do let(:user) { create(:user) } let(:project) { create(:project) } diff --git a/spec/features/dashboard/todos/todos_spec.rb b/spec/features/dashboard/todos/todos_spec.rb index 5ed20b02a6e..96b22a0f64b 100644 --- a/spec/features/dashboard/todos/todos_spec.rb +++ b/spec/features/dashboard/todos/todos_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Dashboard Todos' do +describe 'Dashboard Todos' do let(:user) { create(:user) } let(:author) { create(:user) } let(:project) { create(:project, :public) } diff --git a/spec/features/dashboard/user_filters_projects_spec.rb b/spec/features/dashboard/user_filters_projects_spec.rb index 92f4d4b854c..3746d37b9cd 100644 --- a/spec/features/dashboard/user_filters_projects_spec.rb +++ b/spec/features/dashboard/user_filters_projects_spec.rb @@ -7,7 +7,7 @@ describe 'Dashboard > User filters projects' do let(:project2) { create(:project, name: 'Treasure', namespace: user2.namespace) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/discussion_comments/commit_spec.rb b/spec/features/discussion_comments/commit_spec.rb index 69d35cdbc72..7a3b1d7ed47 100644 --- a/spec/features/discussion_comments/commit_spec.rb +++ b/spec/features/discussion_comments/commit_spec.rb @@ -8,7 +8,7 @@ describe 'Discussion Comments Commit', :js do let(:merge_request) { create(:merge_request, source_project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_commit_path(project, sample_commit.id) diff --git a/spec/features/discussion_comments/issue_spec.rb b/spec/features/discussion_comments/issue_spec.rb index 9812eaf3420..5ec19460bbd 100644 --- a/spec/features/discussion_comments/issue_spec.rb +++ b/spec/features/discussion_comments/issue_spec.rb @@ -6,7 +6,7 @@ describe 'Discussion Comments Issue', :js do let(:issue) { create(:issue, project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_issue_path(project, issue) diff --git a/spec/features/discussion_comments/merge_request_spec.rb b/spec/features/discussion_comments/merge_request_spec.rb index b0019c32189..f940e973923 100644 --- a/spec/features/discussion_comments/merge_request_spec.rb +++ b/spec/features/discussion_comments/merge_request_spec.rb @@ -6,7 +6,7 @@ describe 'Discussion Comments Merge Request', :js do let(:merge_request) { create(:merge_request, source_project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_merge_request_path(project, merge_request) diff --git a/spec/features/discussion_comments/snippets_spec.rb b/spec/features/discussion_comments/snippets_spec.rb index 4a236c4639b..d330e89505e 100644 --- a/spec/features/discussion_comments/snippets_spec.rb +++ b/spec/features/discussion_comments/snippets_spec.rb @@ -6,7 +6,7 @@ describe 'Discussion Comments Snippet', :js do let(:snippet) { create(:project_snippet, :private, project: project, author: user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_snippet_path(project, snippet) diff --git a/spec/features/expand_collapse_diffs_spec.rb b/spec/features/expand_collapse_diffs_spec.rb index 31862b2e8f4..8d801161148 100644 --- a/spec/features/expand_collapse_diffs_spec.rb +++ b/spec/features/expand_collapse_diffs_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Expand and collapse diffs', :js do +describe 'Expand and collapse diffs', :js do let(:branch) { 'expand-collapse-diffs' } let(:project) { create(:project, :repository) } diff --git a/spec/features/explore/new_menu_spec.rb b/spec/features/explore/new_menu_spec.rb index 2516db5422f..0a88988ea09 100644 --- a/spec/features/explore/new_menu_spec.rb +++ b/spec/features/explore/new_menu_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Top Plus Menu', :js do +describe 'Top Plus Menu', :js do let(:user) { create(:user) } let(:group) { create(:group) } let(:project) { create(:project, :repository, creator: user, namespace: user.namespace) } @@ -15,7 +15,7 @@ feature 'Top Plus Menu', :js do sign_in(user) end - scenario 'click on New project shows new project page' do + it 'click on New project shows new project page' do visit root_dashboard_path click_topmenuitem("New project") @@ -24,7 +24,7 @@ feature 'Top Plus Menu', :js do expect(page).to have_content('Project name') end - scenario 'click on New group shows new group page' do + it 'click on New group shows new group page' do visit root_dashboard_path click_topmenuitem("New group") @@ -33,7 +33,7 @@ feature 'Top Plus Menu', :js do expect(page).to have_content('Group name') end - scenario 'click on New snippet shows new snippet page' do + it 'click on New snippet shows new snippet page' do visit root_dashboard_path click_topmenuitem("New snippet") @@ -42,7 +42,7 @@ feature 'Top Plus Menu', :js do expect(page).to have_content('Title') end - scenario 'click on New issue shows new issue page' do + it 'click on New issue shows new issue page' do visit project_path(project) click_topmenuitem("New issue") @@ -51,7 +51,7 @@ feature 'Top Plus Menu', :js do expect(page).to have_content('Title') end - scenario 'click on New merge request shows new merge request page' do + it 'click on New merge request shows new merge request page' do visit project_path(project) click_topmenuitem("New merge request") @@ -61,7 +61,7 @@ feature 'Top Plus Menu', :js do expect(page).to have_content('Target branch') end - scenario 'click on New project snippet shows new snippet page' do + it 'click on New project snippet shows new snippet page' do visit project_path(project) page.within '.header-content' do @@ -74,7 +74,7 @@ feature 'Top Plus Menu', :js do expect(page).to have_content('Title') end - scenario 'Click on New subgroup shows new group page', :nested_groups do + it 'Click on New subgroup shows new group page', :nested_groups do visit group_path(group) click_topmenuitem("New subgroup") @@ -83,7 +83,7 @@ feature 'Top Plus Menu', :js do expect(page).to have_content('Group name') end - scenario 'Click on New project in group shows new project page' do + it 'Click on New project in group shows new project page' do visit group_path(group) page.within '.header-content' do @@ -107,7 +107,7 @@ feature 'Top Plus Menu', :js do sign_in(guest_user) end - scenario 'click on New issue shows new issue page' do + it 'click on New issue shows new issue page' do visit project_path(project) click_topmenuitem("New issue") @@ -116,37 +116,37 @@ feature 'Top Plus Menu', :js do expect(page).to have_content('Title') end - scenario 'has no New merge request menu item' do + it 'has no New merge request menu item' do visit project_path(project) hasnot_topmenuitem("New merge request") end - scenario 'has no New project snippet menu item' do + it 'has no New project snippet menu item' do visit project_path(project) expect(find('.header-new.dropdown')).not_to have_selector('.header-new-project-snippet') end - scenario 'public project has no New merge request menu item' do + it 'public project has no New merge request menu item' do visit project_path(public_project) hasnot_topmenuitem("New merge request") end - scenario 'public project has no New project snippet menu item' do + it 'public project has no New project snippet menu item' do visit project_path(public_project) expect(find('.header-new.dropdown')).not_to have_selector('.header-new-project-snippet') end - scenario 'has no New subgroup menu item' do + it 'has no New subgroup menu item' do visit group_path(group) hasnot_topmenuitem("New subgroup") end - scenario 'has no New project for group menu item' do + it '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') diff --git a/spec/features/global_search_spec.rb b/spec/features/global_search_spec.rb index f8c4db1403c..d7692181453 100644 --- a/spec/features/global_search_spec.rb +++ b/spec/features/global_search_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -feature 'Global search' do +describe 'Global search' do let(:user) { create(:user) } let(:project) { create(:project, namespace: user.namespace) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/group_variables_spec.rb b/spec/features/group_variables_spec.rb index f7863807572..89e0cdd8ed7 100644 --- a/spec/features/group_variables_spec.rb +++ b/spec/features/group_variables_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -feature 'Group variables', :js do +describe 'Group variables', :js do let(:user) { create(:user) } let(:group) { create(:group) } let!(:variable) { create(:ci_group_variable, key: 'test_key', value: 'test value', group: group) } let(:page_path) { group_settings_ci_cd_path(group) } - background do - group.add_master(user) + before do + group.add_maintainer(user) gitlab_sign_in(user) visit page_path diff --git a/spec/features/groups/activity_spec.rb b/spec/features/groups/activity_spec.rb index 0d7d3771071..88fc12ae1e4 100644 --- a/spec/features/groups/activity_spec.rb +++ b/spec/features/groups/activity_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Group activity page' do +describe 'Group activity page' do let(:user) { create(:group_member, :developer, user: create(:user), group: group ).user } let(:group) { create(:group) } let(:path) { activity_group_path(group) } @@ -23,7 +23,7 @@ feature 'Group activity page' do let(:project) { create(:project, :public, namespace: group) } before do - project.add_master(user) + project.add_maintainer(user) visit path end diff --git a/spec/features/groups/empty_states_spec.rb b/spec/features/groups/empty_states_spec.rb index 5828d833ae9..8f5ca781b2c 100644 --- a/spec/features/groups/empty_states_spec.rb +++ b/spec/features/groups/empty_states_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Group empty states' do +describe 'Group empty states' do let(:group) { create(:group) } let(:user) { create(:group_member, :developer, user: create(:user), group: group ).user } @@ -19,7 +19,7 @@ feature 'Group empty states' do let(:project) { create(:project, namespace: group) } before do - project.add_master(user) + project.add_maintainer(user) end context "the project has #{issuable_name}s" do diff --git a/spec/features/groups/group_settings_spec.rb b/spec/features/groups/group_settings_spec.rb index bf329b0bb94..59254ecc982 100644 --- a/spec/features/groups/group_settings_spec.rb +++ b/spec/features/groups/group_settings_spec.rb @@ -1,10 +1,10 @@ require 'spec_helper' -feature 'Edit group settings' do - given(:user) { create(:user) } - given(:group) { create(:group, path: 'foo') } +describe 'Edit group settings' do + let(:user) { create(:user) } + let(:group) { create(:group, path: 'foo') } - background do + before do group.add_owner(user) sign_in(user) end @@ -14,14 +14,14 @@ feature 'Edit group settings' do let(:old_group_full_path) { "/#{group.path}" } let(:new_group_full_path) { "/#{new_group_path}" } - scenario 'the group is accessible via the new path' do + it 'the group is accessible via the new path' do update_path(new_group_path) visit new_group_full_path expect(current_path).to eq(new_group_full_path) expect(find('h1.group-title')).to have_content(group.name) end - scenario 'the old group path redirects to the new path' do + it 'the old group path redirects to the new path' do update_path(new_group_path) visit old_group_full_path expect(current_path).to eq(new_group_full_path) @@ -29,18 +29,18 @@ feature 'Edit group settings' do end context 'with a subgroup' do - given!(:subgroup) { create(:group, parent: group, path: 'subgroup') } - given(:old_subgroup_full_path) { "/#{group.path}/#{subgroup.path}" } - given(:new_subgroup_full_path) { "/#{new_group_path}/#{subgroup.path}" } + let!(:subgroup) { create(:group, parent: group, path: 'subgroup') } + let(:old_subgroup_full_path) { "/#{group.path}/#{subgroup.path}" } + let(:new_subgroup_full_path) { "/#{new_group_path}/#{subgroup.path}" } - scenario 'the subgroup is accessible via the new path' do + it 'the subgroup is accessible via the new path' do update_path(new_group_path) visit new_subgroup_full_path expect(current_path).to eq(new_subgroup_full_path) expect(find('h1.group-title')).to have_content(subgroup.name) end - scenario 'the old subgroup path redirects to the new path' do + it 'the old subgroup path redirects to the new path' do update_path(new_group_path) visit old_subgroup_full_path expect(current_path).to eq(new_subgroup_full_path) @@ -49,9 +49,9 @@ feature 'Edit group settings' do end context 'with a project' do - given!(:project) { create(:project, group: group) } - given(:old_project_full_path) { "/#{group.path}/#{project.path}" } - given(:new_project_full_path) { "/#{new_group_path}/#{project.path}" } + let!(:project) { create(:project, group: group) } + let(:old_project_full_path) { "/#{group.path}/#{project.path}" } + let(:new_project_full_path) { "/#{new_group_path}/#{project.path}" } before(:context) do TestEnv.clean_test_path @@ -61,14 +61,14 @@ feature 'Edit group settings' do TestEnv.clean_test_path end - scenario 'the project is accessible via the new path' do + it 'the project is accessible via the new path' do update_path(new_group_path) visit new_project_full_path expect(current_path).to eq(new_project_full_path) expect(find('.breadcrumbs')).to have_content(project.path) end - scenario 'the old project path redirects to the new path' do + it 'the old project path redirects to the new path' do update_path(new_group_path) visit old_project_full_path expect(current_path).to eq(new_project_full_path) diff --git a/spec/features/groups/issues_spec.rb b/spec/features/groups/issues_spec.rb index e131ded3688..97d8776b15a 100644 --- a/spec/features/groups/issues_spec.rb +++ b/spec/features/groups/issues_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Group issues page' do +describe 'Group issues page' do include FilteredSearchHelpers let(:group) { create(:group) } @@ -80,10 +80,10 @@ feature 'Group issues page' do context 'projects with issues disabled' do describe 'issue dropdown' do - let(:user_in_group) { create(:group_member, :master, user: create(:user), group: group ).user } + let(:user_in_group) { create(:group_member, :maintainer, user: create(:user), group: group ).user } before do - [project, project_with_issues_disabled].each { |project| project.add_master(user_in_group) } + [project, project_with_issues_disabled].each { |project| project.add_maintainer(user_in_group) } sign_in(user_in_group) visit issues_group_path(group) end diff --git a/spec/features/groups/labels/edit_spec.rb b/spec/features/groups/labels/edit_spec.rb index fb338127861..7cfc27a8905 100644 --- a/spec/features/groups/labels/edit_spec.rb +++ b/spec/features/groups/labels/edit_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' -feature 'Edit group label' do - given(:user) { create(:user) } - given(:group) { create(:group) } - given(:label) { create(:group_label, group: group) } +describe 'Edit group label' do + let(:user) { create(:user) } + let(:group) { create(:group) } + let(:label) { create(:group_label, group: group) } - background do + before do group.add_owner(user) sign_in(user) visit edit_group_label_path(group, label) end - scenario 'update label with new title' do + it 'update label with new title' do fill_in 'label_title', with: 'new label name' click_button 'Save changes' diff --git a/spec/features/groups/labels/index_spec.rb b/spec/features/groups/labels/index_spec.rb index 6c1b43a9013..0ce7dad4040 100644 --- a/spec/features/groups/labels/index_spec.rb +++ b/spec/features/groups/labels/index_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' -feature 'Group labels' do +describe 'Group labels' do let(:user) { create(:user) } let(:group) { create(:group) } let!(:label) { create(:group_label, group: group) } - background do + before do group.add_owner(user) sign_in(user) visit group_labels_path(group) end - scenario 'label has edit button', :js do + it 'label has edit button', :js do expect(page).to have_selector('.label-action.edit') end end diff --git a/spec/features/groups/labels/subscription_spec.rb b/spec/features/groups/labels/subscription_spec.rb index 2e06caf98f6..d9543bfa97f 100644 --- a/spec/features/groups/labels/subscription_spec.rb +++ b/spec/features/groups/labels/subscription_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Labels subscription' do +describe 'Labels subscription' do let(:user) { create(:user) } let(:group) { create(:group) } let!(:feature) { create(:group_label, group: group, title: 'feature') } @@ -11,7 +11,7 @@ feature 'Labels subscription' do gitlab_sign_in user end - scenario 'users can subscribe/unsubscribe to group labels', :js do + it 'users can subscribe/unsubscribe to group labels', :js do visit group_labels_path(group) expect(page).to have_content('feature') diff --git a/spec/features/groups/labels/user_sees_links_to_issuables.rb b/spec/features/groups/labels/user_sees_links_to_issuables.rb index 5d6290d2109..1fdba78fa6c 100644 --- a/spec/features/groups/labels/user_sees_links_to_issuables.rb +++ b/spec/features/groups/labels/user_sees_links_to_issuables.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Groups > Labels > User sees links to issuables' do +describe 'Groups > Labels > User sees links to issuables' do set(:group) { create(:group, :public) } before do @@ -8,7 +8,7 @@ feature 'Groups > Labels > User sees links to issuables' do visit group_labels_path(group) end - scenario 'shows links to MRs and issues' do + it 'shows links to MRs and issues' do expect(page).to have_link('view merge requests') expect(page).to have_link('view open issues') end diff --git a/spec/features/groups/members/filter_members_spec.rb b/spec/features/groups/members/filter_members_spec.rb index 5ddb5894624..386d81546d7 100644 --- a/spec/features/groups/members/filter_members_spec.rb +++ b/spec/features/groups/members/filter_members_spec.rb @@ -1,18 +1,18 @@ require 'spec_helper' -feature 'Groups > Members > Filter members' do +describe 'Groups > Members > Filter members' do let(:user) { create(:user) } let(:user_with_2fa) { create(:user, :two_factor_via_otp) } let(:group) { create(:group) } - background do + before do group.add_owner(user) - group.add_master(user_with_2fa) + group.add_maintainer(user_with_2fa) sign_in(user) end - scenario 'shows all members' do + it 'shows all members' do visit_members_list expect(first_member).to include(user.name) @@ -20,7 +20,7 @@ feature 'Groups > Members > Filter members' do expect(page).to have_css('.member-filter-2fa-dropdown .dropdown-toggle-text', text: '2FA: Everyone') end - scenario 'shows only 2FA members' do + it 'shows only 2FA members' do visit_members_list(two_factor: 'enabled') expect(first_member).to include(user_with_2fa.name) @@ -28,7 +28,7 @@ feature 'Groups > Members > Filter members' do expect(page).to have_css('.member-filter-2fa-dropdown .dropdown-toggle-text', text: '2FA: Enabled') end - scenario 'shows only non 2FA members' do + it 'shows only non 2FA members' do visit_members_list(two_factor: 'disabled') expect(first_member).to include(user.name) diff --git a/spec/features/groups/members/leave_group_spec.rb b/spec/features/groups/members/leave_group_spec.rb index 067a2dc850f..7a91c64d7db 100644 --- a/spec/features/groups/members/leave_group_spec.rb +++ b/spec/features/groups/members/leave_group_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' -feature 'Groups > Members > Leave group' do +describe 'Groups > Members > Leave group' do let(:user) { create(:user) } let(:other_user) { create(:user) } let(:group) { create(:group) } - background do + before do gitlab_sign_in(user) end - scenario 'guest leaves the group' do + it 'guest leaves the group' do group.add_guest(user) group.add_owner(other_user) @@ -21,7 +21,7 @@ feature 'Groups > Members > Leave group' do expect(group.users).not_to include(user) end - scenario 'guest leaves the group as last member' do + it 'guest leaves the group as last member' do group.add_guest(user) visit group_path(group) @@ -32,7 +32,7 @@ feature 'Groups > Members > Leave group' do expect(group.users).not_to include(user) end - scenario 'owner leaves the group if they is not the last owner' do + it 'owner leaves the group if they is not the last owner' do group.add_owner(user) group.add_owner(other_user) @@ -44,7 +44,7 @@ feature 'Groups > Members > Leave group' do expect(group.users).not_to include(user) end - scenario 'owner can not leave the group if they is a last owner' do + it 'owner can not leave the group if they is a last owner' do group.add_owner(user) visit group_path(group) diff --git a/spec/features/groups/members/list_members_spec.rb b/spec/features/groups/members/list_members_spec.rb index 5c5d48c3623..33f93fcc470 100644 --- a/spec/features/groups/members/list_members_spec.rb +++ b/spec/features/groups/members/list_members_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Groups > Members > List members' do +describe 'Groups > Members > List members' do include Select2Helper let(:user1) { create(:user, name: 'John Doe') } @@ -8,11 +8,11 @@ feature 'Groups > Members > List members' do let(:group) { create(:group) } let(:nested_group) { create(:group, parent: group) } - background do + before do gitlab_sign_in(user1) end - scenario 'show members from current group and parent', :nested_groups do + it 'show members from current group and parent', :nested_groups do group.add_developer(user1) nested_group.add_developer(user2) @@ -22,7 +22,7 @@ feature 'Groups > Members > List members' do expect(second_row.text).to include(user2.name) end - scenario 'show user once if member of both current group and parent', :nested_groups do + it 'show user once if member of both current group and parent', :nested_groups do group.add_developer(user1) nested_group.add_developer(user1) diff --git a/spec/features/groups/members/manage_members_spec.rb b/spec/features/groups/members/manage_members_spec.rb index 21f7b4999ad..0eda2c7f26d 100644 --- a/spec/features/groups/members/manage_members_spec.rb +++ b/spec/features/groups/members/manage_members_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' -feature 'Groups > Members > Manage members' do +describe 'Groups > Members > Manage members' do include Select2Helper let(:user1) { create(:user, name: 'John Doe') } let(:user2) { create(:user, name: 'Mary Jane') } let(:group) { create(:group) } - background do + before do sign_in(user1) end - scenario 'update user to owner level', :js do + it 'update user to owner level', :js do group.add_owner(user1) group.add_developer(user2) @@ -25,7 +25,7 @@ feature 'Groups > Members > Manage members' do end end - scenario 'add user to group', :js do + it 'add user to group', :js do group.add_owner(user1) visit group_group_members_path(group) @@ -38,7 +38,7 @@ feature 'Groups > Members > Manage members' do end end - scenario 'do not disclose email addresses', :js do + it 'do not disclose email addresses', :js do group.add_owner(user1) create(:user, email: 'undisclosed_email@gitlab.com', name: "Jane 'invisible' Doe") @@ -59,7 +59,7 @@ feature 'Groups > Members > Manage members' do expect(page).to have_content("Jane 'invisible' Doe") end - scenario 'remove user from group', :js do + it 'remove user from group', :js do group.add_owner(user1) group.add_developer(user2) @@ -75,7 +75,7 @@ feature 'Groups > Members > Manage members' do expect(group.users).not_to include(user2) end - scenario 'add yourself to group when already an owner', :js do + it 'add yourself to group when already an owner', :js do group.add_owner(user1) visit group_group_members_path(group) @@ -88,7 +88,7 @@ feature 'Groups > Members > Manage members' do end end - scenario 'invite user to group', :js do + it 'invite user to group', :js do group.add_owner(user1) visit group_group_members_path(group) @@ -102,7 +102,7 @@ feature 'Groups > Members > Manage members' do end end - scenario 'guest can not manage other users' do + it 'guest can not manage other users' do group.add_guest(user1) group.add_developer(user2) diff --git a/spec/features/groups/members/master_manages_access_requests_spec.rb b/spec/features/groups/members/master_manages_access_requests_spec.rb index 2fd6d1ec599..bd615c99412 100644 --- a/spec/features/groups/members/master_manages_access_requests_spec.rb +++ b/spec/features/groups/members/master_manages_access_requests_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -feature 'Groups > Members > Master manages access requests' do - it_behaves_like 'Master manages access requests' do +describe 'Groups > Members > Maintainer manages access requests' do + it_behaves_like 'Maintainer manages access requests' do let(:entity) { create(:group, :public, :access_requestable) } let(:members_page_path) { group_group_members_path(entity) } end diff --git a/spec/features/groups/members/request_access_spec.rb b/spec/features/groups/members/request_access_spec.rb index 10389a74703..94510f917a3 100644 --- a/spec/features/groups/members/request_access_spec.rb +++ b/spec/features/groups/members/request_access_spec.rb @@ -1,25 +1,25 @@ require 'spec_helper' -feature 'Groups > Members > Request access' do +describe 'Groups > Members > Request access' do let(:user) { create(:user) } let(:owner) { create(:user) } let(:group) { create(:group, :public, :access_requestable) } let!(:project) { create(:project, :private, namespace: group) } - background do + before do group.add_owner(owner) sign_in(user) visit group_path(group) end - scenario 'request access feature is disabled' do - group.update_attributes(request_access_enabled: false) + it 'request access feature is disabled' do + group.update(request_access_enabled: false) visit group_path(group) expect(page).not_to have_content 'Request Access' end - scenario 'user can request access to a group' do + it 'user can request access to a group' do perform_enqueued_jobs { click_link 'Request Access' } expect(ActionMailer::Base.deliveries.last.to).to eq [owner.notification_email] @@ -32,13 +32,13 @@ feature 'Groups > Members > Request access' do expect(page).not_to have_content 'Leave group' end - scenario 'user does not see private projects' do + it 'user does not see private projects' do perform_enqueued_jobs { click_link 'Request Access' } expect(page).not_to have_content project.name end - scenario 'user does not see group in the Dashboard > Groups page' do + it 'user does not see group in the Dashboard > Groups page' do perform_enqueued_jobs { click_link 'Request Access' } visit dashboard_groups_path @@ -46,7 +46,7 @@ feature 'Groups > Members > Request access' do expect(page).not_to have_content group.name end - scenario 'user is not listed in the group members page' do + it 'user is not listed in the group members page' do click_link 'Request Access' expect(group.requesters.exists?(user_id: user)).to be_truthy @@ -58,7 +58,7 @@ feature 'Groups > Members > Request access' do end end - scenario 'user can withdraw its request for access' do + it 'user can withdraw its request for access' do click_link 'Request Access' expect(group.requesters.exists?(user_id: user)).to be_truthy @@ -69,7 +69,7 @@ feature 'Groups > Members > Request access' do expect(page).to have_content 'Your access request to the group has been withdrawn.' end - scenario 'member does not see the request access button' do + it 'member does not see the request access button' do group.add_owner(user) visit group_path(group) diff --git a/spec/features/groups/members/sort_members_spec.rb b/spec/features/groups/members/sort_members_spec.rb index e175ad04f86..ee32f6d77fe 100644 --- a/spec/features/groups/members/sort_members_spec.rb +++ b/spec/features/groups/members/sort_members_spec.rb @@ -1,18 +1,18 @@ require 'spec_helper' -feature 'Groups > Members > Sort members' do +describe 'Groups > Members > Sort members' do let(:owner) { create(:user, name: 'John Doe') } let(:developer) { create(:user, name: 'Mary Jane', last_sign_in_at: 5.days.ago) } let(:group) { create(:group) } - background do + before do create(:group_member, :owner, user: owner, group: group, created_at: 5.days.ago) create(:group_member, :developer, user: developer, group: group, created_at: 3.days.ago) sign_in(owner) end - scenario 'sorts alphabetically by default' do + it 'sorts alphabetically by default' do visit_members_list(sort: nil) expect(first_member).to include(owner.name) @@ -20,7 +20,7 @@ feature 'Groups > Members > Sort members' do expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Name, ascending') end - scenario 'sorts by access level ascending' do + it 'sorts by access level ascending' do visit_members_list(sort: :access_level_asc) expect(first_member).to include(developer.name) @@ -28,7 +28,7 @@ feature 'Groups > Members > Sort members' do expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Access level, ascending') end - scenario 'sorts by access level descending' do + it 'sorts by access level descending' do visit_members_list(sort: :access_level_desc) expect(first_member).to include(owner.name) @@ -36,7 +36,7 @@ feature 'Groups > Members > Sort members' do expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Access level, descending') end - scenario 'sorts by last joined' do + it 'sorts by last joined' do visit_members_list(sort: :last_joined) expect(first_member).to include(developer.name) @@ -44,7 +44,7 @@ feature 'Groups > Members > Sort members' do expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Last joined') end - scenario 'sorts by oldest joined' do + it 'sorts by oldest joined' do visit_members_list(sort: :oldest_joined) expect(first_member).to include(owner.name) @@ -52,7 +52,7 @@ feature 'Groups > Members > Sort members' do expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Oldest joined') end - scenario 'sorts by name ascending' do + it 'sorts by name ascending' do visit_members_list(sort: :name_asc) expect(first_member).to include(owner.name) @@ -60,7 +60,7 @@ feature 'Groups > Members > Sort members' do expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Name, ascending') end - scenario 'sorts by name descending' do + it 'sorts by name descending' do visit_members_list(sort: :name_desc) expect(first_member).to include(developer.name) @@ -68,7 +68,7 @@ feature 'Groups > Members > Sort members' do expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Name, descending') end - scenario 'sorts by recent sign in', :clean_gitlab_redis_shared_state do + it 'sorts by recent sign in', :clean_gitlab_redis_shared_state do visit_members_list(sort: :recent_sign_in) expect(first_member).to include(owner.name) @@ -76,7 +76,7 @@ feature 'Groups > Members > Sort members' do expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Recent sign in') end - scenario 'sorts by oldest sign in', :clean_gitlab_redis_shared_state do + it 'sorts by oldest sign in', :clean_gitlab_redis_shared_state do visit_members_list(sort: :oldest_sign_in) expect(first_member).to include(developer.name) diff --git a/spec/features/groups/merge_requests_spec.rb b/spec/features/groups/merge_requests_spec.rb index 921a447f6ee..54a8016c157 100644 --- a/spec/features/groups/merge_requests_spec.rb +++ b/spec/features/groups/merge_requests_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Group merge requests page' do +describe 'Group merge requests page' do include FilteredSearchHelpers let(:path) { merge_requests_group_path(group) } diff --git a/spec/features/groups/milestone_spec.rb b/spec/features/groups/milestone_spec.rb index 2108d763028..80df0618a6a 100644 --- a/spec/features/groups/milestone_spec.rb +++ b/spec/features/groups/milestone_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' -feature 'Group milestones' do +describe 'Group milestones' do let(:group) { create(:group) } let!(:project) { create(:project_empty_repo, group: group) } - let(:user) { create(:group_member, :master, user: create(:user), group: group ).user } + let(:user) { create(:group_member, :maintainer, user: create(:user), group: group ).user } around do |example| Timecop.freeze { example.run } diff --git a/spec/features/groups/milestones_sorting_spec.rb b/spec/features/groups/milestones_sorting_spec.rb index a0fe40cf1d3..bc226ff41c1 100644 --- a/spec/features/groups/milestones_sorting_spec.rb +++ b/spec/features/groups/milestones_sorting_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Milestones sorting', :js do +describe 'Milestones sorting', :js do let(:group) { create(:group) } let!(:project) { create(:project_empty_repo, group: group) } let!(:other_project) { create(:project_empty_repo, group: group) } @@ -9,13 +9,13 @@ feature 'Milestones sorting', :js do let!(:project_milestone2) { create(:milestone, project: project, title: 'v2.0', due_date: 5.days.from_now) } let!(:other_project_milestone2) { create(:milestone, project: other_project, title: 'v2.0', due_date: 5.days.from_now) } let!(:group_milestone) { create(:milestone, group: group, title: 'v3.0', due_date: 7.days.from_now) } - let(:user) { create(:group_member, :master, user: create(:user), group: group ).user } + let(:user) { create(:group_member, :maintainer, user: create(:user), group: group ).user } before do sign_in(user) end - scenario 'visit group milestones and sort by due_date_asc' do + it 'visit group milestones and sort by due_date_asc' do visit group_milestones_path(group) expect(page).to have_button('Due soon') diff --git a/spec/features/groups/settings/group_badges_spec.rb b/spec/features/groups/settings/group_badges_spec.rb index a99da4a119b..070a4a31ffa 100644 --- a/spec/features/groups/settings/group_badges_spec.rb +++ b/spec/features/groups/settings/group_badges_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Group Badges' do +describe 'Group Badges' do include WaitForRequests let(:user) { create(:user) } diff --git a/spec/features/groups/share_lock_spec.rb b/spec/features/groups/share_lock_spec.rb index cefbc15e068..5bbe77019ca 100644 --- a/spec/features/groups/share_lock_spec.rb +++ b/spec/features/groups/share_lock_spec.rb @@ -1,19 +1,19 @@ require 'spec_helper' -feature 'Group share with group lock' do - given(:root_owner) { create(:user) } - given(:root_group) { create(:group) } +describe 'Group share with group lock' do + let(:root_owner) { create(:user) } + let(:root_group) { create(:group) } - background do + before do root_group.add_owner(root_owner) sign_in(root_owner) end context 'with a subgroup', :nested_groups do - given!(:subgroup) { create(:group, parent: root_group) } + let!(:subgroup) { create(:group, parent: root_group) } context 'when enabling the parent group share with group lock' do - scenario 'the subgroup share with group lock becomes enabled' do + it 'the subgroup share with group lock becomes enabled' do visit edit_group_path(root_group) enable_group_lock @@ -23,14 +23,14 @@ feature 'Group share with group lock' do end context 'when disabling the parent group share with group lock (which was already enabled)' do - background do + before do visit edit_group_path(root_group) enable_group_lock end context 'and the subgroup share with group lock is enabled' do - scenario 'the subgroup share with group lock does not change' do + it 'the subgroup share with group lock does not change' do visit edit_group_path(root_group) disable_group_lock @@ -40,13 +40,13 @@ feature 'Group share with group lock' do end context 'but the subgroup share with group lock is disabled' do - background do + before do visit edit_group_path(subgroup) disable_group_lock end - scenario 'the subgroup share with group lock does not change' do + it 'the subgroup share with group lock does not change' do visit edit_group_path(root_group) disable_group_lock diff --git a/spec/features/groups/show_spec.rb b/spec/features/groups/show_spec.rb index b7a7aa0e174..ac961e98a61 100644 --- a/spec/features/groups/show_spec.rb +++ b/spec/features/groups/show_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Group show page' do +describe 'Group show page' do let(:group) { create(:group) } let(:path) { group_path(group) } diff --git a/spec/features/groups/user_sees_users_dropdowns_in_issuables_list_spec.rb b/spec/features/groups/user_sees_users_dropdowns_in_issuables_list_spec.rb index 5ed4f3ad2bc..6d6f206d761 100644 --- a/spec/features/groups/user_sees_users_dropdowns_in_issuables_list_spec.rb +++ b/spec/features/groups/user_sees_users_dropdowns_in_issuables_list_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Groups > User sees users dropdowns in issuables list' do +describe 'Groups > User sees users dropdowns in issuables list' do let(:entity) { create(:group) } let(:user_in_dropdown) { create(:user) } let!(:user_not_in_dropdown) { create(:user) } diff --git a/spec/features/groups_spec.rb b/spec/features/groups_spec.rb index 236768b5d7f..e62bd6f8187 100644 --- a/spec/features/groups_spec.rb +++ b/spec/features/groups_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Group' do +describe 'Group' do before do sign_in(create(:admin)) end @@ -154,6 +154,12 @@ feature 'Group' do end end + it 'focuses confirmation field on remove group' do + click_button('Remove group') + + expect(page).to have_selector '#confirm_name_input:focus' + end + it 'removes group' do expect { remove_with_confirm('Remove group', group.path) }.to change {Group.count}.by(-1) expect(group.members.all.count).to be_zero diff --git a/spec/features/ics/dashboard_issues_spec.rb b/spec/features/ics/dashboard_issues_spec.rb index a4d05c25a90..ea714934ae7 100644 --- a/spec/features/ics/dashboard_issues_spec.rb +++ b/spec/features/ics/dashboard_issues_spec.rb @@ -8,7 +8,7 @@ describe 'Dashboard Issues Calendar Feed' do let(:milestone) { create(:milestone, project_id: project.id, title: 'v1.0') } before do - project.add_master(user) + project.add_maintainer(user) end context 'when authenticated' do diff --git a/spec/features/ide_spec.rb b/spec/features/ide_spec.rb index b3f24c2966d..65989c36c1e 100644 --- a/spec/features/ide_spec.rb +++ b/spec/features/ide_spec.rb @@ -8,7 +8,7 @@ describe 'IDE', :js do let(:subgroup_project) { create(:project, :repository, namespace: subgroup) } before do - subgroup_project.add_master(user) + subgroup_project.add_maintainer(user) sign_in(user) visit project_path(subgroup_project) diff --git a/spec/features/import/manifest_import_spec.rb b/spec/features/import/manifest_import_spec.rb new file mode 100644 index 00000000000..e381d073804 --- /dev/null +++ b/spec/features/import/manifest_import_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' + +describe 'Import multiple repositories by uploading a manifest file', :js, :postgresql do + include Select2Helper + + let(:user) { create(:admin) } + let(:group) { create(:group) } + + before do + sign_in(user) + + group.add_owner(user) + end + + it 'parses manifest file and list repositories' do + visit new_import_manifest_path + + attach_file('manifest', Rails.root.join('spec/fixtures/aosp_manifest.xml')) + click_on 'List available repositories' + + expect(page).to have_button('Import all repositories') + expect(page).to have_content('https://android-review.googlesource.com/platform/build/blueprint') + end + + it 'imports succesfully imports a project' do + visit new_import_manifest_path + + attach_file('manifest', Rails.root.join('spec/fixtures/aosp_manifest.xml')) + click_on 'List available repositories' + + page.within(first_row) do + click_on 'Import' + + expect(page).to have_content 'Done' + expect(page).to have_content("#{group.full_path}/build/make") + end + end + + it 'renders an error if invalid file was provided' do + visit new_import_manifest_path + + attach_file('manifest', Rails.root.join('spec/fixtures/banana_sample.gif')) + click_on 'List available repositories' + + expect(page).to have_content 'The uploaded file is not a valid XML file.' + end + + def first_row + page.all('table.import-jobs tbody tr')[0] + end +end diff --git a/spec/features/invites_spec.rb b/spec/features/invites_spec.rb index a986ddc4abc..9e1a12a9c2a 100644 --- a/spec/features/invites_spec.rb +++ b/spec/features/invites_spec.rb @@ -8,7 +8,7 @@ describe 'Invites' do let(:group_invite) { group.group_members.invite.last } before do - project.add_master(owner) + project.add_maintainer(owner) group.add_user(owner, Gitlab::Access::OWNER) group.add_developer('user@example.com', owner) group_invite.generate_invite_token! diff --git a/spec/features/issuables/close_reopen_report_toggle_spec.rb b/spec/features/issuables/close_reopen_report_toggle_spec.rb index 3df77a104e8..de6f5fe1560 100644 --- a/spec/features/issuables/close_reopen_report_toggle_spec.rb +++ b/spec/features/issuables/close_reopen_report_toggle_spec.rb @@ -46,7 +46,7 @@ describe 'Issuables Close/Reopen/Report toggle' do let(:issuable) { create(:issue, project: project) } before do - project.add_master(user) + project.add_maintainer(user) login_as user end @@ -83,7 +83,7 @@ describe 'Issuables Close/Reopen/Report toggle' do let(:issuable) { create(:merge_request, source_project: project) } before do - project.add_master(user) + project.add_maintainer(user) login_as user end diff --git a/spec/features/issuables/shortcuts_issuable_spec.rb b/spec/features/issuables/shortcuts_issuable_spec.rb index 0a19086ffbd..a0ae6720a9f 100644 --- a/spec/features/issuables/shortcuts_issuable_spec.rb +++ b/spec/features/issuables/shortcuts_issuable_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Blob shortcuts', :js do +describe 'Blob shortcuts', :js do let(:user) { create(:user) } let(:project) { create(:project, :public, :repository) } let(:issue) { create(:issue, project: project, author: user) } diff --git a/spec/features/issues/award_emoji_spec.rb b/spec/features/issues/award_emoji_spec.rb index 1131e1711bf..bf60b18873c 100644 --- a/spec/features/issues/award_emoji_spec.rb +++ b/spec/features/issues/award_emoji_spec.rb @@ -11,7 +11,7 @@ describe 'Awards Emoji' do context 'authorized user' do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/issues/award_spec.rb b/spec/features/issues/award_spec.rb index ddb69d414da..e53a4ce49c7 100644 --- a/spec/features/issues/award_spec.rb +++ b/spec/features/issues/award_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Issue awards', :js do +describe 'Issue awards', :js do let(:user) { create(:user) } let(:project) { create(:project, :public) } let(:issue) { create(:issue, project: project) } diff --git a/spec/features/issues/bulk_assignment_labels_spec.rb b/spec/features/issues/bulk_assignment_labels_spec.rb index cf283119f36..06cb2e36334 100644 --- a/spec/features/issues/bulk_assignment_labels_spec.rb +++ b/spec/features/issues/bulk_assignment_labels_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Issues > Labels bulk assignment' do +describe 'Issues > Labels bulk assignment' do let(:user) { create(:user) } let!(:project) { create(:project) } let!(:issue1) { create(:issue, project: project, title: "Issue 1") } @@ -11,7 +11,7 @@ feature 'Issues > Labels bulk assignment' do context 'as an allowed user', :js do before do - project.add_master(user) + project.add_maintainer(user) sign_in user end diff --git a/spec/features/issues/create_issue_for_discussions_in_merge_request_spec.rb b/spec/features/issues/create_issue_for_discussions_in_merge_request_spec.rb index 52962002c33..ada57285abf 100644 --- a/spec/features/issues/create_issue_for_discussions_in_merge_request_spec.rb +++ b/spec/features/issues/create_issue_for_discussions_in_merge_request_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Resolving all open discussions in a merge request from an issue', :js do +describe 'Resolving all open discussions in a merge request from an issue', :js do let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:merge_request) { create(:merge_request, source_project: project) } @@ -14,7 +14,7 @@ feature 'Resolving all open discussions in a merge request from an issue', :js d describe 'as a user with access to the project' do before do - project.add_master(user) + project.add_maintainer(user) sign_in user visit project_merge_request_path(project, merge_request) end diff --git a/spec/features/issues/create_issue_for_single_discussion_in_merge_request_spec.rb b/spec/features/issues/create_issue_for_single_discussion_in_merge_request_spec.rb index 9170f9295f0..b20730bdb22 100644 --- a/spec/features/issues/create_issue_for_single_discussion_in_merge_request_spec.rb +++ b/spec/features/issues/create_issue_for_single_discussion_in_merge_request_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Resolve an open discussion in a merge request by creating an issue', :js do +describe 'Resolve an open discussion in a merge request by creating an issue', :js do let(:user) { create(:user) } let(:project) { create(:project, :repository, only_allow_merge_if_all_discussions_are_resolved: true) } let(:merge_request) { create(:merge_request, source_project: project) } @@ -14,7 +14,7 @@ feature 'Resolve an open discussion in a merge request by creating an issue', :j describe 'As a user with access to the project' do before do - project.add_master(user) + project.add_maintainer(user) sign_in user visit project_merge_request_path(project, merge_request) end diff --git a/spec/features/issues/filtered_search/dropdown_assignee_spec.rb b/spec/features/issues/filtered_search/dropdown_assignee_spec.rb index c8115db9212..d011d2545bb 100644 --- a/spec/features/issues/filtered_search/dropdown_assignee_spec.rb +++ b/spec/features/issues/filtered_search/dropdown_assignee_spec.rb @@ -20,9 +20,9 @@ describe 'Dropdown assignee', :js do end before do - project.add_master(user) - project.add_master(user_john) - project.add_master(user_jacob) + project.add_maintainer(user) + project.add_maintainer(user_john) + project.add_maintainer(user_jacob) sign_in(user) create(:issue, project: project) @@ -224,7 +224,7 @@ describe 'Dropdown assignee', :js do expect(initial_size).to be > 0 new_user = create(:user) - project.add_master(new_user) + project.add_maintainer(new_user) find('.filtered-search-box .clear-search').click input_filtered_search('assignee:', submit: false, extra_space: false) diff --git a/spec/features/issues/filtered_search/dropdown_author_spec.rb b/spec/features/issues/filtered_search/dropdown_author_spec.rb index 70b4f11410d..50d819a6161 100644 --- a/spec/features/issues/filtered_search/dropdown_author_spec.rb +++ b/spec/features/issues/filtered_search/dropdown_author_spec.rb @@ -28,9 +28,9 @@ describe 'Dropdown author', :js do end before do - project.add_master(user) - project.add_master(user_john) - project.add_master(user_jacob) + project.add_maintainer(user) + project.add_maintainer(user_john) + project.add_maintainer(user_jacob) sign_in(user) create(:issue, project: project) @@ -195,7 +195,7 @@ describe 'Dropdown author', :js do expect(initial_size).to be > 0 new_user = create(:user) - project.add_master(new_user) + project.add_maintainer(new_user) find('.filtered-search-box .clear-search').click filtered_search.set('author') send_keys_to_filtered_search(':') diff --git a/spec/features/issues/filtered_search/dropdown_emoji_spec.rb b/spec/features/issues/filtered_search/dropdown_emoji_spec.rb index 436625a6f7b..be229e8aa7d 100644 --- a/spec/features/issues/filtered_search/dropdown_emoji_spec.rb +++ b/spec/features/issues/filtered_search/dropdown_emoji_spec.rb @@ -28,7 +28,7 @@ describe 'Dropdown emoji', :js do end before do - project.add_master(user) + project.add_maintainer(user) create_list(:award_emoji, 2, user: user, name: 'thumbsup') create_list(:award_emoji, 1, user: user, name: 'thumbsdown') create_list(:award_emoji, 3, user: user, name: 'star') diff --git a/spec/features/issues/filtered_search/dropdown_hint_spec.rb b/spec/features/issues/filtered_search/dropdown_hint_spec.rb index ef40dddfd3a..b99c5a7f4e3 100644 --- a/spec/features/issues/filtered_search/dropdown_hint_spec.rb +++ b/spec/features/issues/filtered_search/dropdown_hint_spec.rb @@ -13,7 +13,7 @@ describe 'Dropdown hint', :js do end before do - project.add_master(user) + project.add_maintainer(user) create(:issue, project: project) end diff --git a/spec/features/issues/filtered_search/dropdown_label_spec.rb b/spec/features/issues/filtered_search/dropdown_label_spec.rb index 18cdb199c70..ca5d506ab04 100644 --- a/spec/features/issues/filtered_search/dropdown_label_spec.rb +++ b/spec/features/issues/filtered_search/dropdown_label_spec.rb @@ -33,7 +33,7 @@ describe 'Dropdown label', :js do end before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) create(:issue, project: project) diff --git a/spec/features/issues/filtered_search/dropdown_milestone_spec.rb b/spec/features/issues/filtered_search/dropdown_milestone_spec.rb index 94710c2f71f..f76d30056da 100644 --- a/spec/features/issues/filtered_search/dropdown_milestone_spec.rb +++ b/spec/features/issues/filtered_search/dropdown_milestone_spec.rb @@ -29,7 +29,7 @@ describe 'Dropdown milestone', :js do end before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) create(:issue, project: project) diff --git a/spec/features/issues/filtered_search/filter_issues_spec.rb b/spec/features/issues/filtered_search/filter_issues_spec.rb index 8dca81a8627..d4949de3f27 100644 --- a/spec/features/issues/filtered_search/filter_issues_spec.rb +++ b/spec/features/issues/filtered_search/filter_issues_spec.rb @@ -24,7 +24,7 @@ describe 'Filter issues', :js do end before do - project.add_master(user) + project.add_maintainer(user) create(:issue, project: project, author: user2, title: "Bug report 1") create(:issue, project: project, author: user2, title: "Bug report 2") diff --git a/spec/features/issues/filtered_search/search_bar_spec.rb b/spec/features/issues/filtered_search/search_bar_spec.rb index 268590da599..8abab3f35d6 100644 --- a/spec/features/issues/filtered_search/search_bar_spec.rb +++ b/spec/features/issues/filtered_search/search_bar_spec.rb @@ -8,7 +8,7 @@ describe 'Search bar', :js do let(:filtered_search) { find('.filtered-search') } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) create(:issue, project: project) diff --git a/spec/features/issues/filtered_search/visual_tokens_spec.rb b/spec/features/issues/filtered_search/visual_tokens_spec.rb index 0ae70c855db..6ac7ccd00f7 100644 --- a/spec/features/issues/filtered_search/visual_tokens_spec.rb +++ b/spec/features/issues/filtered_search/visual_tokens_spec.rb @@ -22,8 +22,8 @@ describe 'Visual tokens', :js do end before do - project.add_user(user, :master) - project.add_user(user_rock, :master) + project.add_user(user, :maintainer) + project.add_user(user_rock, :maintainer) sign_in(user) create(:issue, project: project) diff --git a/spec/features/issues/form_spec.rb b/spec/features/issues/form_spec.rb index 2cb3ae08b0e..1456a2f0375 100644 --- a/spec/features/issues/form_spec.rb +++ b/spec/features/issues/form_spec.rb @@ -13,8 +13,8 @@ describe 'New/edit issue', :js do let!(:issue) { create(:issue, project: project, assignees: [user], milestone: milestone) } before do - project.add_master(user) - project.add_master(user2) + project.add_maintainer(user) + project.add_maintainer(user2) sign_in(user) end @@ -321,7 +321,7 @@ describe 'New/edit issue', :js do let(:sub_group_project) { create(:project, group: nested_group_1) } before do - sub_group_project.add_master(user) + sub_group_project.add_maintainer(user) visit new_project_issue_path(sub_group_project) end diff --git a/spec/features/issues/gfm_autocomplete_spec.rb b/spec/features/issues/gfm_autocomplete_spec.rb index f2624f55c86..98e37d8011a 100644 --- a/spec/features/issues/gfm_autocomplete_spec.rb +++ b/spec/features/issues/gfm_autocomplete_spec.rb @@ -1,13 +1,13 @@ require 'rails_helper' -feature 'GFM autocomplete', :js do +describe 'GFM autocomplete', :js do let(:user) { create(:user, name: '💃speciąl someone💃', username: 'someone.special') } let(:project) { create(:project) } let(:label) { create(:label, project: project, title: 'special+') } let(:issue) { create(:issue, project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_issue_path(project, issue) diff --git a/spec/features/issues/issue_detail_spec.rb b/spec/features/issues/issue_detail_spec.rb index babb0285590..088ab114df3 100644 --- a/spec/features/issues/issue_detail_spec.rb +++ b/spec/features/issues/issue_detail_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Issue Detail', :js do +describe 'Issue Detail', :js do let(:user) { create(:user) } let(:project) { create(:project, :public) } let(:issue) { create(:issue, project: project, author: user) } diff --git a/spec/features/issues/issue_sidebar_spec.rb b/spec/features/issues/issue_sidebar_spec.rb index 830c794376d..3050f23c130 100644 --- a/spec/features/issues/issue_sidebar_spec.rb +++ b/spec/features/issues/issue_sidebar_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Issue Sidebar' do +describe 'Issue Sidebar' do include MobileHelpers let(:group) { create(:group, :nested) } @@ -112,7 +112,7 @@ feature 'Issue Sidebar' do context 'editing issue labels', :js do before do - issue.update_attributes(labels: [label]) + issue.update(labels: [label]) page.within('.block.labels') do find('.edit-link').click end diff --git a/spec/features/issues/markdown_toolbar_spec.rb b/spec/features/issues/markdown_toolbar_spec.rb index fee8fd9b365..042ecdb172a 100644 --- a/spec/features/issues/markdown_toolbar_spec.rb +++ b/spec/features/issues/markdown_toolbar_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Issue markdown toolbar', :js do +describe 'Issue markdown toolbar', :js do let(:project) { create(:project, :public) } let(:issue) { create(:issue, project: project) } let(:user) { create(:user) } diff --git a/spec/features/issues/move_spec.rb b/spec/features/issues/move_spec.rb index 3c01ff345fc..2abc50b04e4 100644 --- a/spec/features/issues/move_spec.rb +++ b/spec/features/issues/move_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'issue move to another project' do +describe 'issue move to another project' do let(:user) { create(:user) } let(:old_project) { create(:project, :repository) } let(:text) { 'Some issue description' } @@ -9,16 +9,18 @@ feature 'issue move to another project' do create(:issue, description: text, project: old_project, author: user) end - background { sign_in(user) } + before do + sign_in(user) + end context 'user does not have permission to move issue' do - background do + before do old_project.add_guest(user) visit issue_path(issue) end - scenario 'moving issue to another project not allowed' do + it 'moving issue to another project not allowed' do expect(page).to have_no_selector('.js-sidebar-move-issue-block') end end @@ -30,14 +32,14 @@ feature 'issue move to another project' do let(:text) { "Text with #{mr.to_reference}" } let(:cross_reference) { old_project.to_reference(new_project) } - background do + before do old_project.add_reporter(user) new_project.add_reporter(user) visit issue_path(issue) end - scenario 'moving issue to another project', :js do + it 'moving issue to another project', :js do find('.js-move-issue').click wait_for_requests all('.js-move-issue-dropdown-item')[0].click @@ -49,7 +51,7 @@ feature 'issue move to another project' do expect(page.current_path).to include project_path(new_project) end - scenario 'searching project dropdown', :js do + it 'searching project dropdown', :js do new_project_search.add_reporter(user) find('.js-move-issue').click @@ -66,9 +68,11 @@ feature 'issue move to another project' do context 'user does not have permission to move the issue to a project', :js do let!(:private_project) { create(:project, :private) } let(:another_project) { create(:project) } - background { another_project.add_guest(user) } + before do + another_project.add_guest(user) + end - scenario 'browsing projects in projects select' do + it 'browsing projects in projects select' do find('.js-move-issue').click wait_for_requests @@ -84,7 +88,7 @@ feature 'issue move to another project' do create(:issue, project: old_project, author: user, moved_to: new_issue) end - scenario 'user wants to move issue that has already been moved' do + it 'user wants to move issue that has already been moved' do expect(page).to have_no_selector('#move_to_project_id') end end diff --git a/spec/features/issues/note_polling_spec.rb b/spec/features/issues/note_polling_spec.rb index 793572851da..3cd7ce6dada 100644 --- a/spec/features/issues/note_polling_spec.rb +++ b/spec/features/issues/note_polling_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Issue notes polling', :js do +describe 'Issue notes polling', :js do include NoteInteractionHelpers let(:project) { create(:project, :public) } diff --git a/spec/features/issues/spam_issues_spec.rb b/spec/features/issues/spam_issues_spec.rb index 73022afbda2..7cce45ff206 100644 --- a/spec/features/issues/spam_issues_spec.rb +++ b/spec/features/issues/spam_issues_spec.rb @@ -17,7 +17,7 @@ describe 'New issue', :js do recaptcha_private_key: 'test private key' ) - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/issues/todo_spec.rb b/spec/features/issues/todo_spec.rb index 4a44ec302fc..0114178b9be 100644 --- a/spec/features/issues/todo_spec.rb +++ b/spec/features/issues/todo_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -feature 'Manually create a todo item from issue', :js do +describe 'Manually create a todo item from issue', :js do let!(:project) { create(:project) } let!(:issue) { create(:issue, project: project) } let!(:user) { create(:user)} before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_issue_path(project, issue) end diff --git a/spec/features/issues/update_issues_spec.rb b/spec/features/issues/update_issues_spec.rb index 7d6edc171f8..845a7c5fc42 100644 --- a/spec/features/issues/update_issues_spec.rb +++ b/spec/features/issues/update_issues_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -feature 'Multiple issue updating from issues#index', :js do +describe 'Multiple issue updating from issues#index', :js do let!(:project) { create(:project) } let!(:issue) { create(:issue, project: project) } let!(:user) { create(:user)} before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/issues/user_uses_slash_commands_spec.rb b/spec/features/issues/user_uses_slash_commands_spec.rb index 17818beb947..5926e442f24 100644 --- a/spec/features/issues/user_uses_slash_commands_spec.rb +++ b/spec/features/issues/user_uses_slash_commands_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Issues > User uses quick actions', :js do +describe 'Issues > User uses quick actions', :js do include Spec::Support::Helpers::Features::NotesHelpers it_behaves_like 'issuable record that supports quick actions in its description and notes', :issue do @@ -12,7 +12,7 @@ feature 'Issues > User uses quick actions', :js do let(:project) { create(:project, :public) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_issue_path(project, issue) end @@ -196,7 +196,7 @@ feature 'Issues > User uses quick actions', :js do let(:target_project) { create(:project, :public) } before do - target_project.add_master(user) + target_project.add_maintainer(user) gitlab_sign_out sign_in(user) visit project_issue_path(project, issue) @@ -258,7 +258,7 @@ feature 'Issues > User uses quick actions', :js do let(:wontfix_target) { create(:label, project: target_project, title: 'wontfix') } before do - target_project.add_master(user) + target_project.add_maintainer(user) gitlab_sign_out sign_in(user) visit project_issue_path(project, issue) diff --git a/spec/features/issues_spec.rb b/spec/features/issues_spec.rb index c6dcd97631d..4d9b8a10e04 100644 --- a/spec/features/issues_spec.rb +++ b/spec/features/issues_spec.rb @@ -398,7 +398,7 @@ describe 'Issues' do before do stub_incoming_email_setting(enabled: true, address: "p+%{key}@gl.ab") - project1.add_master(user) + project1.add_maintainer(user) visit namespace_project_issues_path(user.namespace, project1) end diff --git a/spec/features/labels_hierarchy_spec.rb b/spec/features/labels_hierarchy_spec.rb index 5573148f8bc..6f917f522bc 100644 --- a/spec/features/labels_hierarchy_spec.rb +++ b/spec/features/labels_hierarchy_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Labels Hierarchy', :js, :nested_groups do +describe 'Labels Hierarchy', :js, :nested_groups do include FilteredSearchHelpers let!(:user) { create(:user) } diff --git a/spec/features/markdown/gitlab_flavored_markdown_spec.rb b/spec/features/markdown/gitlab_flavored_markdown_spec.rb index 3c2186b3598..6997ca48427 100644 --- a/spec/features/markdown/gitlab_flavored_markdown_spec.rb +++ b/spec/features/markdown/gitlab_flavored_markdown_spec.rb @@ -6,7 +6,7 @@ describe "GitLab Flavored Markdown" do let(:issue) { create(:issue, project: project) } let(:fred) do create(:user, name: 'fred') do |user| - project.add_master(user) + project.add_maintainer(user) end end diff --git a/spec/features/merge_request/maintainer_edits_fork_spec.rb b/spec/features/merge_request/maintainer_edits_fork_spec.rb index 1808d0c0a0c..7839b97122c 100644 --- a/spec/features/merge_request/maintainer_edits_fork_spec.rb +++ b/spec/features/merge_request/maintainer_edits_fork_spec.rb @@ -18,7 +18,7 @@ describe 'a maintainer edits files on a source-branch of an MR from a fork', :js end before do - target_project.add_master(user) + target_project.add_maintainer(user) sign_in(user) visit project_merge_request_path(target_project, merge_request) diff --git a/spec/features/merge_request/user_allows_commits_from_memebers_who_can_merge_spec.rb b/spec/features/merge_request/user_allows_commits_from_memebers_who_can_merge_spec.rb index 0af37d76539..0ccab5b2fac 100644 --- a/spec/features/merge_request/user_allows_commits_from_memebers_who_can_merge_spec.rb +++ b/spec/features/merge_request/user_allows_commits_from_memebers_who_can_merge_spec.rb @@ -71,7 +71,7 @@ describe 'create a merge request, allowing commits from members who can merge to end before do - target_project.add_master(member) + target_project.add_maintainer(member) sign_in(member) end diff --git a/spec/features/merge_request/user_cherry_picks_spec.rb b/spec/features/merge_request/user_cherry_picks_spec.rb index 61d1bdaa95a..c6ec3f08cc5 100644 --- a/spec/features/merge_request/user_cherry_picks_spec.rb +++ b/spec/features/merge_request/user_cherry_picks_spec.rb @@ -7,7 +7,7 @@ describe 'Merge request > User cherry-picks', :js do let(:merge_request) { create(:merge_request_with_diffs, source_project: project, author: user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/merge_request/user_creates_image_diff_notes_spec.rb b/spec/features/merge_request/user_creates_image_diff_notes_spec.rb index 728e89db400..f0d38dc6a0c 100644 --- a/spec/features/merge_request/user_creates_image_diff_notes_spec.rb +++ b/spec/features/merge_request/user_creates_image_diff_notes_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Merge request > User creates image diff notes', :js do +describe 'Merge request > User creates image diff notes', :js do include NoteInteractionHelpers let(:project) { create(:project, :public, :repository) } diff --git a/spec/features/merge_request/user_customizes_merge_commit_message_spec.rb b/spec/features/merge_request/user_customizes_merge_commit_message_spec.rb index e1e70b6d260..8d2d4279d3c 100644 --- a/spec/features/merge_request/user_customizes_merge_commit_message_spec.rb +++ b/spec/features/merge_request/user_customizes_merge_commit_message_spec.rb @@ -32,7 +32,7 @@ describe 'Merge request < User customizes merge commit message', :js do end before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_merge_request_path(project, merge_request) end diff --git a/spec/features/merge_request/user_merges_immediately_spec.rb b/spec/features/merge_request/user_merges_immediately_spec.rb index b16fc9bfc89..ea61f9675bc 100644 --- a/spec/features/merge_request/user_merges_immediately_spec.rb +++ b/spec/features/merge_request/user_merges_immediately_spec.rb @@ -19,7 +19,7 @@ describe 'Merge requests > User merges immediately', :js do context 'when there is active pipeline for merge request' do before do create(:ci_build, pipeline: pipeline) - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_merge_request_path(project, merge_request) end diff --git a/spec/features/merge_request/user_merges_only_if_pipeline_succeeds_spec.rb b/spec/features/merge_request/user_merges_only_if_pipeline_succeeds_spec.rb index a045791f6b4..8372b61f872 100644 --- a/spec/features/merge_request/user_merges_only_if_pipeline_succeeds_spec.rb +++ b/spec/features/merge_request/user_merges_only_if_pipeline_succeeds_spec.rb @@ -5,7 +5,7 @@ describe 'Merge request > User merges only if pipeline succeeds', :js do let(:project) { merge_request.target_project } before do - project.add_master(merge_request.author) + project.add_maintainer(merge_request.author) sign_in(merge_request.author) end diff --git a/spec/features/merge_request/user_merges_when_pipeline_succeeds_spec.rb b/spec/features/merge_request/user_merges_when_pipeline_succeeds_spec.rb index db92a3504f3..53ed5d78598 100644 --- a/spec/features/merge_request/user_merges_when_pipeline_succeeds_spec.rb +++ b/spec/features/merge_request/user_merges_when_pipeline_succeeds_spec.rb @@ -17,7 +17,7 @@ describe 'Merge request > User merges when pipeline succeeds', :js do end before do - project.add_master(user) + project.add_maintainer(user) end context 'when there is active pipeline for merge request' do diff --git a/spec/features/merge_request/user_posts_diff_notes_spec.rb b/spec/features/merge_request/user_posts_diff_notes_spec.rb index 13cc5f256eb..02d19db3828 100644 --- a/spec/features/merge_request/user_posts_diff_notes_spec.rb +++ b/spec/features/merge_request/user_posts_diff_notes_spec.rb @@ -198,7 +198,7 @@ describe 'Merge request > User posts diff notes', :js do context 'when the MR only supports legacy diff notes' do before do - merge_request.merge_request_diff.update_attributes(start_commit_sha: nil) + merge_request.merge_request_diff.update(start_commit_sha: nil) visit diffs_project_merge_request_path(project, merge_request, view: 'inline') end diff --git a/spec/features/merge_request/user_posts_notes_spec.rb b/spec/features/merge_request/user_posts_notes_spec.rb index fa819cbc385..260c5f9c28b 100644 --- a/spec/features/merge_request/user_posts_notes_spec.rb +++ b/spec/features/merge_request/user_posts_notes_spec.rb @@ -14,7 +14,7 @@ describe 'Merge request > User posts notes', :js do end before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_merge_request_path(project, merge_request) end diff --git a/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb b/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb index a0b9d6cb059..bf4d5396df9 100644 --- a/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb +++ b/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb @@ -19,7 +19,7 @@ describe 'Merge request > User resolves diff notes and discussions', :js do context 'no discussions' do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) note.destroy visit_merge_request @@ -33,7 +33,7 @@ describe 'Merge request > User resolves diff notes and discussions', :js do context 'as authorized user' do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit_merge_request end diff --git a/spec/features/merge_request/user_resolves_outdated_diff_discussions_spec.rb b/spec/features/merge_request/user_resolves_outdated_diff_discussions_spec.rb index fdf9a84e997..777464ef841 100644 --- a/spec/features/merge_request/user_resolves_outdated_diff_discussions_spec.rb +++ b/spec/features/merge_request/user_resolves_outdated_diff_discussions_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Merge request > User resolves outdated diff discussions', :js do +describe 'Merge request > User resolves outdated diff discussions', :js do let(:project) { create(:project, :repository, :public) } let(:merge_request) do diff --git a/spec/features/merge_request/user_sees_avatar_on_diff_notes_spec.rb b/spec/features/merge_request/user_sees_avatar_on_diff_notes_spec.rb index 0a8296bd722..428eb414274 100644 --- a/spec/features/merge_request/user_sees_avatar_on_diff_notes_spec.rb +++ b/spec/features/merge_request/user_sees_avatar_on_diff_notes_spec.rb @@ -19,7 +19,7 @@ describe 'Merge request > User sees avatars on diff notes', :js do let!(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, position: position) } before do - project.add_master(user) + project.add_maintainer(user) sign_in user set_cookie('sidebar_collapsed', 'true') diff --git a/spec/features/merge_request/user_sees_closing_issues_message_spec.rb b/spec/features/merge_request/user_sees_closing_issues_message_spec.rb index 726f35557a7..d7c784b14c5 100644 --- a/spec/features/merge_request/user_sees_closing_issues_message_spec.rb +++ b/spec/features/merge_request/user_sees_closing_issues_message_spec.rb @@ -18,7 +18,7 @@ describe 'Merge request > User sees closing issues message', :js do let(:merge_request_title) { 'Merge Request Title' } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_merge_request_path(project, merge_request) wait_for_requests diff --git a/spec/features/merge_request/user_sees_deleted_target_branch_spec.rb b/spec/features/merge_request/user_sees_deleted_target_branch_spec.rb index 01115318370..46c21a2b155 100644 --- a/spec/features/merge_request/user_sees_deleted_target_branch_spec.rb +++ b/spec/features/merge_request/user_sees_deleted_target_branch_spec.rb @@ -6,7 +6,7 @@ describe 'Merge request > User sees deleted target branch', :js do let(:user) { project.creator } before do - project.add_master(user) + project.add_maintainer(user) DeleteBranchService.new(project, user).execute('feature') sign_in(user) visit project_merge_request_path(project, merge_request) diff --git a/spec/features/merge_request/user_sees_discussions_spec.rb b/spec/features/merge_request/user_sees_discussions_spec.rb index 10390bd5864..7b8c3bacfe2 100644 --- a/spec/features/merge_request/user_sees_discussions_spec.rb +++ b/spec/features/merge_request/user_sees_discussions_spec.rb @@ -6,7 +6,7 @@ describe 'Merge request > User sees discussions', :js do let(:merge_request) { create(:merge_request, source_project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/merge_request/user_sees_empty_state_spec.rb b/spec/features/merge_request/user_sees_empty_state_spec.rb index a939c7e9001..482f31b02d4 100644 --- a/spec/features/merge_request/user_sees_empty_state_spec.rb +++ b/spec/features/merge_request/user_sees_empty_state_spec.rb @@ -5,7 +5,7 @@ describe 'Merge request > User sees empty state' do let(:user) { project.creator } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/merge_request/user_sees_merge_button_depending_on_unresolved_discussions_spec.rb b/spec/features/merge_request/user_sees_merge_button_depending_on_unresolved_discussions_spec.rb index 85df43df38e..f6b771facf8 100644 --- a/spec/features/merge_request/user_sees_merge_button_depending_on_unresolved_discussions_spec.rb +++ b/spec/features/merge_request/user_sees_merge_button_depending_on_unresolved_discussions_spec.rb @@ -6,7 +6,7 @@ describe 'Merge request > User sees merge button depending on unresolved discuss let!(:merge_request) { create(:merge_request_with_diff_notes, source_project: project, author: user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/merge_request/user_sees_merge_widget_spec.rb b/spec/features/merge_request/user_sees_merge_widget_spec.rb index 51a65407aec..b6b3844f2ae 100644 --- a/spec/features/merge_request/user_sees_merge_widget_spec.rb +++ b/spec/features/merge_request/user_sees_merge_widget_spec.rb @@ -10,8 +10,8 @@ describe 'Merge request > User sees merge widget', :js do let(:merge_request_in_only_mwps_project) { create(:merge_request, source_project: project_only_mwps) } before do - project.add_master(user) - project_only_mwps.add_master(user) + project.add_maintainer(user) + project_only_mwps.add_maintainer(user) sign_in(user) end @@ -275,7 +275,7 @@ describe 'Merge request > User sees merge widget', :js do let(:user2) { create(:user) } before do - project.add_master(user2) + project.add_maintainer(user2) sign_out(:user) sign_in(user2) merge_request.update(target_project: fork_project) diff --git a/spec/features/merge_request/user_sees_pipelines_spec.rb b/spec/features/merge_request/user_sees_pipelines_spec.rb index a42c016392b..45cccbee63e 100644 --- a/spec/features/merge_request/user_sees_pipelines_spec.rb +++ b/spec/features/merge_request/user_sees_pipelines_spec.rb @@ -7,7 +7,7 @@ describe 'Merge request > User sees pipelines', :js do let(:user) { project.creator } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -70,7 +70,7 @@ describe 'Merge request > User sees pipelines', :js do end before do - project.add_master(user) + project.add_maintainer(user) sign_in user end diff --git a/spec/features/merge_request/user_sees_versions_spec.rb b/spec/features/merge_request/user_sees_versions_spec.rb index 11e0806ba62..f42b4dcbb47 100644 --- a/spec/features/merge_request/user_sees_versions_spec.rb +++ b/spec/features/merge_request/user_sees_versions_spec.rb @@ -10,7 +10,7 @@ describe 'Merge request > User sees versions', :js do let!(:params) { {} } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit diffs_project_merge_request_path(project, merge_request, params) end diff --git a/spec/features/merge_request/user_sees_wip_help_message_spec.rb b/spec/features/merge_request/user_sees_wip_help_message_spec.rb index bc25243244e..92cc73ddf1f 100644 --- a/spec/features/merge_request/user_sees_wip_help_message_spec.rb +++ b/spec/features/merge_request/user_sees_wip_help_message_spec.rb @@ -5,7 +5,7 @@ describe 'Merge request > User sees WIP help message' do let(:user) { project.creator } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/merge_request/user_selects_branches_for_new_mr_spec.rb b/spec/features/merge_request/user_selects_branches_for_new_mr_spec.rb index ed6e29335d1..ae41cf90576 100644 --- a/spec/features/merge_request/user_selects_branches_for_new_mr_spec.rb +++ b/spec/features/merge_request/user_selects_branches_for_new_mr_spec.rb @@ -11,7 +11,7 @@ describe 'Merge request > User selects branches for new MR', :js do end before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/merge_request/user_toggles_whitespace_changes_spec.rb b/spec/features/merge_request/user_toggles_whitespace_changes_spec.rb index 2e95a628013..dd860382daa 100644 --- a/spec/features/merge_request/user_toggles_whitespace_changes_spec.rb +++ b/spec/features/merge_request/user_toggles_whitespace_changes_spec.rb @@ -6,7 +6,7 @@ describe 'Merge request > User toggles whitespace changes', :js do let(:user) { project.creator } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit diffs_project_merge_request_path(project, merge_request) end diff --git a/spec/features/merge_request/user_uses_slash_commands_spec.rb b/spec/features/merge_request/user_uses_slash_commands_spec.rb index 83ad4b45b5a..b81478a481f 100644 --- a/spec/features/merge_request/user_uses_slash_commands_spec.rb +++ b/spec/features/merge_request/user_uses_slash_commands_spec.rb @@ -21,7 +21,7 @@ describe 'Merge request > User uses quick actions', :js do let!(:milestone) { create(:milestone, project: project, title: 'ASAP') } before do - project.add_master(user) + project.add_maintainer(user) end describe 'time tracking' do @@ -147,7 +147,7 @@ describe 'Merge request > User uses quick actions', :js do let(:new_url_opts) { { merge_request: { source_branch: 'feature' } } } before do - another_project.add_master(user) + another_project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/merge_requests/user_mass_updates_spec.rb b/spec/features/merge_requests/user_mass_updates_spec.rb index 199ba7e87ad..bb327159cb0 100644 --- a/spec/features/merge_requests/user_mass_updates_spec.rb +++ b/spec/features/merge_requests/user_mass_updates_spec.rb @@ -6,7 +6,7 @@ describe 'Merge requests > User mass updates', :js do let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/merge_requests/user_squashes_merge_request_spec.rb b/spec/features/merge_requests/user_squashes_merge_request_spec.rb index 6c952791591..ec1153b7f7f 100644 --- a/spec/features/merge_requests/user_squashes_merge_request_spec.rb +++ b/spec/features/merge_requests/user_squashes_merge_request_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'User squashes a merge request', :js do +describe 'User squashes a merge request', :js do let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:source_branch) { 'csv' } @@ -46,7 +46,7 @@ feature 'User squashes a merge request', :js do # Prevent source branch from being removed so we can use be_merged_to_root_ref # method to check if squash was performed or not allow_any_instance_of(MergeRequest).to receive(:force_remove_source_branch?).and_return(false) - project.add_master(user) + project.add_maintainer(user) sign_in user end diff --git a/spec/features/milestone_spec.rb b/spec/features/milestone_spec.rb index b0db6870ddf..a0673b12738 100644 --- a/spec/features/milestone_spec.rb +++ b/spec/features/milestone_spec.rb @@ -1,18 +1,18 @@ require 'rails_helper' -feature 'Milestone' do +describe 'Milestone' do let(:group) { create(:group, :public) } let(:project) { create(:project, :public, namespace: group) } let(:user) { create(:user) } before do create(:group_member, group: group, user: user) - project.add_master(user) + project.add_maintainer(user) sign_in(user) end - feature 'Create a milestone' do - scenario 'shows an informative message for a new milestone' do + describe 'Create a milestone' do + it 'shows an informative message for a new milestone' do visit new_project_milestone_path(project) page.within '.milestone-form' do @@ -28,8 +28,8 @@ feature 'Milestone' do end end - feature 'Open a milestone with closed issues' do - scenario 'shows an informative message' do + describe 'Open a milestone with closed issues' do + it 'shows an informative message' do milestone = create(:milestone, project: project, title: 8.7) create(:issue, title: "Bugfix1", project: project, milestone: milestone, state: "closed") @@ -39,8 +39,8 @@ feature 'Milestone' do end end - feature 'Open a project milestone with an existing title' do - scenario 'displays validation message when there is a project milestone with same title' do + describe 'Open a project milestone with an existing title' do + it 'displays validation message when there is a project milestone with same title' do milestone = create(:milestone, project: project, title: 8.7) visit new_project_milestone_path(project) @@ -52,7 +52,7 @@ feature 'Milestone' do expect(find('.alert-danger')).to have_content('already being used for another group or project milestone.') end - scenario 'displays validation message when there is a group milestone with same title' do + it 'displays validation message when there is a group milestone with same title' do milestone = create(:milestone, project_id: nil, group: project.group, title: 8.7) visit new_group_milestone_path(project.group) @@ -66,8 +66,8 @@ feature 'Milestone' do end end - feature 'Open a milestone', :js do - scenario 'shows total issue time spent correctly when no time has been logged' do + describe 'Open a milestone', :js do + it 'shows total issue time spent correctly when no time has been logged' do milestone = create(:milestone, project: project, title: 8.7) visit project_milestone_path(project, milestone) @@ -79,7 +79,7 @@ feature 'Milestone' do end end - scenario 'shows total issue time spent' do + it 'shows total issue time spent' do milestone = create(:milestone, project: project, title: 8.7) issue1 = create(:issue, project: project, milestone: milestone) issue2 = create(:issue, project: project, milestone: milestone) @@ -98,8 +98,8 @@ feature 'Milestone' do end end - feature 'Deleting a milestone' do - scenario "The delete milestone button does not show for unauthorized users" do + describe 'Deleting a milestone' do + it "The delete milestone button does not show for unauthorized users" do create(:milestone, project: project, title: 8.7) sign_out(user) @@ -109,7 +109,7 @@ feature 'Milestone' do end end - feature 'deprecation popover', :js do + describe 'deprecation popover', :js do it 'opens deprecation popover' do milestone = create(:milestone, project: project) diff --git a/spec/features/milestones/user_edits_milestone_spec.rb b/spec/features/milestones/user_edits_milestone_spec.rb new file mode 100644 index 00000000000..077295f1cc0 --- /dev/null +++ b/spec/features/milestones/user_edits_milestone_spec.rb @@ -0,0 +1,22 @@ +require "rails_helper" + +describe "User edits milestone", :js do + set(:user) { create(:user) } + set(:project) { create(:project) } + set(:milestone) { create(:milestone, project: project, start_date: Date.today, due_date: 5.days.from_now) } + + before do + project.add_developer(user) + sign_in(user) + + visit(edit_project_milestone_path(project, milestone)) + end + + it "shows the right start date and due date" do + start_date = milestone.start_date.strftime("%F") + due_date = milestone.due_date.strftime("%F") + + expect(page).to have_field(with: start_date) + expect(page).to have_field(with: due_date) + end +end diff --git a/spec/features/oauth_login_spec.rb b/spec/features/oauth_login_spec.rb index 013cdaa6479..f4105730402 100644 --- a/spec/features/oauth_login_spec.rb +++ b/spec/features/oauth_login_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'OAuth Login', :js, :allow_forgery_protection do +describe 'OAuth Login', :js, :allow_forgery_protection do include DeviseHelpers def enter_code(code) diff --git a/spec/features/participants_autocomplete_spec.rb b/spec/features/participants_autocomplete_spec.rb index b3bb8c48b4a..134731a4639 100644 --- a/spec/features/participants_autocomplete_spec.rb +++ b/spec/features/participants_autocomplete_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Member autocomplete', :js do +describe 'Member autocomplete', :js do let(:project) { create(:project, :public) } let(:user) { create(:user) } let(:author) { create(:user) } diff --git a/spec/features/password_reset_spec.rb b/spec/features/password_reset_spec.rb index 73a526c3d8a..dcc63dff9f5 100644 --- a/spec/features/password_reset_spec.rb +++ b/spec/features/password_reset_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Password reset' do +describe 'Password reset' do describe 'throttling' do it 'sends reset instructions when not previously sent' do user = create(:user) diff --git a/spec/features/profiles/account_spec.rb b/spec/features/profiles/account_spec.rb index 95947d2f111..90d0e9bb77c 100644 --- a/spec/features/profiles/account_spec.rb +++ b/spec/features/profiles/account_spec.rb @@ -1,25 +1,25 @@ require 'rails_helper' -feature 'Profile > Account', :js do - given(:user) { create(:user, username: 'foo') } +describe 'Profile > Account', :js do + let(:user) { create(:user, username: 'foo') } before do sign_in(user) end describe 'Change username' do - given(:new_username) { 'bar' } - given(:new_user_path) { "/#{new_username}" } - given(:old_user_path) { "/#{user.username}" } + let(:new_username) { 'bar' } + let(:new_user_path) { "/#{new_username}" } + let(:old_user_path) { "/#{user.username}" } - scenario 'the user is accessible via the new path' do + it 'the user is accessible via the new path' do update_username(new_username) visit new_user_path expect(current_path).to eq(new_user_path) expect(find('.user-info')).to have_content(new_username) end - scenario 'the old user path redirects to the new path' do + it 'the old user path redirects to the new path' do update_username(new_username) visit old_user_path expect(current_path).to eq(new_user_path) @@ -27,9 +27,9 @@ feature 'Profile > Account', :js do end context 'with a project' do - given!(:project) { create(:project, namespace: user.namespace) } - given(:new_project_path) { "/#{new_username}/#{project.path}" } - given(:old_project_path) { "/#{user.username}/#{project.path}" } + let!(:project) { create(:project, namespace: user.namespace) } + let(:new_project_path) { "/#{new_username}/#{project.path}" } + let(:old_project_path) { "/#{user.username}/#{project.path}" } before(:context) do TestEnv.clean_test_path @@ -39,14 +39,14 @@ feature 'Profile > Account', :js do TestEnv.clean_test_path end - scenario 'the project is accessible via the new path' do + it 'the project is accessible via the new path' do update_username(new_username) visit new_project_path expect(current_path).to eq(new_project_path) expect(find('.breadcrumbs-sub-title')).to have_content('Details') end - scenario 'the old project path redirects to the new path' do + it 'the old project path redirects to the new path' do update_username(new_username) visit old_project_path expect(current_path).to eq(new_project_path) diff --git a/spec/features/profiles/active_sessions_spec.rb b/spec/features/profiles/active_sessions_spec.rb index 4045cfd21c4..d3050760c06 100644 --- a/spec/features/profiles/active_sessions_spec.rb +++ b/spec/features/profiles/active_sessions_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Profile > Active Sessions', :clean_gitlab_redis_shared_state do +describe 'Profile > Active Sessions', :clean_gitlab_redis_shared_state do let(:user) do create(:user).tap do |user| user.current_sign_in_at = Time.current @@ -13,7 +13,7 @@ feature 'Profile > Active Sessions', :clean_gitlab_redis_shared_state do end end - scenario 'User sees their active sessions' do + it 'User sees their active sessions' do Capybara::Session.new(:session1) Capybara::Session.new(:session2) @@ -60,7 +60,7 @@ feature 'Profile > Active Sessions', :clean_gitlab_redis_shared_state do end end - scenario 'User can revoke a session', :js, :redis_session_store do + it 'User can revoke a session', :js, :redis_session_store do Capybara::Session.new(:session1) Capybara::Session.new(:session2) diff --git a/spec/features/profiles/chat_names_spec.rb b/spec/features/profiles/chat_names_spec.rb index 5c959acbbc9..c72069f6262 100644 --- a/spec/features/profiles/chat_names_spec.rb +++ b/spec/features/profiles/chat_names_spec.rb @@ -1,19 +1,19 @@ require 'rails_helper' -feature 'Profile > Chat' do - given(:user) { create(:user) } - given(:service) { create(:service) } +describe 'Profile > Chat' do + let(:user) { create(:user) } + let(:service) { create(:service) } before do sign_in(user) end describe 'uses authorization link' do - given(:params) do + let(:params) do { team_id: 'T00', team_domain: 'my_chat_team', user_id: 'U01', user_name: 'my_chat_user' } end - given!(:authorize_url) { ChatNames::AuthorizeUserService.new(service, params).execute } - given(:authorize_path) { URI.parse(authorize_url).request_uri } + let!(:authorize_url) { ChatNames::AuthorizeUserService.new(service, params).execute } + let(:authorize_path) { URI.parse(authorize_url).request_uri } before do visit authorize_path @@ -24,13 +24,13 @@ feature 'Profile > Chat' do click_button 'Authorize' end - scenario 'goes to list of chat names and see chat account' do + it 'goes to list of chat names and see chat account' do expect(page.current_path).to eq(profile_chat_names_path) expect(page).to have_content('my_chat_team') expect(page).to have_content('my_chat_user') end - scenario 'second use of link is denied' do + it 'second use of link is denied' do visit authorize_path expect(page).to have_gitlab_http_status(:not_found) @@ -42,13 +42,13 @@ feature 'Profile > Chat' do click_button 'Deny' end - scenario 'goes to list of chat names and do not see chat account' do + it 'goes to list of chat names and do not see chat account' do expect(page.current_path).to eq(profile_chat_names_path) expect(page).not_to have_content('my_chat_team') expect(page).not_to have_content('my_chat_user') end - scenario 'second use of link is denied' do + it 'second use of link is denied' do visit authorize_path expect(page).to have_gitlab_http_status(:not_found) @@ -57,18 +57,18 @@ feature 'Profile > Chat' do end describe 'visits chat accounts' do - given!(:chat_name) { create(:chat_name, user: user, service: service) } + let!(:chat_name) { create(:chat_name, user: user, service: service) } before do visit profile_chat_names_path end - scenario 'sees chat user' do + it 'sees chat user' do expect(page).to have_content(chat_name.team_domain) expect(page).to have_content(chat_name.chat_name) end - scenario 'removes chat account' do + it 'removes chat account' do click_link 'Remove' expect(page).to have_content("You don't have any active chat names.") diff --git a/spec/features/profiles/emails_spec.rb b/spec/features/profiles/emails_spec.rb index 11cc8aae6f3..bc6d54b5ed7 100644 --- a/spec/features/profiles/emails_spec.rb +++ b/spec/features/profiles/emails_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Profile > Emails' do +describe 'Profile > Emails' do let(:user) { create(:user) } before do @@ -12,7 +12,7 @@ feature 'Profile > Emails' do visit profile_emails_path end - scenario 'saves the new email' do + it 'saves the new email' do fill_in('Email', with: 'my@email.com') click_button('Add email address') @@ -21,7 +21,7 @@ feature 'Profile > Emails' do expect(page).to have_content('Resend confirmation email') end - scenario 'does not add a duplicate email' do + it 'does not add a duplicate email' do fill_in('Email', with: user.email) click_button('Add email address') @@ -31,7 +31,7 @@ feature 'Profile > Emails' do end end - scenario 'User removes email' do + it 'User removes email' do user.emails.create(email: 'my@email.com') visit profile_emails_path expect(page).to have_content("my@email.com") @@ -40,7 +40,7 @@ feature 'Profile > Emails' do expect(page).not_to have_content("my@email.com") end - scenario 'User confirms email' do + it 'User confirms email' do email = user.emails.create(email: 'my@email.com') visit profile_emails_path expect(page).to have_content("#{email.email} Unverified") @@ -52,7 +52,7 @@ feature 'Profile > Emails' do expect(page).to have_content("#{email.email} Verified") end - scenario 'User re-sends confirmation email' do + it 'User re-sends confirmation email' do email = user.emails.create(email: 'my@email.com') visit profile_emails_path @@ -60,7 +60,7 @@ feature 'Profile > Emails' do expect(page).to have_content("Confirmation email sent to #{email.email}") end - scenario 'old unconfirmed emails show Send Confirmation button' do + it 'old unconfirmed emails show Send Confirmation button' do email = user.emails.create(email: 'my@email.com') email.update_attribute(:confirmation_sent_at, nil) visit profile_emails_path diff --git a/spec/features/profiles/gpg_keys_spec.rb b/spec/features/profiles/gpg_keys_spec.rb index 59233e92f93..ec3ec795b63 100644 --- a/spec/features/profiles/gpg_keys_spec.rb +++ b/spec/features/profiles/gpg_keys_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Profile > GPG Keys' do +describe 'Profile > GPG Keys' do let(:user) { create(:user, email: GpgHelpers::User2.emails.first) } before do @@ -12,7 +12,7 @@ feature 'Profile > GPG Keys' do visit profile_gpg_keys_path end - scenario 'saves the new key' do + it 'saves the new key' do fill_in('Key', with: GpgHelpers::User2.public_key) click_button('Add key') @@ -21,7 +21,7 @@ feature 'Profile > GPG Keys' do expect(page).to have_content(GpgHelpers::User2.fingerprint) end - scenario 'with multiple subkeys' do + it 'with multiple subkeys' do fill_in('Key', with: GpgHelpers::User3.public_key) click_button('Add key') @@ -34,7 +34,7 @@ feature 'Profile > GPG Keys' do end end - scenario 'User sees their key' do + it 'User sees their key' do create(:gpg_key, user: user, key: GpgHelpers::User2.public_key) visit profile_gpg_keys_path @@ -43,7 +43,7 @@ feature 'Profile > GPG Keys' do expect(page).to have_content(GpgHelpers::User2.fingerprint) end - scenario 'User removes a key via the key index' do + it 'User removes a key via the key index' do create(:gpg_key, user: user, key: GpgHelpers::User2.public_key) visit profile_gpg_keys_path @@ -52,7 +52,7 @@ feature 'Profile > GPG Keys' do expect(page).to have_content('Your GPG keys (0)') end - scenario 'User revokes a key via the key index' do + it 'User revokes a key via the key index' do gpg_key = create :gpg_key, user: user, key: GpgHelpers::User2.public_key gpg_signature = create :gpg_signature, gpg_key: gpg_key, verification_status: :verified diff --git a/spec/features/profiles/keys_spec.rb b/spec/features/profiles/keys_spec.rb index b04a5422fed..e6586fc8a0a 100644 --- a/spec/features/profiles/keys_spec.rb +++ b/spec/features/profiles/keys_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Profile > SSH Keys' do +describe 'Profile > SSH Keys' do let(:user) { create(:user) } before do @@ -12,13 +12,13 @@ feature 'Profile > SSH Keys' do visit profile_keys_path end - scenario 'auto-populates the title', :js do + it 'auto-populates the title', :js do fill_in('Key', with: attributes_for(:key).fetch(:key)) expect(page).to have_field("Title", with: "dummy@gitlab.com") end - scenario 'saves the new key' do + it 'saves the new key' do attrs = attributes_for(:key) fill_in('Key', with: attrs[:key]) @@ -30,13 +30,27 @@ feature 'Profile > SSH Keys' do expect(find('.breadcrumbs-sub-title')).to have_link(attrs[:title]) end + it 'shows a confirmable warning if the key does not start with ssh-' do + attrs = attributes_for(:key) + + fill_in('Key', with: 'invalid-key') + fill_in('Title', with: attrs[:title]) + click_button('Add key') + + expect(page).to have_selector('.js-add-ssh-key-validation-warning') + + find('.js-add-ssh-key-validation-confirm-submit').click + + expect(page).to have_content('Key is invalid') + end + context 'when only DSA and ECDSA keys are allowed' do before do forbidden = ApplicationSetting::FORBIDDEN_KEY_VALUE stub_application_setting(rsa_key_restriction: forbidden, ed25519_key_restriction: forbidden) end - scenario 'shows a validation error' do + it 'shows a validation error' do attrs = attributes_for(:key) fill_in('Key', with: attrs[:key]) @@ -48,14 +62,14 @@ feature 'Profile > SSH Keys' do end end - scenario 'User sees their keys' do + it 'User sees their keys' do key = create(:key, user: user) visit profile_keys_path expect(page).to have_content(key.title) end - scenario 'User removes a key via the key index' do + it 'User removes a key via the key index' do create(:key, user: user) visit profile_keys_path @@ -64,7 +78,7 @@ feature 'Profile > SSH Keys' do expect(page).to have_content('Your SSH keys (0)') end - scenario 'User removes a key via its details page' do + it 'User removes a key via its details page' do key = create(:key, user: user) visit profile_key_path(key) diff --git a/spec/features/profiles/password_spec.rb b/spec/features/profiles/password_spec.rb index f9c6ff90ca1..5e3569e4beb 100644 --- a/spec/features/profiles/password_spec.rb +++ b/spec/features/profiles/password_spec.rb @@ -117,7 +117,7 @@ describe 'Profile > Password' do before do sign_in(user) - user.update_attributes(password_expires_at: 1.hour.ago) + user.update(password_expires_at: 1.hour.ago) user.identities.delete expect(user.ldap_user?).to eq false end diff --git a/spec/features/profiles/user_changes_notified_of_own_activity_spec.rb b/spec/features/profiles/user_changes_notified_of_own_activity_spec.rb index d5fe5bdffc5..f618bc330ea 100644 --- a/spec/features/profiles/user_changes_notified_of_own_activity_spec.rb +++ b/spec/features/profiles/user_changes_notified_of_own_activity_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -feature 'Profile > Notifications > User changes notified_of_own_activity setting', :js do +describe 'Profile > Notifications > User changes notified_of_own_activity setting', :js do let(:user) { create(:user) } before do sign_in(user) end - scenario 'User opts into receiving notifications about their own activity' do + it 'User opts into receiving notifications about their own activity' do visit profile_notifications_path expect(page).not_to have_checked_field('user[notified_of_own_activity]') @@ -18,7 +18,7 @@ feature 'Profile > Notifications > User changes notified_of_own_activity setting expect(page).to have_checked_field('user[notified_of_own_activity]') end - scenario 'User opts out of receiving notifications about their own activity' do + it 'User opts out of receiving notifications about their own activity' do user.update!(notified_of_own_activity: true) visit profile_notifications_path diff --git a/spec/features/profiles/user_visits_notifications_tab_spec.rb b/spec/features/profiles/user_visits_notifications_tab_spec.rb index 95953fbcfac..db797bb586f 100644 --- a/spec/features/profiles/user_visits_notifications_tab_spec.rb +++ b/spec/features/profiles/user_visits_notifications_tab_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -feature 'User visits the notifications tab', :js do +describe 'User visits the notifications tab', :js do let(:project) { create(:project) } let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(profile_notifications_path) end diff --git a/spec/features/profiles/user_visits_profile_spec.rb b/spec/features/profiles/user_visits_profile_spec.rb index 713112477c8..2dc4547b2d8 100644 --- a/spec/features/profiles/user_visits_profile_spec.rb +++ b/spec/features/profiles/user_visits_profile_spec.rb @@ -29,7 +29,7 @@ describe 'User visits their profile' do let!(:project) do create(:project, :repository, namespace: group) do |project| create(:closed_issue_event, project: project) - project.add_master(user) + project.add_maintainer(user) end end diff --git a/spec/features/project_variables_spec.rb b/spec/features/project_variables_spec.rb index 0ba2224359a..a93df3696d2 100644 --- a/spec/features/project_variables_spec.rb +++ b/spec/features/project_variables_spec.rb @@ -8,7 +8,7 @@ describe 'Project variables', :js do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) project.variables << variable visit page_path diff --git a/spec/features/projects/activity/rss_spec.rb b/spec/features/projects/activity/rss_spec.rb index 4ac34adde0e..411134e7b8e 100644 --- a/spec/features/projects/activity/rss_spec.rb +++ b/spec/features/projects/activity/rss_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Project Activity RSS' do +describe 'Project Activity RSS' do let(:project) { create(:project, :public) } let(:user) { project.owner } let(:path) { activity_project_path(project) } diff --git a/spec/features/projects/activity/user_sees_activity_spec.rb b/spec/features/projects/activity/user_sees_activity_spec.rb index 644a837dc14..e0248911b5f 100644 --- a/spec/features/projects/activity/user_sees_activity_spec.rb +++ b/spec/features/projects/activity/user_sees_activity_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Projects > Activity > User sees activity' do +describe 'Projects > Activity > User sees activity' do let(:project) { create(:project, :repository, :public) } let(:user) { project.creator } diff --git a/spec/features/projects/actve_tabs_spec.rb b/spec/features/projects/actve_tabs_spec.rb index ce5606b63ae..7c6110c533b 100644 --- a/spec/features/projects/actve_tabs_spec.rb +++ b/spec/features/projects/actve_tabs_spec.rb @@ -5,7 +5,7 @@ describe 'Project active tab' do let(:project) { create(:project, :repository) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/artifacts/file_spec.rb b/spec/features/projects/artifacts/file_spec.rb index df1d17bdcb7..993d0040434 100644 --- a/spec/features/projects/artifacts/file_spec.rb +++ b/spec/features/projects/artifacts/file_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Artifact file', :js do +describe 'Artifact file', :js do let(:project) { create(:project, :public) } let(:pipeline) { create(:ci_empty_pipeline, project: project) } let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) } diff --git a/spec/features/projects/artifacts/raw_spec.rb b/spec/features/projects/artifacts/raw_spec.rb index 0bec6e9ad31..d8ee9adda6b 100644 --- a/spec/features/projects/artifacts/raw_spec.rb +++ b/spec/features/projects/artifacts/raw_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Raw artifact', :js do +describe 'Raw artifact', :js do let(:project) { create(:project, :public) } let(:pipeline) { create(:ci_empty_pipeline, project: project) } let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) } diff --git a/spec/features/projects/awards/user_interacts_with_awards_in_issue_spec.rb b/spec/features/projects/awards/user_interacts_with_awards_in_issue_spec.rb index 12e07647ecd..4d860893abe 100644 --- a/spec/features/projects/awards/user_interacts_with_awards_in_issue_spec.rb +++ b/spec/features/projects/awards/user_interacts_with_awards_in_issue_spec.rb @@ -6,7 +6,7 @@ describe 'User interacts with awards in an issue', :js do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_issue_path(project, issue)) diff --git a/spec/features/projects/badges/coverage_spec.rb b/spec/features/projects/badges/coverage_spec.rb index f51001edcd7..8522ea747fa 100644 --- a/spec/features/projects/badges/coverage_spec.rb +++ b/spec/features/projects/badges/coverage_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' -feature 'test coverage badge' do - given!(:user) { create(:user) } - given!(:project) { create(:project, :private) } +describe 'test coverage badge' do + let!(:user) { create(:user) } + let!(:project) { create(:project, :private) } context 'when user has access to view badge' do - background do + before do project.add_developer(user) sign_in(user) end - scenario 'user requests coverage badge image for pipeline' do + it 'user requests coverage badge image for pipeline' do create_pipeline do |pipeline| create_build(pipeline, coverage: 100, name: 'test:1') create_build(pipeline, coverage: 90, name: 'test:2') @@ -21,7 +21,7 @@ feature 'test coverage badge' do expect_coverage_badge('95.00%') end - scenario 'user requests coverage badge for specific job' do + it 'user requests coverage badge for specific job' do create_pipeline do |pipeline| create_build(pipeline, coverage: 50, name: 'test:1') create_build(pipeline, coverage: 50, name: 'test:2') @@ -33,7 +33,7 @@ feature 'test coverage badge' do expect_coverage_badge('85.00%') end - scenario 'user requests coverage badge for pipeline without coverage' do + it 'user requests coverage badge for pipeline without coverage' do create_pipeline do |pipeline| create_build(pipeline, coverage: nil, name: 'test') end @@ -45,9 +45,11 @@ feature 'test coverage badge' do end context 'when user does not have access to view badge' do - background { sign_in(user) } + before do + sign_in(user) + end - scenario 'user requests test coverage badge image' do + it 'user requests test coverage badge image' do show_test_coverage_badge expect(page).to have_gitlab_http_status(404) diff --git a/spec/features/projects/badges/list_spec.rb b/spec/features/projects/badges/list_spec.rb index 0abef4bc447..e30b908c60d 100644 --- a/spec/features/projects/badges/list_spec.rb +++ b/spec/features/projects/badges/list_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' -feature 'list of badges' do - background do +describe 'list of badges' do + before do user = create(:user) project = create(:project, :repository) - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_settings_ci_cd_path(project) end - scenario 'user wants to see build status badge' do + it 'user wants to see build status badge' do page.within('.pipeline-status') do expect(page).to have_content 'pipeline status' expect(page).to have_content 'Markdown' @@ -24,7 +24,7 @@ feature 'list of badges' do end end - scenario 'user wants to see coverage report badge' do + it 'user wants to see coverage report badge' do page.within('.coverage-report') do expect(page).to have_content 'coverage report' expect(page).to have_content 'Markdown' @@ -39,7 +39,7 @@ feature 'list of badges' do end end - scenario 'user changes current ref of build status badge', :js do + it 'user changes current ref of build status badge', :js do page.within('.pipeline-status') do first('.js-project-refs-dropdown').click diff --git a/spec/features/projects/badges/pipeline_badge_spec.rb b/spec/features/projects/badges/pipeline_badge_spec.rb index b83ea8f4eaa..8c4488b2ca6 100644 --- a/spec/features/projects/badges/pipeline_badge_spec.rb +++ b/spec/features/projects/badges/pipeline_badge_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Pipeline Badge' do +describe 'Pipeline Badge' do set(:project) { create(:project, :repository, :public) } let(:ref) { project.default_branch } diff --git a/spec/features/projects/blobs/blob_line_permalink_updater_spec.rb b/spec/features/projects/blobs/blob_line_permalink_updater_spec.rb index c12e56d2c3f..96f514f4f04 100644 --- a/spec/features/projects/blobs/blob_line_permalink_updater_spec.rb +++ b/spec/features/projects/blobs/blob_line_permalink_updater_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Blob button line permalinks (BlobLinePermalinkUpdater)', :js do +describe 'Blob button line permalinks (BlobLinePermalinkUpdater)', :js do include TreeHelper let(:project) { create(:project, :public, :repository) } diff --git a/spec/features/projects/blobs/blob_show_spec.rb b/spec/features/projects/blobs/blob_show_spec.rb index e7b305925f7..27589428896 100644 --- a/spec/features/projects/blobs/blob_show_spec.rb +++ b/spec/features/projects/blobs/blob_show_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'File blob', :js do +describe 'File blob', :js do include MobileHelpers let(:project) { create(:project, :public, :repository) } @@ -144,7 +144,7 @@ feature 'File blob', :js do context 'Markdown file (stored in LFS)' do before do - project.add_master(project.creator) + project.add_maintainer(project.creator) Files::CreateService.new( project, @@ -237,7 +237,7 @@ feature 'File blob', :js do context 'PDF file' do before do - project.add_master(project.creator) + project.add_maintainer(project.creator) Files::CreateService.new( project, @@ -350,7 +350,7 @@ feature 'File blob', :js do context 'empty file' do before do - project.add_master(project.creator) + project.add_maintainer(project.creator) Files::CreateService.new( project, @@ -418,7 +418,7 @@ feature 'File blob', :js do context '.gitlab-ci.yml' do before do - project.add_master(project.creator) + project.add_maintainer(project.creator) Files::CreateService.new( project, @@ -446,7 +446,7 @@ feature 'File blob', :js do context '.gitlab/route-map.yml' do before do - project.add_master(project.creator) + project.add_maintainer(project.creator) Files::CreateService.new( project, @@ -494,7 +494,7 @@ feature 'File blob', :js do context '*.gemspec' do before do - project.add_master(project.creator) + project.add_maintainer(project.creator) Files::CreateService.new( project, diff --git a/spec/features/projects/blobs/edit_spec.rb b/spec/features/projects/blobs/edit_spec.rb index 89d3bd24b89..0e036b4ea68 100644 --- a/spec/features/projects/blobs/edit_spec.rb +++ b/spec/features/projects/blobs/edit_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Editing file blob', :js do +describe 'Editing file blob', :js do include TreeHelper let(:project) { create(:project, :public, :repository) } @@ -134,11 +134,11 @@ feature 'Editing file blob', :js do end end - context 'as master' do + context 'as maintainer' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_edit_blob_path(project, tree_join(branch, file_path)) end diff --git a/spec/features/projects/blobs/shortcuts_blob_spec.rb b/spec/features/projects/blobs/shortcuts_blob_spec.rb index 9f1fef80ab5..aeed38aeb76 100644 --- a/spec/features/projects/blobs/shortcuts_blob_spec.rb +++ b/spec/features/projects/blobs/shortcuts_blob_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Blob shortcuts' do +describe 'Blob shortcuts' do include TreeHelper let(:project) { create(:project, :public, :repository) } let(:path) { project.repository.ls_files(project.repository.root_ref)[0] } diff --git a/spec/features/projects/blobs/user_creates_new_blob_in_new_project_spec.rb b/spec/features/projects/blobs/user_creates_new_blob_in_new_project_spec.rb index b7d063596c1..8a0b92190dd 100644 --- a/spec/features/projects/blobs/user_creates_new_blob_in_new_project_spec.rb +++ b/spec/features/projects/blobs/user_creates_new_blob_in_new_project_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'User creates blob in new project', :js do +describe 'User creates blob in new project', :js do let(:user) { create(:user) } let(:project) { create(:project, :empty_repo) } @@ -24,9 +24,9 @@ feature 'User creates blob in new project', :js do end end - describe 'as a master' do + describe 'as a maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'creating a file' diff --git a/spec/features/projects/branches/download_buttons_spec.rb b/spec/features/projects/branches/download_buttons_spec.rb index 605298ba8ab..c8dc72a34ec 100644 --- a/spec/features/projects/branches/download_buttons_spec.rb +++ b/spec/features/projects/branches/download_buttons_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' -feature 'Download buttons in branches page' do - given(:user) { create(:user) } - given(:role) { :developer } - given(:status) { 'success' } - given(:project) { create(:project, :repository) } +describe 'Download buttons in branches page' do + let(:user) { create(:user) } + let(:role) { :developer } + let(:status) { 'success' } + let(:project) { create(:project, :repository) } - given(:pipeline) do + let(:pipeline) do create(:ci_pipeline, project: project, sha: project.commit('binary-encoding').sha, @@ -14,14 +14,14 @@ feature 'Download buttons in branches page' do status: status) end - given!(:build) do + let!(:build) do create(:ci_build, :success, :artifacts, pipeline: pipeline, status: pipeline.status, name: 'build') end - background do + before do sign_in(user) project.add_role(user, role) end @@ -32,7 +32,7 @@ feature 'Download buttons in branches page' do visit project_branches_filtered_path(project, state: 'all', search: 'binary-encoding') end - scenario 'shows download artifacts button' do + it 'shows download artifacts button' do href = latest_succeeded_project_artifacts_path(project, 'binary-encoding/download', job: 'build') expect(page).to have_link "Download '#{build.name}'", href: href diff --git a/spec/features/projects/branches/new_branch_ref_dropdown_spec.rb b/spec/features/projects/branches/new_branch_ref_dropdown_spec.rb index 0be434a567b..0faf73db7da 100644 --- a/spec/features/projects/branches/new_branch_ref_dropdown_spec.rb +++ b/spec/features/projects/branches/new_branch_ref_dropdown_spec.rb @@ -6,7 +6,7 @@ describe 'New Branch Ref Dropdown', :js do let(:toggle) { find('.create-from .dropdown-menu-toggle') } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit new_project_branch_path(project) diff --git a/spec/features/projects/branches_spec.rb b/spec/features/projects/branches_spec.rb index b7ce1b9993a..97757e8da92 100644 --- a/spec/features/projects/branches_spec.rb +++ b/spec/features/projects/branches_spec.rb @@ -182,10 +182,10 @@ describe 'Branches' do end end - context 'logged in as master' do + context 'logged in as maintainer' do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) end describe 'Initial branches page' do diff --git a/spec/features/projects/clusters/applications_spec.rb b/spec/features/projects/clusters/applications_spec.rb index 7b2c57aa652..a65ca662350 100644 --- a/spec/features/projects/clusters/applications_spec.rb +++ b/spec/features/projects/clusters/applications_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -feature 'Clusters Applications', :js do +describe 'Clusters Applications', :js do include GoogleApi::CloudPlatformHelpers let(:project) { create(:project) } let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -19,7 +19,7 @@ feature 'Clusters Applications', :js do context 'when cluster is being created' do let(:cluster) { create(:cluster, :providing_by_gcp, projects: [project])} - scenario 'user is unable to install applications' do + it 'user is unable to install applications' do page.within('.js-cluster-application-row-helm') do expect(page.find(:css, '.js-cluster-application-install-button')['disabled']).to eq('true') expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Install') @@ -30,7 +30,7 @@ feature 'Clusters Applications', :js do context 'when cluster is created' do let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project])} - scenario 'user can install applications' do + it 'user can install applications' do page.within('.js-cluster-application-row-helm') do expect(page.find(:css, '.js-cluster-application-install-button')['disabled']).to be_nil expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Install') diff --git a/spec/features/projects/clusters/gcp_spec.rb b/spec/features/projects/clusters/gcp_spec.rb index 3db384e5b65..31e3ebf675d 100644 --- a/spec/features/projects/clusters/gcp_spec.rb +++ b/spec/features/projects/clusters/gcp_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -feature 'Gcp Cluster', :js do +describe 'Gcp Cluster', :js do include GoogleApi::CloudPlatformHelpers let(:project) { create(:project) } let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) gitlab_sign_in(user) allow(Projects::ClustersController).to receive(:STATUS_POLLING_INTERVAL) { 100 } end @@ -16,9 +16,9 @@ feature 'Gcp Cluster', :js do let(:project_id) { 'test-project-1234' } before do - allow_any_instance_of(Projects::Clusters::GcpController) + allow_any_instance_of(Projects::ClustersController) .to receive(:token_in_session).and_return('token') - allow_any_instance_of(Projects::Clusters::GcpController) + allow_any_instance_of(Projects::ClustersController) .to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s) end @@ -27,7 +27,7 @@ feature 'Gcp Cluster', :js do visit project_clusters_path(project) click_link 'Add Kubernetes cluster' - click_link 'Create on Google Kubernetes Engine' + click_link 'Create new Cluster on GKE' end context 'when user filled form with valid parameters' do @@ -148,7 +148,7 @@ feature 'Gcp Cluster', :js do visit project_clusters_path(project) click_link 'Add Kubernetes cluster' - click_link 'Create on Google Kubernetes Engine' + click_link 'Create new Cluster on GKE' end it 'user sees a login page' do @@ -162,7 +162,7 @@ feature 'Gcp Cluster', :js do visit project_clusters_path(project) click_link 'Add Kubernetes cluster' - click_link 'Add an existing Kubernetes cluster' + click_link 'Add existing cluster' end it 'user does not see the "Environment scope" field' do @@ -187,7 +187,7 @@ feature 'Gcp Cluster', :js do it 'user sees offer on cluster GCP login page' do click_link 'Add Kubernetes cluster' - click_link 'Create on Google Kubernetes Engine' + click_link 'Create new Cluster on GKE' expect(page).to have_css('.gcp-signup-offer') end diff --git a/spec/features/projects/clusters/interchangeability_spec.rb b/spec/features/projects/clusters/interchangeability_spec.rb index 3ddb35c755c..0033e12b6b1 100644 --- a/spec/features/projects/clusters/interchangeability_spec.rb +++ b/spec/features/projects/clusters/interchangeability_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Interchangeability between KubernetesService and Platform::Kubernetes' do +describe 'Interchangeability between KubernetesService and Platform::Kubernetes' do EXCEPT_METHODS = %i[test title description help fields initialize_properties namespace namespace= api_url api_url= deprecated? deprecation_message].freeze EXCEPT_METHODS_GREP_V = %w[_touched? _changed? _was].freeze diff --git a/spec/features/projects/clusters/user_spec.rb b/spec/features/projects/clusters/user_spec.rb index 698b64a659c..babf47cc341 100644 --- a/spec/features/projects/clusters/user_spec.rb +++ b/spec/features/projects/clusters/user_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -feature 'User Cluster', :js do +describe 'User Cluster', :js do include GoogleApi::CloudPlatformHelpers let(:project) { create(:project) } let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) gitlab_sign_in(user) allow(Projects::ClustersController).to receive(:STATUS_POLLING_INTERVAL) { 100 } end @@ -17,7 +17,7 @@ feature 'User Cluster', :js do visit project_clusters_path(project) click_link 'Add Kubernetes cluster' - click_link 'Add an existing Kubernetes cluster' + click_link 'Add existing cluster' end context 'when user filled form with valid parameters' do diff --git a/spec/features/projects/clusters_spec.rb b/spec/features/projects/clusters_spec.rb index a251a2f4e52..91eac9c8278 100644 --- a/spec/features/projects/clusters_spec.rb +++ b/spec/features/projects/clusters_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -feature 'Clusters', :js do +describe 'Clusters', :js do include GoogleApi::CloudPlatformHelpers let(:project) { create(:project) } let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) gitlab_sign_in(user) end @@ -83,7 +83,7 @@ feature 'Clusters', :js do visit project_clusters_path(project) click_link 'Add Kubernetes cluster' - click_link 'Create on Google Kubernetes Engine' + click_link 'Create new Cluster on GKE' end it 'user sees a login page' do diff --git a/spec/features/projects/commit/builds_spec.rb b/spec/features/projects/commit/builds_spec.rb index 36a746ac83d..bd254caddfb 100644 --- a/spec/features/projects/commit/builds_spec.rb +++ b/spec/features/projects/commit/builds_spec.rb @@ -1,22 +1,22 @@ require 'spec_helper' -feature 'project commit pipelines', :js do - given(:project) { create(:project, :repository) } +describe 'project commit pipelines', :js do + let(:project) { create(:project, :repository) } - background do + before do user = create(:user) - project.add_master(user) + project.add_maintainer(user) sign_in(user) end context 'when no builds triggered yet' do - background do + before do create(:ci_pipeline, project: project, sha: project.commit.sha, ref: 'master') end - scenario 'user views commit pipelines page' do + it 'user views commit pipelines page' do visit pipelines_project_commit_path(project, project.commit.sha) page.within('.table-holder') do diff --git a/spec/features/projects/commit/cherry_pick_spec.rb b/spec/features/projects/commit/cherry_pick_spec.rb index 1df45865d6f..bc3c00dafe2 100644 --- a/spec/features/projects/commit/cherry_pick_spec.rb +++ b/spec/features/projects/commit/cherry_pick_spec.rb @@ -9,7 +9,7 @@ describe 'Cherry-pick Commits' do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) visit project_commit_path(project, master_pickable_commit.id) end diff --git a/spec/features/projects/commit/comments/user_adds_comment_spec.rb b/spec/features/projects/commit/comments/user_adds_comment_spec.rb index 53866c32c69..6397df086a7 100644 --- a/spec/features/projects/commit/comments/user_adds_comment_spec.rb +++ b/spec/features/projects/commit/comments/user_adds_comment_spec.rb @@ -62,7 +62,7 @@ describe "User adds a comment on a commit", :js do click_diff_line(sample_commit.line_code) expect(page).to have_css(".js-temp-notes-holder form.new-note") - .and have_css(".js-close-discussion-note-form", text: "Discard draft") + .and have_css(".js-close-discussion-note-form", text: "Cancel") # The `Cancel` button closes the current form. The page should not have any open forms after that. find(".js-close-discussion-note-form").click diff --git a/spec/features/projects/commit/diff_notes_spec.rb b/spec/features/projects/commit/diff_notes_spec.rb index 4dbfc6f6edf..e2aefa35fad 100644 --- a/spec/features/projects/commit/diff_notes_spec.rb +++ b/spec/features/projects/commit/diff_notes_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -feature 'Commit diff', :js do +describe 'Commit diff', :js do include RepoHelpers let(:user) { create(:user) } let(:project) { create(:project, :public, :repository) } before do - project.add_master(user) + project.add_maintainer(user) sign_in user end diff --git a/spec/features/projects/commit/mini_pipeline_graph_spec.rb b/spec/features/projects/commit/mini_pipeline_graph_spec.rb index 91282063a8d..19f6ebf2c1a 100644 --- a/spec/features/projects/commit/mini_pipeline_graph_spec.rb +++ b/spec/features/projects/commit/mini_pipeline_graph_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Mini Pipeline Graph in Commit View', :js do +describe 'Mini Pipeline Graph in Commit View', :js do let(:project) { create(:project, :public, :repository) } context 'when commit has pipelines' do diff --git a/spec/features/projects/commits/rss_spec.rb b/spec/features/projects/commits/rss_spec.rb index 0bc207da970..cfc2637f1b2 100644 --- a/spec/features/projects/commits/rss_spec.rb +++ b/spec/features/projects/commits/rss_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Project Commits RSS' do +describe 'Project Commits RSS' do let(:user) { create(:user) } let(:project) { create(:project, :repository, visibility_level: Gitlab::VisibilityLevel::PUBLIC) } let(:path) { project_commits_path(project, :master) } diff --git a/spec/features/projects/commits/user_browses_commits_spec.rb b/spec/features/projects/commits/user_browses_commits_spec.rb index 35ed6620548..23d8d606790 100644 --- a/spec/features/projects/commits/user_browses_commits_spec.rb +++ b/spec/features/projects/commits/user_browses_commits_spec.rb @@ -7,7 +7,7 @@ describe 'User browses commits' do let(:project) { create(:project, :repository, namespace: user.namespace) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/compare_spec.rb b/spec/features/projects/compare_spec.rb index 7e863d9df32..69600884909 100644 --- a/spec/features/projects/compare_spec.rb +++ b/spec/features/projects/compare_spec.rb @@ -5,7 +5,7 @@ describe "Compare", :js do let(:project) { create(:project, :repository) } before do - project.add_master(user) + project.add_maintainer(user) sign_in user end diff --git a/spec/features/projects/deploy_keys_spec.rb b/spec/features/projects/deploy_keys_spec.rb index 1552a3512dd..e12532e97fa 100644 --- a/spec/features/projects/deploy_keys_spec.rb +++ b/spec/features/projects/deploy_keys_spec.rb @@ -5,7 +5,7 @@ describe 'Project deploy keys', :js do let(:project) { create(:project_empty_repo) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/diffs/diff_show_spec.rb b/spec/features/projects/diffs/diff_show_spec.rb index 9bfcb1e816a..df05625d105 100644 --- a/spec/features/projects/diffs/diff_show_spec.rb +++ b/spec/features/projects/diffs/diff_show_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Diff file viewer', :js do +describe 'Diff file viewer', :js do let(:project) { create(:project, :public, :repository) } def visit_commit(sha, anchor: nil) @@ -24,7 +24,7 @@ feature 'Diff file viewer', :js do context 'Ruby file (stored in LFS)' do before do - project.add_master(project.creator) + project.add_maintainer(project.creator) @commit_id = Files::CreateService.new( project, diff --git a/spec/features/projects/environments/environment_metrics_spec.rb b/spec/features/projects/environments/environment_metrics_spec.rb index 82a722c5960..edbab14f7c1 100644 --- a/spec/features/projects/environments/environment_metrics_spec.rb +++ b/spec/features/projects/environments/environment_metrics_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' -feature 'Environment > Metrics' do +describe 'Environment > Metrics' do include PrometheusHelpers - given(:user) { create(:user) } - given(:project) { create(:prometheus_project) } - given(:pipeline) { create(:ci_pipeline, project: project) } - given(:build) { create(:ci_build, pipeline: pipeline) } - given(:environment) { create(:environment, project: project) } - given(:current_time) { Time.now.utc } + let(:user) { create(:user) } + let(:project) { create(:prometheus_project) } + let(:pipeline) { create(:ci_pipeline, project: project) } + let(:build) { create(:ci_build, pipeline: pipeline) } + let(:environment) { create(:environment, project: project) } + let(:current_time) { Time.now.utc } - background do + before do project.add_developer(user) create(:deployment, environment: environment, deployable: build) stub_all_prometheus_requests(environment.slug) @@ -24,7 +24,7 @@ feature 'Environment > Metrics' do end context 'with deployments and related deployable present' do - scenario 'shows metrics' do + it 'shows metrics' do click_link('See metrics') expect(page).to have_css('div#prometheus-graphs') diff --git a/spec/features/projects/environments/environment_spec.rb b/spec/features/projects/environments/environment_spec.rb index b233af83eec..4c5dda29fee 100644 --- a/spec/features/projects/environments/environment_spec.rb +++ b/spec/features/projects/environments/environment_spec.rb @@ -1,42 +1,42 @@ require 'spec_helper' -feature 'Environment' do - given(:project) { create(:project) } - given(:user) { create(:user) } - given(:role) { :developer } +describe 'Environment' do + let(:project) { create(:project) } + let(:user) { create(:user) } + let(:role) { :developer } - background do + before do sign_in(user) project.add_role(user, role) end - feature 'environment details page' do - given!(:environment) { create(:environment, project: project) } - given!(:permissions) { } - given!(:deployment) { } - given!(:action) { } + describe 'environment details page' do + let!(:environment) { create(:environment, project: project) } + let!(:permissions) { } + let!(:deployment) { } + let!(:action) { } before do visit_environment(environment) end - scenario 'shows environment name' do + it 'shows environment name' do expect(page).to have_content(environment.name) end context 'without deployments' do - scenario 'does show no deployments' do + it 'does show no deployments' do expect(page).to have_content('You don\'t have any deployments right now.') end end context 'with deployments' do context 'when there is no related deployable' do - given(:deployment) do + let(:deployment) do create(:deployment, environment: environment, deployable: nil) end - scenario 'does show deployment SHA' do + it 'does show deployment SHA' do expect(page).to have_link(deployment.short_sha) expect(page).not_to have_link('Re-deploy') expect(page).not_to have_terminal_button @@ -44,27 +44,27 @@ feature 'Environment' do end context 'with related deployable present' do - given(:pipeline) { create(:ci_pipeline, project: project) } - given(:build) { create(:ci_build, pipeline: pipeline) } + let(:pipeline) { create(:ci_pipeline, project: project) } + let(:build) { create(:ci_build, pipeline: pipeline) } - given(:deployment) do + let(:deployment) do create(:deployment, environment: environment, deployable: build) end - scenario 'does show build name' do + it 'does show build name' do expect(page).to have_link("#{build.name} (##{build.id})") expect(page).to have_link('Re-deploy') expect(page).not_to have_terminal_button end context 'with manual action' do - given(:action) do + let(:action) do create(:ci_build, :manual, pipeline: pipeline, name: 'deploy to production') end context 'when user has ability to trigger deployment' do - given(:permissions) do + let(:permissions) do create(:protected_branch, :developers_can_merge, name: action.ref, project: project) end @@ -91,21 +91,21 @@ feature 'Environment' do end context 'with external_url' do - given(:environment) { create(:environment, project: project, external_url: 'https://git.gitlab.com') } - given(:build) { create(:ci_build, pipeline: pipeline) } - given(:deployment) { create(:deployment, environment: environment, deployable: build) } + let(:environment) { create(:environment, project: project, external_url: 'https://git.gitlab.com') } + let(:build) { create(:ci_build, pipeline: pipeline) } + let(:deployment) { create(:deployment, environment: environment, deployable: build) } - scenario 'does show an external link button' do + it 'does show an external link button' do expect(page).to have_link(nil, href: environment.external_url) end end context 'with terminal' do shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do - context 'for project master' do - let(:role) { :master } + context 'for project maintainer' do + let(:role) { :maintainer } - scenario 'it shows the terminal button' do + it 'it shows the terminal button' do expect(page).to have_terminal_button end @@ -126,7 +126,7 @@ feature 'Environment' do context 'for developer' do let(:role) { :developer } - scenario 'does not show terminal button' do + it 'does not show terminal button' do expect(page).not_to have_terminal_button end end @@ -148,25 +148,26 @@ feature 'Environment' do context 'when environment is available' do context 'with stop action' do - given(:action) do + let(:action) do create(:ci_build, :manual, pipeline: pipeline, name: 'close_app') end - given(:deployment) do + let(:deployment) do create(:deployment, environment: environment, deployable: build, on_stop: 'close_app') end context 'when user has ability to stop environment' do - given(:permissions) do + let(:permissions) do create(:protected_branch, :developers_can_merge, name: action.ref, project: project) end it 'allows to stop environment' do - click_link('Stop') + click_button('Stop') + click_button('Stop environment') # confirm modal expect(page).to have_content('close_app') end @@ -174,25 +175,25 @@ feature 'Environment' do context 'when user has no ability to stop environment' do it 'does not allow to stop environment' do - expect(page).to have_no_link('Stop') + expect(page).not_to have_button('Stop') end end context 'for reporter' do let(:role) { :reporter } - scenario 'does not show stop button' do - expect(page).not_to have_link('Stop') + it 'does not show stop button' do + expect(page).not_to have_button('Stop') end end end end context 'when environment is stopped' do - given(:environment) { create(:environment, project: project, state: :stopped) } + let(:environment) { create(:environment, project: project, state: :stopped) } - scenario 'does not show stop button' do - expect(page).not_to have_link('Stop') + it 'does not show stop button' do + expect(page).not_to have_button('Stop') end end end @@ -200,7 +201,7 @@ feature 'Environment' do end end - feature 'environment folders', :js do + describe 'environment folders', :js do context 'when folder name contains special charaters' do before do create(:environment, project: project, @@ -219,21 +220,21 @@ feature 'Environment' do end end - feature 'auto-close environment when branch is deleted' do - given(:project) { create(:project, :repository) } + describe 'auto-close environment when branch is deleted' do + let(:project) { create(:project, :repository) } - given!(:environment) do + let!(:environment) do create(:environment, :with_review_app, project: project, ref: 'feature') end - scenario 'user visits environment page' do + it 'user visits environment page' do visit_environment(environment) - expect(page).to have_link('Stop') + expect(page).to have_button('Stop') end - scenario 'user deletes the branch with running environment' do + it 'user deletes the branch with running environment' do visit project_branches_filtered_path(project, state: 'all', search: 'feature') remove_branch_with_hooks(project, user, 'feature') do @@ -242,7 +243,7 @@ feature 'Environment' do visit_environment(environment) - expect(page).to have_no_link('Stop') + expect(page).not_to have_button('Stop') end ## diff --git a/spec/features/projects/environments/environments_spec.rb b/spec/features/projects/environments/environments_spec.rb index f9defa22d35..f0890018286 100644 --- a/spec/features/projects/environments/environments_spec.rb +++ b/spec/features/projects/environments/environments_spec.rb @@ -1,15 +1,19 @@ require 'spec_helper' -feature 'Environments page', :js do - given(:project) { create(:project) } - given(:user) { create(:user) } - given(:role) { :developer } +describe 'Environments page', :js do + let(:project) { create(:project) } + let(:user) { create(:user) } + let(:role) { :developer } - background do + before do project.add_role(user, role) sign_in(user) end + def stop_button_selector + %q{button[data-original-title="Stop environment"]} + end + describe 'page tabs' do it 'shows "Available" and "Stopped" tab with links' do visit_environments(project) @@ -99,7 +103,7 @@ feature 'Environments page', :js do end describe 'environments table' do - given!(:environment) do + let!(:environment) do create(:environment, project: project, state: :available) end @@ -120,14 +124,14 @@ feature 'Environments page', :js do end it 'does not show stip button when environment is not stoppable' do - expect(page).not_to have_selector('.stop-env-link') + expect(page).not_to have_selector(stop_button_selector) end end context 'when there are deployments' do - given(:project) { create(:project, :repository) } + let(:project) { create(:project, :repository) } - given!(:deployment) do + let!(:deployment) do create(:deployment, environment: environment, sha: project.commit.id) end @@ -140,14 +144,14 @@ feature 'Environments page', :js do end context 'when builds and manual actions are present' do - given!(:pipeline) { create(:ci_pipeline, project: project) } - given!(:build) { create(:ci_build, pipeline: pipeline) } + let!(:pipeline) { create(:ci_pipeline, project: project) } + let!(:build) { create(:ci_build, pipeline: pipeline) } - given!(:action) do + let!(:action) do create(:ci_build, :manual, pipeline: pipeline, name: 'deploy to production') end - given!(:deployment) do + let!(:deployment) do create(:deployment, environment: environment, deployable: build, sha: project.commit.id) @@ -178,7 +182,7 @@ feature 'Environments page', :js do end it 'shows a stop button' do - expect(page).not_to have_selector('.stop-env-link') + expect(page).not_to have_selector(stop_button_selector) end it 'does not show external link button' do @@ -190,9 +194,9 @@ feature 'Environments page', :js do end context 'with external_url' do - given(:environment) { create(:environment, project: project, external_url: 'https://git.gitlab.com') } - given(:build) { create(:ci_build, pipeline: pipeline) } - given(:deployment) { create(:deployment, environment: environment, deployable: build) } + let(:environment) { create(:environment, project: project, external_url: 'https://git.gitlab.com') } + let(:build) { create(:ci_build, pipeline: pipeline) } + let(:deployment) { create(:deployment, environment: environment, deployable: build) } it 'shows an external link button' do expect(page).to have_link(nil, href: environment.external_url) @@ -200,33 +204,33 @@ feature 'Environments page', :js do end context 'with stop action' do - given(:action) do + let(:action) do create(:ci_build, :manual, pipeline: pipeline, name: 'close_app') end - given(:deployment) do + let(:deployment) do create(:deployment, environment: environment, deployable: build, on_stop: 'close_app') end it 'shows a stop button' do - expect(page).to have_selector('.stop-env-link') + expect(page).to have_selector(stop_button_selector) end context 'when user is a reporter' do let(:role) { :reporter } it 'does not show stop button' do - expect(page).not_to have_selector('.stop-env-link') + expect(page).not_to have_selector(stop_button_selector) end end end context 'when kubernetes terminal is available' do shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do - context 'for project master' do - let(:role) { :master } + context 'for project maintainer' do + let(:role) { :maintainer } it 'shows the terminal button' do expect(page).to have_terminal_button @@ -271,9 +275,9 @@ feature 'Environments page', :js do end context 'user is a developer' do - given(:role) { :developer } + let(:role) { :developer } - scenario 'developer creates a new environment with a valid name' do + it 'developer creates a new environment with a valid name' do within(".top-area") { click_link 'New environment' } fill_in('Name', with: 'production') click_on 'Save' @@ -281,7 +285,7 @@ feature 'Environments page', :js do expect(page).to have_content('production') end - scenario 'developer creates a new environmetn with invalid name' do + it 'developer creates a new environmetn with invalid name' do within(".top-area") { click_link 'New environment' } fill_in('Name', with: 'name,with,commas') click_on 'Save' @@ -291,9 +295,9 @@ feature 'Environments page', :js do end context 'user is a reporter' do - given(:role) { :reporter } + let(:role) { :reporter } - scenario 'reporters tries to create a new environment' do + it 'reporters tries to create a new environment' do expect(page).not_to have_link('New environment') end end @@ -309,7 +313,7 @@ feature 'Environments page', :js do state: :available) end - scenario 'users unfurls an environment folder' do + it 'users unfurls an environment folder' do visit_environments(project) expect(page).not_to have_content 'review-1' @@ -335,7 +339,7 @@ feature 'Environments page', :js do state: :available) end - scenario 'user opens folder view' do + it 'user opens folder view' do visit folder_project_environments_path(project, 'staging.review') wait_for_requests diff --git a/spec/features/projects/features_visibility_spec.rb b/spec/features/projects/features_visibility_spec.rb index b0eb7c5b42a..ab16fdee883 100644 --- a/spec/features/projects/features_visibility_spec.rb +++ b/spec/features/projects/features_visibility_spec.rb @@ -8,7 +8,7 @@ describe 'Edit Project Settings' do describe 'project features visibility selectors', :js do before do - project.add_master(member) + project.add_maintainer(member) sign_in(member) end @@ -165,7 +165,7 @@ describe 'Edit Project Settings' do describe 'repository visibility', :js do before do - project.add_master(member) + project.add_maintainer(member) sign_in(member) visit edit_project_path(project) end diff --git a/spec/features/projects/files/project_owner_creates_license_file_spec.rb b/spec/features/projects/files/project_owner_creates_license_file_spec.rb index b410199fd1f..ac6c8c337fa 100644 --- a/spec/features/projects/files/project_owner_creates_license_file_spec.rb +++ b/spec/features/projects/files/project_owner_creates_license_file_spec.rb @@ -2,16 +2,16 @@ require 'spec_helper' describe 'Projects > Files > Project owner creates a license file', :js do let(:project) { create(:project, :repository) } - let(:project_master) { project.owner } + let(:project_maintainer) { project.owner } before do - project.repository.delete_file(project_master, 'LICENSE', + project.repository.delete_file(project_maintainer, 'LICENSE', message: 'Remove LICENSE', branch_name: 'master') - sign_in(project_master) + sign_in(project_maintainer) visit project_path(project) end - it 'project master creates a license file manually from a template' do + it 'project maintainer creates a license file manually from a template' do visit project_tree_path(project, project.repository.root_ref) find('.add-to-tree').click click_link 'New file' @@ -35,7 +35,7 @@ describe 'Projects > Files > Project owner creates a license file', :js do expect(page).to have_content("Copyright (c) #{Time.now.year} #{project.namespace.human_name}") end - it 'project master creates a license file from the "Add license" link' do + it 'project maintainer creates a license file from the "Add license" link' do click_link 'Add License' expect(page).to have_content('New file') diff --git a/spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb b/spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb index 53d8ace7c94..801291c1f77 100644 --- a/spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb +++ b/spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb @@ -2,13 +2,13 @@ require 'spec_helper' describe 'Projects > Files > Project owner sees a link to create a license file in empty project', :js do let(:project) { create(:project_empty_repo) } - let(:project_master) { project.owner } + let(:project_maintainer) { project.owner } before do - sign_in(project_master) + sign_in(project_maintainer) end - it 'project master creates a license file from a template' do + it 'project maintainer creates a license file from a template' do visit project_path(project) click_on 'Add License' expect(page).to have_content('New file') diff --git a/spec/features/projects/files/template_selector_menu_spec.rb b/spec/features/projects/files/template_selector_menu_spec.rb index b549a69ddf3..6b313824acd 100644 --- a/spec/features/projects/files/template_selector_menu_spec.rb +++ b/spec/features/projects/files/template_selector_menu_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -feature 'Template selector menu', :js do +describe 'Template selector menu', :js do let(:project) { create(:project, :repository) } let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in user end @@ -14,7 +14,7 @@ feature 'Template selector menu', :js do create_and_edit_file('README.md') end - scenario 'is not displayed' do + it 'is not displayed' do check_template_selector_menu_display(false) end @@ -23,7 +23,7 @@ feature 'Template selector menu', :js do click_link 'Preview' end - scenario 'template selector menu is not displayed' do + it 'template selector menu is not displayed' do check_template_selector_menu_display(false) click_link 'Write' check_template_selector_menu_display(false) @@ -36,7 +36,7 @@ feature 'Template selector menu', :js do visit project_edit_blob_path(project, File.join(project.default_branch, 'LICENSE')) end - scenario 'is displayed' do + it 'is displayed' do check_template_selector_menu_display(true) end @@ -45,7 +45,7 @@ feature 'Template selector menu', :js do click_link 'Preview' end - scenario 'template selector menu is hidden and shown correctly' do + it 'template selector menu is hidden and shown correctly' do check_template_selector_menu_display(false) click_link 'Write' check_template_selector_menu_display(true) diff --git a/spec/features/projects/files/user_browses_files_spec.rb b/spec/features/projects/files/user_browses_files_spec.rb index 41f6c52fb8a..f56174fc85c 100644 --- a/spec/features/projects/files/user_browses_files_spec.rb +++ b/spec/features/projects/files/user_browses_files_spec.rb @@ -147,11 +147,8 @@ describe "User browses files" do page.within(".tree-table") do click_link("README.md") end - - # rubocop:disable Lint/Void # Test the full URLs of links instead of relative paths by `have_link(text: "...", href: "...")`. find("a", text: /^empty$/)["href"] == project_blob_url(project, "markdown/d/README.md") - # rubocop:enable Lint/Void end it "shows correct content of directory" do diff --git a/spec/features/projects/files/user_creates_files_spec.rb b/spec/features/projects/files/user_creates_files_spec.rb index 208cc8d81f7..d4dda43c823 100644 --- a/spec/features/projects/files/user_creates_files_spec.rb +++ b/spec/features/projects/files/user_creates_files_spec.rb @@ -12,7 +12,7 @@ describe 'Projects > Files > User creates files' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/files/user_deletes_files_spec.rb b/spec/features/projects/files/user_deletes_files_spec.rb index 36d3e001a64..0e9f83a16ce 100644 --- a/spec/features/projects/files/user_deletes_files_spec.rb +++ b/spec/features/projects/files/user_deletes_files_spec.rb @@ -17,7 +17,7 @@ describe 'Projects > Files > User deletes files' do context 'when an user has write access' do before do - project.add_master(user) + project.add_maintainer(user) visit(project_tree_path_root_ref) end diff --git a/spec/features/projects/files/user_edits_files_spec.rb b/spec/features/projects/files/user_edits_files_spec.rb index dc6e4fd27cb..ccc1bc1bc10 100644 --- a/spec/features/projects/files/user_edits_files_spec.rb +++ b/spec/features/projects/files/user_edits_files_spec.rb @@ -31,7 +31,7 @@ describe 'Projects > Files > User edits files' do context 'when an user has write access' do before do - project.add_master(user) + project.add_maintainer(user) visit(project_tree_path_root_ref) end diff --git a/spec/features/projects/files/user_find_file_spec.rb b/spec/features/projects/files/user_find_file_spec.rb index df405e70dd4..e2d881b34d2 100644 --- a/spec/features/projects/files/user_find_file_spec.rb +++ b/spec/features/projects/files/user_find_file_spec.rb @@ -6,7 +6,7 @@ describe 'User find project file' do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) visit project_tree_path(project, project.repository.root_ref) end diff --git a/spec/features/projects/files/user_reads_pipeline_status_spec.rb b/spec/features/projects/files/user_reads_pipeline_status_spec.rb index 2fb9da2f0a2..ff0aa933a3e 100644 --- a/spec/features/projects/files/user_reads_pipeline_status_spec.rb +++ b/spec/features/projects/files/user_reads_pipeline_status_spec.rb @@ -7,7 +7,7 @@ describe 'user reads pipeline status', :js do let(:x110_pipeline) { create_pipeline('x1.1.0', 'failed') } before do - project.add_master(user) + project.add_maintainer(user) project.repository.add_tag(user, 'x1.1.0', 'v1.1.0') v110_pipeline @@ -17,7 +17,7 @@ describe 'user reads pipeline status', :js do end shared_examples 'visiting project tree' do - scenario 'sees the correct pipeline status' do + it 'sees the correct pipeline status' do visit project_tree_path(project, expected_pipeline.ref) wait_for_requests diff --git a/spec/features/projects/files/user_replaces_files_spec.rb b/spec/features/projects/files/user_replaces_files_spec.rb index 9ac3417b671..3a81e77c4ba 100644 --- a/spec/features/projects/files/user_replaces_files_spec.rb +++ b/spec/features/projects/files/user_replaces_files_spec.rb @@ -19,7 +19,7 @@ describe 'Projects > Files > User replaces files' do context 'when an user has write access' do before do - project.add_master(user) + project.add_maintainer(user) visit(project_tree_path_root_ref) end diff --git a/spec/features/projects/files/user_uploads_files_spec.rb b/spec/features/projects/files/user_uploads_files_spec.rb index 8b212faa29d..af3fc528a20 100644 --- a/spec/features/projects/files/user_uploads_files_spec.rb +++ b/spec/features/projects/files/user_uploads_files_spec.rb @@ -14,7 +14,7 @@ describe 'Projects > Files > User uploads files' do let(:project2_tree_path_root_ref) { project_tree_path(project2, project2.repository.root_ref) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/fork_spec.rb b/spec/features/projects/fork_spec.rb index 1743b1e083f..cd5fef8238e 100644 --- a/spec/features/projects/fork_spec.rb +++ b/spec/features/projects/fork_spec.rb @@ -129,11 +129,11 @@ describe 'Project fork' do end end - context 'master in group' do + context 'maintainer in group' do let(:group) { create(:group) } before do - group.add_master(user) + group.add_maintainer(user) end it 'allows user to fork project to group or to user namespace' do diff --git a/spec/features/projects/graph_spec.rb b/spec/features/projects/graph_spec.rb index 335174b7729..9665f1755d6 100644 --- a/spec/features/projects/graph_spec.rb +++ b/spec/features/projects/graph_spec.rb @@ -6,7 +6,7 @@ describe 'Project Graph', :js do let(:branch_name) { 'master' } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/hook_logs/user_reads_log_spec.rb b/spec/features/projects/hook_logs/user_reads_log_spec.rb index 18e975fa653..086cd4b9f03 100644 --- a/spec/features/projects/hook_logs/user_reads_log_spec.rb +++ b/spec/features/projects/hook_logs/user_reads_log_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' -feature 'Hook logs' do - given(:web_hook_log) { create(:web_hook_log, response_body: '<script>') } - given(:project) { web_hook_log.web_hook.project } - given(:user) { create(:user) } +describe 'Hook logs' do + let(:web_hook_log) { create(:web_hook_log, response_body: '<script>') } + let(:project) { web_hook_log.web_hook.project } + let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end - scenario 'user reads log without getting XSS' do + it 'user reads log without getting XSS' do visit( project_hook_hook_log_path( project, web_hook_log.web_hook, web_hook_log)) diff --git a/spec/features/projects/import_export/export_file_spec.rb b/spec/features/projects/import_export/export_file_spec.rb index 6732cf61767..eb281cd2122 100644 --- a/spec/features/projects/import_export/export_file_spec.rb +++ b/spec/features/projects/import_export/export_file_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' # It looks up for any sensitive word inside the JSON, so if a sensitive word is found # we'll have to either include it adding the model that includes it to the +safe_list+ # or make sure the attribute is blacklisted in the +import_export.yml+ configuration -feature 'Import/Export - project export integration test', :js do +describe 'Import/Export - project export integration test', :js do include Select2Helper include ExportFileHelper @@ -23,8 +23,9 @@ feature 'Import/Export - project export integration test', :js do let(:project) { setup_project } - background do + before do allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) + stub_feature_flags(import_export_object_storage: false) end after do @@ -36,7 +37,7 @@ feature 'Import/Export - project export integration test', :js do sign_in(user) end - scenario 'exports a project successfully' do + it 'exports a project successfully' do visit edit_project_path(project) expect(page).to have_content('Export project') diff --git a/spec/features/projects/import_export/import_file_spec.rb b/spec/features/projects/import_export/import_file_spec.rb index d0912e645bc..9cbfb62d872 100644 --- a/spec/features/projects/import_export/import_file_spec.rb +++ b/spec/features/projects/import_export/import_file_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -feature 'Import/Export - project import integration test', :js do +describe 'Import/Export - project import integration test', :js do include Select2Helper let(:user) { create(:user) } let(:file) { File.join(Rails.root, 'spec', 'features', 'projects', 'import_export', 'test_project_export.tar.gz') } let(:export_path) { "#{Dir.tmpdir}/import_file_spec" } - background do + before do allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) gitlab_sign_in(user) end @@ -22,7 +22,7 @@ feature 'Import/Export - project import integration test', :js do let(:project_path) { 'test-project-path' + SecureRandom.hex } context 'prefilled the path' do - scenario 'user imports an exported project successfully' do + it 'user imports an exported project successfully' do visit new_project_path select2(namespace.id, from: '#project_namespace_id') @@ -51,7 +51,7 @@ feature 'Import/Export - project import integration test', :js do end context 'path is not prefilled' do - scenario 'user imports an exported project successfully' do + it 'user imports an exported project successfully' do visit new_project_path click_import_project_tab click_link 'GitLab export' @@ -68,7 +68,7 @@ feature 'Import/Export - project import integration test', :js do end end - scenario 'invalid project' do + it 'invalid project' do project = create(:project, namespace: user.namespace) visit new_project_path diff --git a/spec/features/projects/import_export/namespace_export_file_spec.rb b/spec/features/projects/import_export/namespace_export_file_spec.rb index 7d056b0c140..9bb8a2063b5 100644 --- a/spec/features/projects/import_export/namespace_export_file_spec.rb +++ b/spec/features/projects/import_export/namespace_export_file_spec.rb @@ -5,6 +5,7 @@ describe 'Import/Export - Namespace export file cleanup', :js do before do allow(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) + stub_feature_flags(import_export_object_storage: false) end after do diff --git a/spec/features/projects/import_export/test_project_export.tar.gz b/spec/features/projects/import_export/test_project_export.tar.gz Binary files differindex ceba4dfec57..3b5df47e0b6 100644 --- a/spec/features/projects/import_export/test_project_export.tar.gz +++ b/spec/features/projects/import_export/test_project_export.tar.gz diff --git a/spec/features/projects/issuable_templates_spec.rb b/spec/features/projects/issuable_templates_spec.rb index e26caf1f456..a57edc394f9 100644 --- a/spec/features/projects/issuable_templates_spec.rb +++ b/spec/features/projects/issuable_templates_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'issuable templates', :js do +describe 'issuable templates', :js do include ProjectForksHelper let(:user) { create(:user) } @@ -8,7 +8,7 @@ feature 'issuable templates', :js do let(:issue_form_location) { '#content-body .issuable-details .detail-page-description' } before do - project.add_master(user) + project.add_maintainer(user) sign_in user end @@ -18,7 +18,7 @@ feature 'issuable templates', :js do let(:issue) { create(:issue, author: user, assignees: [user], project: project) } let(:description_addition) { ' appending to description' } - background do + before do project.repository.create_file( user, '.gitlab/issue_templates/bug.md', @@ -36,14 +36,14 @@ feature 'issuable templates', :js do fill_in :'issuable-title', with: 'test issue title' end - scenario 'user selects "bug" template' do + it 'user selects "bug" template' do select_template 'bug' wait_for_requests assert_template(page_part: issue_form_location) save_changes end - scenario 'user selects "bug" template and then "no template"' do + it 'user selects "bug" template and then "no template"' do select_template 'bug' wait_for_requests select_option 'No template' @@ -51,7 +51,7 @@ feature 'issuable templates', :js do save_changes('') end - scenario 'user selects "bug" template, edits description and then selects "reset template"' do + it 'user selects "bug" template, edits description and then selects "reset template"' do select_template 'bug' wait_for_requests find_field('issue-description').send_keys(description_addition) @@ -67,7 +67,7 @@ feature 'issuable templates', :js do let(:template_content) { 'this is a test "bug" template' } let(:issue) { create(:issue, author: user, assignees: [user], project: project) } - background do + before do project.repository.create_file( user, '.gitlab/issue_templates/bug.md', @@ -80,7 +80,7 @@ feature 'issuable templates', :js do fill_in :'issue-description', with: prior_description end - scenario 'user selects "bug" template' do + it 'user selects "bug" template' do select_template 'bug' wait_for_requests assert_template(page_part: issue_form_location) @@ -92,7 +92,7 @@ feature 'issuable templates', :js do let(:template_content) { 'this is a test "feature-proposal" template' } let(:merge_request) { create(:merge_request, :with_diffs, source_project: project) } - background do + before do project.repository.create_file( user, '.gitlab/merge_request_templates/feature-proposal.md', @@ -103,7 +103,7 @@ feature 'issuable templates', :js do fill_in :'merge_request[title]', with: 'test merge request title' end - scenario 'user selects "feature-proposal" template' do + it 'user selects "feature-proposal" template' do select_template 'feature-proposal' wait_for_requests assert_template @@ -117,7 +117,7 @@ feature 'issuable templates', :js do let(:forked_project) { fork_project(project, fork_user, repository: true) } let(:merge_request) { create(:merge_request, :with_diffs, source_project: forked_project, target_project: project) } - background do + before do sign_out(:user) project.add_developer(fork_user) @@ -136,7 +136,7 @@ feature 'issuable templates', :js do context 'feature proposal template' do context 'template exists in target project' do - scenario 'user selects template' do + it 'user selects template' do select_template 'feature-proposal' wait_for_requests assert_template diff --git a/spec/features/projects/issues/rss_spec.rb b/spec/features/projects/issues/rss_spec.rb index 8b1f7d432ee..0e1383cd607 100644 --- a/spec/features/projects/issues/rss_spec.rb +++ b/spec/features/projects/issues/rss_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Project Issues RSS' do +describe 'Project Issues RSS' do let(:project) { create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC) } let(:path) { project_issues_path(project) } diff --git a/spec/features/projects/issues/user_comments_on_issue_spec.rb b/spec/features/projects/issues/user_comments_on_issue_spec.rb index 353f487485d..ba5b80ed04b 100644 --- a/spec/features/projects/issues/user_comments_on_issue_spec.rb +++ b/spec/features/projects/issues/user_comments_on_issue_spec.rb @@ -63,6 +63,14 @@ describe "User comments on issue", :js do page.within(".current-note-edit-form") do fill_in("note[note]", with: comment) + find('textarea').send_keys [:control, :shift, 'p'] + expect(page).to have_selector('.current-note-edit-form .md-preview-holder') + expect(page.find('.current-note-edit-form .md-preview-holder p')).to have_content(comment) + end + + expect(page).to have_selector('.new-note .note-textarea') + + page.within(".current-note-edit-form") do click_button("Save comment") end diff --git a/spec/features/projects/issues/user_creates_issue_spec.rb b/spec/features/projects/issues/user_creates_issue_spec.rb index e76f7c5589d..5e8662100c5 100644 --- a/spec/features/projects/issues/user_creates_issue_spec.rb +++ b/spec/features/projects/issues/user_creates_issue_spec.rb @@ -17,6 +17,9 @@ describe "User creates issue" do expect(page).to have_no_content("Assign to") .and have_no_content("Labels") .and have_no_content("Milestone") + + expect(page.find('#issue_title')['placeholder']).to eq 'Title' + expect(page.find('#issue_description')['placeholder']).to eq 'Write a comment or drag your files here…' end issue_title = "500 error on profile" diff --git a/spec/features/projects/jobs/permissions_spec.rb b/spec/features/projects/jobs/permissions_spec.rb index e9588daf37d..e639f0cf82e 100644 --- a/spec/features/projects/jobs/permissions_spec.rb +++ b/spec/features/projects/jobs/permissions_spec.rb @@ -90,7 +90,7 @@ describe 'Project Jobs Permissions' do before do archive = fixture_file_upload('spec/fixtures/ci_build_artifacts.zip') - job.update_attributes(legacy_artifacts_file: archive) + job.update(legacy_artifacts_file: archive) end context 'when public access for jobs is disabled' do diff --git a/spec/features/projects/jobs/user_browses_job_spec.rb b/spec/features/projects/jobs/user_browses_job_spec.rb index ce0b38b7239..50e957bf12b 100644 --- a/spec/features/projects/jobs/user_browses_job_spec.rb +++ b/spec/features/projects/jobs/user_browses_job_spec.rb @@ -8,7 +8,7 @@ describe 'User browses a job', :js do let!(:build) { create(:ci_build, :success, :trace_artifact, :coverage, pipeline: pipeline) } before do - project.add_master(user) + project.add_maintainer(user) project.enable_ci sign_in(user) diff --git a/spec/features/projects/jobs/user_browses_jobs_spec.rb b/spec/features/projects/jobs/user_browses_jobs_spec.rb index 786ec327b92..08786fe1630 100644 --- a/spec/features/projects/jobs/user_browses_jobs_spec.rb +++ b/spec/features/projects/jobs/user_browses_jobs_spec.rb @@ -7,7 +7,7 @@ describe 'User browses jobs' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) project.enable_ci project.update_attribute(:build_coverage_regex, /Coverage (\d+)%/) diff --git a/spec/features/projects/jobs_spec.rb b/spec/features/projects/jobs_spec.rb index d2aaf60e72c..35b1c46ecf6 100644 --- a/spec/features/projects/jobs_spec.rb +++ b/spec/features/projects/jobs_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'tempfile' -feature 'Jobs', :clean_gitlab_redis_shared_state do +describe 'Jobs', :clean_gitlab_redis_shared_state do let(:user) { create(:user) } let(:user_access_level) { :developer } let(:project) { create(:project, :repository) } @@ -165,7 +165,7 @@ feature 'Jobs', :clean_gitlab_redis_shared_state do it 'links to issues/new with the title and description filled in' do button_title = "Job Failed ##{job.id}" - job_url = project_job_path(project, job) + job_url = project_job_url(project, job, host: page.server.host, port: page.server.port) options = { issue: { title: button_title, description: "Job [##{job.id}](#{job_url}) failed for #{job.sha}:\n" } } href = new_project_issue_path(project, options) @@ -187,7 +187,7 @@ feature 'Jobs', :clean_gitlab_redis_shared_state do context "Download artifacts" do before do - job.update_attributes(legacy_artifacts_file: artifacts_file) + job.update(legacy_artifacts_file: artifacts_file) visit project_job_path(project, job) end @@ -198,8 +198,8 @@ feature 'Jobs', :clean_gitlab_redis_shared_state do context 'Artifacts expire date' do before do - job.update_attributes(legacy_artifacts_file: artifacts_file, - artifacts_expire_at: expire_at) + job.update(legacy_artifacts_file: artifacts_file, + artifacts_expire_at: expire_at) visit project_job_path(project, job) end @@ -259,7 +259,7 @@ feature 'Jobs', :clean_gitlab_redis_shared_state do end end - feature 'Raw trace' do + describe 'Raw trace' do before do job.run! @@ -271,7 +271,7 @@ feature 'Jobs', :clean_gitlab_redis_shared_state do end end - feature 'HTML trace', :js do + describe 'HTML trace', :js do before do job.run! @@ -291,7 +291,7 @@ feature 'Jobs', :clean_gitlab_redis_shared_state do end end - feature 'Variables' do + describe 'Variables' do let(:trigger_request) { create(:ci_trigger_request) } let(:job) do @@ -530,14 +530,14 @@ feature 'Jobs', :clean_gitlab_redis_shared_state do describe "GET /:project/jobs/:id/download" do before do - job.update_attributes(legacy_artifacts_file: artifacts_file) + job.update(legacy_artifacts_file: artifacts_file) visit project_job_path(project, job) click_link 'Download' end context "Build from other project" do before do - job2.update_attributes(legacy_artifacts_file: artifacts_file) + job2.update(legacy_artifacts_file: artifacts_file) visit download_project_job_artifacts_path(project, job2) end diff --git a/spec/features/projects/labels/issues_sorted_by_priority_spec.rb b/spec/features/projects/labels/issues_sorted_by_priority_spec.rb index 0292a3192d8..6178f11ded7 100644 --- a/spec/features/projects/labels/issues_sorted_by_priority_spec.rb +++ b/spec/features/projects/labels/issues_sorted_by_priority_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Issue prioritization' do +describe 'Issue prioritization' do let(:user) { create(:user) } let(:project) { create(:project, name: 'test', namespace: user.namespace) } @@ -13,7 +13,7 @@ feature 'Issue prioritization' do # According to https://gitlab.com/gitlab-org/gitlab-ce/issues/14189#note_4360653 context 'when issues have one label' do - scenario 'Are sorted properly' do + it 'Are sorted properly' do # Issues issue_1 = create(:issue, title: 'issue_1', project: project) issue_2 = create(:issue, title: 'issue_2', project: project) @@ -43,7 +43,7 @@ feature 'Issue prioritization' do end context 'when issues have multiple labels' do - scenario 'Are sorted properly' do + it 'Are sorted properly' do # Issues issue_1 = create(:issue, title: 'issue_1', project: project) issue_2 = create(:issue, title: 'issue_2', project: project) diff --git a/spec/features/projects/labels/subscription_spec.rb b/spec/features/projects/labels/subscription_spec.rb index fafd338e448..49227eebf3d 100644 --- a/spec/features/projects/labels/subscription_spec.rb +++ b/spec/features/projects/labels/subscription_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Labels subscription' do +describe 'Labels subscription' do let(:user) { create(:user) } let(:group) { create(:group) } let(:project) { create(:project, :public, namespace: group) } @@ -13,7 +13,7 @@ feature 'Labels subscription' do sign_in user end - scenario 'users can subscribe/unsubscribe to labels', :js do + it 'users can subscribe/unsubscribe to labels', :js do visit project_labels_path(project) expect(page).to have_content('bug') diff --git a/spec/features/projects/labels/update_prioritization_spec.rb b/spec/features/projects/labels/update_prioritization_spec.rb index 359381c391c..996040fde02 100644 --- a/spec/features/projects/labels/update_prioritization_spec.rb +++ b/spec/features/projects/labels/update_prioritization_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Prioritize labels' do +describe 'Prioritize labels' do include DragTo let(:user) { create(:user) } @@ -17,7 +17,7 @@ feature 'Prioritize labels' do sign_in user end - scenario 'user can prioritize a group label', :js do + it 'user can prioritize a group label', :js do visit project_labels_path(project) expect(page).to have_content('Star labels to start sorting by priority') @@ -34,7 +34,7 @@ feature 'Prioritize labels' do end end - scenario 'user can unprioritize a group label', :js do + it 'user can unprioritize a group label', :js do create(:label_priority, project: project, label: feature, priority: 1) visit project_labels_path(project) @@ -52,7 +52,7 @@ feature 'Prioritize labels' do end end - scenario 'user can prioritize a project label', :js do + it 'user can prioritize a project label', :js do visit project_labels_path(project) expect(page).to have_content('Star labels to start sorting by priority') @@ -69,7 +69,7 @@ feature 'Prioritize labels' do end end - scenario 'user can unprioritize a project label', :js do + it 'user can unprioritize a project label', :js do create(:label_priority, project: project, label: bug, priority: 1) visit project_labels_path(project) @@ -88,7 +88,7 @@ feature 'Prioritize labels' do end end - scenario 'user can sort prioritized labels and persist across reloads', :js do + it 'user can sort prioritized labels and persist across reloads', :js do create(:label_priority, project: project, label: bug, priority: 1) create(:label_priority, project: project, label: feature, priority: 2) diff --git a/spec/features/projects/labels/user_creates_labels_spec.rb b/spec/features/projects/labels/user_creates_labels_spec.rb index 9fd7f3ee775..c71b04fea09 100644 --- a/spec/features/projects/labels/user_creates_labels_spec.rb +++ b/spec/features/projects/labels/user_creates_labels_spec.rb @@ -18,7 +18,7 @@ describe "User creates labels" do context "in project" do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(new_project_label_path(project)) @@ -69,7 +69,7 @@ describe "User creates labels" do before do create(:label, project: project, title: "bug") # Create label for `project` (not `another_project`) project. - another_project.add_master(user) + another_project.add_maintainer(user) sign_in(user) visit(new_project_label_path(another_project)) diff --git a/spec/features/projects/labels/user_edits_labels_spec.rb b/spec/features/projects/labels/user_edits_labels_spec.rb index d1041ff5c1e..0708bbd40ce 100644 --- a/spec/features/projects/labels/user_edits_labels_spec.rb +++ b/spec/features/projects/labels/user_edits_labels_spec.rb @@ -6,7 +6,7 @@ describe "User edits labels" do set(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(edit_project_label_path(project, label)) diff --git a/spec/features/projects/labels/user_removes_labels_spec.rb b/spec/features/projects/labels/user_removes_labels_spec.rb index efa74015c6e..b0ce03a1c31 100644 --- a/spec/features/projects/labels/user_removes_labels_spec.rb +++ b/spec/features/projects/labels/user_removes_labels_spec.rb @@ -5,7 +5,7 @@ describe "User removes labels" do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/labels/user_sees_links_to_issuables.rb b/spec/features/projects/labels/user_sees_links_to_issuables.rb index aa56fd7f74e..c404fc8d66f 100644 --- a/spec/features/projects/labels/user_sees_links_to_issuables.rb +++ b/spec/features/projects/labels/user_sees_links_to_issuables.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Projects > Labels > User sees links to issuables' do +describe 'Projects > Labels > User sees links to issuables' do set(:user) { create(:user) } before do @@ -16,7 +16,7 @@ feature 'Projects > Labels > User sees links to issuables' do context 'when merge requests and issues are enabled for the project' do let(:project) { create(:project, :public) } - scenario 'shows links to MRs and issues' do + it 'shows links to MRs and issues' do expect(page).to have_link('view merge requests') expect(page).to have_link('view open issues') end @@ -25,7 +25,7 @@ feature 'Projects > Labels > User sees links to issuables' do context 'when issues are disabled for the project' do let(:project) { create(:project, :public, issues_access_level: ProjectFeature::DISABLED) } - scenario 'shows links to MRs but not to issues' do + it 'shows links to MRs but not to issues' do expect(page).to have_link('view merge requests') expect(page).not_to have_link('view open issues') end @@ -34,7 +34,7 @@ feature 'Projects > Labels > User sees links to issuables' do context 'when merge requests are disabled for the project' do let(:project) { create(:project, :public, merge_requests_access_level: ProjectFeature::DISABLED) } - scenario 'shows links to issues but not to MRs' do + it 'shows links to issues but not to MRs' do expect(page).not_to have_link('view merge requests') expect(page).to have_link('view open issues') end @@ -48,7 +48,7 @@ feature 'Projects > Labels > User sees links to issuables' do context 'when merge requests and issues are enabled for the project' do let(:project) { create(:project, :public, namespace: group) } - scenario 'shows links to MRs and issues' do + it 'shows links to MRs and issues' do expect(page).to have_link('view merge requests') expect(page).to have_link('view open issues') end @@ -57,7 +57,7 @@ feature 'Projects > Labels > User sees links to issuables' do context 'when issues are disabled for the project' do let(:project) { create(:project, :public, namespace: group, issues_access_level: ProjectFeature::DISABLED) } - scenario 'shows links to MRs and issues' do + it 'shows links to MRs and issues' do expect(page).to have_link('view merge requests') expect(page).to have_link('view open issues') end @@ -66,7 +66,7 @@ feature 'Projects > Labels > User sees links to issuables' do context 'when merge requests are disabled for the project' do let(:project) { create(:project, :public, namespace: group, merge_requests_access_level: ProjectFeature::DISABLED) } - scenario 'shows links to MRs and issues' do + it 'shows links to MRs and issues' do expect(page).to have_link('view merge requests') expect(page).to have_link('view open issues') end diff --git a/spec/features/projects/members/anonymous_user_sees_members_spec.rb b/spec/features/projects/members/anonymous_user_sees_members_spec.rb index e2a48bfd1d4..b3ed725f602 100644 --- a/spec/features/projects/members/anonymous_user_sees_members_spec.rb +++ b/spec/features/projects/members/anonymous_user_sees_members_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' -feature 'Projects > Members > Anonymous user sees members' do +describe 'Projects > Members > Anonymous user sees members' do let(:user) { create(:user) } let(:group) { create(:group, :public) } let(:project) { create(:project, :public) } - background do - project.add_master(user) + before do + project.add_maintainer(user) create(:project_group_link, project: project, group: group) end - scenario "anonymous user visits the project's members page and sees the list of members" do + it "anonymous user visits the project's members page and sees the list of members" do visit project_project_members_path(project) expect(current_path).to eq( diff --git a/spec/features/projects/members/group_member_cannot_leave_group_project_spec.rb b/spec/features/projects/members/group_member_cannot_leave_group_project_spec.rb index 6b450fa4e45..0ab29660189 100644 --- a/spec/features/projects/members/group_member_cannot_leave_group_project_spec.rb +++ b/spec/features/projects/members/group_member_cannot_leave_group_project_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' -feature 'Projects > Members > Group member cannot leave group project' do +describe 'Projects > Members > Group member cannot leave group project' do let(:user) { create(:user) } let(:group) { create(:group) } let(:project) { create(:project, namespace: group) } - background do + before do group.add_developer(user) sign_in(user) visit project_path(project) end - scenario 'user does not see a "Leave project" link' do + it 'user does not see a "Leave project" link' do expect(page).not_to have_content 'Leave project' end end diff --git a/spec/features/projects/members/group_member_cannot_request_access_to_his_group_project_spec.rb b/spec/features/projects/members/group_member_cannot_request_access_to_his_group_project_spec.rb index 296a80a3c60..bb475ea95e5 100644 --- a/spec/features/projects/members/group_member_cannot_request_access_to_his_group_project_spec.rb +++ b/spec/features/projects/members/group_member_cannot_request_access_to_his_group_project_spec.rb @@ -1,39 +1,39 @@ require 'spec_helper' -feature 'Projects > Members > Group member cannot request access to his group project' do +describe 'Projects > Members > Group member cannot request access to his group project' do let(:user) { create(:user) } let(:group) { create(:group) } let(:project) { create(:project, namespace: group) } - scenario 'owner does not see the request access button' do + it 'owner does not see the request access button' do group.add_owner(user) login_and_visit_project_page(user) expect(page).not_to have_content 'Request Access' end - scenario 'master does not see the request access button' do - group.add_master(user) + it 'maintainer does not see the request access button' do + group.add_maintainer(user) login_and_visit_project_page(user) expect(page).not_to have_content 'Request Access' end - scenario 'developer does not see the request access button' do + it 'developer does not see the request access button' do group.add_developer(user) login_and_visit_project_page(user) expect(page).not_to have_content 'Request Access' end - scenario 'reporter does not see the request access button' do + it 'reporter does not see the request access button' do group.add_reporter(user) login_and_visit_project_page(user) expect(page).not_to have_content 'Request Access' end - scenario 'guest does not see the request access button' do + it 'guest does not see the request access button' do group.add_guest(user) login_and_visit_project_page(user) diff --git a/spec/features/projects/members/group_members_spec.rb b/spec/features/projects/members/group_members_spec.rb index e22b6fa6c43..41b2beb40b9 100644 --- a/spec/features/projects/members/group_members_spec.rb +++ b/spec/features/projects/members/group_members_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Projects members' do +describe 'Projects members' do let(:user) { create(:user) } let(:developer) { create(:user) } let(:group) { create(:group, :public, :access_requestable) } @@ -10,7 +10,7 @@ feature 'Projects members' do let(:project_requester) { create(:user) } let(:group_requester) { create(:user) } - background do + before do project.add_developer(developer) group.add_owner(user) sign_in(user) @@ -22,7 +22,7 @@ feature 'Projects members' do visit project_settings_members_path(project) end - scenario 'does not appear in the project members page' do + it 'does not appear in the project members page' do page.within first('.content-list') do expect(page).not_to have_content('test2@abc.com') end @@ -36,7 +36,7 @@ feature 'Projects members' do visit project_settings_members_path(project) end - scenario 'shows the project invitee, the project developer, and the group owner' do + it 'shows the project invitee, the project developer, and the group owner' do page.within first('.content-list') do expect(page).to have_content('test1@abc.com') expect(page).not_to have_content('test2@abc.com') @@ -57,7 +57,7 @@ feature 'Projects members' do visit project_settings_members_path(project) end - scenario 'does not appear in the project members page' do + it 'does not appear in the project members page' do page.within first('.content-list') do expect(page).not_to have_content(group_requester.name) end @@ -71,7 +71,7 @@ feature 'Projects members' do visit project_settings_members_path(project) end - scenario 'shows the project requester, the project developer, and the group owner' do + it 'shows the project requester, the project developer, and the group owner' do page.within first('.content-list') do expect(page).to have_content(project_requester.name) expect(page).not_to have_content(group_requester.name) diff --git a/spec/features/projects/members/group_requester_cannot_request_access_to_project_spec.rb b/spec/features/projects/members/group_requester_cannot_request_access_to_project_spec.rb index 6d729f2f85f..ea3894c92bd 100644 --- a/spec/features/projects/members/group_requester_cannot_request_access_to_project_spec.rb +++ b/spec/features/projects/members/group_requester_cannot_request_access_to_project_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' -feature 'Projects > Members > Group requester cannot request access to project', :js do +describe 'Projects > Members > Group requester cannot request access to project', :js do let(:user) { create(:user) } let(:owner) { create(:user) } let(:group) { create(:group, :public, :access_requestable) } let(:project) { create(:project, :public, :access_requestable, namespace: group) } - background do + before do group.add_owner(owner) sign_in(user) visit group_path(group) @@ -14,7 +14,7 @@ feature 'Projects > Members > Group requester cannot request access to project', visit project_path(project) end - scenario 'group requester does not see the request access / withdraw access request button' do + it 'group requester does not see the request access / withdraw access request button' do expect(page).not_to have_content 'Request Access' expect(page).not_to have_content 'Withdraw Access Request' end diff --git a/spec/features/projects/members/groups_with_access_list_spec.rb b/spec/features/projects/members/groups_with_access_list_spec.rb index e6d0c6e00f8..c0b5d943e96 100644 --- a/spec/features/projects/members/groups_with_access_list_spec.rb +++ b/spec/features/projects/members/groups_with_access_list_spec.rb @@ -1,19 +1,19 @@ require 'spec_helper' -feature 'Projects > Members > Groups with access list', :js do +describe 'Projects > Members > Groups with access list', :js do let(:user) { create(:user) } let(:group) { create(:group, :public) } let(:project) { create(:project, :public) } - background do - project.add_master(user) + before do + project.add_maintainer(user) @group_link = create(:project_group_link, project: project, group: group) sign_in(user) visit project_settings_members_path(project) end - scenario 'updates group access level' do + it 'updates group access level' do click_button @group_link.human_access page.within '.dropdown-menu' do @@ -27,7 +27,7 @@ feature 'Projects > Members > Groups with access list', :js do expect(first('.group_member')).to have_content('Guest') end - scenario 'updates expiry date' do + it 'updates expiry date' do tomorrow = Date.today + 3 fill_in "member_expires_at_#{group.id}", with: tomorrow.strftime("%F") @@ -39,7 +39,7 @@ feature 'Projects > Members > Groups with access list', :js do end end - scenario 'deletes group link' do + it 'deletes group link' do page.within(first('.group_member')) do accept_confirm { find('.btn-remove').click } end @@ -49,7 +49,7 @@ feature 'Projects > Members > Groups with access list', :js do end context 'search in existing members (yes, this filters the groups list as well)' do - scenario 'finds no results' do + it 'finds no results' do page.within '.member-search-form' do fill_in 'search', with: 'testing 123' find('.member-search-btn').click @@ -58,7 +58,7 @@ feature 'Projects > Members > Groups with access list', :js do expect(page).not_to have_selector('.group_member') end - scenario 'finds results' do + it 'finds results' do page.within '.member-search-form' do fill_in 'search', with: group.name find('.member-search-btn').click diff --git a/spec/features/projects/members/list_spec.rb b/spec/features/projects/members/list_spec.rb index 65b11a1d9e7..c2e980e75b8 100644 --- a/spec/features/projects/members/list_spec.rb +++ b/spec/features/projects/members/list_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Project members list' do +describe 'Project members list' do include Select2Helper let(:user1) { create(:user, name: 'John Doe') } @@ -8,12 +8,12 @@ feature 'Project members list' do let(:group) { create(:group) } let(:project) { create(:project, namespace: group) } - background do + before do sign_in(user1) group.add_owner(user1) end - scenario 'show members from project and group' do + it 'show members from project and group' do project.add_developer(user2) visit_members_page @@ -22,7 +22,7 @@ feature 'Project members list' do expect(second_row.text).to include(user2.name) end - scenario 'show user once if member of both group and project' do + it 'show user once if member of both group and project' do project.add_developer(user1) visit_members_page @@ -31,7 +31,7 @@ feature 'Project members list' do expect(second_row).to be_blank end - scenario 'update user acess level', :js do + it 'update user acess level', :js do project.add_developer(user2) visit_members_page @@ -44,7 +44,7 @@ feature 'Project members list' do end end - scenario 'add user to project', :js do + it 'add user to project', :js do visit_members_page add_user(user2.id, 'Reporter') @@ -55,7 +55,7 @@ feature 'Project members list' do end end - scenario 'remove user from project', :js do + it 'remove user from project', :js do other_user = create(:user) project.add_developer(other_user) @@ -71,7 +71,7 @@ feature 'Project members list' do expect(project.users).not_to include(other_user) end - scenario 'invite user to project', :js do + it 'invite user to project', :js do visit_members_page add_user('test@example.com', 'Reporter') diff --git a/spec/features/projects/members/master_adds_member_with_expiration_date_spec.rb b/spec/features/projects/members/master_adds_member_with_expiration_date_spec.rb index 8fe340d3bae..26de6fb33fd 100644 --- a/spec/features/projects/members/master_adds_member_with_expiration_date_spec.rb +++ b/spec/features/projects/members/master_adds_member_with_expiration_date_spec.rb @@ -1,19 +1,19 @@ require 'spec_helper' -feature 'Projects > Members > Master adds member with expiration date', :js do +describe 'Projects > Members > Maintainer adds member with expiration date', :js do include Select2Helper include ActiveSupport::Testing::TimeHelpers - let(:master) { create(:user) } + let(:maintainer) { create(:user) } let(:project) { create(:project) } let!(:new_member) { create(:user) } - background do - project.add_master(master) - sign_in(master) + before do + project.add_maintainer(maintainer) + sign_in(maintainer) end - scenario 'expiration date is displayed in the members list' do + it 'expiration date is displayed in the members list' do travel_to Time.zone.parse('2016-08-06 08:00') do date = 4.days.from_now visit project_project_members_path(project) @@ -30,7 +30,7 @@ feature 'Projects > Members > Master adds member with expiration date', :js do end end - scenario 'change expiration date' do + it 'change expiration date' do travel_to Time.zone.parse('2016-08-06 08:00') do date = 3.days.from_now project.team.add_users([new_member.id], :developer, expires_at: Date.today.to_s(:medium)) diff --git a/spec/features/projects/members/master_manages_access_requests_spec.rb b/spec/features/projects/members/master_manages_access_requests_spec.rb index 3ac6ca4fc86..adc8202cde7 100644 --- a/spec/features/projects/members/master_manages_access_requests_spec.rb +++ b/spec/features/projects/members/master_manages_access_requests_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -feature 'Projects > Members > Master manages access requests' do - it_behaves_like 'Master manages access requests' do +describe 'Projects > Members > Maintainer manages access requests' do + it_behaves_like 'Maintainer manages access requests' do let(:entity) { create(:project, :public, :access_requestable) } let(:members_page_path) { project_project_members_path(entity) } end diff --git a/spec/features/projects/members/member_cannot_request_access_to_his_project_spec.rb b/spec/features/projects/members/member_cannot_request_access_to_his_project_spec.rb index 47911c32a72..f612ad8d551 100644 --- a/spec/features/projects/members/member_cannot_request_access_to_his_project_spec.rb +++ b/spec/features/projects/members/member_cannot_request_access_to_his_project_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' -feature 'Projects > Members > Member cannot request access to his project' do +describe 'Projects > Members > Member cannot request access to his project' do let(:member) { create(:user) } let(:project) { create(:project) } - background do + before do project.add_developer(member) sign_in(member) visit project_path(project) end - scenario 'member does not see the request access button' do + it 'member does not see the request access button' do expect(page).not_to have_content 'Request Access' end end diff --git a/spec/features/projects/members/member_leaves_project_spec.rb b/spec/features/projects/members/member_leaves_project_spec.rb index e54c2c76975..94b29de4686 100644 --- a/spec/features/projects/members/member_leaves_project_spec.rb +++ b/spec/features/projects/members/member_leaves_project_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' -feature 'Projects > Members > Member leaves project' do +describe 'Projects > Members > Member leaves project' do let(:user) { create(:user) } let(:project) { create(:project, :repository) } - background do + before do project.add_developer(user) sign_in(user) visit project_path(project) end - scenario 'user leaves project' do + it 'user leaves project' do click_link 'Leave project' expect(current_path).to eq(dashboard_projects_path) diff --git a/spec/features/projects/members/owner_cannot_leave_project_spec.rb b/spec/features/projects/members/owner_cannot_leave_project_spec.rb index 15162d01c44..0aa005adb4d 100644 --- a/spec/features/projects/members/owner_cannot_leave_project_spec.rb +++ b/spec/features/projects/members/owner_cannot_leave_project_spec.rb @@ -1,14 +1,14 @@ require 'spec_helper' -feature 'Projects > Members > Owner cannot leave project' do +describe 'Projects > Members > Owner cannot leave project' do let(:project) { create(:project) } - background do + before do sign_in(project.owner) visit project_path(project) end - scenario 'user does not see a "Leave project" link' do + it 'user does not see a "Leave project" link' do expect(page).not_to have_content 'Leave project' end end diff --git a/spec/features/projects/members/owner_cannot_request_access_to_his_project_spec.rb b/spec/features/projects/members/owner_cannot_request_access_to_his_project_spec.rb index c27925c8dc4..eb1b720af05 100644 --- a/spec/features/projects/members/owner_cannot_request_access_to_his_project_spec.rb +++ b/spec/features/projects/members/owner_cannot_request_access_to_his_project_spec.rb @@ -1,14 +1,14 @@ require 'spec_helper' -feature 'Projects > Members > Owner cannot request access to his project' do +describe 'Projects > Members > Owner cannot request access to his project' do let(:project) { create(:project) } - background do + before do sign_in(project.owner) visit project_path(project) end - scenario 'owner does not see the request access button' do + it 'owner does not see the request access button' do expect(page).not_to have_content 'Request Access' end end diff --git a/spec/features/projects/members/share_with_group_spec.rb b/spec/features/projects/members/share_with_group_spec.rb index 134c8b8bc39..c6d85e5d22f 100644 --- a/spec/features/projects/members/share_with_group_spec.rb +++ b/spec/features/projects/members/share_with_group_spec.rb @@ -1,21 +1,21 @@ require 'spec_helper' -feature 'Project > Members > Share with Group', :js do +describe 'Project > Members > Share with Group', :js do include Select2Helper include ActionView::Helpers::DateHelper - let(:master) { create(:user) } + let(:maintainer) { create(:user) } describe 'Share with group lock' do shared_examples 'the project can be shared with groups' do - scenario 'the "Share with group" tab exists' do + it 'the "Share with group" tab exists' do visit project_settings_members_path(project) expect(page).to have_selector('#share-with-group-tab') end end shared_examples 'the project cannot be shared with groups' do - scenario 'the "Share with group" tab does not exist' do + it 'the "Share with group" tab does not exist' do visit project_settings_members_path(project) expect(page).to have_selector('#add-member-tab') expect(page).not_to have_selector('#share-with-group-tab') @@ -26,15 +26,15 @@ feature 'Project > Members > Share with Group', :js do let!(:group_to_share_with) { create(:group) } let(:project) { create(:project, namespace: create(:group)) } - background do - project.add_master(master) - sign_in(master) + before do + project.add_maintainer(maintainer) + sign_in(maintainer) end context 'when the group has "Share with group lock" disabled' do it_behaves_like 'the project can be shared with groups' - scenario 'the project can be shared with another group' do + it 'the project can be shared with another group' do visit project_settings_members_path(project) click_on 'share-with-group-tab' @@ -64,9 +64,9 @@ feature 'Project > Members > Share with Group', :js do let(:subgroup) { create(:group, parent: root_group) } let(:project) { create(:project, namespace: subgroup) } - background do - project.add_master(master) - sign_in(master) + before do + project.add_maintainer(maintainer) + sign_in(maintainer) end context 'when the root_group has "Share with group lock" disabled' do @@ -112,8 +112,8 @@ feature 'Project > Members > Share with Group', :js do end before do - project.add_master(master) - sign_in(master) + project.add_maintainer(maintainer) + sign_in(maintainer) visit project_settings_members_path(project) @@ -126,7 +126,7 @@ feature 'Project > Members > Share with Group', :js do find('.btn-create').click end - scenario 'the group link shows the expiration time with a warning class' do + it 'the group link shows the expiration time with a warning class' do page.within('.project-members-groups') do # Using distance_of_time_in_words_to_now because it is not the same as # subtraction, and this way avoids time zone issues as well @@ -141,12 +141,12 @@ feature 'Project > Members > Share with Group', :js do context 'with multiple groups to choose from' do let(:project) { create(:project) } - background do - project.add_master(master) - sign_in(master) + before do + project.add_maintainer(maintainer) + sign_in(maintainer) - create(:group).add_owner(master) - create(:group).add_owner(master) + create(:group).add_owner(maintainer) + create(:group).add_owner(maintainer) visit project_settings_members_path(project) @@ -173,14 +173,14 @@ feature 'Project > Members > Share with Group', :js do let!(:group_to_share_with) { create(:group) } let!(:project) { create(:project, namespace: nested_group) } - background do - project.add_master(master) - sign_in(master) - group.add_master(master) - group_to_share_with.add_master(master) + before do + project.add_maintainer(maintainer) + sign_in(maintainer) + group.add_maintainer(maintainer) + group_to_share_with.add_maintainer(maintainer) end - scenario 'the groups dropdown does not show ancestors', :nested_groups do + it 'the groups dropdown does not show ancestors', :nested_groups do visit project_settings_members_path(project) click_on 'share-with-group-tab' diff --git a/spec/features/projects/members/sorting_spec.rb b/spec/features/projects/members/sorting_spec.rb index afa173c59e5..220775b514d 100644 --- a/spec/features/projects/members/sorting_spec.rb +++ b/spec/features/projects/members/sorting_spec.rb @@ -1,85 +1,85 @@ require 'spec_helper' -feature 'Projects > Members > Sorting' do - let(:master) { create(:user, name: 'John Doe') } +describe 'Projects > Members > Sorting' do + let(:maintainer) { create(:user, name: 'John Doe') } let(:developer) { create(:user, name: 'Mary Jane', last_sign_in_at: 5.days.ago) } - let(:project) { create(:project, namespace: master.namespace, creator: master) } + let(:project) { create(:project, namespace: maintainer.namespace, creator: maintainer) } - background do + before do create(:project_member, :developer, user: developer, project: project, created_at: 3.days.ago) - sign_in(master) + sign_in(maintainer) end - scenario 'sorts alphabetically by default' do + it 'sorts alphabetically by default' do visit_members_list(sort: nil) - expect(first_member).to include(master.name) + expect(first_member).to include(maintainer.name) expect(second_member).to include(developer.name) expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Name, ascending') end - scenario 'sorts by access level ascending' do + it 'sorts by access level ascending' do visit_members_list(sort: :access_level_asc) expect(first_member).to include(developer.name) - expect(second_member).to include(master.name) + expect(second_member).to include(maintainer.name) expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Access level, ascending') end - scenario 'sorts by access level descending' do + it 'sorts by access level descending' do visit_members_list(sort: :access_level_desc) - expect(first_member).to include(master.name) + expect(first_member).to include(maintainer.name) expect(second_member).to include(developer.name) expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Access level, descending') end - scenario 'sorts by last joined' do + it 'sorts by last joined' do visit_members_list(sort: :last_joined) - expect(first_member).to include(master.name) + expect(first_member).to include(maintainer.name) expect(second_member).to include(developer.name) expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Last joined') end - scenario 'sorts by oldest joined' do + it 'sorts by oldest joined' do visit_members_list(sort: :oldest_joined) expect(first_member).to include(developer.name) - expect(second_member).to include(master.name) + expect(second_member).to include(maintainer.name) expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Oldest joined') end - scenario 'sorts by name ascending' do + it 'sorts by name ascending' do visit_members_list(sort: :name_asc) - expect(first_member).to include(master.name) + expect(first_member).to include(maintainer.name) expect(second_member).to include(developer.name) expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Name, ascending') end - scenario 'sorts by name descending' do + it 'sorts by name descending' do visit_members_list(sort: :name_desc) expect(first_member).to include(developer.name) - expect(second_member).to include(master.name) + expect(second_member).to include(maintainer.name) expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Name, descending') end - scenario 'sorts by recent sign in', :clean_gitlab_redis_shared_state do + it 'sorts by recent sign in', :clean_gitlab_redis_shared_state do visit_members_list(sort: :recent_sign_in) - expect(first_member).to include(master.name) + expect(first_member).to include(maintainer.name) expect(second_member).to include(developer.name) expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Recent sign in') end - scenario 'sorts by oldest sign in', :clean_gitlab_redis_shared_state do + it 'sorts by oldest sign in', :clean_gitlab_redis_shared_state do visit_members_list(sort: :oldest_sign_in) expect(first_member).to include(developer.name) - expect(second_member).to include(master.name) + expect(second_member).to include(maintainer.name) expect(page).to have_css('.member-sort-dropdown .dropdown-toggle-text', text: 'Oldest sign in') end diff --git a/spec/features/projects/members/user_requests_access_spec.rb b/spec/features/projects/members/user_requests_access_spec.rb index 672d5daa3d8..50ba67f0ffc 100644 --- a/spec/features/projects/members/user_requests_access_spec.rb +++ b/spec/features/projects/members/user_requests_access_spec.rb @@ -1,26 +1,26 @@ require 'spec_helper' -feature 'Projects > Members > User requests access', :js do +describe 'Projects > Members > User requests access', :js do let(:user) { create(:user) } let(:project) { create(:project, :public, :access_requestable, :repository) } - let(:master) { project.owner } + let(:maintainer) { project.owner } - background do + before do sign_in(user) visit project_path(project) end - scenario 'request access feature is disabled' do - project.update_attributes(request_access_enabled: false) + it 'request access feature is disabled' do + project.update(request_access_enabled: false) visit project_path(project) expect(page).not_to have_content 'Request Access' end - scenario 'user can request access to a project' do + it 'user can request access to a project' do perform_enqueued_jobs { click_link 'Request Access' } - expect(ActionMailer::Base.deliveries.last.to).to eq [master.notification_email] + expect(ActionMailer::Base.deliveries.last.to).to eq [maintainer.notification_email] expect(ActionMailer::Base.deliveries.last.subject).to eq "Request to join the #{project.full_name} project" expect(project.requesters.exists?(user_id: user)).to be_truthy @@ -31,7 +31,7 @@ feature 'Projects > Members > User requests access', :js do end context 'code access is restricted' do - scenario 'user can request access' do + it 'user can request access' do project.project_feature.update!(repository_access_level: ProjectFeature::PRIVATE, builds_access_level: ProjectFeature::PRIVATE, merge_requests_access_level: ProjectFeature::PRIVATE) @@ -41,7 +41,7 @@ feature 'Projects > Members > User requests access', :js do end end - scenario 'user is not listed in the project members page' do + it 'user is not listed in the project members page' do click_link 'Request Access' expect(project.requesters.exists?(user_id: user)).to be_truthy @@ -55,7 +55,7 @@ feature 'Projects > Members > User requests access', :js do end end - scenario 'user can withdraw its request for access' do + it 'user can withdraw its request for access' do click_link 'Request Access' expect(project.requesters.exists?(user_id: user)).to be_truthy diff --git a/spec/features/projects/merge_request_button_spec.rb b/spec/features/projects/merge_request_button_spec.rb index b571d5a0e26..69561b4d733 100644 --- a/spec/features/projects/merge_request_button_spec.rb +++ b/spec/features/projects/merge_request_button_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Merge Request button' do +describe 'Merge Request button' do shared_examples 'Merge request button only shown when allowed' do let(:user) { create(:user) } let(:project) { create(:project, :public, :repository) } diff --git a/spec/features/projects/merge_requests/user_closes_merge_request_spec.rb b/spec/features/projects/merge_requests/user_closes_merge_request_spec.rb index b257f447439..2d12d690151 100644 --- a/spec/features/projects/merge_requests/user_closes_merge_request_spec.rb +++ b/spec/features/projects/merge_requests/user_closes_merge_request_spec.rb @@ -6,7 +6,7 @@ describe 'User closes a merge requests', :js do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(merge_request_path(merge_request)) diff --git a/spec/features/projects/merge_requests/user_comments_on_commit_spec.rb b/spec/features/projects/merge_requests/user_comments_on_commit_spec.rb index 0a952cfc2a9..8ea358bcc70 100644 --- a/spec/features/projects/merge_requests/user_comments_on_commit_spec.rb +++ b/spec/features/projects/merge_requests/user_comments_on_commit_spec.rb @@ -9,7 +9,7 @@ describe 'User comments on a commit', :js do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_commit_path(project, sample_commit.id)) diff --git a/spec/features/projects/merge_requests/user_comments_on_diff_spec.rb b/spec/features/projects/merge_requests/user_comments_on_diff_spec.rb index 1828b60fec7..441b080bee5 100644 --- a/spec/features/projects/merge_requests/user_comments_on_diff_spec.rb +++ b/spec/features/projects/merge_requests/user_comments_on_diff_spec.rb @@ -11,7 +11,7 @@ describe 'User comments on a diff', :js do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(diffs_project_merge_request_path(project, merge_request)) @@ -31,7 +31,7 @@ describe 'User comments on a diff', :js do page.within('.files > div:nth-child(3)') do expect(page).to have_content('Line is wrong') - find('.js-toggle-diff-comments').click + find('.js-btn-vue-toggle-comments').click expect(page).not_to have_content('Line is wrong') end @@ -64,7 +64,7 @@ describe 'User comments on a diff', :js do # Hide the comment. page.within('.files > div:nth-child(3)') do - find('.js-toggle-diff-comments').click + find('.js-btn-vue-toggle-comments').click expect(page).not_to have_content('Line is wrong') end @@ -77,7 +77,7 @@ describe 'User comments on a diff', :js do # Show the comment. page.within('.files > div:nth-child(3)') do - find('.js-toggle-diff-comments').click + find('.js-btn-vue-toggle-comments').click end # Now both the comments should be shown. diff --git a/spec/features/projects/merge_requests/user_comments_on_merge_request_spec.rb b/spec/features/projects/merge_requests/user_comments_on_merge_request_spec.rb index f90aaba3caf..69bdab85d81 100644 --- a/spec/features/projects/merge_requests/user_comments_on_merge_request_spec.rb +++ b/spec/features/projects/merge_requests/user_comments_on_merge_request_spec.rb @@ -8,7 +8,7 @@ describe 'User comments on a merge request', :js do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(merge_request_path(merge_request)) diff --git a/spec/features/projects/merge_requests/user_creates_merge_request_spec.rb b/spec/features/projects/merge_requests/user_creates_merge_request_spec.rb index 1f21ef7b382..38b4e4a6d1b 100644 --- a/spec/features/projects/merge_requests/user_creates_merge_request_spec.rb +++ b/spec/features/projects/merge_requests/user_creates_merge_request_spec.rb @@ -8,7 +8,7 @@ describe "User creates a merge request", :js do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/merge_requests/user_edits_merge_request_spec.rb b/spec/features/projects/merge_requests/user_edits_merge_request_spec.rb index 3d19a2923b9..7de0f9daac6 100644 --- a/spec/features/projects/merge_requests/user_edits_merge_request_spec.rb +++ b/spec/features/projects/merge_requests/user_edits_merge_request_spec.rb @@ -8,7 +8,7 @@ describe 'User edits a merge request', :js do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(edit_project_merge_request_path(project, merge_request)) diff --git a/spec/features/projects/merge_requests/user_manages_subscription_spec.rb b/spec/features/projects/merge_requests/user_manages_subscription_spec.rb index f55eb5c6664..68a835e7f77 100644 --- a/spec/features/projects/merge_requests/user_manages_subscription_spec.rb +++ b/spec/features/projects/merge_requests/user_manages_subscription_spec.rb @@ -6,7 +6,7 @@ describe 'User manages subscription', :js do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(merge_request_path(merge_request)) diff --git a/spec/features/projects/merge_requests/user_reopens_merge_request_spec.rb b/spec/features/projects/merge_requests/user_reopens_merge_request_spec.rb index ba3c9789da1..745b4537e72 100644 --- a/spec/features/projects/merge_requests/user_reopens_merge_request_spec.rb +++ b/spec/features/projects/merge_requests/user_reopens_merge_request_spec.rb @@ -6,7 +6,7 @@ describe 'User reopens a merge requests', :js do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(merge_request_path(merge_request)) diff --git a/spec/features/projects/merge_requests/user_sorts_merge_requests_spec.rb b/spec/features/projects/merge_requests/user_sorts_merge_requests_spec.rb index 305658f1b5d..e401933aed2 100644 --- a/spec/features/projects/merge_requests/user_sorts_merge_requests_spec.rb +++ b/spec/features/projects/merge_requests/user_sorts_merge_requests_spec.rb @@ -9,7 +9,7 @@ describe 'User sorts merge requests' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_merge_requests_path(project)) diff --git a/spec/features/projects/merge_requests/user_views_open_merge_request_spec.rb b/spec/features/projects/merge_requests/user_views_open_merge_request_spec.rb index 3aac93eaf7c..6ac495aa03d 100644 --- a/spec/features/projects/merge_requests/user_views_open_merge_request_spec.rb +++ b/spec/features/projects/merge_requests/user_views_open_merge_request_spec.rb @@ -31,7 +31,7 @@ describe 'User views an open merge request' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(edit_project_merge_request_path(project, merge_request)) diff --git a/spec/features/projects/milestones/milestone_spec.rb b/spec/features/projects/milestones/milestone_spec.rb index 20a52d6011f..ff31092b910 100644 --- a/spec/features/projects/milestones/milestone_spec.rb +++ b/spec/features/projects/milestones/milestone_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Project milestone' do +describe 'Project milestone' do let(:user) { create(:user) } let(:project) { create(:project, name: 'test', namespace: user.namespace) } let(:milestone) { create(:milestone, project: project) } diff --git a/spec/features/projects/milestones/milestones_sorting_spec.rb b/spec/features/projects/milestones/milestones_sorting_spec.rb index b64786d4eec..dc711377e6e 100644 --- a/spec/features/projects/milestones/milestones_sorting_spec.rb +++ b/spec/features/projects/milestones/milestones_sorting_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Milestones sorting', :js do +describe 'Milestones sorting', :js do let(:user) { create(:user) } let(:project) { create(:project, name: 'test', namespace: user.namespace) } @@ -17,7 +17,7 @@ feature 'Milestones sorting', :js do sign_in(user) end - scenario 'visit project milestones and sort by due_date_asc' do + it 'visit project milestones and sort by due_date_asc' do visit project_milestones_path(project) expect(page).to have_button('Due soon') diff --git a/spec/features/projects/milestones/new_spec.rb b/spec/features/projects/milestones/new_spec.rb index 6595bff549b..0b5ab547dce 100644 --- a/spec/features/projects/milestones/new_spec.rb +++ b/spec/features/projects/milestones/new_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Creating a new project milestone', :js do +describe 'Creating a new project milestone', :js do let(:user) { create(:user) } let(:project) { create(:project, name: 'test', namespace: user.namespace) } diff --git a/spec/features/projects/milestones/user_interacts_with_labels_spec.rb b/spec/features/projects/milestones/user_interacts_with_labels_spec.rb index f6a82f80d65..a6d58be7b13 100644 --- a/spec/features/projects/milestones/user_interacts_with_labels_spec.rb +++ b/spec/features/projects/milestones/user_interacts_with_labels_spec.rb @@ -11,7 +11,7 @@ describe 'User interacts with labels' do let(:label_enhancement) { create(:label, project: project, title: 'enhancement') } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) issue1.labels << [label_bug, label_feature] diff --git a/spec/features/projects/new_project_spec.rb b/spec/features/projects/new_project_spec.rb index fee6287558e..bbe08ff83ff 100644 --- a/spec/features/projects/new_project_spec.rb +++ b/spec/features/projects/new_project_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'New project' do +describe 'New project' do include Select2Helper let(:user) { create(:admin) } @@ -25,6 +25,22 @@ feature 'New project' do expect(page).to have_link('GitLab export') end + describe 'manifest import option' do + before do + visit new_project_path + + find('#import-project-tab').click + end + + context 'when using postgres', :postgresql do + it { expect(page).to have_link('Manifest file') } + end + + context 'when using mysql', :mysql do + it { expect(page).not_to have_link('Manifest file') } + end + end + context 'Visibility level selector', :js do Gitlab::VisibilityLevel.options.each do |key, level| it "sets selector to #{key}" do @@ -48,6 +64,15 @@ feature 'New project' do end end + context 'Readme selector' do + it 'shows the initialize with Readme checkbox' do + visit new_project_path + + expect(page).to have_css('input#project_initialize_with_readme') + expect(page).to have_content('Initialize repository with a README') + end + end + context 'Namespace selector' do context 'with user namespace' do before do @@ -85,7 +110,7 @@ feature 'New project' do let(:subgroup) { create(:group, parent: group) } before do - group.add_master(user) + group.add_maintainer(user) visit new_project_path(namespace_id: subgroup.id) end @@ -192,5 +217,16 @@ feature 'New project' do expect(current_path).to eq new_import_google_code_path end end + + context 'from manifest file', :postgresql do + before do + first('.import_manifest').click + end + + it 'shows import instructions' do + expect(page).to have_content('Manifest file import') + expect(current_path).to eq new_import_manifest_path + end + end end end diff --git a/spec/features/projects/pages_spec.rb b/spec/features/projects/pages_spec.rb index a2899ec0f48..831f22a0e69 100644 --- a/spec/features/projects/pages_spec.rb +++ b/spec/features/projects/pages_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -feature 'Pages' do - given(:project) { create(:project) } - given(:user) { create(:user) } - given(:role) { :master } +describe 'Pages' do + let(:project) { create(:project) } + let(:user) { create(:user) } + let(:role) { :maintainer } - background do + before do allow(Gitlab.config.pages).to receive(:enabled).and_return(true) project.add_role(user, role) @@ -14,7 +14,7 @@ feature 'Pages' do end shared_examples 'no pages deployed' do - scenario 'does not see anything to destroy' do + it 'does not see anything to destroy' do visit project_pages_path(project) expect(page).to have_content('Configure pages') @@ -24,16 +24,16 @@ feature 'Pages' do end context 'when user is the owner' do - background do + before do project.namespace.update(owner: user) end context 'when pages deployed' do - background do + before do allow_any_instance_of(Project).to receive(:pages_deployed?) { true } end - scenario 'renders Access pages' do + it 'renders Access pages' do visit project_pages_path(project) expect(page).to have_content('Access pages') @@ -48,7 +48,7 @@ feature 'Pages' do end context 'when pages are exposed on external HTTP address', :http_pages_enabled do - given(:project) { create(:project, pages_https_only: false) } + let(:project) { create(:project, pages_https_only: false) } shared_examples 'adds new domain' do it 'adds new domain' do @@ -210,11 +210,11 @@ feature 'Pages' do context 'when the user is not the owner' do context 'when pages deployed' do - background do + before do allow_any_instance_of(Project).to receive(:pages_deployed?) { true } end - scenario 'sees "Only the project owner can remove pages" text' do + it 'sees "Only the project owner can remove pages" text' do visit project_pages_path(project) expect(page).to have_text('Only the project owner can remove pages') @@ -225,13 +225,13 @@ feature 'Pages' do end describe 'HTTPS settings', :js, :https_pages_enabled do - background do + before do project.namespace.update(owner: user) allow_any_instance_of(Project).to receive(:pages_deployed?) { true } end - scenario 'tries to change the setting' do + it 'tries to change the setting' do visit project_pages_path(project) expect(page).to have_content("Force domains with SSL certificates to use HTTPS") @@ -251,7 +251,7 @@ feature 'Pages' do allow(service).to receive(:execute).and_return(status: :error) end - scenario 'tries to change the setting' do + it 'tries to change the setting' do visit project_pages_path(project) uncheck :project_pages_https_only @@ -263,13 +263,13 @@ feature 'Pages' do end context 'non-HTTPS domain exists' do - given(:project) { create(:project, pages_https_only: false) } + let(:project) { create(:project, pages_https_only: false) } before do create(:pages_domain, :without_key, :without_certificate, project: project) end - scenario 'the setting is disabled' do + it 'the setting is disabled' do visit project_pages_path(project) expect(page).to have_field(:project_pages_https_only, disabled: true) @@ -278,7 +278,7 @@ feature 'Pages' do end context 'HTTPS pages are disabled', :https_pages_disabled do - scenario 'the setting is unavailable' do + it 'the setting is unavailable' do visit project_pages_path(project) expect(page).not_to have_field(:project_pages_https_only) diff --git a/spec/features/projects/pipeline_schedules_spec.rb b/spec/features/projects/pipeline_schedules_spec.rb index 065d00d51d4..ee6b67b2188 100644 --- a/spec/features/projects/pipeline_schedules_spec.rb +++ b/spec/features/projects/pipeline_schedules_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Pipeline Schedules', :js do +describe 'Pipeline Schedules', :js do include PipelineSchedulesHelper let!(:project) { create(:project, :repository) } @@ -9,9 +9,9 @@ feature 'Pipeline Schedules', :js do let(:scope) { nil } let!(:user) { create(:user) } - context 'logged in as master' do + context 'logged in as maintainer' do before do - project.add_master(user) + project.add_maintainer(user) gitlab_sign_in(user) end @@ -155,7 +155,7 @@ feature 'Pipeline Schedules', :js do end context 'when user creates a new pipeline schedule with variables' do - background do + before do visit_pipelines_schedules click_link 'New schedule' fill_in_schedule_form @@ -166,7 +166,7 @@ feature 'Pipeline Schedules', :js do save_pipeline_schedule end - scenario 'user sees the new variable in edit window' do + it 'user sees the new variable in edit window' do find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click page.within('.ci-variable-list') do expect(find(".ci-variable-row:nth-child(1) .js-ci-variable-input-key").value).to eq('AAA') @@ -178,7 +178,7 @@ feature 'Pipeline Schedules', :js do end context 'when user edits a variable of a pipeline schedule' do - background do + before do create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule| create(:ci_pipeline_schedule_variable, key: 'AAA', value: 'AAA123', pipeline_schedule: pipeline_schedule) end @@ -192,7 +192,7 @@ feature 'Pipeline Schedules', :js do click_button 'Save pipeline schedule' end - scenario 'user sees the updated variable in edit window' do + it 'user sees the updated variable in edit window' do find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click page.within('.ci-variable-list') do expect(find(".ci-variable-row:nth-child(1) .js-ci-variable-input-key").value).to eq('foo') @@ -202,7 +202,7 @@ feature 'Pipeline Schedules', :js do end context 'when user removes a variable of a pipeline schedule' do - background do + before do create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule| create(:ci_pipeline_schedule_variable, key: 'AAA', value: 'AAA123', pipeline_schedule: pipeline_schedule) end @@ -213,7 +213,7 @@ feature 'Pipeline Schedules', :js do click_button 'Save pipeline schedule' end - scenario 'user does not see the removed variable in edit window' do + it 'user does not see the removed variable in edit window' do find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click page.within('.ci-variable-list') do expect(find(".ci-variable-row:nth-child(1) .js-ci-variable-input-key").value).to eq('') @@ -223,13 +223,13 @@ feature 'Pipeline Schedules', :js do end context 'when active is true and next_run_at is NULL' do - background do + before do create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule| pipeline_schedule.update_attribute(:cron, nil) # Consequently next_run_at will be nil end end - scenario 'user edit and recover the problematic pipeline schedule' do + it 'user edit and recover the problematic pipeline schedule' do visit_pipelines_schedules find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click fill_in 'schedule_cron', with: '* 1 2 3 4' diff --git a/spec/features/projects/pipelines/pipelines_spec.rb b/spec/features/projects/pipelines/pipelines_spec.rb index 9c165b17704..4a83bcc3efb 100644 --- a/spec/features/projects/pipelines/pipelines_spec.rb +++ b/spec/features/projects/pipelines/pipelines_spec.rb @@ -595,7 +595,7 @@ describe 'Pipelines', :js do before do create(:ci_empty_pipeline, status: 'success', project: project, sha: project.commit.id, ref: 'master') - project.add_master(user) + project.add_maintainer(user) visit project_pipelines_path(project) end @@ -606,7 +606,7 @@ describe 'Pipelines', :js do describe 'user clicks the button' do context 'when project already has jobs_cache_index' do before do - project.update_attributes(jobs_cache_index: 1) + project.update(jobs_cache_index: 1) end it 'increments jobs_cache_index' do diff --git a/spec/features/projects/remote_mirror_spec.rb b/spec/features/projects/remote_mirror_spec.rb index 81a6b613cc8..5259a8942dc 100644 --- a/spec/features/projects/remote_mirror_spec.rb +++ b/spec/features/projects/remote_mirror_spec.rb @@ -1,19 +1,19 @@ require 'spec_helper' -feature 'Project remote mirror', :feature do +describe 'Project remote mirror', :feature do let(:project) { create(:project, :repository, :remote_mirror) } let(:remote_mirror) { project.remote_mirrors.first } let(:user) { create(:user) } describe 'On a project', :js do before do - project.add_master(user) + project.add_maintainer(user) sign_in user end context 'when last_error is present but last_update_at is not' do it 'renders error message without timstamp' do - remote_mirror.update_attributes(last_error: 'Some new error', last_update_at: nil) + remote_mirror.update(last_error: 'Some new error', last_update_at: nil) visit project_mirror_path(project) @@ -23,7 +23,7 @@ feature 'Project remote mirror', :feature do context 'when last_error and last_update_at are present' do it 'renders error message with timestamp' do - remote_mirror.update_attributes(last_error: 'Some new error', last_update_at: Time.now - 5.minutes) + remote_mirror.update(last_error: 'Some new error', last_update_at: Time.now - 5.minutes) visit project_mirror_path(project) diff --git a/spec/features/projects/services/user_activates_asana_spec.rb b/spec/features/projects/services/user_activates_asana_spec.rb index db836d2985c..c44e07dd3b4 100644 --- a/spec/features/projects/services/user_activates_asana_spec.rb +++ b/spec/features/projects/services/user_activates_asana_spec.rb @@ -5,7 +5,7 @@ describe 'User activates Asana' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_settings_integrations_path(project)) diff --git a/spec/features/projects/services/user_activates_assembla_spec.rb b/spec/features/projects/services/user_activates_assembla_spec.rb index f099b332785..9c3884a7c74 100644 --- a/spec/features/projects/services/user_activates_assembla_spec.rb +++ b/spec/features/projects/services/user_activates_assembla_spec.rb @@ -5,7 +5,7 @@ describe 'User activates Assembla' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_settings_integrations_path(project)) diff --git a/spec/features/projects/services/user_activates_atlassian_bamboo_ci_spec.rb b/spec/features/projects/services/user_activates_atlassian_bamboo_ci_spec.rb index a00c2e0ad99..19573565265 100644 --- a/spec/features/projects/services/user_activates_atlassian_bamboo_ci_spec.rb +++ b/spec/features/projects/services/user_activates_atlassian_bamboo_ci_spec.rb @@ -5,7 +5,7 @@ describe 'User activates Atlassian Bamboo CI' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_settings_integrations_path(project)) diff --git a/spec/features/projects/services/user_activates_emails_on_push_spec.rb b/spec/features/projects/services/user_activates_emails_on_push_spec.rb index 3769875b29c..cc55f7b2060 100644 --- a/spec/features/projects/services/user_activates_emails_on_push_spec.rb +++ b/spec/features/projects/services/user_activates_emails_on_push_spec.rb @@ -5,7 +5,7 @@ describe 'User activates Emails on push' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_settings_integrations_path(project)) diff --git a/spec/features/projects/services/user_activates_flowdock_spec.rb b/spec/features/projects/services/user_activates_flowdock_spec.rb index 5298d8acaf5..f981b7e9da9 100644 --- a/spec/features/projects/services/user_activates_flowdock_spec.rb +++ b/spec/features/projects/services/user_activates_flowdock_spec.rb @@ -5,7 +5,7 @@ describe 'User activates Flowdock' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_settings_integrations_path(project)) diff --git a/spec/features/projects/services/user_activates_hipchat_spec.rb b/spec/features/projects/services/user_activates_hipchat_spec.rb index a9bf16642c7..2f5313c91f9 100644 --- a/spec/features/projects/services/user_activates_hipchat_spec.rb +++ b/spec/features/projects/services/user_activates_hipchat_spec.rb @@ -5,7 +5,7 @@ describe 'User activates HipChat' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_settings_integrations_path(project)) diff --git a/spec/features/projects/services/user_activates_irker_spec.rb b/spec/features/projects/services/user_activates_irker_spec.rb index 435663c818f..4c8e321b411 100644 --- a/spec/features/projects/services/user_activates_irker_spec.rb +++ b/spec/features/projects/services/user_activates_irker_spec.rb @@ -5,7 +5,7 @@ describe 'User activates Irker (IRC gateway)' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_settings_integrations_path(project)) diff --git a/spec/features/projects/services/user_activates_issue_tracker_spec.rb b/spec/features/projects/services/user_activates_issue_tracker_spec.rb index e9502178bd7..7cd5b12802b 100644 --- a/spec/features/projects/services/user_activates_issue_tracker_spec.rb +++ b/spec/features/projects/services/user_activates_issue_tracker_spec.rb @@ -15,7 +15,7 @@ describe 'User activates issue tracker', :js do end before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_settings_integrations_path(project) diff --git a/spec/features/projects/services/user_activates_jetbrains_teamcity_ci_spec.rb b/spec/features/projects/services/user_activates_jetbrains_teamcity_ci_spec.rb index 1048803fde8..28d83a8b961 100644 --- a/spec/features/projects/services/user_activates_jetbrains_teamcity_ci_spec.rb +++ b/spec/features/projects/services/user_activates_jetbrains_teamcity_ci_spec.rb @@ -5,7 +5,7 @@ describe 'User activates JetBrains TeamCity CI' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_settings_integrations_path(project)) diff --git a/spec/features/projects/services/user_activates_jira_spec.rb b/spec/features/projects/services/user_activates_jira_spec.rb index 429128ec096..08e1855d034 100644 --- a/spec/features/projects/services/user_activates_jira_spec.rb +++ b/spec/features/projects/services/user_activates_jira_spec.rb @@ -17,7 +17,7 @@ describe 'User activates Jira', :js do end before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_settings_integrations_path(project) diff --git a/spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb b/spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb index fce41ce347f..25b74cc481d 100644 --- a/spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb +++ b/spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Setup Mattermost slash commands', :js do +describe 'Setup Mattermost slash commands', :js do let(:user) { create(:user) } let(:project) { create(:project) } let(:service) { project.create_mattermost_slash_commands_service } @@ -8,7 +8,7 @@ feature 'Setup Mattermost slash commands', :js do before do stub_mattermost_setting(enabled: mattermost_enabled) - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit edit_project_service_path(project, service) end diff --git a/spec/features/projects/services/user_activates_packagist_spec.rb b/spec/features/projects/services/user_activates_packagist_spec.rb index b0cc818f093..756e9b33c07 100644 --- a/spec/features/projects/services/user_activates_packagist_spec.rb +++ b/spec/features/projects/services/user_activates_packagist_spec.rb @@ -5,7 +5,7 @@ describe 'User activates Packagist' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_settings_integrations_path(project)) diff --git a/spec/features/projects/services/user_activates_pivotaltracker_spec.rb b/spec/features/projects/services/user_activates_pivotaltracker_spec.rb index d5d109ba48b..1d6b19e0b0c 100644 --- a/spec/features/projects/services/user_activates_pivotaltracker_spec.rb +++ b/spec/features/projects/services/user_activates_pivotaltracker_spec.rb @@ -5,7 +5,7 @@ describe 'User activates PivotalTracker' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_settings_integrations_path(project)) diff --git a/spec/features/projects/services/user_activates_prometheus_spec.rb b/spec/features/projects/services/user_activates_prometheus_spec.rb index 33f884eb148..61361c8a2e3 100644 --- a/spec/features/projects/services/user_activates_prometheus_spec.rb +++ b/spec/features/projects/services/user_activates_prometheus_spec.rb @@ -5,7 +5,7 @@ describe 'User activates Prometheus' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_settings_integrations_path(project)) diff --git a/spec/features/projects/services/user_activates_pushover_spec.rb b/spec/features/projects/services/user_activates_pushover_spec.rb index 9b7e8d62792..24612ee1457 100644 --- a/spec/features/projects/services/user_activates_pushover_spec.rb +++ b/spec/features/projects/services/user_activates_pushover_spec.rb @@ -5,7 +5,7 @@ describe 'User activates Pushover' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_settings_integrations_path(project)) diff --git a/spec/features/projects/services/user_activates_slack_notifications_spec.rb b/spec/features/projects/services/user_activates_slack_notifications_spec.rb index fae9ebd1bd6..24b5d5259db 100644 --- a/spec/features/projects/services/user_activates_slack_notifications_spec.rb +++ b/spec/features/projects/services/user_activates_slack_notifications_spec.rb @@ -6,7 +6,7 @@ describe 'User activates Slack notifications' do let(:project) { create(:project, slack_service: service) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -29,7 +29,7 @@ describe 'User activates Slack notifications' do context 'when service is already configured' do before do service.fields - service.update_attributes( + service.update( push_channel: 1, issue_channel: 2, merge_request_channel: 3, diff --git a/spec/features/projects/services/user_activates_slack_slash_command_spec.rb b/spec/features/projects/services/user_activates_slack_slash_command_spec.rb index 4a88654210c..08cfddf7993 100644 --- a/spec/features/projects/services/user_activates_slack_slash_command_spec.rb +++ b/spec/features/projects/services/user_activates_slack_slash_command_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' -feature 'Slack slash commands' do - given(:user) { create(:user) } - given(:project) { create(:project) } - given(:service) { project.create_slack_slash_commands_service } +describe 'Slack slash commands' do + let(:user) { create(:user) } + let(:project) { create(:project) } + let(:service) { project.create_slack_slash_commands_service } - background do - project.add_master(user) + before do + project.add_maintainer(user) sign_in(user) visit edit_project_service_path(project, service) end diff --git a/spec/features/projects/services/user_views_services_spec.rb b/spec/features/projects/services/user_views_services_spec.rb index 5c5e8b66642..e9c8cf0fe34 100644 --- a/spec/features/projects/services/user_views_services_spec.rb +++ b/spec/features/projects/services/user_views_services_spec.rb @@ -5,7 +5,7 @@ describe 'User views services' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_settings_integrations_path(project)) diff --git a/spec/features/projects/settings/forked_project_settings_spec.rb b/spec/features/projects/settings/forked_project_settings_spec.rb index a4d1b78b83b..df33d215602 100644 --- a/spec/features/projects/settings/forked_project_settings_spec.rb +++ b/spec/features/projects/settings/forked_project_settings_spec.rb @@ -7,8 +7,8 @@ describe 'Projects > Settings > For a forked project', :js do let(:forked_project) { fork_project(original_project, user) } before do - original_project.add_master(user) - forked_project.add_master(user) + original_project.add_maintainer(user) + forked_project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/settings/integration_settings_spec.rb b/spec/features/projects/settings/integration_settings_spec.rb index 5178d63050e..8745ff72df0 100644 --- a/spec/features/projects/settings/integration_settings_spec.rb +++ b/spec/features/projects/settings/integration_settings_spec.rb @@ -21,8 +21,8 @@ describe 'Projects > Settings > Integration settings' do end end - context 'for master' do - let(:role) { :master } + context 'for maintainer' do + let(:role) { :maintainer } context 'Webhooks' do let(:hook) { create(:project_hook, :all_events_enabled, enable_ssl_verification: true, project: project) } diff --git a/spec/features/projects/settings/lfs_settings_spec.rb b/spec/features/projects/settings/lfs_settings_spec.rb index 342be1d2a9d..befb306b48d 100644 --- a/spec/features/projects/settings/lfs_settings_spec.rb +++ b/spec/features/projects/settings/lfs_settings_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe 'Projects > Settings > LFS settings' do let(:project) { create(:project) } let(:user) { create(:user) } - let(:role) { :master } + let(:role) { :maintainer } context 'LFS enabled setting' do before do @@ -13,8 +13,8 @@ describe 'Projects > Settings > LFS settings' do project.add_role(user, role) end - context 'for master' do - let(:role) { :master } + context 'for maintainer' do + let(:role) { :maintainer } it 'displays the correct elements', :js do visit edit_project_path(project) diff --git a/spec/features/projects/settings/pipelines_settings_spec.rb b/spec/features/projects/settings/pipelines_settings_spec.rb index cfdae246c09..742ecf82c38 100644 --- a/spec/features/projects/settings/pipelines_settings_spec.rb +++ b/spec/features/projects/settings/pipelines_settings_spec.rb @@ -21,8 +21,8 @@ describe "Projects > Settings > Pipelines settings" do end end - context 'for master' do - let(:role) { :master } + context 'for maintainer' do + let(:role) { :maintainer } it 'be allowed to change' do visit project_settings_ci_cd_path(project) diff --git a/spec/features/projects/settings/project_badges_spec.rb b/spec/features/projects/settings/project_badges_spec.rb index 4893bef8884..2ec94274f80 100644 --- a/spec/features/projects/settings/project_badges_spec.rb +++ b/spec/features/projects/settings/project_badges_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Project Badges' do +describe 'Project Badges' do include WaitForRequests let(:user) { create(:user) } @@ -12,7 +12,7 @@ feature 'Project Badges' do let!(:group_badge) { create(:group_badge, group: group) } before do - group.add_master(user) + group.add_maintainer(user) sign_in(user) visit(project_settings_badges_path(project)) diff --git a/spec/features/projects/settings/repository_settings_spec.rb b/spec/features/projects/settings/repository_settings_spec.rb index 08b40653764..a0f5b234ebc 100644 --- a/spec/features/projects/settings/repository_settings_spec.rb +++ b/spec/features/projects/settings/repository_settings_spec.rb @@ -20,8 +20,8 @@ describe 'Projects > Settings > Repository settings' do end end - context 'for master' do - let(:role) { :master } + context 'for maintainer' do + let(:role) { :maintainer } context 'Deploy Keys', :js do let(:private_deploy_key) { create(:deploy_key, title: 'private_deploy_key', public: false) } @@ -101,7 +101,7 @@ describe 'Projects > Settings > Repository settings' do visit project_settings_repository_path(project) end - scenario 'view deploy tokens' do + it 'view deploy tokens' do within('.deploy-tokens') do expect(page).to have_content(deploy_token.name) expect(page).to have_content('read_repository') @@ -109,7 +109,7 @@ describe 'Projects > Settings > Repository settings' do end end - scenario 'add a new deploy token' do + it 'add a new deploy token' do fill_in 'deploy_token_name', with: 'new_deploy_key' fill_in 'deploy_token_expires_at', with: (Date.today + 1.month).to_s check 'deploy_token_read_repository' @@ -124,7 +124,7 @@ describe 'Projects > Settings > Repository settings' do let(:user2) { create(:user) } before do - project.add_master(user2) + project.add_maintainer(user2) visit project_settings_repository_path(project) end diff --git a/spec/features/projects/settings/user_archives_project_spec.rb b/spec/features/projects/settings/user_archives_project_spec.rb index 38c8a8c2468..5008eab4d39 100644 --- a/spec/features/projects/settings/user_archives_project_spec.rb +++ b/spec/features/projects/settings/user_archives_project_spec.rb @@ -4,7 +4,7 @@ describe 'Projects > Settings > User archives a project' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) diff --git a/spec/features/projects/settings/user_changes_avatar_spec.rb b/spec/features/projects/settings/user_changes_avatar_spec.rb index 2dcc79d8a12..64335163016 100644 --- a/spec/features/projects/settings/user_changes_avatar_spec.rb +++ b/spec/features/projects/settings/user_changes_avatar_spec.rb @@ -5,7 +5,7 @@ describe 'Projects > Settings > User changes avatar' do let(:user) { project.creator } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/settings/user_interacts_with_deploy_keys_spec.rb b/spec/features/projects/settings/user_interacts_with_deploy_keys_spec.rb index 71a077039b7..ecfb49b9efe 100644 --- a/spec/features/projects/settings/user_interacts_with_deploy_keys_spec.rb +++ b/spec/features/projects/settings/user_interacts_with_deploy_keys_spec.rb @@ -50,7 +50,7 @@ describe "User interacts with deploy keys", :js do before do create(:deploy_keys_project, project: another_project, deploy_key: deploy_key) - another_project.add_master(user) + another_project.add_maintainer(user) end it "shows deploy keys" do @@ -110,7 +110,7 @@ describe "User interacts with deploy keys", :js do before do create(:deploy_keys_project, project: another_project, deploy_key: deploy_key) - another_project.add_master(user) + another_project.add_maintainer(user) end it_behaves_like "attaches a key" diff --git a/spec/features/projects/settings/user_manages_group_links_spec.rb b/spec/features/projects/settings/user_manages_group_links_spec.rb index 92ce2ca83c7..2f1824d7849 100644 --- a/spec/features/projects/settings/user_manages_group_links_spec.rb +++ b/spec/features/projects/settings/user_manages_group_links_spec.rb @@ -9,10 +9,10 @@ describe 'Projects > Settings > User manages group links' do let(:group_market) { create(:group, name: 'Market', path: 'market') } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) - share_link = project.project_group_links.new(group_access: Gitlab::Access::MASTER) + share_link = project.project_group_links.new(group_access: Gitlab::Access::MAINTAINER) share_link.group_id = group_ops.id share_link.save! diff --git a/spec/features/projects/settings/user_manages_project_members_spec.rb b/spec/features/projects/settings/user_manages_project_members_spec.rb index d3003753ae6..b8ca11d53f0 100644 --- a/spec/features/projects/settings/user_manages_project_members_spec.rb +++ b/spec/features/projects/settings/user_manages_project_members_spec.rb @@ -9,7 +9,7 @@ describe 'Projects > Settings > User manages project members' do let(:user_mike) { create(:user, name: 'Mike') } before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(user_dmitriy) sign_in(user) end @@ -30,7 +30,7 @@ describe 'Projects > Settings > User manages project members' do end it 'imports a team from another project' do - project2.add_master(user) + project2.add_maintainer(user) project2.add_reporter(user_mike) visit(project_project_members_path(project)) @@ -54,7 +54,7 @@ describe 'Projects > Settings > User manages project members' do group.add_owner(user) group.add_developer(user_dmitriy) - share_link = project.project_group_links.new(group_access: Gitlab::Access::MASTER) + share_link = project.project_group_links.new(group_access: Gitlab::Access::MAINTAINER) share_link.group_id = group.id share_link.save! diff --git a/spec/features/projects/settings/user_sees_revoke_deploy_token_modal_spec.rb b/spec/features/projects/settings/user_sees_revoke_deploy_token_modal_spec.rb new file mode 100644 index 00000000000..069704a1305 --- /dev/null +++ b/spec/features/projects/settings/user_sees_revoke_deploy_token_modal_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' + +describe 'Repository Settings > User sees revoke deploy token modal', :js do + let(:project) { create(:project, :public, :repository) } + let(:user) { project.creator } + let(:role) { :developer } + let!(:deploy_token) { create(:deploy_token, :gitlab_deploy_token, projects: [project]) } + + before do + project.add_role(user, role) + sign_in(user) + visit(project_settings_repository_path(project)) + click_link('Revoke') + end + + it 'shows the revoke deploy token modal' do + expect(page).to have_content('You are about to revoke') + end + + it 'closes the revoke deploy token modal with escape keypress' do + find('.modal.show').send_keys(:escape) + + expect(page).not_to have_content('You are about to revoke') + end +end diff --git a/spec/features/projects/settings/user_transfers_a_project_spec.rb b/spec/features/projects/settings/user_transfers_a_project_spec.rb index 96b7cf1f93b..2fdbc04fa62 100644 --- a/spec/features/projects/settings/user_transfers_a_project_spec.rb +++ b/spec/features/projects/settings/user_transfers_a_project_spec.rb @@ -10,7 +10,7 @@ describe 'Projects > Settings > User transfers a project', :js do sign_in(user) end - def transfer_project(project, group) + def transfer_project(project, group, confirm: true) visit edit_project_path(project) page.within('.js-project-transfer-form') do @@ -21,6 +21,8 @@ describe 'Projects > Settings > User transfers a project', :js do click_button('Transfer project') + return unless confirm + fill_in 'confirm_name_input', with: project.name click_button 'Confirm' @@ -28,6 +30,11 @@ describe 'Projects > Settings > User transfers a project', :js do wait_for_requests end + it 'focuses on the confirmation field' do + transfer_project(project, group, confirm: false) + expect(page).to have_selector '#confirm_name_input:focus' + end + it 'allows transferring a project to a group' do old_path = project_path(project) transfer_project(project, group) diff --git a/spec/features/projects/settings/visibility_settings_spec.rb b/spec/features/projects/settings/visibility_settings_spec.rb index 2ec6990313f..1fbc108697f 100644 --- a/spec/features/projects/settings/visibility_settings_spec.rb +++ b/spec/features/projects/settings/visibility_settings_spec.rb @@ -59,12 +59,12 @@ describe 'Projects > Settings > Visibility settings', :js do end end - context 'as master' do - let(:master_user) { create(:user) } + context 'as maintainer' do + let(:maintainer_user) { create(:user) } before do - project.add_master(master_user) - sign_in(master_user) + project.add_maintainer(maintainer_user) + sign_in(maintainer_user) visit edit_project_path(project) end diff --git a/spec/features/projects/show/developer_views_empty_project_instructions_spec.rb b/spec/features/projects/show/developer_views_empty_project_instructions_spec.rb index 8803b5222be..227bdf524fe 100644 --- a/spec/features/projects/show/developer_views_empty_project_instructions_spec.rb +++ b/spec/features/projects/show/developer_views_empty_project_instructions_spec.rb @@ -1,23 +1,23 @@ require 'rails_helper' -feature 'Projects > Show > Developer views empty project instructions' do +describe 'Projects > Show > Developer views empty project instructions' do let(:project) { create(:project, :empty_repo) } let(:developer) { create(:user) } - background do + before do project.add_developer(developer) sign_in(developer) end context 'without an SSH key' do - scenario 'defaults to HTTP' do + it 'defaults to HTTP' do visit_project expect_instructions_for('http') end - scenario 'switches to SSH', :js do + it 'switches to SSH', :js do visit_project select_protocol('SSH') @@ -27,17 +27,17 @@ feature 'Projects > Show > Developer views empty project instructions' do end context 'with an SSH key' do - background do + before do create(:personal_key, user: developer) end - scenario 'defaults to SSH' do + it 'defaults to SSH' do visit_project expect_instructions_for('ssh') end - scenario 'switches to HTTP', :js do + it 'switches to HTTP', :js do visit_project select_protocol('HTTP') diff --git a/spec/features/projects/show/download_buttons_spec.rb b/spec/features/projects/show/download_buttons_spec.rb index 254affd4a94..3a2dcc5aa55 100644 --- a/spec/features/projects/show/download_buttons_spec.rb +++ b/spec/features/projects/show/download_buttons_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' -feature 'Projects > Show > Download buttons' do - given(:user) { create(:user) } - given(:role) { :developer } - given(:status) { 'success' } - given(:project) { create(:project, :repository) } +describe 'Projects > Show > Download buttons' do + let(:user) { create(:user) } + let(:role) { :developer } + let(:status) { 'success' } + let(:project) { create(:project, :repository) } - given(:pipeline) do + let(:pipeline) do create(:ci_pipeline, project: project, sha: project.commit.sha, @@ -14,14 +14,14 @@ feature 'Projects > Show > Download buttons' do status: status) end - given!(:build) do + let!(:build) do create(:ci_build, :success, :artifacts, pipeline: pipeline, status: pipeline.status, name: 'build') end - background do + before do sign_in(user) project.add_role(user, role) end @@ -32,13 +32,13 @@ feature 'Projects > Show > Download buttons' do visit project_path(project) end - scenario 'shows download artifacts button' do + it 'shows download artifacts button' do href = latest_succeeded_project_artifacts_path(project, "#{project.default_branch}/download", job: 'build') expect(page).to have_link "Download '#{build.name}'", href: href end - scenario 'download links have download attribute' do + it 'download links have download attribute' do expect(page).to have_selector('a', text: 'Download') page.all('a', text: 'Download').each do |link| expect(link[:download]).to eq '' diff --git a/spec/features/projects/show/no_password_spec.rb b/spec/features/projects/show/no_password_spec.rb index b3b3212556c..8259d482fd9 100644 --- a/spec/features/projects/show/no_password_spec.rb +++ b/spec/features/projects/show/no_password_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'No Password Alert' do +describe 'No Password Alert' do let(:project) { create(:project, :repository, namespace: user.namespace) } context 'with internal auth enabled' do diff --git a/spec/features/projects/show/rss_spec.rb b/spec/features/projects/show/rss_spec.rb index 52164d30c40..4d9135b9677 100644 --- a/spec/features/projects/show/rss_spec.rb +++ b/spec/features/projects/show/rss_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Projects > Show > RSS' do +describe 'Projects > Show > RSS' do let(:user) { create(:user) } let(:project) { create(:project, :repository, visibility_level: Gitlab::VisibilityLevel::PUBLIC) } let(:path) { project_path(project) } diff --git a/spec/features/projects/show/user_manages_notifications_spec.rb b/spec/features/projects/show/user_manages_notifications_spec.rb index 31b105229be..546619e88ec 100644 --- a/spec/features/projects/show/user_manages_notifications_spec.rb +++ b/spec/features/projects/show/user_manages_notifications_spec.rb @@ -16,4 +16,36 @@ describe 'Projects > Show > User manages notifications', :js do expect(page).to have_content 'On mention' end end + + context 'custom notification settings' do + let(:email_events) do + [ + :new_note, + :new_issue, + :reopen_issue, + :close_issue, + :reassign_issue, + :issue_due, + :new_merge_request, + :push_to_merge_request, + :reopen_merge_request, + :close_merge_request, + :reassign_merge_request, + :merge_merge_request, + :failed_pipeline, + :success_pipeline + ] + end + + it 'shows notification settings checkbox' do + first('.notifications-btn').click + page.find('a[data-notification-level="custom"]').click + + page.within('.custom-notifications-form') do + email_events.each do |event_name| + expect(page).to have_selector("input[name='notification_setting[#{event_name}]']") + end + end + end + end end diff --git a/spec/features/projects/show/user_sees_deletion_failure_message_spec.rb b/spec/features/projects/show/user_sees_deletion_failure_message_spec.rb index aa23bef6fd8..d9d57298929 100644 --- a/spec/features/projects/show/user_sees_deletion_failure_message_spec.rb +++ b/spec/features/projects/show/user_sees_deletion_failure_message_spec.rb @@ -8,7 +8,7 @@ describe 'Projects > Show > User sees a deletion failure message' do end it 'shows error message if deletion for project fails' do - project.update_attributes(delete_error: "Something went wrong", pending_delete: false) + project.update(delete_error: "Something went wrong", pending_delete: false) visit project_path(project) diff --git a/spec/features/projects/show/user_sees_setup_shortcut_buttons_spec.rb b/spec/features/projects/show/user_sees_setup_shortcut_buttons_spec.rb index e44361fbe26..0405e21a0d7 100644 --- a/spec/features/projects/show/user_sees_setup_shortcut_buttons_spec.rb +++ b/spec/features/projects/show/user_sees_setup_shortcut_buttons_spec.rb @@ -5,6 +5,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do # see spec/features/projects/files/project_owner_creates_license_file_spec.rb # see spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb + include FakeBlobHelpers + let(:user) { create(:user) } describe 'empty project' do @@ -36,9 +38,9 @@ describe 'Projects > Show > User sees setup shortcut buttons' do end end - describe 'as a master' do + describe 'as a maintainer' do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_path(project) @@ -136,16 +138,62 @@ describe 'Projects > Show > User sees setup shortcut buttons' do end end - describe 'as a master' do + describe 'as a maintainer' do before do allow_any_instance_of(AutoDevopsHelper).to receive(:show_auto_devops_callout?).and_return(false) - project.add_master(user) + project.add_maintainer(user) sign_in(user) + end - visit project_path(project) + context 'Readme button' do + before do + allow(Project).to receive(:find_by_full_path) + .with(project.full_path, follow_redirects: true) + .and_return(project) + end + + context 'when the project has a populated Readme' do + it 'show the "Readme" anchor' do + visit project_path(project) + + expect(project.repository.readme).not_to be_nil + + page.within('.project-stats') do + expect(page).not_to have_link('Add Readme', href: presenter.add_readme_path) + expect(page).to have_link('Readme', href: presenter.readme_path) + end + end + + context 'when the project has an empty Readme' do + it 'show the "Readme" anchor' do + allow(project.repository).to receive(:readme).and_return(fake_blob(path: 'README.md', data: '', size: 0)) + + visit project_path(project) + + page.within('.project-stats') do + expect(page).not_to have_link('Add Readme', href: presenter.add_readme_path) + expect(page).to have_link('Readme', href: presenter.readme_path) + end + end + end + end + + context 'when the project does not have a Readme' do + it 'shows the "Add Readme" button' do + allow(project.repository).to receive(:readme).and_return(nil) + + visit project_path(project) + + page.within('.project-stats') do + expect(page).to have_link('Add Readme', href: presenter.add_readme_path) + end + end + end end it 'no "Add Changelog" button if the project already has a changelog' do + visit project_path(project) + expect(project.repository.changelog).not_to be_nil page.within('.project-stats') do @@ -154,6 +202,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do end it 'no "Add License" button if the project already has a license' do + visit project_path(project) + expect(project.repository.license_blob).not_to be_nil page.within('.project-stats') do @@ -162,6 +212,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do end it 'no "Add Contribution guide" button if the project already has a contribution guide' do + visit project_path(project) + expect(project.repository.contribution_guide).not_to be_nil page.within('.project-stats') do @@ -171,6 +223,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do describe 'GitLab CI configuration button' do it '"Set up CI/CD" button linked to new file populated for a .gitlab-ci.yml' do + visit project_path(project) + expect(project.repository.gitlab_ci_yml).to be_nil page.within('.project-stats') do @@ -211,6 +265,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do describe 'Auto DevOps button' do it '"Enable Auto DevOps" button linked to settings page' do + visit project_path(project) + page.within('.project-stats') do expect(page).to have_link('Enable Auto DevOps', href: project_settings_ci_cd_path(project, anchor: 'autodevops-settings')) end @@ -263,6 +319,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do describe 'Kubernetes cluster button' do it '"Add Kubernetes cluster" button linked to clusters page' do + visit project_path(project) + page.within('.project-stats') do expect(page).to have_link('Add Kubernetes cluster', href: new_project_cluster_path(project)) end diff --git a/spec/features/projects/snippets/create_snippet_spec.rb b/spec/features/projects/snippets/create_snippet_spec.rb index 2388feeb980..6d8a72dd6a3 100644 --- a/spec/features/projects/snippets/create_snippet_spec.rb +++ b/spec/features/projects/snippets/create_snippet_spec.rb @@ -16,7 +16,7 @@ describe 'Projects > Snippets > Create Snippet', :js do context 'when a user is authenticated' do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_snippets_path(project) diff --git a/spec/features/projects/snippets/show_spec.rb b/spec/features/projects/snippets/show_spec.rb index 004ac55b656..3cc797277dd 100644 --- a/spec/features/projects/snippets/show_spec.rb +++ b/spec/features/projects/snippets/show_spec.rb @@ -6,7 +6,7 @@ describe 'Projects > Snippets > Project snippet', :js do let(:snippet) { create(:project_snippet, project: project, file_name: file_name, content: content) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/snippets/user_comments_on_snippet_spec.rb b/spec/features/projects/snippets/user_comments_on_snippet_spec.rb index 01cf9740d1f..d82e350e0f7 100644 --- a/spec/features/projects/snippets/user_comments_on_snippet_spec.rb +++ b/spec/features/projects/snippets/user_comments_on_snippet_spec.rb @@ -6,7 +6,7 @@ describe 'Projects > Snippets > User comments on a snippet', :js do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_snippet_path(project, snippet)) diff --git a/spec/features/projects/snippets/user_deletes_snippet_spec.rb b/spec/features/projects/snippets/user_deletes_snippet_spec.rb index e64837ad59e..2bd8bb9d551 100644 --- a/spec/features/projects/snippets/user_deletes_snippet_spec.rb +++ b/spec/features/projects/snippets/user_deletes_snippet_spec.rb @@ -6,7 +6,7 @@ describe 'Projects > Snippets > User deletes a snippet' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_snippet_path(project, snippet)) diff --git a/spec/features/projects/snippets/user_updates_snippet_spec.rb b/spec/features/projects/snippets/user_updates_snippet_spec.rb index eaedbbf32b6..33f77d55f89 100644 --- a/spec/features/projects/snippets/user_updates_snippet_spec.rb +++ b/spec/features/projects/snippets/user_updates_snippet_spec.rb @@ -6,7 +6,7 @@ describe 'Projects > Snippets > User updates a snippet' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_snippet_path(project, snippet)) diff --git a/spec/features/projects/snippets/user_views_snippets_spec.rb b/spec/features/projects/snippets/user_views_snippets_spec.rb index 376b76e0001..1243db9d9f7 100644 --- a/spec/features/projects/snippets/user_views_snippets_spec.rb +++ b/spec/features/projects/snippets/user_views_snippets_spec.rb @@ -8,7 +8,7 @@ describe 'Projects > Snippets > User views snippets' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_snippets_path(project)) diff --git a/spec/features/projects/sub_group_issuables_spec.rb b/spec/features/projects/sub_group_issuables_spec.rb index eb2d3ff50a0..50e7e934cf6 100644 --- a/spec/features/projects/sub_group_issuables_spec.rb +++ b/spec/features/projects/sub_group_issuables_spec.rb @@ -7,7 +7,7 @@ describe 'Subgroup Issuables', :js, :nested_groups do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in user end diff --git a/spec/features/projects/tags/download_buttons_spec.rb b/spec/features/projects/tags/download_buttons_spec.rb index b62498194c4..fbfd8cee7aa 100644 --- a/spec/features/projects/tags/download_buttons_spec.rb +++ b/spec/features/projects/tags/download_buttons_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -feature 'Download buttons in tags page' do - given(:user) { create(:user) } - given(:role) { :developer } - given(:status) { 'success' } - given(:tag) { 'v1.0.0' } - given(:project) { create(:project, :repository) } +describe 'Download buttons in tags page' do + let(:user) { create(:user) } + let(:role) { :developer } + let(:status) { 'success' } + let(:tag) { 'v1.0.0' } + let(:project) { create(:project, :repository) } - given(:pipeline) do + let(:pipeline) do create(:ci_pipeline, project: project, sha: project.commit(tag).sha, @@ -15,14 +15,14 @@ feature 'Download buttons in tags page' do status: status) end - given!(:build) do + let!(:build) do create(:ci_build, :success, :artifacts, pipeline: pipeline, status: pipeline.status, name: 'build') end - background do + before do sign_in(user) project.add_role(user, role) end @@ -33,7 +33,7 @@ feature 'Download buttons in tags page' do visit project_tags_path(project) end - scenario 'shows download artifacts button' do + it 'shows download artifacts button' do href = latest_succeeded_project_artifacts_path(project, "#{tag}/download", job: 'build') expect(page).to have_link "Download '#{build.name}'", href: href diff --git a/spec/features/projects/tree/create_directory_spec.rb b/spec/features/projects/tree/create_directory_spec.rb index 3017048e506..d3aa4912099 100644 --- a/spec/features/projects/tree/create_directory_spec.rb +++ b/spec/features/projects/tree/create_directory_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -feature 'Multi-file editor new directory', :js do +describe 'Multi-file editor new directory', :js do let(:user) { create(:user) } let(:project) { create(:project, :repository) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_tree_path(project, :master) @@ -22,9 +22,7 @@ feature 'Multi-file editor new directory', :js do end it 'creates directory in current directory' do - find('.add-to-tree').click - - click_link('New directory') + all('.ide-tree-header button').last.click page.within('.modal') do find('.form-control').set('folder name') @@ -32,9 +30,7 @@ feature 'Multi-file editor new directory', :js do click_button('Create directory') end - find('.add-to-tree').click - - click_link('New file') + first('.ide-tree-header button').click page.within('.modal-dialog') do find('.form-control').set('file name') diff --git a/spec/features/projects/tree/create_file_spec.rb b/spec/features/projects/tree/create_file_spec.rb index 56471c8e7aa..f836783cbff 100644 --- a/spec/features/projects/tree/create_file_spec.rb +++ b/spec/features/projects/tree/create_file_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -feature 'Multi-file editor new file', :js do +describe 'Multi-file editor new file', :js do let(:user) { create(:user) } let(:project) { create(:project, :repository) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_path(project) @@ -22,9 +22,7 @@ feature 'Multi-file editor new file', :js do end it 'creates file in current directory' do - find('.add-to-tree').click - - click_link('New file') + first('.ide-tree-header button').click page.within('.modal') do find('.form-control').set('file name') diff --git a/spec/features/projects/tree/rss_spec.rb b/spec/features/projects/tree/rss_spec.rb index f52b3cc1d86..022167d9c5f 100644 --- a/spec/features/projects/tree/rss_spec.rb +++ b/spec/features/projects/tree/rss_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Project Tree RSS' do +describe 'Project Tree RSS' do let(:user) { create(:user) } let(:project) { create(:project, :repository, visibility_level: Gitlab::VisibilityLevel::PUBLIC) } let(:path) { project_tree_path(project, :master) } diff --git a/spec/features/projects/tree/tree_show_spec.rb b/spec/features/projects/tree/tree_show_spec.rb index c4b3fb9d171..9e15163fd72 100644 --- a/spec/features/projects/tree/tree_show_spec.rb +++ b/spec/features/projects/tree/tree_show_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -feature 'Projects tree' do +describe 'Projects tree' do let(:user) { create(:user) } let(:project) { create(:project, :repository) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_tree_path(project, 'master') diff --git a/spec/features/projects/tree/upload_file_spec.rb b/spec/features/projects/tree/upload_file_spec.rb index 4dfc325b37e..dcf7d314f8e 100644 --- a/spec/features/projects/tree/upload_file_spec.rb +++ b/spec/features/projects/tree/upload_file_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -feature 'Multi-file editor upload file', :js do +describe 'Multi-file editor upload file', :js do let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:txt_file) { File.join(Rails.root, 'spec', 'fixtures', 'doc_sample.txt') } let(:img_file) { File.join(Rails.root, 'spec', 'fixtures', 'dk.png') } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_tree_path(project, :master) @@ -24,14 +24,10 @@ feature 'Multi-file editor upload file', :js do end it 'uploads text file' do - find('.add-to-tree').click - # make the field visible so capybara can use it execute_script('document.querySelector("#file-upload").classList.remove("hidden")') attach_file('file-upload', txt_file) - find('.add-to-tree').click - expect(page).to have_selector('.multi-file-tab', text: 'doc_sample.txt') expect(find('.blob-editor-container .lines-content')['innerText']).to have_content(File.open(txt_file, &:readline)) end diff --git a/spec/features/projects/user_creates_project_spec.rb b/spec/features/projects/user_creates_project_spec.rb index f95469ad070..83d18996f4e 100644 --- a/spec/features/projects/user_creates_project_spec.rb +++ b/spec/features/projects/user_creates_project_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'User creates a project', :js do +describe 'User creates a project', :js do let(:user) { create(:user) } before do diff --git a/spec/features/projects/user_uses_shortcuts_spec.rb b/spec/features/projects/user_uses_shortcuts_spec.rb index 495a010b32c..df9ee69aadb 100644 --- a/spec/features/projects/user_uses_shortcuts_spec.rb +++ b/spec/features/projects/user_uses_shortcuts_spec.rb @@ -5,7 +5,7 @@ describe 'User uses shortcuts', :js do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(project_path(project)) @@ -110,6 +110,14 @@ describe 'User uses shortcuts', :js do end context 'when navigating to the Operations pages' do + it 'redirects to the Metrics page' do + find('body').native.send_key('g') + find('body').native.send_key('l') + + expect(page).to have_active_navigation('Operations') + expect(page).to have_active_sub_navigation('Metrics') + end + it 'redirects to the Environments page' do find('body').native.send_key('g') find('body').native.send_key('e') diff --git a/spec/features/projects/user_views_empty_project_spec.rb b/spec/features/projects/user_views_empty_project_spec.rb index 7b982301ffc..b7c0834d33a 100644 --- a/spec/features/projects/user_views_empty_project_spec.rb +++ b/spec/features/projects/user_views_empty_project_spec.rb @@ -15,9 +15,9 @@ describe 'User views an empty project' do end end - describe 'as a master' do + describe 'as a maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'allowing push to default branch' diff --git a/spec/features/projects/view_on_env_spec.rb b/spec/features/projects/view_on_env_spec.rb index 84ec32b3fac..a48ad94e9fa 100644 --- a/spec/features/projects/view_on_env_spec.rb +++ b/spec/features/projects/view_on_env_spec.rb @@ -7,7 +7,7 @@ describe 'View on environment', :js do let(:user) { project.creator } before do - project.add_master(user) + project.add_maintainer(user) end context 'when the branch has a route map' do diff --git a/spec/features/projects/wiki/markdown_preview_spec.rb b/spec/features/projects/wiki/markdown_preview_spec.rb index bbdd98a7623..ed5f8105487 100644 --- a/spec/features/projects/wiki/markdown_preview_spec.rb +++ b/spec/features/projects/wiki/markdown_preview_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Projects > Wiki > User previews markdown changes', :js do +describe 'Projects > Wiki > User previews markdown changes', :js do let(:user) { create(:user) } let(:project) { create(:project, :wiki_repo, namespace: user.namespace) } let(:wiki_content) do @@ -9,11 +9,12 @@ feature 'Projects > Wiki > User previews markdown changes', :js do [relative link 1](../relative) [relative link 2](./relative) [relative link 3](./e/f/relative) +[spaced link](title with spaces) HEREDOC end - background do - project.add_master(user) + before do + project.add_maintainer(user) sign_in(user) @@ -42,6 +43,7 @@ feature 'Projects > Wiki > User previews markdown changes', :js do expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/relative\">relative link 1</a>") expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/relative\">relative link 2</a>") expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/e/f/relative\">relative link 3</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>") end end @@ -64,6 +66,7 @@ feature 'Projects > Wiki > User previews markdown changes', :js do expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>") expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>") expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>") end end @@ -86,6 +89,7 @@ feature 'Projects > Wiki > User previews markdown changes', :js do expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>") expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>") expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>") end end end @@ -119,6 +123,7 @@ feature 'Projects > Wiki > User previews markdown changes', :js do expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/relative\">relative link 1</a>") expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/relative\">relative link 2</a>") expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/e/f/relative\">relative link 3</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>") end end @@ -136,6 +141,7 @@ feature 'Projects > Wiki > User previews markdown changes', :js do expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>") expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>") expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>") end end @@ -153,6 +159,7 @@ feature 'Projects > Wiki > User previews markdown changes', :js do expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>") expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>") expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>") end end end diff --git a/spec/features/projects/wiki/shortcuts_spec.rb b/spec/features/projects/wiki/shortcuts_spec.rb index 6178361082e..c01be1f14ed 100644 --- a/spec/features/projects/wiki/shortcuts_spec.rb +++ b/spec/features/projects/wiki/shortcuts_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Wiki shortcuts', :js do +describe 'Wiki shortcuts', :js do let(:user) { create(:user) } let(:project) { create(:project, :wiki_repo, namespace: user.namespace) } let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: { title: 'home', content: 'Home page' }) } @@ -10,7 +10,7 @@ feature 'Wiki shortcuts', :js do visit project_wiki_path(project, wiki_page) end - scenario 'Visit edit wiki page using "e" keyboard shortcut' do + it 'Visit edit wiki page using "e" keyboard shortcut' do find('body').native.send_key('e') expect(find('.wiki-page-title')).to have_content('Edit Page') diff --git a/spec/features/projects/wiki/user_creates_wiki_page_spec.rb b/spec/features/projects/wiki/user_creates_wiki_page_spec.rb index 746b3ada789..33a074cdd8b 100644 --- a/spec/features/projects/wiki/user_creates_wiki_page_spec.rb +++ b/spec/features/projects/wiki/user_creates_wiki_page_spec.rb @@ -6,7 +6,7 @@ describe "User creates wiki page" do let(:project) { create(:project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/wiki/user_deletes_wiki_page_spec.rb b/spec/features/projects/wiki/user_deletes_wiki_page_spec.rb index 2c67cec6b67..5007794cd77 100644 --- a/spec/features/projects/wiki/user_deletes_wiki_page_spec.rb +++ b/spec/features/projects/wiki/user_deletes_wiki_page_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'User deletes wiki page', :js do +describe 'User deletes wiki page', :js do let(:user) { create(:user) } let(:project) { create(:project, :wiki_repo, namespace: user.namespace) } let(:wiki_page) { create(:wiki_page, wiki: project.wiki) } diff --git a/spec/features/projects/wiki/user_git_access_wiki_page_spec.rb b/spec/features/projects/wiki/user_git_access_wiki_page_spec.rb index 823399ac3c3..db97d59e918 100644 --- a/spec/features/projects/wiki/user_git_access_wiki_page_spec.rb +++ b/spec/features/projects/wiki/user_git_access_wiki_page_spec.rb @@ -9,7 +9,7 @@ describe 'Projects > Wiki > User views Git access wiki page' do sign_in(user) end - scenario 'Visit Wiki Page Current Commit' do + it 'Visit Wiki Page Current Commit' do visit project_wiki_path(project, wiki_page) click_link 'Clone repository' diff --git a/spec/features/projects/wiki/user_updates_wiki_page_spec.rb b/spec/features/projects/wiki/user_updates_wiki_page_spec.rb index 2ccbc15b6da..2840d28cf30 100644 --- a/spec/features/projects/wiki/user_updates_wiki_page_spec.rb +++ b/spec/features/projects/wiki/user_updates_wiki_page_spec.rb @@ -4,7 +4,7 @@ describe 'User updates wiki page' do shared_examples 'wiki page user update' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/wiki/user_views_wiki_in_project_page_spec.rb b/spec/features/projects/wiki/user_views_wiki_in_project_page_spec.rb index 92b50169476..fb0ebe22bf7 100644 --- a/spec/features/projects/wiki/user_views_wiki_in_project_page_spec.rb +++ b/spec/features/projects/wiki/user_views_wiki_in_project_page_spec.rb @@ -4,7 +4,7 @@ describe 'Projects > Wiki > User views wiki in project page' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects/wiki/user_views_wiki_page_spec.rb b/spec/features/projects/wiki/user_views_wiki_page_spec.rb index 1de7d9a56a8..0ef7f35f64a 100644 --- a/spec/features/projects/wiki/user_views_wiki_page_spec.rb +++ b/spec/features/projects/wiki/user_views_wiki_page_spec.rb @@ -11,7 +11,7 @@ describe 'User views a wiki page' do end before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/projects_spec.rb b/spec/features/projects_spec.rb index cfe979a8647..39b47d99040 100644 --- a/spec/features/projects_spec.rb +++ b/spec/features/projects_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Project' do +describe 'Project' do include ProjectForksHelper describe 'creating from template' do @@ -151,10 +151,16 @@ feature 'Project' do before do sign_in(user) - project.add_master(user) + project.add_maintainer(user) visit edit_project_path(project) end + it 'focuses on the confirmation field' do + click_button 'Remove project' + + expect(page).to have_selector '#confirm_name_input:focus' + end + it 'removes a project' do expect { remove_with_confirm('Remove project', project.path) }.to change { Project.count }.by(-1) expect(page).to have_content "Project '#{project.full_name}' is in the process of being deleted." @@ -169,7 +175,7 @@ feature 'Project' do let(:project) { create(:forked_project_with_submodules) } before do - project.add_master(user) + project.add_maintainer(user) sign_in user visit project_path(project) end @@ -198,7 +204,7 @@ feature 'Project' do let(:project) { create(:project, :repository) } before do - project.add_master(user) + project.add_maintainer(user) sign_in user visit project_path(project) end diff --git a/spec/features/protected_branches_spec.rb b/spec/features/protected_branches_spec.rb index 39bd4af6cd0..63c38a25f4b 100644 --- a/spec/features/protected_branches_spec.rb +++ b/spec/features/protected_branches_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Protected Branches', :js do +describe 'Protected Branches', :js do let(:user) { create(:user) } let(:admin) { create(:admin) } let(:project) { create(:project, :repository) } @@ -28,9 +28,9 @@ feature 'Protected Branches', :js do end end - context 'logged in as master' do + context 'logged in as maintainer' do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/protected_tags_spec.rb b/spec/features/protected_tags_spec.rb index efccaeaff6c..c8e92cd1c07 100644 --- a/spec/features/protected_tags_spec.rb +++ b/spec/features/protected_tags_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Protected Tags', :js do +describe 'Protected Tags', :js do let(:user) { create(:user, :admin) } let(:project) { create(:project, :repository) } diff --git a/spec/features/raven_js_spec.rb b/spec/features/raven_js_spec.rb index a9e815eaf4f..b0923b451ee 100644 --- a/spec/features/raven_js_spec.rb +++ b/spec/features/raven_js_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'RavenJS' do +describe 'RavenJS' do let(:raven_path) { '/raven.chunk.js' } it 'should not load raven if sentry is disabled' do diff --git a/spec/features/reportable_note/commit_spec.rb b/spec/features/reportable_note/commit_spec.rb index 9b6864eb90f..54ebda9dcab 100644 --- a/spec/features/reportable_note/commit_spec.rb +++ b/spec/features/reportable_note/commit_spec.rb @@ -7,7 +7,7 @@ describe 'Reportable note on commit', :js do let(:project) { create(:project, :repository) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/reportable_note/issue_spec.rb b/spec/features/reportable_note/issue_spec.rb index f5a1950e48e..bce1f7a3780 100644 --- a/spec/features/reportable_note/issue_spec.rb +++ b/spec/features/reportable_note/issue_spec.rb @@ -7,7 +7,7 @@ describe 'Reportable note on issue', :js do let!(:note) { create(:note_on_issue, noteable: issue, project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_issue_path(project, issue) diff --git a/spec/features/reportable_note/merge_request_spec.rb b/spec/features/reportable_note/merge_request_spec.rb index 1f69257f7ed..d00324156c4 100644 --- a/spec/features/reportable_note/merge_request_spec.rb +++ b/spec/features/reportable_note/merge_request_spec.rb @@ -6,7 +6,7 @@ describe 'Reportable note on merge request', :js do let(:merge_request) { create(:merge_request, source_project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_merge_request_path(project, merge_request) diff --git a/spec/features/reportable_note/snippets_spec.rb b/spec/features/reportable_note/snippets_spec.rb index 98ef50b78de..06218d9b286 100644 --- a/spec/features/reportable_note/snippets_spec.rb +++ b/spec/features/reportable_note/snippets_spec.rb @@ -5,7 +5,7 @@ describe 'Reportable note on snippets', :js do let(:project) { create(:project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/runners_spec.rb b/spec/features/runners_spec.rb index fe0b03a7e00..0c6cf3dc477 100644 --- a/spec/features/runners_spec.rb +++ b/spec/features/runners_spec.rb @@ -1,20 +1,20 @@ require 'spec_helper' -feature 'Runners' do - given(:user) { create(:user) } +describe 'Runners' do + let(:user) { create(:user) } - background do + before do sign_in(user) end context 'when user opens runners page' do - given(:project) { create(:project) } + let(:project) { create(:project) } - background do - project.add_master(user) + before do + project.add_maintainer(user) end - scenario 'user can see a button to install runners on kubernetes clusters' do + it 'user can see a button to install runners on kubernetes clusters' do visit project_runners_path(project) expect(page).to have_link('Install Runner on Kubernetes', href: project_clusters_path(project)) @@ -22,16 +22,16 @@ feature 'Runners' do end context 'when a project has enabled shared_runners' do - given(:project) { create(:project) } + let(:project) { create(:project) } - background do - project.add_master(user) + before do + project.add_maintainer(user) end context 'when a project_type runner is activated on the project' do - given!(:specific_runner) { create(:ci_runner, :project, projects: [project]) } + let!(:specific_runner) { create(:ci_runner, :project, projects: [project]) } - scenario 'user sees the specific runner' do + it 'user sees the specific runner' do visit project_runners_path(project) within '.activated-specific-runners' do @@ -43,7 +43,7 @@ feature 'Runners' do expect(page).to have_content(specific_runner.platform) end - scenario 'user can pause and resume the specific runner' do + it 'user can pause and resume the specific runner' do visit project_runners_path(project) within '.activated-specific-runners' do @@ -63,7 +63,7 @@ feature 'Runners' do end end - scenario 'user removes an activated specific runner if this is last project for that runners' do + it 'user removes an activated specific runner if this is last project for that runners' do visit project_runners_path(project) within '.activated-specific-runners' do @@ -73,7 +73,7 @@ feature 'Runners' do expect(page).not_to have_content(specific_runner.display_name) end - scenario 'user edits the runner to be protected' do + it 'user edits the runner to be protected' do visit project_runners_path(project) within '.activated-specific-runners' do @@ -89,11 +89,11 @@ feature 'Runners' do end context 'when a runner has a tag' do - background do + before do specific_runner.update(tag_list: ['tag']) end - scenario 'user edits runner not to run untagged jobs' do + it 'user edits runner not to run untagged jobs' do visit project_runners_path(project) within '.activated-specific-runners' do @@ -110,9 +110,9 @@ feature 'Runners' do end context 'when a shared runner is activated on the project' do - given!(:shared_runner) { create(:ci_runner, :instance) } + let!(:shared_runner) { create(:ci_runner, :instance) } - scenario 'user sees CI/CD setting page' do + it 'user sees CI/CD setting page' do visit project_runners_path(project) expect(page.find('.available-shared-runners')).to have_content(shared_runner.display_name) @@ -121,14 +121,14 @@ feature 'Runners' do end context 'when a specific runner exists in another project' do - given(:another_project) { create(:project) } - given!(:specific_runner) { create(:ci_runner, :project, projects: [another_project]) } + let(:another_project) { create(:project) } + let!(:specific_runner) { create(:ci_runner, :project, projects: [another_project]) } - background do - another_project.add_master(user) + before do + another_project.add_maintainer(user) end - scenario 'user enables and disables a specific runner' do + it 'user enables and disables a specific runner' do visit project_runners_path(project) within '.available-specific-runners' do @@ -146,14 +146,14 @@ feature 'Runners' do end context 'when application settings have shared_runners_text' do - given(:shared_runners_text) { 'custom **shared** runners description' } - given(:shared_runners_html) { 'custom shared runners description' } + let(:shared_runners_text) { 'custom **shared** runners description' } + let(:shared_runners_html) { 'custom shared runners description' } - background do + before do stub_application_setting(shared_runners_text: shared_runners_text) end - scenario 'user sees shared runners description' do + it 'user sees shared runners description' do visit project_runners_path(project) expect(page.find('.shared-runners-description')).to have_content(shared_runners_html) @@ -162,13 +162,13 @@ feature 'Runners' do end context 'when a project has disabled shared_runners' do - given(:project) { create(:project, shared_runners_enabled: false) } + let(:project) { create(:project, shared_runners_enabled: false) } - background do - project.add_master(user) + before do + project.add_maintainer(user) end - scenario 'user enables shared runners' do + it 'user enables shared runners' do visit project_runners_path(project) click_on 'Enable shared Runners' @@ -178,21 +178,21 @@ feature 'Runners' do end context 'group runners in project settings' do - background do - project.add_master(user) + before do + project.add_maintainer(user) end - given(:group) { create :group } + let(:group) { create :group } context 'as project and group maintainer' do - background do - group.add_master(user) + before do + group.add_maintainer(user) end context 'project with a group but no group runner' do - given(:project) { create :project, group: group } + let(:project) { create :project, group: group } - scenario 'group runners are not available' do + it 'group runners are not available' do visit project_runners_path(project) expect(page).to have_content 'This group does not provide any group Runners yet' @@ -205,9 +205,9 @@ feature 'Runners' do context 'as project maintainer' do context 'project without a group' do - given(:project) { create :project } + let(:project) { create :project } - scenario 'group runners are not available' do + it 'group runners are not available' do visit project_runners_path(project) expect(page).to have_content 'This project does not belong to a group and can therefore not make use of group Runners.' @@ -215,10 +215,10 @@ feature 'Runners' do end context 'project with a group but no group runner' do - given(:group) { create(:group) } - given(:project) { create(:project, group: group) } + let(:group) { create(:group) } + let(:project) { create(:project, group: group) } - scenario 'group runners are not available' do + it 'group runners are not available' do visit project_runners_path(project) expect(page).to have_content 'This group does not provide any group Runners yet.' @@ -229,18 +229,18 @@ feature 'Runners' do end context 'project with a group and a group runner' do - given(:group) { create(:group) } - given(:project) { create(:project, group: group) } - given!(:ci_runner) { create(:ci_runner, :group, groups: [group], description: 'group-runner') } + let(:group) { create(:group) } + let(:project) { create(:project, group: group) } + let!(:ci_runner) { create(:ci_runner, :group, groups: [group], description: 'group-runner') } - scenario 'group runners are available' do + it 'group runners are available' do visit project_runners_path(project) expect(page).to have_content 'Available group Runners : 1' expect(page).to have_content 'group-runner' end - scenario 'group runners may be disabled for a project' do + it 'group runners may be disabled for a project' do visit project_runners_path(project) click_on 'Disable group Runners' @@ -258,13 +258,13 @@ feature 'Runners' do end context 'group runners in group settings' do - given(:group) { create(:group) } - background do - group.add_master(user) + let(:group) { create(:group) } + before do + group.add_maintainer(user) end context 'group with no runners' do - scenario 'there are no runners displayed' do + it 'there are no runners displayed' do visit group_settings_ci_cd_path(group) expect(page).to have_content 'This group does not provide any group Runners yet' @@ -274,7 +274,7 @@ feature 'Runners' do context 'group with a runner' do let!(:runner) { create(:ci_runner, :group, groups: [group], description: 'group-runner') } - scenario 'the runner is visible' do + it 'the runner is visible' do visit group_settings_ci_cd_path(group) expect(page).not_to have_content 'This group does not provide any group Runners yet' @@ -282,7 +282,7 @@ feature 'Runners' do expect(page).to have_content 'group-runner' end - scenario 'user can pause and resume the group runner' do + it 'user can pause and resume the group runner' do visit group_settings_ci_cd_path(group) expect(page).to have_content('Pause') @@ -299,7 +299,7 @@ feature 'Runners' do expect(page).not_to have_content('Resume') end - scenario 'user can view runner details' do + it 'user can view runner details' do visit group_settings_ci_cd_path(group) expect(page).to have_content(runner.display_name) @@ -309,7 +309,7 @@ feature 'Runners' do expect(page).to have_content(runner.platform) end - scenario 'user can remove a group runner' do + it 'user can remove a group runner' do visit group_settings_ci_cd_path(group) click_on 'Remove Runner' @@ -317,7 +317,7 @@ feature 'Runners' do expect(page).not_to have_content(runner.display_name) end - scenario 'user edits the runner to be protected' do + it 'user edits the runner to be protected' do visit group_settings_ci_cd_path(group) first('.edit-runner > a').click @@ -331,11 +331,11 @@ feature 'Runners' do end context 'when a runner has a tag' do - background do + before do runner.update(tag_list: ['tag']) end - scenario 'user edits runner not to run untagged jobs' do + it 'user edits runner not to run untagged jobs' do visit group_settings_ci_cd_path(group) first('.edit-runner > a').click diff --git a/spec/features/search/user_searches_for_code_spec.rb b/spec/features/search/user_searches_for_code_spec.rb index 9e089c5a6cb..ecec2f3e043 100644 --- a/spec/features/search/user_searches_for_code_spec.rb +++ b/spec/features/search/user_searches_for_code_spec.rb @@ -6,7 +6,7 @@ describe 'User searches for code' do context 'when signed in' do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/search/user_searches_for_issues_spec.rb b/spec/features/search/user_searches_for_issues_spec.rb index d6120ff8517..4bff269f89e 100644 --- a/spec/features/search/user_searches_for_issues_spec.rb +++ b/spec/features/search/user_searches_for_issues_spec.rb @@ -8,7 +8,7 @@ describe 'User searches for issues', :js do context 'when signed in' do before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(search_path) diff --git a/spec/features/search/user_searches_for_merge_requests_spec.rb b/spec/features/search/user_searches_for_merge_requests_spec.rb index 68e2f7a857d..75d44e413cb 100644 --- a/spec/features/search/user_searches_for_merge_requests_spec.rb +++ b/spec/features/search/user_searches_for_merge_requests_spec.rb @@ -7,7 +7,7 @@ describe 'User searches for merge requests', :js do let!(:merge_request2) { create(:merge_request, :simple, title: 'Bar', source_project: project, target_project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(search_path) diff --git a/spec/features/search/user_searches_for_milestones_spec.rb b/spec/features/search/user_searches_for_milestones_spec.rb index fc6cd81eb68..7d52c4c8bcc 100644 --- a/spec/features/search/user_searches_for_milestones_spec.rb +++ b/spec/features/search/user_searches_for_milestones_spec.rb @@ -7,7 +7,7 @@ describe 'User searches for milestones', :js do let!(:milestone2) { create(:milestone, title: 'Bar', project: project) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(search_path) diff --git a/spec/features/search/user_searches_for_wiki_pages_spec.rb b/spec/features/search/user_searches_for_wiki_pages_spec.rb index 5098fb49ee1..3ee753b7d23 100644 --- a/spec/features/search/user_searches_for_wiki_pages_spec.rb +++ b/spec/features/search/user_searches_for_wiki_pages_spec.rb @@ -6,7 +6,7 @@ describe 'User searches for wiki pages', :js do let!(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: { title: 'test_wiki', content: 'Some Wiki content' }) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit(search_path) diff --git a/spec/features/security/group/internal_access_spec.rb b/spec/features/security/group/internal_access_spec.rb index 5067f0b0a49..51b32ba6c03 100644 --- a/spec/features/security/group/internal_access_spec.rb +++ b/spec/features/security/group/internal_access_spec.rb @@ -23,7 +23,7 @@ describe 'Internal Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_allowed_for(:master).of(group) } + it { is_expected.to be_allowed_for(:maintainer).of(group) } it { is_expected.to be_allowed_for(:developer).of(group) } it { is_expected.to be_allowed_for(:reporter).of(group) } it { is_expected.to be_allowed_for(:guest).of(group) } @@ -38,7 +38,7 @@ describe 'Internal Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_allowed_for(:master).of(group) } + it { is_expected.to be_allowed_for(:maintainer).of(group) } it { is_expected.to be_allowed_for(:developer).of(group) } it { is_expected.to be_allowed_for(:reporter).of(group) } it { is_expected.to be_allowed_for(:guest).of(group) } @@ -54,7 +54,7 @@ describe 'Internal Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_allowed_for(:master).of(group) } + it { is_expected.to be_allowed_for(:maintainer).of(group) } it { is_expected.to be_allowed_for(:developer).of(group) } it { is_expected.to be_allowed_for(:reporter).of(group) } it { is_expected.to be_allowed_for(:guest).of(group) } @@ -69,7 +69,7 @@ describe 'Internal Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_allowed_for(:master).of(group) } + it { is_expected.to be_allowed_for(:maintainer).of(group) } it { is_expected.to be_allowed_for(:developer).of(group) } it { is_expected.to be_allowed_for(:reporter).of(group) } it { is_expected.to be_allowed_for(:guest).of(group) } @@ -84,7 +84,7 @@ describe 'Internal Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_denied_for(:master).of(group) } + it { is_expected.to be_denied_for(:maintainer).of(group) } it { is_expected.to be_denied_for(:developer).of(group) } it { is_expected.to be_denied_for(:reporter).of(group) } it { is_expected.to be_denied_for(:guest).of(group) } diff --git a/spec/features/security/group/private_access_spec.rb b/spec/features/security/group/private_access_spec.rb index ff32413dc7e..4705cd12d23 100644 --- a/spec/features/security/group/private_access_spec.rb +++ b/spec/features/security/group/private_access_spec.rb @@ -23,7 +23,7 @@ describe 'Private Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_allowed_for(:master).of(group) } + it { is_expected.to be_allowed_for(:maintainer).of(group) } it { is_expected.to be_allowed_for(:developer).of(group) } it { is_expected.to be_allowed_for(:reporter).of(group) } it { is_expected.to be_allowed_for(:guest).of(group) } @@ -38,7 +38,7 @@ describe 'Private Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_allowed_for(:master).of(group) } + it { is_expected.to be_allowed_for(:maintainer).of(group) } it { is_expected.to be_allowed_for(:developer).of(group) } it { is_expected.to be_allowed_for(:reporter).of(group) } it { is_expected.to be_allowed_for(:guest).of(group) } @@ -54,7 +54,7 @@ describe 'Private Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_allowed_for(:master).of(group) } + it { is_expected.to be_allowed_for(:maintainer).of(group) } it { is_expected.to be_allowed_for(:developer).of(group) } it { is_expected.to be_allowed_for(:reporter).of(group) } it { is_expected.to be_allowed_for(:guest).of(group) } @@ -69,7 +69,7 @@ describe 'Private Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_allowed_for(:master).of(group) } + it { is_expected.to be_allowed_for(:maintainer).of(group) } it { is_expected.to be_allowed_for(:developer).of(group) } it { is_expected.to be_allowed_for(:reporter).of(group) } it { is_expected.to be_allowed_for(:guest).of(group) } @@ -84,7 +84,7 @@ describe 'Private Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_denied_for(:master).of(group) } + it { is_expected.to be_denied_for(:maintainer).of(group) } it { is_expected.to be_denied_for(:developer).of(group) } it { is_expected.to be_denied_for(:reporter).of(group) } it { is_expected.to be_denied_for(:guest).of(group) } diff --git a/spec/features/security/group/public_access_spec.rb b/spec/features/security/group/public_access_spec.rb index 16d114fb3f7..3a53c3c2bc7 100644 --- a/spec/features/security/group/public_access_spec.rb +++ b/spec/features/security/group/public_access_spec.rb @@ -23,7 +23,7 @@ describe 'Public Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_allowed_for(:master).of(group) } + it { is_expected.to be_allowed_for(:maintainer).of(group) } it { is_expected.to be_allowed_for(:developer).of(group) } it { is_expected.to be_allowed_for(:reporter).of(group) } it { is_expected.to be_allowed_for(:guest).of(group) } @@ -38,7 +38,7 @@ describe 'Public Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_allowed_for(:master).of(group) } + it { is_expected.to be_allowed_for(:maintainer).of(group) } it { is_expected.to be_allowed_for(:developer).of(group) } it { is_expected.to be_allowed_for(:reporter).of(group) } it { is_expected.to be_allowed_for(:guest).of(group) } @@ -54,7 +54,7 @@ describe 'Public Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_allowed_for(:master).of(group) } + it { is_expected.to be_allowed_for(:maintainer).of(group) } it { is_expected.to be_allowed_for(:developer).of(group) } it { is_expected.to be_allowed_for(:reporter).of(group) } it { is_expected.to be_allowed_for(:guest).of(group) } @@ -69,7 +69,7 @@ describe 'Public Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_allowed_for(:master).of(group) } + it { is_expected.to be_allowed_for(:maintainer).of(group) } it { is_expected.to be_allowed_for(:developer).of(group) } it { is_expected.to be_allowed_for(:reporter).of(group) } it { is_expected.to be_allowed_for(:guest).of(group) } @@ -84,7 +84,7 @@ describe 'Public Group access' do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(group) } - it { is_expected.to be_denied_for(:master).of(group) } + it { is_expected.to be_denied_for(:maintainer).of(group) } it { is_expected.to be_denied_for(:developer).of(group) } it { is_expected.to be_denied_for(:reporter).of(group) } it { is_expected.to be_denied_for(:guest).of(group) } diff --git a/spec/features/security/project/internal_access_spec.rb b/spec/features/security/project/internal_access_spec.rb index a7928857b7d..001e6c10eb2 100644 --- a/spec/features/security/project/internal_access_spec.rb +++ b/spec/features/security/project/internal_access_spec.rb @@ -17,7 +17,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -31,7 +31,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -45,7 +45,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -59,7 +59,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -73,7 +73,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -87,7 +87,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -101,7 +101,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -115,7 +115,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -130,7 +130,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -144,7 +144,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -158,7 +158,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -172,7 +172,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -187,7 +187,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -201,7 +201,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -215,7 +215,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -229,7 +229,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -243,7 +243,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -262,7 +262,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -281,7 +281,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -295,7 +295,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -309,7 +309,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -324,7 +324,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -343,7 +343,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -359,7 +359,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -381,7 +381,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -397,7 +397,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -419,7 +419,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -435,7 +435,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -450,7 +450,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -464,7 +464,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -479,7 +479,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -494,7 +494,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -508,7 +508,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -530,7 +530,7 @@ describe "Internal Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } diff --git a/spec/features/security/project/private_access_spec.rb b/spec/features/security/project/private_access_spec.rb index a4396b20afd..c6618355eea 100644 --- a/spec/features/security/project/private_access_spec.rb +++ b/spec/features/security/project/private_access_spec.rb @@ -17,7 +17,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -31,7 +31,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -45,7 +45,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -59,7 +59,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -73,7 +73,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -87,7 +87,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -101,7 +101,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -115,7 +115,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -130,7 +130,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -144,7 +144,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -158,7 +158,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -172,7 +172,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -187,7 +187,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -201,7 +201,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -215,7 +215,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -234,7 +234,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -253,7 +253,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -267,7 +267,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -281,7 +281,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -308,7 +308,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -334,7 +334,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -362,7 +362,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -395,7 +395,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -425,7 +425,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -440,7 +440,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -455,7 +455,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -469,7 +469,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -483,7 +483,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -497,7 +497,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -511,7 +511,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -533,7 +533,7 @@ describe "Private Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } diff --git a/spec/features/security/project/public_access_spec.rb b/spec/features/security/project/public_access_spec.rb index fccdeb0e5b7..3717dc13f1e 100644 --- a/spec/features/security/project/public_access_spec.rb +++ b/spec/features/security/project/public_access_spec.rb @@ -17,7 +17,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -31,7 +31,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -45,7 +45,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -59,7 +59,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -73,7 +73,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -87,7 +87,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -101,7 +101,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -115,7 +115,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -129,7 +129,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -144,7 +144,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -163,7 +163,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -179,7 +179,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -201,7 +201,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -217,7 +217,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -239,7 +239,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -255,7 +255,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -270,7 +270,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -284,7 +284,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -299,7 +299,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -314,7 +314,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -328,7 +328,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -344,7 +344,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -357,7 +357,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -371,7 +371,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -385,7 +385,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -400,7 +400,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -414,7 +414,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -428,7 +428,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -442,7 +442,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -456,7 +456,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -475,7 +475,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -494,7 +494,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -508,7 +508,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_denied_for(:developer).of(project) } it { is_expected.to be_denied_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -530,7 +530,7 @@ describe "Public Project Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } diff --git a/spec/features/security/project/snippet/internal_access_spec.rb b/spec/features/security/project/snippet/internal_access_spec.rb index d7dc99c0a57..b87eb86b88b 100644 --- a/spec/features/security/project/snippet/internal_access_spec.rb +++ b/spec/features/security/project/snippet/internal_access_spec.rb @@ -13,7 +13,7 @@ describe "Internal Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -27,7 +27,7 @@ describe "Internal Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -42,7 +42,7 @@ describe "Internal Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -56,7 +56,7 @@ describe "Internal Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -72,7 +72,7 @@ describe "Internal Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -86,7 +86,7 @@ describe "Internal Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } diff --git a/spec/features/security/project/snippet/private_access_spec.rb b/spec/features/security/project/snippet/private_access_spec.rb index 3ec1a388185..ead91d9a5fa 100644 --- a/spec/features/security/project/snippet/private_access_spec.rb +++ b/spec/features/security/project/snippet/private_access_spec.rb @@ -12,7 +12,7 @@ describe "Private Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -26,7 +26,7 @@ describe "Private Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -40,7 +40,7 @@ describe "Private Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -54,7 +54,7 @@ describe "Private Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } diff --git a/spec/features/security/project/snippet/public_access_spec.rb b/spec/features/security/project/snippet/public_access_spec.rb index 39b104bfe27..9bab3a474b8 100644 --- a/spec/features/security/project/snippet/public_access_spec.rb +++ b/spec/features/security/project/snippet/public_access_spec.rb @@ -14,7 +14,7 @@ describe "Public Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -28,7 +28,7 @@ describe "Public Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_denied_for(:guest).of(project) } @@ -43,7 +43,7 @@ describe "Public Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -57,7 +57,7 @@ describe "Public Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -71,7 +71,7 @@ describe "Public Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -87,7 +87,7 @@ describe "Public Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -101,7 +101,7 @@ describe "Public Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } @@ -115,7 +115,7 @@ describe "Public Project Snippets Access" do it { is_expected.to be_allowed_for(:admin) } it { is_expected.to be_allowed_for(:owner).of(project) } - it { is_expected.to be_allowed_for(:master).of(project) } + it { is_expected.to be_allowed_for(:maintainer).of(project) } it { is_expected.to be_allowed_for(:developer).of(project) } it { is_expected.to be_allowed_for(:reporter).of(project) } it { is_expected.to be_allowed_for(:guest).of(project) } diff --git a/spec/features/signed_commits_spec.rb b/spec/features/signed_commits_spec.rb index db141ef7096..3d05474dca2 100644 --- a/spec/features/signed_commits_spec.rb +++ b/spec/features/signed_commits_spec.rb @@ -5,7 +5,7 @@ describe 'GPG signed commits', :js do it 'changes from unverified to verified when the user changes his email to match the gpg key' do user = create :user, email: 'unrelated.user@example.org' - project.add_master(user) + project.add_maintainer(user) Sidekiq::Testing.inline! do create :gpg_key, key: GpgHelpers::User1.public_key, user: user @@ -23,7 +23,7 @@ describe 'GPG signed commits', :js do # user changes his email which makes the gpg key verified Sidekiq::Testing.inline! do user.skip_reconfirmation! - user.update_attributes!(email: GpgHelpers::User1.emails.first) + user.update!(email: GpgHelpers::User1.emails.first) end visit project_commits_path(project, :'signed-commits') @@ -36,7 +36,7 @@ describe 'GPG signed commits', :js do it 'changes from unverified to verified when the user adds the missing gpg key' do user = create :user, email: GpgHelpers::User1.emails.first - project.add_master(user) + project.add_maintainer(user) sign_in(user) @@ -86,7 +86,7 @@ describe 'GPG signed commits', :js do before do user = create :user - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/features/snippets/explore_spec.rb b/spec/features/snippets/explore_spec.rb index 835fd90adc8..c08f25875f8 100644 --- a/spec/features/snippets/explore_spec.rb +++ b/spec/features/snippets/explore_spec.rb @@ -1,11 +1,11 @@ require 'rails_helper' -feature 'Explore Snippets' do +describe 'Explore Snippets' do let!(:public_snippet) { create(:personal_snippet, :public) } let!(:internal_snippet) { create(:personal_snippet, :internal) } let!(:private_snippet) { create(:personal_snippet, :private) } - scenario 'User should see snippets that are not private' do + it 'User should see snippets that are not private' do sign_in create(:user) visit explore_snippets_path @@ -14,7 +14,7 @@ feature 'Explore Snippets' do expect(page).not_to have_content(private_snippet.title) end - scenario 'External user should see only public snippets' do + it 'External user should see only public snippets' do sign_in create(:user, :external) visit explore_snippets_path @@ -23,7 +23,7 @@ feature 'Explore Snippets' do expect(page).not_to have_content(private_snippet.title) end - scenario 'Not authenticated user should see only public snippets' do + it 'Not authenticated user should see only public snippets' do visit explore_snippets_path expect(page).to have_content(public_snippet.title) diff --git a/spec/features/snippets/internal_snippet_spec.rb b/spec/features/snippets/internal_snippet_spec.rb index 3a2768c424f..f6215b481dc 100644 --- a/spec/features/snippets/internal_snippet_spec.rb +++ b/spec/features/snippets/internal_snippet_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'Internal Snippets', :js do +describe 'Internal Snippets', :js do let(:internal_snippet) { create(:personal_snippet, :internal) } describe 'normal user' do @@ -8,13 +8,13 @@ feature 'Internal Snippets', :js do sign_in(create(:user)) end - scenario 'sees internal snippets' do + it 'sees internal snippets' do visit snippet_path(internal_snippet) expect(page).to have_content(internal_snippet.content) end - scenario 'sees raw internal snippets' do + it 'sees raw internal snippets' do visit raw_snippet_path(internal_snippet) expect(page).to have_content(internal_snippet.content) diff --git a/spec/features/snippets/public_snippets_spec.rb b/spec/features/snippets/public_snippets_spec.rb index bdeeca7187e..71c72b98fad 100644 --- a/spec/features/snippets/public_snippets_spec.rb +++ b/spec/features/snippets/public_snippets_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' -feature 'Public Snippets', :js do - scenario 'Unauthenticated user should see public snippets' do +describe 'Public Snippets', :js do + it 'Unauthenticated user should see public snippets' do public_snippet = create(:personal_snippet, :public) visit snippet_path(public_snippet) @@ -10,7 +10,7 @@ feature 'Public Snippets', :js do expect(page).to have_content(public_snippet.content) end - scenario 'Unauthenticated user should see raw public snippets' do + it 'Unauthenticated user should see raw public snippets' do public_snippet = create(:personal_snippet, :public) visit raw_snippet_path(public_snippet) diff --git a/spec/features/snippets/search_snippets_spec.rb b/spec/features/snippets/search_snippets_spec.rb index cd66a2cb20c..c137b0bcd96 100644 --- a/spec/features/snippets/search_snippets_spec.rb +++ b/spec/features/snippets/search_snippets_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' -feature 'Search Snippets' do - scenario 'User searches for snippets by title' do +describe 'Search Snippets' do + it 'User searches for snippets by title' do public_snippet = create(:personal_snippet, :public, title: 'Beginning and Middle') private_snippet = create(:personal_snippet, :private, title: 'Middle and End') @@ -19,7 +19,7 @@ feature 'Search Snippets' do expect(page).to have_link(private_snippet.title) end - scenario 'User searches for snippet contents' do + it 'User searches for snippet contents' do create(:personal_snippet, :public, title: 'Many lined snippet', diff --git a/spec/features/snippets/show_spec.rb b/spec/features/snippets/show_spec.rb index 5a48f5774ca..f31457db92f 100644 --- a/spec/features/snippets/show_spec.rb +++ b/spec/features/snippets/show_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Snippet', :js do +describe 'Snippet', :js do let(:project) { create(:project, :repository) } let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content) } @@ -68,6 +68,26 @@ feature 'Snippet', :js do end end + context 'with cached Redcarpet html' do + let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content, cached_markdown_version: CacheMarkdownField::CACHE_REDCARPET_VERSION) } + let(:file_name) { 'test.md' } + let(:content) { "1. one\n - sublist\n" } + + it 'renders correctly' do + expect(page).to have_xpath("//ol//li//ul") + end + end + + context 'with cached CommonMark html' do + let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content, cached_markdown_version: CacheMarkdownField::CACHE_COMMONMARK_VERSION) } + let(:file_name) { 'test.md' } + let(:content) { "1. one\n - sublist\n" } + + it 'renders correctly' do + expect(page).not_to have_xpath("//ol//li//ul") + end + end + context 'switching to the simple viewer' do before do find('.js-blob-viewer-switch-btn[data-viewer=simple]').click diff --git a/spec/features/snippets/user_creates_snippet_spec.rb b/spec/features/snippets/user_creates_snippet_spec.rb index 941765b7578..879c46d7c4e 100644 --- a/spec/features/snippets/user_creates_snippet_spec.rb +++ b/spec/features/snippets/user_creates_snippet_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'User creates snippet', :js do +describe 'User creates snippet', :js do include DropzoneHelper let(:user) { create(:user) } @@ -18,7 +18,7 @@ feature 'User creates snippet', :js do end end - scenario 'Authenticated user creates a snippet' do + it 'Authenticated user creates a snippet' do fill_form click_button('Create snippet') @@ -32,7 +32,7 @@ feature 'User creates snippet', :js do expect(page).to have_content('Hello World!') end - scenario 'previews a snippet with file' do + it 'previews a snippet with file' do fill_in 'personal_snippet_description', with: 'My Snippet' dropzone_file Rails.root.join('spec', 'fixtures', 'banana_sample.gif') find('.js-md-preview-button').click @@ -48,7 +48,7 @@ feature 'User creates snippet', :js do end end - scenario 'uploads a file when dragging into textarea' do + it 'uploads a file when dragging into textarea' do fill_form dropzone_file Rails.root.join('spec', 'fixtures', 'banana_sample.gif') @@ -65,7 +65,7 @@ feature 'User creates snippet', :js do expect(reqs.first.status_code).to eq(200) end - scenario 'validation fails for the first time' do + it 'validation fails for the first time' do fill_in 'personal_snippet_title', with: 'My Snippet Title' click_button('Create snippet') @@ -90,7 +90,7 @@ feature 'User creates snippet', :js do expect(reqs.first.status_code).to eq(200) end - scenario 'Authenticated user creates a snippet with + in filename' do + it 'Authenticated user creates a snippet with + in filename' do fill_in 'personal_snippet_title', with: 'My Snippet Title' page.within('.file-editor') do find(:xpath, "//input[@id='personal_snippet_file_name']").set 'snippet+file+name' diff --git a/spec/features/snippets/user_deletes_snippet_spec.rb b/spec/features/snippets/user_deletes_snippet_spec.rb index ae5b883c477..7bdccacb0fa 100644 --- a/spec/features/snippets/user_deletes_snippet_spec.rb +++ b/spec/features/snippets/user_deletes_snippet_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'User deletes snippet' do +describe 'User deletes snippet' do let(:user) { create(:user) } let(:content) { 'puts "test"' } let(:snippet) { create(:personal_snippet, :public, content: content, author: user) } diff --git a/spec/features/snippets/user_edits_snippet_spec.rb b/spec/features/snippets/user_edits_snippet_spec.rb index 71de6b6bd1c..77f62990158 100644 --- a/spec/features/snippets/user_edits_snippet_spec.rb +++ b/spec/features/snippets/user_edits_snippet_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'User edits snippet', :js do +describe 'User edits snippet', :js do include DropzoneHelper let(:file_name) { 'test.rb' } diff --git a/spec/features/snippets/user_snippets_spec.rb b/spec/features/snippets/user_snippets_spec.rb index 7bc27486787..e3065a899cc 100644 --- a/spec/features/snippets/user_snippets_spec.rb +++ b/spec/features/snippets/user_snippets_spec.rb @@ -1,23 +1,23 @@ require 'rails_helper' -feature 'User Snippets' do +describe 'User Snippets' do let(:author) { create(:user) } let!(:public_snippet) { create(:personal_snippet, :public, author: author, title: "This is a public snippet") } let!(:internal_snippet) { create(:personal_snippet, :internal, author: author, title: "This is an internal snippet") } let!(:private_snippet) { create(:personal_snippet, :private, author: author, title: "This is a private snippet") } - background do + before do sign_in author visit dashboard_snippets_path end - scenario 'View all of my snippets' do + it 'View all of my snippets' do expect(page).to have_content(public_snippet.title) expect(page).to have_content(internal_snippet.title) expect(page).to have_content(private_snippet.title) end - scenario 'View my public snippets' do + it 'View my public snippets' do page.within('.snippet-scope-menu') do click_link "Public" end @@ -27,7 +27,7 @@ feature 'User Snippets' do expect(page).not_to have_content(private_snippet.title) end - scenario 'View my internal snippets' do + it 'View my internal snippets' do page.within('.snippet-scope-menu') do click_link "Internal" end @@ -37,7 +37,7 @@ feature 'User Snippets' do expect(page).not_to have_content(private_snippet.title) end - scenario 'View my private snippets' do + it 'View my private snippets' do page.within('.snippet-scope-menu') do click_link "Private" end diff --git a/spec/features/tags/master_creates_tag_spec.rb b/spec/features/tags/master_creates_tag_spec.rb index 6701f575a23..db2970f3340 100644 --- a/spec/features/tags/master_creates_tag_spec.rb +++ b/spec/features/tags/master_creates_tag_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -feature 'Master creates tag' do +describe 'Maintainer creates tag' do let(:user) { create(:user) } let(:project) { create(:project, :repository, namespace: user.namespace) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -14,25 +14,25 @@ feature 'Master creates tag' do visit project_tags_path(project) end - scenario 'with an invalid name displays an error' do + it 'with an invalid name displays an error' do create_tag_in_form(tag: 'v 1.0', ref: 'master') expect(page).to have_content 'Tag name invalid' end - scenario 'with an invalid reference displays an error' do + it 'with an invalid reference displays an error' do create_tag_in_form(tag: 'v2.0', ref: 'foo') expect(page).to have_content 'Target foo is invalid' end - scenario 'that already exists displays an error' do + it 'that already exists displays an error' do create_tag_in_form(tag: 'v1.1.0', ref: 'master') expect(page).to have_content 'Tag v1.1.0 already exists' end - scenario 'with multiline message displays the message in a <pre> block' do + it 'with multiline message displays the message in a <pre> block' do create_tag_in_form(tag: 'v3.0', ref: 'master', message: "Awesome tag message\n\n- hello\n- world") expect(current_path).to eq( @@ -43,7 +43,7 @@ feature 'Master creates tag' do end end - scenario 'with multiline release notes parses the release note as Markdown' do + it 'with multiline release notes parses the release note as Markdown' do create_tag_in_form(tag: 'v4.0', ref: 'master', desc: "Awesome release notes\n\n- hello\n- world") expect(current_path).to eq( @@ -55,7 +55,7 @@ feature 'Master creates tag' do end end - scenario 'opens dropdown for ref', :js do + it 'opens dropdown for ref', :js do click_link 'New tag' ref_row = find('.form-group:nth-of-type(2) .col-sm-10') page.within ref_row do diff --git a/spec/features/tags/master_deletes_tag_spec.rb b/spec/features/tags/master_deletes_tag_spec.rb index 9981bfa4609..8d567e925ef 100644 --- a/spec/features/tags/master_deletes_tag_spec.rb +++ b/spec/features/tags/master_deletes_tag_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' -feature 'Master deletes tag' do +describe 'Maintainer deletes tag' do let(:user) { create(:user) } let(:project) { create(:project, :repository, namespace: user.namespace) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_tags_path(project) end context 'from the tags list page', :js do - scenario 'deletes the tag' do + it 'deletes the tag' do expect(page).to have_content 'v1.1.0' delete_first_tag @@ -21,7 +21,7 @@ feature 'Master deletes tag' do end context 'from a specific tag page' do - scenario 'deletes the tag' do + it 'deletes the tag' do click_on 'v1.0.0' expect(current_path).to eq( project_tag_path(project, 'v1.0.0')) @@ -35,30 +35,15 @@ feature 'Master deletes tag' do end context 'when pre-receive hook fails', :js do - context 'when Gitaly operation_user_delete_tag feature is enabled' do - before do - allow_any_instance_of(Gitlab::GitalyClient::OperationService).to receive(:rm_tag) - .and_raise(Gitlab::Git::PreReceiveError, 'Do not delete tags') - end - - scenario 'shows the error message' do - delete_first_tag - - expect(page).to have_content('Do not delete tags') - end + before do + allow_any_instance_of(Gitlab::GitalyClient::OperationService).to receive(:rm_tag) + .and_raise(Gitlab::Git::PreReceiveError, 'Do not delete tags') end - context 'when Gitaly operation_user_delete_tag feature is disabled', :skip_gitaly_mock do - before do - allow_any_instance_of(Gitlab::Git::HooksService).to receive(:execute) - .and_raise(Gitlab::Git::PreReceiveError, 'Do not delete tags') - end - - scenario 'shows the error message' do - delete_first_tag + it 'shows the error message' do + delete_first_tag - expect(page).to have_content('Do not delete tags') - end + expect(page).to have_content('Do not delete tags') end end diff --git a/spec/features/tags/master_updates_tag_spec.rb b/spec/features/tags/master_updates_tag_spec.rb index 26f51bee887..d8b5b3c4cc4 100644 --- a/spec/features/tags/master_updates_tag_spec.rb +++ b/spec/features/tags/master_updates_tag_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' -feature 'Master updates tag' do +describe 'Maintainer updates tag' do let(:user) { create(:user) } let(:project) { create(:project, :repository, namespace: user.namespace) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) visit project_tags_path(project) end context 'from the tags list page' do - scenario 'updates the release notes' do + it 'updates the release notes' do page.within(first('.content-list .controls')) do click_link 'Edit release notes' end @@ -25,7 +25,7 @@ feature 'Master updates tag' do expect(page).to have_content 'Awesome release notes' end - scenario 'description has emoji autocomplete', :js do + it 'description has emoji autocomplete', :js do page.within(first('.content-list .controls')) do click_link 'Edit release notes' end @@ -38,7 +38,7 @@ feature 'Master updates tag' do end context 'from a specific tag page' do - scenario 'updates the release notes' do + it 'updates the release notes' do click_on 'v1.1.0' click_link 'Edit release notes' fill_in 'release_description', with: 'Awesome release notes' diff --git a/spec/features/tags/master_views_tags_spec.rb b/spec/features/tags/master_views_tags_spec.rb index b625e7065cc..3f4fe549f3e 100644 --- a/spec/features/tags/master_views_tags_spec.rb +++ b/spec/features/tags/master_views_tags_spec.rb @@ -1,10 +1,10 @@ require 'spec_helper' -feature 'Master views tags' do +describe 'Maintainer views tags' do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end @@ -19,7 +19,7 @@ feature 'Master views tags' do visit project_tags_path(project) end - scenario 'displays a specific message' do + it 'displays a specific message' do expect(page).to have_content 'Repository has no tags yet.' end end @@ -32,7 +32,7 @@ feature 'Master views tags' do visit project_tags_path(project) end - scenario 'avoids a N+1 query in branches index' do + it 'avoids a N+1 query in branches index' do control_count = ActiveRecord::QueryRecorder.new { visit project_tags_path(project) }.count %w(one two three four five).each { |tag| repository.add_tag(user, tag, 'master', 'foo') } @@ -40,11 +40,11 @@ feature 'Master views tags' do expect { visit project_tags_path(project) }.not_to exceed_query_limit(control_count) end - scenario 'views the tags list page' do + it 'views the tags list page' do expect(page).to have_content 'v1.0.0' end - scenario 'views a specific tag page' do + it 'views a specific tag page' do click_on 'v1.0.0' expect(current_path).to eq( @@ -54,7 +54,7 @@ feature 'Master views tags' do end describe 'links on the tag page' do - scenario 'has a button to browse files' do + it 'has a button to browse files' do click_on 'v1.0.0' expect(current_path).to eq( @@ -66,7 +66,7 @@ feature 'Master views tags' do project_tree_path(project, 'v1.0.0')) end - scenario 'has a button to browse commits' do + it 'has a button to browse commits' do click_on 'v1.0.0' expect(current_path).to eq( diff --git a/spec/features/task_lists_spec.rb b/spec/features/task_lists_spec.rb index f37d8998045..9c9127980a1 100644 --- a/spec/features/task_lists_spec.rb +++ b/spec/features/task_lists_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Task Lists' do +describe 'Task Lists' do include Warden::Test::Helpers let(:project) { create(:project, :repository) } @@ -65,7 +65,7 @@ feature 'Task Lists' do before do Warden.test_mode! - project.add_master(user) + project.add_maintainer(user) project.add_guest(user2) login_as(user) diff --git a/spec/features/triggers_spec.rb b/spec/features/triggers_spec.rb index 6be2606fd0d..919859c145a 100644 --- a/spec/features/triggers_spec.rb +++ b/spec/features/triggers_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Triggers', :js do +describe 'Triggers', :js do let(:trigger_title) { 'trigger desc' } let(:user) { create(:user) } let(:user2) { create(:user) } @@ -10,15 +10,15 @@ feature 'Triggers', :js do sign_in(user) @project = create(:project) - @project.add_master(user) - @project.add_master(user2) + @project.add_maintainer(user) + @project.add_maintainer(user2) @project.add_guest(guest_user) visit project_settings_ci_cd_path(@project) end describe 'create trigger workflow' do - scenario 'prevents adding new trigger with no description' do + it 'prevents adding new trigger with no description' do fill_in 'trigger_description', with: '' click_button 'Add trigger' @@ -26,7 +26,7 @@ feature 'Triggers', :js do expect(page.find('form.gl-show-field-errors .gl-field-error')).to be_visible end - scenario 'adds new trigger with description' do + it 'adds new trigger with description' do fill_in 'trigger_description', with: 'trigger desc' click_button 'Add trigger' @@ -40,7 +40,7 @@ feature 'Triggers', :js do describe 'edit trigger workflow' do let(:new_trigger_title) { 'new trigger' } - scenario 'click on edit trigger opens edit trigger page' do + it 'click on edit trigger opens edit trigger page' do create(:ci_trigger, owner: user, project: @project, description: trigger_title) visit project_settings_ci_cd_path(@project) @@ -49,7 +49,7 @@ feature 'Triggers', :js do expect(page.find('#trigger_description').value).to have_content 'trigger desc' end - scenario 'edit trigger and save' do + it 'edit trigger and save' do create(:ci_trigger, owner: user, project: @project, description: trigger_title) visit project_settings_ci_cd_path(@project) @@ -64,7 +64,7 @@ feature 'Triggers', :js do expect(page.find('.triggers-list .trigger-owner')).to have_content user.name end - scenario 'edit "legacy" trigger and save' do + it 'edit "legacy" trigger and save' do # Create new trigger without owner association, i.e. Legacy trigger create(:ci_trigger, owner: nil, project: @project) visit project_settings_ci_cd_path(@project) @@ -87,12 +87,12 @@ feature 'Triggers', :js do visit project_settings_ci_cd_path(@project) end - scenario 'button "Take ownership" has correct alert' do + it 'button "Take ownership" has correct alert' do expected_alert = 'By taking ownership you will bind this trigger to your user account. With this the trigger will have access to all your projects as if it was you. Are you sure?' expect(page.find('a.btn-trigger-take-ownership')['data-confirm']).to eq expected_alert end - scenario 'take trigger ownership' do + it 'take trigger ownership' do # See if "Take ownership" on trigger works post trigger creation page.accept_confirm do first(:link, "Take ownership").send_keys(:return) @@ -110,12 +110,12 @@ feature 'Triggers', :js do visit project_settings_ci_cd_path(@project) end - scenario 'button "Revoke" has correct alert' do + it 'button "Revoke" has correct alert' do expected_alert = 'By revoking a trigger you will break any processes making use of it. Are you sure?' expect(page.find('a.btn-trigger-revoke')['data-confirm']).to eq expected_alert end - scenario 'revoke trigger' do + it 'revoke trigger' do # See if "Revoke" on trigger works post trigger creation page.accept_confirm do find('a.btn-trigger-revoke').send_keys(:return) @@ -127,11 +127,11 @@ feature 'Triggers', :js do end describe 'show triggers workflow' do - scenario 'contains trigger description placeholder' do + it 'contains trigger description placeholder' do expect(page.find('#trigger_description')['placeholder']).to eq 'Trigger description' end - scenario 'show "legacy" badge for legacy trigger' do + it 'show "legacy" badge for legacy trigger' do create(:ci_trigger, owner: nil, project: @project) visit project_settings_ci_cd_path(@project) @@ -140,7 +140,7 @@ feature 'Triggers', :js do expect(page.find('.triggers-list')).to have_selector('a[title="Edit"]') end - scenario 'show "invalid" badge for trigger with owner having insufficient permissions' do + it 'show "invalid" badge for trigger with owner having insufficient permissions' do create(:ci_trigger, owner: guest_user, project: @project, description: trigger_title) visit project_settings_ci_cd_path(@project) @@ -149,7 +149,7 @@ feature 'Triggers', :js do expect(page.find('.triggers-list')).not_to have_selector('a[title="Edit"]') end - scenario 'do not show "Edit" or full token for not owned trigger' do + it 'do not show "Edit" or full token for not owned trigger' do # Create trigger with user different from current_user create(:ci_trigger, owner: user2, project: @project, description: trigger_title) visit project_settings_ci_cd_path(@project) @@ -163,7 +163,7 @@ feature 'Triggers', :js do expect(page.find('.triggers-list')).not_to have_selector('a[title="Edit"]') end - scenario 'show "Edit" and full token for owned trigger' do + it 'show "Edit" and full token for owned trigger' do create(:ci_trigger, owner: user, project: @project, description: trigger_title) visit project_settings_ci_cd_path(@project) diff --git a/spec/features/u2f_spec.rb b/spec/features/u2f_spec.rb index fb65b570dd6..f245c1ebbd9 100644 --- a/spec/features/u2f_spec.rb +++ b/spec/features/u2f_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', :js do +describe 'Using U2F (Universal 2nd Factor) Devices for Authentication', :js do def manage_two_factor_authentication click_on 'Manage two-factor authentication' expect(page).to have_content("Setup new U2F device") diff --git a/spec/features/uploads/user_uploads_avatar_to_group_spec.rb b/spec/features/uploads/user_uploads_avatar_to_group_spec.rb index c8db82a562f..a07edc42eae 100644 --- a/spec/features/uploads/user_uploads_avatar_to_group_spec.rb +++ b/spec/features/uploads/user_uploads_avatar_to_group_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' -feature 'User uploads avatar to group' do - scenario 'they see the new avatar' do +describe 'User uploads avatar to group' do + it 'they see the new avatar' do user = create(:user) group = create(:group) group.add_owner(user) diff --git a/spec/features/uploads/user_uploads_avatar_to_profile_spec.rb b/spec/features/uploads/user_uploads_avatar_to_profile_spec.rb index 766bb4f09cd..4db73fccfb6 100644 --- a/spec/features/uploads/user_uploads_avatar_to_profile_spec.rb +++ b/spec/features/uploads/user_uploads_avatar_to_profile_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'User uploads avatar to profile' do +describe 'User uploads avatar to profile' do let!(:user) { create(:user) } let(:avatar_file_path) { Rails.root.join('spec', 'fixtures', 'dk.png') } @@ -9,7 +9,7 @@ feature 'User uploads avatar to profile' do visit profile_path end - scenario 'they see their new avatar on their profile' do + it 'they see their new avatar on their profile' do attach_file('user_avatar', avatar_file_path, visible: false) click_button 'Update profile settings' @@ -21,7 +21,7 @@ feature 'User uploads avatar to profile' do expect(user.reload.avatar.file).to exist end - scenario 'their new avatar is immediately visible in the header', :js do + it 'their new avatar is immediately visible in the header', :js do find('.js-user-avatar-input', visible: false).set(avatar_file_path) click_button 'Set new profile picture' diff --git a/spec/features/uploads/user_uploads_file_to_note_spec.rb b/spec/features/uploads/user_uploads_file_to_note_spec.rb index 972c10aaf23..24a00c86b0a 100644 --- a/spec/features/uploads/user_uploads_file_to_note_spec.rb +++ b/spec/features/uploads/user_uploads_file_to_note_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'User uploads file to note' do +describe 'User uploads file to note' do include DropzoneHelper let(:user) { create(:user) } @@ -71,7 +71,7 @@ feature 'User uploads file to note' do expect(page).not_to have_selector('.uploading-progress-container', visible: true) end - scenario 'they see the attached file', :js do + it 'they see the attached file', :js do dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')]) click_button 'Comment' wait_for_requests diff --git a/spec/features/users/active_sessions_spec.rb b/spec/features/users/active_sessions_spec.rb index 631d7e3bced..25349b5d036 100644 --- a/spec/features/users/active_sessions_spec.rb +++ b/spec/features/users/active_sessions_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -feature 'Active user sessions', :clean_gitlab_redis_shared_state do - scenario 'Successful login adds a new active user login' do +describe 'Active user sessions', :clean_gitlab_redis_shared_state do + it 'Successful login adds a new active user login' do now = Time.zone.parse('2018-03-12 09:06') Timecop.freeze(now) do user = create(:user) @@ -24,7 +24,7 @@ feature 'Active user sessions', :clean_gitlab_redis_shared_state do end end - scenario 'Successful login cleans up obsolete entries' do + it 'Successful login cleans up obsolete entries' do user = create(:user) Gitlab::Redis::SharedState.with do |redis| @@ -38,7 +38,7 @@ feature 'Active user sessions', :clean_gitlab_redis_shared_state do end end - scenario 'Sessionless login does not clean up obsolete entries' do + it 'Sessionless login does not clean up obsolete entries' do user = create(:user) personal_access_token = create(:personal_access_token, user: user) @@ -54,7 +54,7 @@ feature 'Active user sessions', :clean_gitlab_redis_shared_state do end end - scenario 'Logout deletes the active user login' do + it 'Logout deletes the active user login' do user = create(:user) gitlab_sign_in(user) expect(current_path).to eq root_path diff --git a/spec/features/users/login_spec.rb b/spec/features/users/login_spec.rb index 24a2c89f50b..21891b9ccda 100644 --- a/spec/features/users/login_spec.rb +++ b/spec/features/users/login_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -feature 'Login' do +describe 'Login' do include TermsHelper - scenario 'Successful user signin invalidates password reset token' do + it 'Successful user signin invalidates password reset token' do user = create(:user) expect(user.reset_password_token).to be_nil diff --git a/spec/features/users/rss_spec.rb b/spec/features/users/rss_spec.rb index c3734b5c808..9af4447056e 100644 --- a/spec/features/users/rss_spec.rb +++ b/spec/features/users/rss_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'User RSS' do +describe 'User RSS' do let(:user) { create(:user) } let(:path) { user_path(create(:user)) } diff --git a/spec/features/users/show_spec.rb b/spec/features/users/show_spec.rb index b5bbb2c0ea5..3e2fb704bc6 100644 --- a/spec/features/users/show_spec.rb +++ b/spec/features/users/show_spec.rb @@ -14,4 +14,28 @@ describe 'User page' do expect(page).to have_link('Snippets') end end + + context 'signup disabled' do + it 'shows the sign in link' do + stub_application_setting(signup_enabled: false) + + visit(user_path(user)) + + page.within '.navbar-nav' do + expect(page).to have_link('Sign in') + end + end + end + + context 'signup enabled' do + it 'shows the sign in and register link' do + stub_application_setting(signup_enabled: true) + + visit(user_path(user)) + + page.within '.navbar-nav' do + expect(page).to have_link('Sign in / Register') + end + end + end end diff --git a/spec/features/users/user_browses_projects_on_user_page_spec.rb b/spec/features/users/user_browses_projects_on_user_page_spec.rb index 5478e38ce70..6a9b281fb4c 100644 --- a/spec/features/users/user_browses_projects_on_user_page_spec.rb +++ b/spec/features/users/user_browses_projects_on_user_page_spec.rb @@ -4,19 +4,19 @@ describe 'Users > User browses projects on user page', :js do let!(:user) { create :user } let!(:private_project) do create :project, :private, name: 'private', namespace: user.namespace do |project| - project.add_master(user) + project.add_maintainer(user) end end let!(:internal_project) do create :project, :internal, name: 'internal', namespace: user.namespace do |project| - project.add_master(user) + project.add_maintainer(user) end end let!(:public_project) do create :project, :public, name: 'public', namespace: user.namespace do |project| - project.add_master(user) + project.add_maintainer(user) end end diff --git a/spec/finders/access_requests_finder_spec.rb b/spec/finders/access_requests_finder_spec.rb index 650f7229647..605777462bb 100644 --- a/spec/finders/access_requests_finder_spec.rb +++ b/spec/finders/access_requests_finder_spec.rb @@ -51,7 +51,7 @@ describe AccessRequestsFinder do context 'when current user can see access requests' do before do - project.add_master(user) + project.add_maintainer(user) group.add_owner(user) end @@ -78,7 +78,7 @@ describe AccessRequestsFinder do context 'when current user can see access requests' do before do - project.add_master(user) + project.add_maintainer(user) group.add_owner(user) end diff --git a/spec/finders/admin/projects_finder_spec.rb b/spec/finders/admin/projects_finder_spec.rb index 7901d5fee28..44cc8debd04 100644 --- a/spec/finders/admin/projects_finder_spec.rb +++ b/spec/finders/admin/projects_finder_spec.rb @@ -54,7 +54,7 @@ describe Admin::ProjectsFinder do context 'filter by visibility_level' do before do - private_project.add_master(user) + private_project.add_maintainer(user) end context 'private' do diff --git a/spec/finders/concerns/finder_with_cross_project_access_spec.rb b/spec/finders/concerns/finder_with_cross_project_access_spec.rb index c784fb87972..1ff65a8101b 100644 --- a/spec/finders/concerns/finder_with_cross_project_access_spec.rb +++ b/spec/finders/concerns/finder_with_cross_project_access_spec.rb @@ -25,7 +25,7 @@ describe FinderWithCrossProjectAccess do let!(:result) { create(:issue) } before do - result.project.add_master(user) + result.project.add_maintainer(user) end def expect_access_check_on_result diff --git a/spec/finders/contributed_projects_finder_spec.rb b/spec/finders/contributed_projects_finder_spec.rb index 60ea98e61c7..9155a8d6fe9 100644 --- a/spec/finders/contributed_projects_finder_spec.rb +++ b/spec/finders/contributed_projects_finder_spec.rb @@ -10,9 +10,9 @@ describe ContributedProjectsFinder do let!(:private_project) { create(:project, :private) } before do - private_project.add_master(source_user) + private_project.add_maintainer(source_user) private_project.add_developer(current_user) - public_project.add_master(source_user) + public_project.add_maintainer(source_user) create(:push_event, project: public_project, author: source_user) create(:push_event, project: private_project, author: source_user) diff --git a/spec/finders/environments_finder_spec.rb b/spec/finders/environments_finder_spec.rb index 3a8a1e7de74..3cd421f22eb 100644 --- a/spec/finders/environments_finder_spec.rb +++ b/spec/finders/environments_finder_spec.rb @@ -7,7 +7,7 @@ describe EnvironmentsFinder do let(:environment) { create(:environment, project: project) } before do - project.add_master(user) + project.add_maintainer(user) end context 'tagged deployment' do diff --git a/spec/finders/group_members_finder_spec.rb b/spec/finders/group_members_finder_spec.rb index 63e15b365a4..f545da3aee4 100644 --- a/spec/finders/group_members_finder_spec.rb +++ b/spec/finders/group_members_finder_spec.rb @@ -9,9 +9,9 @@ describe GroupMembersFinder, '#execute' do let(:user4) { create(:user) } it 'returns members for top-level group' do - member1 = group.add_master(user1) - member2 = group.add_master(user2) - member3 = group.add_master(user3) + member1 = group.add_maintainer(user1) + member2 = group.add_maintainer(user2) + member3 = group.add_maintainer(user3) result = described_class.new(group).execute @@ -19,11 +19,11 @@ describe GroupMembersFinder, '#execute' do end it 'returns members for nested group', :nested_groups do - group.add_master(user2) + group.add_maintainer(user2) nested_group.request_access(user4) - member1 = group.add_master(user1) - member3 = nested_group.add_master(user2) - member4 = nested_group.add_master(user3) + member1 = group.add_maintainer(user1) + member3 = nested_group.add_maintainer(user2) + member4 = nested_group.add_maintainer(user3) result = described_class.new(nested_group).execute @@ -31,11 +31,11 @@ describe GroupMembersFinder, '#execute' do end it 'returns members for descendant groups if requested', :nested_groups do - member1 = group.add_master(user2) - member2 = group.add_master(user1) - nested_group.add_master(user2) - member3 = nested_group.add_master(user3) - member4 = nested_group.add_master(user4) + member1 = group.add_maintainer(user2) + member2 = group.add_maintainer(user1) + nested_group.add_maintainer(user2) + member3 = nested_group.add_maintainer(user3) + member4 = nested_group.add_maintainer(user4) result = described_class.new(group).execute(include_descendants: true) diff --git a/spec/finders/group_projects_finder_spec.rb b/spec/finders/group_projects_finder_spec.rb index be80ee7d767..d6d95906f5e 100644 --- a/spec/finders/group_projects_finder_spec.rb +++ b/spec/finders/group_projects_finder_spec.rb @@ -17,16 +17,16 @@ describe GroupProjectsFinder do let!(:subgroup_private_project) { create(:project, :private, path: '7', group: subgroup) } before do - shared_project_1.project_group_links.create(group_access: Gitlab::Access::MASTER, group: group) - shared_project_2.project_group_links.create(group_access: Gitlab::Access::MASTER, group: group) - shared_project_3.project_group_links.create(group_access: Gitlab::Access::MASTER, group: group) + shared_project_1.project_group_links.create(group_access: Gitlab::Access::MAINTAINER, group: group) + shared_project_2.project_group_links.create(group_access: Gitlab::Access::MAINTAINER, group: group) + shared_project_3.project_group_links.create(group_access: Gitlab::Access::MAINTAINER, group: group) end subject { finder.execute } describe 'with a group member current user' do before do - group.add_master(current_user) + group.add_maintainer(current_user) end context "only shared" do @@ -68,7 +68,7 @@ describe GroupProjectsFinder do describe 'without group member current_user' do before do - shared_project_2.add_master(current_user) + shared_project_2.add_maintainer(current_user) current_user.reload end @@ -81,7 +81,7 @@ describe GroupProjectsFinder do context "with external user" do before do - current_user.update_attributes(external: true) + current_user.update(external: true) end it { is_expected.to match_array([shared_project_2, shared_project_1]) } @@ -93,8 +93,8 @@ describe GroupProjectsFinder do context "without external user" do before do - private_project.add_master(current_user) - subgroup_private_project.add_master(current_user) + private_project.add_maintainer(current_user) + subgroup_private_project.add_maintainer(current_user) end context 'with subgroups projects', :nested_groups do @@ -112,7 +112,7 @@ describe GroupProjectsFinder do context "with external user" do before do - current_user.update_attributes(external: true) + current_user.update(external: true) end context 'with subgroups projects', :nested_groups do diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb index 74e91b02f0f..07a2fa86dd7 100644 --- a/spec/finders/issues_finder_spec.rb +++ b/spec/finders/issues_finder_spec.rb @@ -26,7 +26,7 @@ describe IssuesFinder do let(:issues) { described_class.new(search_user, params.reverse_merge(scope: scope, state: 'opened')).execute } before(:context) do - project1.add_master(user) + project1.add_maintainer(user) project2.add_developer(user) project2.add_developer(user2) project3.add_developer(user) diff --git a/spec/finders/joined_groups_finder_spec.rb b/spec/finders/joined_groups_finder_spec.rb index 29a47e005a6..ae3e55f90f1 100644 --- a/spec/finders/joined_groups_finder_spec.rb +++ b/spec/finders/joined_groups_finder_spec.rb @@ -15,7 +15,7 @@ describe JoinedGroupsFinder do context 'without a user' do before do - public_group.add_master(profile_owner) + public_group.add_maintainer(profile_owner) end it 'only shows public groups from profile owner' do @@ -25,9 +25,9 @@ describe JoinedGroupsFinder do context "with a user" do before do - private_group.add_master(profile_owner) - internal_group.add_master(profile_owner) - public_group.add_master(profile_owner) + private_group.add_maintainer(profile_owner) + internal_group.add_maintainer(profile_owner) + public_group.add_maintainer(profile_owner) end context "when the profile visitor is in the private group" do @@ -53,7 +53,7 @@ describe JoinedGroupsFinder do context 'external users' do before do - profile_visitor.update_attributes(external: true) + profile_visitor.update(external: true) end context 'if not a member' do @@ -64,7 +64,7 @@ describe JoinedGroupsFinder do context "if authorized" do before do - internal_group.add_master(profile_visitor) + internal_group.add_maintainer(profile_visitor) end it "shows internal groups if authorized" do diff --git a/spec/finders/members_finder_spec.rb b/spec/finders/members_finder_spec.rb index 2fc5299b0f4..db48f00cd74 100644 --- a/spec/finders/members_finder_spec.rb +++ b/spec/finders/members_finder_spec.rb @@ -11,9 +11,9 @@ describe MembersFinder, '#execute' do it 'returns members for project and parent groups', :nested_groups do nested_group.request_access(user1) - member1 = group.add_master(user2) - member2 = nested_group.add_master(user3) - member3 = project.add_master(user4) + member1 = group.add_maintainer(user2) + member2 = nested_group.add_maintainer(user3) + member3 = project.add_maintainer(user4) result = described_class.new(project, user2).execute @@ -23,9 +23,9 @@ describe MembersFinder, '#execute' do it 'includes nested group members if asked', :nested_groups do project = create(:project, namespace: group) nested_group.request_access(user1) - member1 = group.add_master(user2) - member2 = nested_group.add_master(user3) - member3 = project.add_master(user4) + member1 = group.add_maintainer(user2) + member2 = nested_group.add_maintainer(user3) + member3 = project.add_maintainer(user4) result = described_class.new(project, user2).execute(include_descendants: true) diff --git a/spec/finders/merge_requests_finder_spec.rb b/spec/finders/merge_requests_finder_spec.rb index 669ec602f11..35d0eeda8f6 100644 --- a/spec/finders/merge_requests_finder_spec.rb +++ b/spec/finders/merge_requests_finder_spec.rb @@ -24,7 +24,7 @@ describe MergeRequestsFinder do let!(:merge_request5) { create(:merge_request, :simple, author: user, source_project: project4, target_project: project4) } before do - project1.add_master(user) + project1.add_maintainer(user) project2.add_developer(user) project3.add_developer(user) project2.add_developer(user2) @@ -142,7 +142,7 @@ describe MergeRequestsFinder do end before do - new_project.add_master(user) + new_project.add_maintainer(user) end it 'filters by created_after' do diff --git a/spec/finders/move_to_project_finder_spec.rb b/spec/finders/move_to_project_finder_spec.rb index 74639d4147f..1511cb0e04c 100644 --- a/spec/finders/move_to_project_finder_spec.rb +++ b/spec/finders/move_to_project_finder_spec.rb @@ -8,7 +8,7 @@ describe MoveToProjectFinder do let(:guest_project) { create(:project) } let(:reporter_project) { create(:project) } let(:developer_project) { create(:project) } - let(:master_project) { create(:project) } + let(:maintainer_project) { create(:project) } subject { described_class.new(user) } @@ -23,9 +23,9 @@ describe MoveToProjectFinder do it 'returns projects equal or above Gitlab::Access::REPORTER ordered by id in descending order' do reporter_project.add_reporter(user) developer_project.add_developer(user) - master_project.add_master(user) + maintainer_project.add_maintainer(user) - expect(subject.execute(project).to_a).to eq([master_project, developer_project, reporter_project]) + expect(subject.execute(project).to_a).to eq([maintainer_project, developer_project, reporter_project]) end it 'does not include the source project' do @@ -45,7 +45,7 @@ describe MoveToProjectFinder do it 'does not return projects for which issues are disabled' do reporter_project.add_reporter(user) - reporter_project.update_attributes(issues_enabled: false) + reporter_project.update(issues_enabled: false) other_reporter_project = create(:project) other_reporter_project.add_reporter(user) @@ -57,9 +57,9 @@ describe MoveToProjectFinder do reporter_project.add_reporter(user) developer_project.add_developer(user) - master_project.add_master(user) + maintainer_project.add_maintainer(user) - expect(subject.execute(project).to_a).to eq([master_project, developer_project]) + expect(subject.execute(project).to_a).to eq([maintainer_project, developer_project]) end it 'returns projects after the given offset id' do @@ -67,9 +67,9 @@ describe MoveToProjectFinder do reporter_project.add_reporter(user) developer_project.add_developer(user) - master_project.add_master(user) + maintainer_project.add_maintainer(user) - expect(subject.execute(project, search: nil, offset_id: master_project.id).to_a).to eq([developer_project, reporter_project]) + expect(subject.execute(project, search: nil, offset_id: maintainer_project.id).to_a).to eq([developer_project, reporter_project]) expect(subject.execute(project, search: nil, offset_id: developer_project.id).to_a).to eq([reporter_project]) expect(subject.execute(project, search: nil, offset_id: reporter_project.id).to_a).to be_empty end @@ -84,10 +84,10 @@ describe MoveToProjectFinder do it 'returns projects matching a search query' do foo_project = create(:project) - foo_project.add_master(user) + foo_project.add_maintainer(user) wadus_project = create(:project, name: 'wadus') - wadus_project.add_master(user) + wadus_project.add_maintainer(user) expect(subject.execute(project).to_a).to eq([wadus_project, foo_project]) expect(subject.execute(project, search: 'wadus').to_a).to eq([wadus_project]) diff --git a/spec/finders/notes_finder_spec.rb b/spec/finders/notes_finder_spec.rb index 232f35c86f9..b776e9d856a 100644 --- a/spec/finders/notes_finder_spec.rb +++ b/spec/finders/notes_finder_spec.rb @@ -5,7 +5,7 @@ describe NotesFinder do let(:project) { create(:project) } before do - project.add_master(user) + project.add_maintainer(user) end describe '#execute' do diff --git a/spec/finders/personal_projects_finder_spec.rb b/spec/finders/personal_projects_finder_spec.rb index 00c551a1f65..ef7dd0cd4a8 100644 --- a/spec/finders/personal_projects_finder_spec.rb +++ b/spec/finders/personal_projects_finder_spec.rb @@ -35,7 +35,7 @@ describe PersonalProjectsFinder do context 'external' do before do - current_user.update_attributes(external: true) + current_user.update(external: true) end it { is_expected.to eq([public_project, private_project]) } diff --git a/spec/finders/pipelines_finder_spec.rb b/spec/finders/pipelines_finder_spec.rb index d6253b605b9..c6e832ad69b 100644 --- a/spec/finders/pipelines_finder_spec.rb +++ b/spec/finders/pipelines_finder_spec.rb @@ -1,9 +1,10 @@ require 'spec_helper' describe PipelinesFinder do - let(:project) { create(:project, :repository) } - - subject { described_class.new(project, params).execute } + let(:project) { create(:project, :public, :repository) } + let(:current_user) { nil } + let(:params) { {} } + subject { described_class.new(project, current_user, params).execute } describe "#execute" do context 'when params is empty' do @@ -223,5 +224,27 @@ describe PipelinesFinder do end end end + + context 'when the project has limited access to piplines' do + let(:project) { create(:project, :private, :repository) } + let(:current_user) { create(:user) } + let!(:pipelines) { create_list(:ci_pipeline, 2, project: project) } + + context 'when the user has access' do + before do + project.add_developer(current_user) + end + + it 'is expected to return pipelines' do + is_expected.to contain_exactly(*pipelines) + end + end + + context 'the user is not allowed to read pipelines' do + it 'returns empty' do + is_expected.to be_empty + end + end + end end end diff --git a/spec/finders/projects_finder_spec.rb b/spec/finders/projects_finder_spec.rb index 0dfe6ba9c32..7931ad9b9f0 100644 --- a/spec/finders/projects_finder_spec.rb +++ b/spec/finders/projects_finder_spec.rb @@ -41,7 +41,7 @@ describe ProjectsFinder do describe 'with private projects' do before do - private_project.add_master(user) + private_project.add_maintainer(user) end it { is_expected.to match_array([public_project, internal_project, private_project]) } @@ -56,7 +56,7 @@ describe ProjectsFinder do describe 'filter by visibility_level' do before do - private_project.add_master(user) + private_project.add_maintainer(user) end context 'private' do diff --git a/spec/fixtures/aosp_manifest.xml b/spec/fixtures/aosp_manifest.xml new file mode 100644 index 00000000000..cfd0094b735 --- /dev/null +++ b/spec/fixtures/aosp_manifest.xml @@ -0,0 +1,685 @@ +<?xml version="1.0" encoding="UTF-8"?> +<manifest> + + <remote name="aosp" + fetch=".." + review="https://android-review.googlesource.com/" /> + <default revision="master" + remote="aosp" + sync-j="4" /> + + <project path="build/make" name="platform/build" groups="pdk" > + <copyfile src="core/root.mk" dest="Makefile" /> + <linkfile src="CleanSpec.mk" dest="build/CleanSpec.mk" /> + <linkfile src="buildspec.mk.default" dest="build/buildspec.mk.default" /> + <linkfile src="core" dest="build/core" /> + <linkfile src="envsetup.sh" dest="build/envsetup.sh" /> + <linkfile src="target" dest="build/target" /> + <linkfile src="tools" dest="build/tools" /> + </project> + <project path="build/blueprint" name="platform/build/blueprint" groups="pdk,tradefed" /> + <project path="build/kati" name="platform/build/kati" groups="pdk,tradefed" /> + <project path="build/soong" name="platform/build/soong" groups="pdk,tradefed" > + <linkfile src="root.bp" dest="Android.bp" /> + <linkfile src="bootstrap.bash" dest="bootstrap.bash" /> + </project> + <project path="art" name="platform/art" groups="pdk" /> + <project path="bionic" name="platform/bionic" groups="pdk" /> + <project path="bootable/recovery" name="platform/bootable/recovery" groups="pdk" /> + <project path="compatibility/cdd" name="platform/compatibility/cdd" groups="pdk" /> + <project path="cts" name="platform/cts" groups="cts,pdk-cw-fs,pdk-fs" /> + <project path="dalvik" name="platform/dalvik" groups="pdk-cw-fs,pdk-fs" /> + <project path="developers/build" name="platform/developers/build" groups="developers" /> + <project path="developers/demos" name="platform/developers/demos" groups="developers" /> + <project path="developers/samples/android" name="platform/developers/samples/android" groups="developers" /> + <project path="development" name="platform/development" groups="developers,pdk-cw-fs,pdk-fs" /> + <project path="device/asus/fugu" name="device/asus/fugu" groups="device,fugu,broadcom_pdk" /> + <project path="device/asus/fugu-kernel" name="device/asus/fugu-kernel" groups="device,fugu,broadcom_pdk" clone-depth="1" /> + <project path="device/common" name="device/common" groups="pdk-cw-fs,pdk" /> + <project path="device/generic/arm64" name="device/generic/arm64" groups="pdk" /> + <project path="device/generic/armv7-a-neon" name="device/generic/armv7-a-neon" groups="pdk" /> + <project path="device/generic/car" name="device/generic/car" groups="pdk" /> + <project path="device/generic/common" name="device/generic/common" groups="pdk" /> + <project path="device/generic/goldfish" name="device/generic/goldfish" groups="pdk" /> + <project path="device/generic/goldfish-opengl" name="device/generic/goldfish-opengl" groups="pdk" /> + <project path="device/generic/mini-emulator-arm64" name="device/generic/mini-emulator-arm64" groups="pdk" /> + <project path="device/generic/mini-emulator-armv7-a-neon" name="device/generic/mini-emulator-armv7-a-neon" groups="pdk" /> + <project path="device/generic/mini-emulator-x86" name="device/generic/mini-emulator-x86" groups="pdk" /> + <project path="device/generic/mini-emulator-x86_64" name="device/generic/mini-emulator-x86_64" groups="pdk" /> + <project path="device/generic/qemu" name="device/generic/qemu" groups="pdk" /> + <project path="device/generic/uml" name="device/generic/uml" groups="device,pdk" /> + <project path="device/generic/x86" name="device/generic/x86" groups="pdk" /> + <project path="device/generic/x86_64" name="device/generic/x86_64" groups="pdk" /> + <project path="device/google/accessory/arduino" name="device/google/accessory/arduino" groups="device,pdk" /> + <project path="device/google/accessory/demokit" name="device/google/accessory/demokit" groups="device,pdk" /> + <project path="device/google/atv" name="device/google/atv" groups="device,broadcom_pdk,generic_fs,pdk" /> + <project path="device/google/contexthub" name="device/google/contexthub" groups="device,marlin,pdk" /> + <project path="device/google/cuttlefish" name="device/google/cuttlefish" groups="device" /> + <project path="device/google/cuttlefish_common" name="device/google/cuttlefish_common" groups="device" /> + <project path="device/google/cuttlefish_kernel" name="device/google/cuttlefish_kernel" groups="device" clone-depth="1" /> + <project path="device/google/dragon" name="device/google/dragon" groups="device,dragon" /> + <project path="device/google/dragon-kernel" name="device/google/dragon-kernel" groups="device,dragon" clone-depth="1" /> + <project path="device/google/marlin" name="device/google/marlin" groups="device,marlin,pdk" /> + <project path="device/google/marlin-kernel" name="device/google/marlin-kernel" groups="device,marlin,pdk" clone-depth="1" /> + <project path="device/google/muskie" name="device/google/muskie" groups="device,muskie" /> + <project path="device/google/taimen" name="device/google/taimen" groups="device,taimen" /> + <project path="device/google/vrservices" name="device/google/vrservices" groups="pdk" clone-depth="1" /> + <project path="device/google/wahoo" name="device/google/wahoo" groups="device,wahoo" /> + <project path="device/google/wahoo-kernel" name="device/google/wahoo-kernel" groups="device,wahoo" clone-depth="1" /> + <project path="device/huawei/angler" name="device/huawei/angler" groups="device,angler,broadcom_pdk" /> + <project path="device/huawei/angler-kernel" name="device/huawei/angler-kernel" groups="device,angler,broadcom_pdk" clone-depth="1" /> + <project path="device/lge/bullhead" name="device/lge/bullhead" groups="device,bullhead" /> + <project path="device/lge/bullhead-kernel" name="device/lge/bullhead-kernel" groups="device,bullhead" clone-depth="1" /> + <project path="device/linaro/bootloader/arm-trusted-firmware" name="device/linaro/bootloader/arm-trusted-firmware" /> + <project path="device/linaro/bootloader/edk2" name="device/linaro/bootloader/edk2" /> + <project path="device/linaro/bootloader/OpenPlatformPkg" name="device/linaro/bootloader/OpenPlatformPkg" /> + <project path="device/linaro/hikey" name="device/linaro/hikey" groups="device,hikey,pdk" /> + <project path="device/linaro/hikey-kernel" name="device/linaro/hikey-kernel" groups="device,hikey,pdk" clone-depth="1" /> + <project path="device/sample" name="device/sample" groups="pdk" /> + <project path="external/aac" name="platform/external/aac" groups="pdk" /> + <project path="external/abi-compliance-checker" name="platform/external/abi-compliance-checker" groups="pdk" /> + <project path="external/abi-dumper" name="platform/external/abi-dumper" groups="pdk" /> + <project path="external/adt-infra" name="platform/external/adt-infra" groups="adt-infra,notdefault,pdk-fs" /> + <project path="external/android-clat" name="platform/external/android-clat" groups="pdk" /> + <project path="external/androidplot" name="platform/external/androidplot" groups="pdk" /> + <project path="external/annotation-tools" name="platform/external/annotation-tools" groups="pdk" /> + <project path="external/ant-glob" name="platform/external/ant-glob" groups="pdk" /> + <project path="external/antlr" name="platform/external/antlr" groups="pdk" /> + <project path="external/apache-commons-math" name="platform/external/apache-commons-math" groups="pdk" /> + <project path="external/apache-harmony" name="platform/external/apache-harmony" groups="pdk" /> + <project path="external/apache-http" name="platform/external/apache-http" groups="pdk" /> + <project path="external/apache-xml" name="platform/external/apache-xml" groups="pdk" /> + <project path="external/archive-patcher" name="platform/external/archive-patcher" groups="pdk" /> + <project path="external/arm-neon-tests" name="platform/external/arm-neon-tests" groups="vendor" /> + <project path="external/autotest" name="platform/external/autotest" groups="pdk-fs" /> + <project path="external/avb" name="platform/external/avb" groups="pdk" /> + <project path="external/bart" name="platform/external/bart" groups="pdk" /> + <project path="external/blktrace" name="platform/external/blktrace" groups="pdk" /> + <project path="external/boringssl" name="platform/external/boringssl" groups="pdk" /> + <project path="external/bouncycastle" name="platform/external/bouncycastle" groups="pdk" /> + <project path="external/brotli" name="platform/external/brotli" groups="pdk" /> + <project path="external/bsdiff" name="platform/external/bsdiff" groups="pdk" /> + <project path="external/bzip2" name="platform/external/bzip2" groups="pdk" /> + <project path="external/caliper" name="platform/external/caliper" groups="pdk" /> + <project path="external/cblas" name="platform/external/cblas" groups="pdk" /> + <project path="external/chromium-libpac" name="platform/external/chromium-libpac" groups="pdk" /> + <project path="external/chromium-trace" name="platform/external/chromium-trace" groups="pdk" /> + <project path="external/chromium-webview" name="platform/external/chromium-webview" groups="pdk" clone-depth="1" /> + <project path="external/clang" name="platform/external/clang" groups="pdk" /> + <project path="external/cldr" name="platform/external/cldr" groups="pdk" /> + <project path="external/cmockery" name="platform/external/cmockery" groups="pdk" /> + <project path="external/cn-cbor" name="platform/external/cn-cbor" groups="pdk" /> + <project path="external/compiler-rt" name="platform/external/compiler-rt" groups="pdk" /> + <project path="external/conscrypt" name="platform/external/conscrypt" groups="pdk" /> + <project path="external/crcalc" name="platform/external/crcalc" groups="pdk" /> + <project path="external/cros/system_api" name="platform/external/cros/system_api" groups="pdk" /> + <project path="external/curl" name="platform/external/curl" groups="pdk" /> + <project path="external/dagger2" name="platform/external/dagger2" groups="pdk" /> + <project path="external/deqp" name="platform/external/deqp" groups="pdk-fs" /> + <project path="external/desugar" name="platform/external/desugar" groups="pdk" /> + <project path="external/devlib" name="platform/external/devlib" groups="pdk" /> + <project path="external/dexmaker" name="platform/external/dexmaker" groups="pdk" /> + <project path="external/dhcpcd-6.8.2" name="platform/external/dhcpcd-6.8.2" groups="pdk" /> + <project path="external/dlmalloc" name="platform/external/dlmalloc" groups="pdk" /> + <project path="external/dng_sdk" name="platform/external/dng_sdk" groups="pdk" /> + <project path="external/dnsmasq" name="platform/external/dnsmasq" groups="pdk" /> + <project path="external/doclava" name="platform/external/doclava" groups="pdk" /> + <project path="external/dokka" name="platform/external/dokka" groups="pdk" /> + <project path="external/drm_hwcomposer" name="platform/external/drm_hwcomposer" groups="drm_hwcomposer,pdk-fs" /> + <project path="external/droiddriver" name="platform/external/droiddriver" groups="pdk" /> + <project path="external/drrickorang" name="platform/external/drrickorang" groups="pdk" /> + <project path="external/dtc" name="platform/external/dtc" groups="pdk"/> + <project path="external/e2fsprogs" name="platform/external/e2fsprogs" groups="pdk" /> + <project path="external/easymock" name="platform/external/easymock" groups="pdk" /> + <project path="external/eigen" name="platform/external/eigen" groups="pdk" /> + <project path="external/elfutils" name="platform/external/elfutils" groups="pdk" /> + <project path="external/emma" name="platform/external/emma" groups="pdk" /> + <project path="external/error_prone" name="platform/external/error_prone" groups="pdk" /> + <project path="external/esd" name="platform/external/esd" groups="pdk" /> + <project path="external/expat" name="platform/external/expat" groups="pdk" /> + <project path="external/eyes-free" name="platform/external/eyes-free" groups="pdk" /> + <project path="external/f2fs-tools" name="platform/external/f2fs-tools" groups="pdk" /> + <project path="external/fdlibm" name="platform/external/fdlibm" groups="pdk" /> + <project path="external/fec" name="platform/external/fec" groups="pdk" /> + <project path="external/flac" name="platform/external/flac" groups="pdk" /> + <project path="external/flatbuffers" name="platform/external/flatbuffers" groups="pdk" /> + <project path="external/fonttools" name="platform/external/fonttools" groups="pdk" /> + <project path="external/freetype" name="platform/external/freetype" groups="pdk" /> + <project path="external/fsck_msdos" name="platform/external/fsck_msdos" groups="pdk" /> + <project path="external/gemmlowp" name="platform/external/gemmlowp" groups="pdk" /> + <project path="external/gflags" name="platform/external/gflags" groups="pdk" /> + <project path="external/giflib" name="platform/external/giflib" groups="pdk,qcom_msm8x26" /> + <project path="external/glide" name="platform/external/glide" groups="pdk" /> + <project path="external/golang-protobuf" name="platform/external/golang-protobuf" groups="pdk" /> + <project path="external/google-benchmark" name="platform/external/google-benchmark" groups="pdk" /> + <project path="external/google-breakpad" name="platform/external/google-breakpad" groups="pdk-fs" /> + <project path="external/google-fonts/carrois-gothic-sc" name="platform/external/google-fonts/carrois-gothic-sc" groups="pdk" /> + <project path="external/google-fonts/coming-soon" name="platform/external/google-fonts/coming-soon" groups="pdk" /> + <project path="external/google-fonts/cutive-mono" name="platform/external/google-fonts/cutive-mono" groups="pdk" /> + <project path="external/google-fonts/dancing-script" name="platform/external/google-fonts/dancing-script" groups="pdk" /> + <project path="external/google-styleguide" name="platform/external/google-styleguide" groups="pdk" /> + <project path="external/google-tv-pairing-protocol" name="platform/external/google-tv-pairing-protocol" groups="pdk" /> + <project path="external/googletest" name="platform/external/googletest" groups="pdk" /> + <project path="external/gptfdisk" name="platform/external/gptfdisk" groups="pdk" /> + <project path="external/guava" name="platform/external/guava" groups="pdk" /> + <project path="external/guice" name="platform/external/guice" groups="pdk" /> + <project path="external/hamcrest" name="platform/external/hamcrest" groups="pdk" /> + <project path="external/harfbuzz_ng" name="platform/external/harfbuzz_ng" groups="pdk,qcom_msm8x26" /> + <project path="external/hyphenation-patterns" name="platform/external/hyphenation-patterns" groups="pdk" /> + <project path="external/icu" name="platform/external/icu" groups="pdk" /> + <project path="external/ImageMagick" name="platform/external/ImageMagick" groups="pdk" /> + <project path="external/ims" name="platform/external/ims" groups="pdk" /> + <project path="external/iproute2" name="platform/external/iproute2" groups="pdk" /> + <project path="external/ipsec-tools" name="platform/external/ipsec-tools" groups="pdk" /> + <project path="external/iptables" name="platform/external/iptables" groups="pdk" /> + <project path="external/iputils" name="platform/external/iputils" groups="pdk" /> + <project path="external/iw" name="platform/external/iw" groups="pdk" /> + <project path="external/jacoco" name="platform/external/jacoco" groups="pdk" /> + <project path="external/jarjar" name="platform/external/jarjar" groups="pdk" /> + <project path="external/javaparser" name="platform/external/javaparser" groups="pdk" /> + <project path="external/javasqlite" name="platform/external/javasqlite" groups="pdk" /> + <project path="external/javassist" name="platform/external/javassist" groups="pdk" /> + <project path="external/jcommander" name="platform/external/jcommander" groups="pdk" /> + <project path="external/jdiff" name="platform/external/jdiff" groups="pdk" /> + <project path="external/jemalloc" name="platform/external/jemalloc" groups="pdk" /> + <project path="external/jline" name="platform/external/jline" groups="pdk,tradefed,pdk-fs" /> + <project path="external/jmdns" name="platform/external/jmdns" groups="pdk" /> + <project path="external/jsilver" name="platform/external/jsilver" groups="pdk" /> + <project path="external/jsmn" name="platform/external/jsmn" groups="pdk" /> + <project path="external/jsoncpp" name="platform/external/jsoncpp" groups="pdk" /> + <project path="external/jsr305" name="platform/external/jsr305" groups="pdk" /> + <project path="external/jsr330" name="platform/external/jsr330" groups="pdk" /> + <project path="external/junit" name="platform/external/junit" groups="pdk" /> + <project path="external/junit-params" name="platform/external/junit-params" groups="pdk" /> + <project path="external/kernel-headers" name="platform/external/kernel-headers" groups="pdk" /> + <project path="external/kmod" name="platform/external/kmod" groups="pdk" /> + <project path="external/kotlinc" name="platform/external/kotlinc" groups="pdk" /> + <project path="external/ksoap2" name="platform/external/ksoap2" groups="pdk" /> + <project path="external/libavc" name="platform/external/libavc" groups="pdk" /> + <project path="external/libbackup" name="platform/external/libbackup" groups="pdk" /> + <project path="external/libbrillo" name="platform/external/libbrillo" groups="pdk" /> + <project path="external/libcap" name="platform/external/libcap" groups="pdk" /> + <project path="external/libcap-ng" name="platform/external/libcap-ng" groups="pdk" /> + <project path="external/libchrome" name="platform/external/libchrome" groups="pdk" /> + <project path="external/libconstrainedcrypto" name="platform/external/libconstrainedcrypto" groups="pdk" /> + <project path="external/libcups" name="platform/external/libcups" groups="pdk-cw-fs,pdk-fs" /> + <project path="external/libcxx" name="platform/external/libcxx" groups="pdk" /> + <project path="external/libcxxabi" name="platform/external/libcxxabi" groups="pdk" /> + <project path="external/libdaemon" name="platform/external/libdaemon" groups="pdk" /> + <project path="external/libdivsufsort" name="platform/external/libdivsufsort" groups="pdk" /> + <project path="external/libdrm" name="platform/external/libdrm" groups="pdk" /> + <project path="external/libedit" name="platform/external/libedit" groups="pdk" /> + <project path="external/libese" name="platform/external/libese" groups="pdk" /> + <project path="external/libevent" name="platform/external/libevent" groups="pdk" /> + <project path="external/libexif" name="platform/external/libexif" groups="pdk" /> + <project path="external/libgsm" name="platform/external/libgsm" groups="pdk" /> + <project path="external/libhevc" name="platform/external/libhevc" groups="pdk" /> + <project path="external/libjpeg-turbo" name="platform/external/libjpeg-turbo" groups="pdk" /> + <project path="external/libldac" name="platform/external/libldac" groups="pdk" /> + <project path="external/libmicrohttpd" name="platform/external/libmicrohttpd" groups="pdk" /> + <project path="external/libmpeg2" name="platform/external/libmpeg2" groups="pdk" /> + <project path="external/libmtp" name="platform/external/libmtp" groups="pdk" /> + <project path="external/libnetfilter_conntrack" name="platform/external/libnetfilter_conntrack" groups="pdk" /> + <project path="external/libnfnetlink" name="platform/external/libnfnetlink" groups="pdk" /> + <project path="external/libnl" name="platform/external/libnl" groups="pdk" /> + <project path="external/libogg" name="platform/external/libogg" groups="pdk" /> + <project path="external/libopus" name="platform/external/libopus" groups="pdk" /> + <project path="external/libpcap" name="platform/external/libpcap" groups="pdk" /> + <project path="external/libphonenumber" name="platform/external/libphonenumber" groups="pdk" /> + <project path="external/libpng" name="platform/external/libpng" groups="pdk" /> + <project path="external/libtextclassifier" name="platform/external/libtextclassifier" groups="pdk" /> + <project path="external/libunwind" name="platform/external/libunwind" groups="pdk" /> + <project path="external/libunwind_llvm" name="platform/external/libunwind_llvm" groups="pdk" /> + <project path="external/libusb" name="platform/external/libusb" groups="pdk" /> + <project path="external/libusb-compat" name="platform/external/libusb-compat" groups="pdk" /> + <project path="external/libvncserver" name="platform/external/libvncserver" groups="pdk" /> + <project path="external/libvorbis" name="platform/external/libvorbis" groups="pdk" /> + <project path="external/libvpx" name="platform/external/libvpx" groups="pdk" /> + <project path="external/libvterm" name="platform/external/libvterm" groups="pdk" /> + <project path="external/libxcam" name="platform/external/libxcam" groups="pdk" /> + <project path="external/libxml2" name="platform/external/libxml2" groups="pdk,libxml2" /> + <project path="external/libyuv" name="platform/external/libyuv" groups="pdk,libyuv" /> + <project path="external/linux-kselftest" name="platform/external/linux-kselftest" groups="vts,pdk" /> + <project path="external/lisa" name="platform/external/lisa" groups="pdk" /> + <project path="external/llvm" name="platform/external/llvm" groups="pdk" /> + <project path="external/lmfit" name="platform/external/lmfit" groups="pdk" /> + <project path="external/ltp" name="platform/external/ltp" groups="vts,pdk" /> + <project path="external/lz4" name="platform/external/lz4" groups="pdk" /> + <project path="external/lzma" name="platform/external/lzma" groups="pdk" /> + <project path="external/markdown" name="platform/external/markdown" groups="pdk" /> + <project path="external/mdnsresponder" name="platform/external/mdnsresponder" groups="pdk" /> + <project path="external/mesa3d" name="platform/external/mesa3d" groups="pdk-cw-fs,pdk-fs" /> + <project path="external/Microsoft-GSL" name="platform/external/Microsoft-GSL" groups="pdk" /> + <project path="external/minijail" name="platform/external/minijail" groups="pdk" /> + <project path="external/mksh" name="platform/external/mksh" groups="pdk" /> + <project path="external/mmc-utils" name="platform/external/mmc-utils" groups="pdk" /> + <project path="external/mockftpserver" name="platform/external/mockftpserver" groups="pdk" /> + <project path="external/mockito" name="platform/external/mockito" groups="pdk" /> + <project path="external/mockwebserver" name="platform/external/mockwebserver" groups="pdk" /> + <project path="external/modp_b64" name="platform/external/modp_b64" groups="pdk" /> + <project path="external/mp4parser" name="platform/external/mp4parser" groups="pdk" /> + <project path="external/mtpd" name="platform/external/mtpd" groups="pdk" /> + <project path="external/nanohttpd" name="platform/external/nanohttpd" groups="pdk" /> + <project path="external/nanopb-c" name="platform/external/nanopb-c" groups="pdk" /> + <project path="external/naver-fonts" name="platform/external/naver-fonts" groups="pdk" /> + <project path="external/neven" name="platform/external/neven" groups="pdk" /> + <project path="external/nfacct" name="platform/external/nfacct" groups="pdk" /> + <project path="external/nist-pkits" name="platform/external/nist-pkits" groups="pdk" /> + <project path="external/nist-sip" name="platform/external/nist-sip" groups="pdk" /> + <project path="external/noto-fonts" name="platform/external/noto-fonts" groups="pdk" /> + <project path="external/oauth" name="platform/external/oauth" groups="pdk" /> + <project path="external/objenesis" name="platform/external/objenesis" groups="pdk" /> + <project path="external/oj-libjdwp" name="platform/external/oj-libjdwp" groups="pdk" /> + <project path="external/okhttp" name="platform/external/okhttp" groups="pdk" /> + <project path="external/one-true-awk" name="platform/external/one-true-awk" groups="pdk" /> + <project path="external/opencv" name="platform/external/opencv" groups="pdk-cw-fs,pdk-fs" /> + <project path="external/owasp/sanitizer" name="platform/external/owasp/sanitizer" groups="pdk" /> + <project path="external/parameter-framework" name="platform/external/parameter-framework" groups="pdk" /> + <project path="external/pcre" name="platform/external/pcre" groups="pdk" /> + <project path="external/pdfium" name="platform/external/pdfium" groups="pdk" /> + <project path="external/perf_data_converter" name="platform/external/perf_data_converter" groups="pdk" /> + <project path="external/perfetto" name="platform/external/perfetto" groups="pdk" /> + <project path="external/piex" name="platform/external/piex" groups="pdk" /> + <project path="external/ply" name="platform/external/ply" groups="pdk" /> + <project path="external/ppp" name="platform/external/ppp" groups="pdk" /> + <project path="external/proguard" name="platform/external/proguard" groups="pdk" /> + <project path="external/protobuf" name="platform/external/protobuf" groups="pdk" /> + <project path="external/puffin" name="platform/external/puffin" groups="pdk" /> + <project path="external/python/appdirs" name="platform/external/python/appdirs" groups="vts,pdk" /> + <project path="external/python/cachetools" name="platform/external/python/cachetools" groups="vts,pdk" /> + <project path="external/python/cpython2" name="platform/external/python/cpython2" groups="pdk" /> + <project path="external/python/cpython3" name="platform/external/python/cpython3" groups="pdk" /> + <project path="external/python/dateutil" name="platform/external/python/dateutil" groups="pdk" /> + <project path="external/python/dill" name="platform/external/python/dill" groups="vts,pdk" /> + <project path="external/python/enum" name="platform/external/python/enum" groups="vts,pdk" /> + <project path="external/python/enum34" name="platform/external/python/enum34" groups="vts,pdk" /> + <project path="external/python/future" name="platform/external/python/future" groups="vts,pdk" /> + <project path="external/python/futures" name="platform/external/python/futures" groups="vts,pdk" /> + <project path="external/python/gapic-google-cloud-pubsub-v1" name="platform/external/python/gapic-google-cloud-pubsub-v1" groups="vts,pdk" /> + <project path="external/python/google-api-python-client" name="platform/external/python/google-api-python-client" groups="vts,pdk" /> + <project path="external/python/google-auth" name="platform/external/python/google-auth" groups="vts,pdk" /> + <project path="external/python/google-auth-httplib2" name="platform/external/python/google-auth-httplib2" groups="vts,pdk" /> + <project path="external/python/google-cloud-core" name="platform/external/python/google-cloud-core" groups="vts,pdk" /> + <project path="external/python/google-cloud-pubsub" name="platform/external/python/google-cloud-pubsub" groups="vts,pdk" /> + <project path="external/python/google-gax" name="platform/external/python/google-gax" groups="vts,pdk" /> + <project path="external/python/googleapis" name="platform/external/python/googleapis" groups="vts,pdk" /> + <project path="external/python/grpc-google-iam-v1" name="platform/external/python/grpc-google-iam-v1" groups="vts,pdk" /> + <project path="external/python/grpcio" name="platform/external/python/grpcio" groups="vts,pdk" /> + <project path="external/python/httplib2" name="platform/external/python/httplib2" groups="vts,pdk" /> + <project path="external/python/matplotlib" name="platform/external/python/matplotlib" groups="vts,pdk" /> + <project path="external/python/numpy" name="platform/external/python/numpy" groups="vts,pdk" /> + <project path="external/python/oauth2client" name="platform/external/python/oauth2client" groups="vts,pdk" /> + <project path="external/python/olefile" name="platform/external/python/olefile" groups="vts,pdk" /> + <project path="external/python/packaging" name="platform/external/python/packaging" groups="vts,pdk" /> + <project path="external/python/parse" name="platform/external/python/parse" groups="vts,pdk" /> + <project path="external/python/Pillow" name="platform/external/python/Pillow" groups="vts,pdk" /> + <project path="external/python/ply" name="platform/external/python/ply" groups="vts,pdk" /> + <project path="external/python/proto-google-cloud-pubsub-v1" name="platform/external/python/proto-google-cloud-pubsub-v1" groups="vts,pdk" /> + <project path="external/python/protobuf" name="platform/external/python/protobuf" groups="vts,pdk" /> + <project path="external/python/pyasn1" name="platform/external/python/pyasn1" groups="vts,pdk" /> + <project path="external/python/pyasn1-modules" name="platform/external/python/pyasn1-modules" groups="vts,pdk" /> + <project path="external/python/pyparsing" name="platform/external/python/pyparsing" groups="vts,pdk" /> + <project path="external/python/requests" name="platform/external/python/requests" groups="vts,pdk" /> + <project path="external/python/rsa" name="platform/external/python/rsa" groups="vts,pdk" /> + <project path="external/python/scipy" name="platform/external/python/scipy" groups="vts,pdk" /> + <project path="external/python/setuptools" name="platform/external/python/setuptools" groups="vts,pdk" /> + <project path="external/python/six" name="platform/external/python/six" groups="vts,pdk" /> + <project path="external/python/uritemplates" name="platform/external/python/uritemplates" groups="vts,pdk" /> + <project path="external/replicaisland" name="platform/external/replicaisland" groups="pdk" /> + <project path="external/rmi4utils" name="platform/external/rmi4utils" groups="pdk" /> + <project path="external/robolectric" name="platform/external/robolectric" groups="pdk-cw-fs,pdk-fs" /> + <project path="external/roboto-fonts" name="platform/external/roboto-fonts" groups="pdk" /> + <project path="external/rootdev" name="platform/external/rootdev" groups="pdk" /> + <project path="external/safe-iop" name="platform/external/safe-iop" groups="pdk" /> + <project path="external/scapy" name="platform/external/scapy" groups="pdk-fs" /> + <project path="external/scrypt" name="platform/external/scrypt" groups="pdk" /> + <project path="external/seccomp-tests" name="platform/external/seccomp-tests" groups="pdk" /> + <project path="external/selinux" name="platform/external/selinux" groups="pdk" /> + <project path="external/sfntly" name="platform/external/sfntly" groups="pdk,qcom_msm8x26" /> + <project path="external/shaderc/spirv-headers" name="platform/external/shaderc/spirv-headers" groups="pdk" /> + <project path="external/shflags" name="platform/external/shflags" groups="pdk" /> + <project path="external/skia" name="platform/external/skia" groups="pdk,qcom_msm8x26" /> + <project path="external/sl4a" name="platform/external/sl4a" groups="pdk" /> + <project path="external/slf4j" name="platform/external/slf4j" groups="pdk" /> + <project path="external/smali" name="platform/external/smali" groups="pdk" /> + <project path="external/snakeyaml" name="platform/external/snakeyaml" groups="pdk" /> + <project path="external/sonic" name="platform/external/sonic" groups="pdk" /> + <project path="external/sonivox" name="platform/external/sonivox" groups="pdk" /> + <project path="external/speex" name="platform/external/speex" groups="pdk" /> + <project path="external/spirv-llvm" name="platform/external/spirv-llvm" groups="pdk" /> + <project path="external/sqlite" name="platform/external/sqlite" groups="pdk" /> + <project path="external/squashfs-tools" name="platform/external/squashfs-tools" groups="pdk" /> + <project path="external/strace" name="platform/external/strace" groups="pdk" /> + <project path="external/stressapptest" name="platform/external/stressapptest" groups="pdk" /> + <project path="external/subsampling-scale-image-view" name="platform/external/subsampling-scale-image-view" clone-depth="1" /> + <project path="external/swiftshader" name="platform/external/swiftshader" groups="pdk" /> + <project path="external/syslinux" name="platform/external/syslinux" groups="pdk" /> + <project path="external/tagsoup" name="platform/external/tagsoup" groups="pdk" /> + <project path="external/tcpdump" name="platform/external/tcpdump" groups="pdk" /> + <project path="external/tensorflow" name="platform/external/tensorflow" groups="pdk" /> + <project path="external/testng" name="platform/external/testng" groups="pdk" /> + <project path="external/tinyalsa" name="platform/external/tinyalsa" groups="pdk" /> + <project path="external/tinycompress" name="platform/external/tinycompress" groups="pdk" /> + <project path="external/tinyxml" name="platform/external/tinyxml" groups="pdk" /> + <project path="external/tinyxml2" name="platform/external/tinyxml2" groups="pdk" /> + <project path="external/toolchain-utils" name="platform/external/toolchain-utils" /> + <project path="external/toybox" name="platform/external/toybox" groups="pdk" /> + <project path="external/tpm2" name="platform/external/tpm2" groups="pdk" /> + <project path="external/trappy" name="platform/external/trappy" groups="pdk" /> + <project path="external/tremolo" name="platform/external/tremolo" groups="pdk" /> + <project path="external/turbine" name="platform/external/turbine" groups="pdk" /> + <project path="external/unicode" name="platform/external/unicode" groups="pdk" /> + <project path="external/universal-tween-engine" name="platform/external/universal-tween-engine" /> + <project path="external/v4l2_codec2" name="platform/external/v4l2_codec2" groups="pdk" /> + <project path="external/v8" name="platform/external/v8" groups="pdk" /> + <project path="external/valgrind" name="platform/external/valgrind" groups="pdk" /> + <project path="external/vboot_reference" name="platform/external/vboot_reference" groups="vboot,pdk-fs" /> + <project path="external/vixl" name="platform/external/vixl" groups="pdk" /> + <project path="external/vogar" name="platform/external/vogar" groups="pdk" /> + <project path="external/volley" name="platform/external/volley" groups="pdk" /> + <project path="external/vulkan-validation-layers" name="platform/external/vulkan-validation-layers" groups="pdk" /> + <project path="external/walt" name="platform/external/walt" groups="pdk" /> + <project path="external/webp" name="platform/external/webp" groups="pdk,qcom_msm8x26" /> + <project path="external/webrtc" name="platform/external/webrtc" groups="pdk" /> + <project path="external/webview_support_interfaces" name="platform/external/webview_support_interfaces" groups="pdk" /> + <project path="external/wpa_supplicant_8" name="platform/external/wpa_supplicant_8" groups="pdk" /> + <project path="external/wycheproof" name="platform/external/wycheproof" groups="pdk" /> + <project path="external/x264" name="platform/external/x264" groups="pdk" /> + <project path="external/xmlrpcpp" name="platform/external/xmlrpcpp" groups="pdk" /> + <project path="external/xmp_toolkit" name="platform/external/xmp_toolkit" groups="pdk" /> + <project path="external/xz-embedded" name="platform/external/xz-embedded" groups="pdk" /> + <project path="external/zlib" name="platform/external/zlib" groups="pdk" /> + <project path="external/zopfli" name="platform/external/zopfli" groups="pdk" /> + <project path="external/zxing" name="platform/external/zxing" groups="pdk" /> + <project path="frameworks/av" name="platform/frameworks/av" groups="pdk" /> + <project path="frameworks/base" name="platform/frameworks/base" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/compile/libbcc" name="platform/frameworks/compile/libbcc" groups="pdk" /> + <project path="frameworks/compile/mclinker" name="platform/frameworks/compile/mclinker" groups="pdk" /> + <project path="frameworks/compile/slang" name="platform/frameworks/compile/slang" groups="pdk" /> + <project path="frameworks/data-binding" name="platform/frameworks/data-binding" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/ex" name="platform/frameworks/ex" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/hardware/interfaces" name="platform/frameworks/hardware/interfaces" groups="pdk" /> + <project path="frameworks/layoutlib" name="platform/frameworks/layoutlib" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/minikin" name="platform/frameworks/minikin" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/ml" name="platform/frameworks/ml" groups="pdk" /> + <project path="frameworks/multidex" name="platform/frameworks/multidex" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/native" name="platform/frameworks/native" groups="pdk" /> + <project path="frameworks/opt/bitmap" name="platform/frameworks/opt/bitmap" groups="pdk-fs" /> + <project path="frameworks/opt/calendar" name="platform/frameworks/opt/calendar" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/opt/car/services" name="platform/frameworks/opt/car/services" groups="pdk-fs" /> + <project path="frameworks/opt/chips" name="platform/frameworks/opt/chips" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/opt/colorpicker" name="platform/frameworks/opt/colorpicker" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/opt/datetimepicker" name="platform/frameworks/opt/datetimepicker" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/opt/inputmethodcommon" name="platform/frameworks/opt/inputmethodcommon" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/opt/net/ethernet" name="platform/frameworks/opt/net/ethernet" groups="pdk-fs" /> + <project path="frameworks/opt/net/ims" name="platform/frameworks/opt/net/ims" groups="frameworks_ims,pdk-cw-fs,pdk-fs" /> + <project path="frameworks/opt/net/lowpan" name="platform/frameworks/opt/net/lowpan" groups="pdk-fs" /> + <project path="frameworks/opt/net/voip" name="platform/frameworks/opt/net/voip" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/opt/net/wifi" name="platform/frameworks/opt/net/wifi" groups="pdk" /> + <project path="frameworks/opt/photoviewer" name="platform/frameworks/opt/photoviewer" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/opt/setupwizard" name="platform/frameworks/opt/setupwizard" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/opt/telephony" name="platform/frameworks/opt/telephony" groups="pdk" /> + <project path="frameworks/opt/timezonepicker" name="platform/frameworks/opt/timezonepicker" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/opt/vcard" name="platform/frameworks/opt/vcard" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/rs" name="platform/frameworks/rs" groups="pdk" /> + <project path="frameworks/support" name="platform/frameworks/support" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/webview" name="platform/frameworks/webview" groups="pdk-cw-fs,pdk-fs" /> + <project path="frameworks/wilhelm" name="platform/frameworks/wilhelm" groups="pdk-cw-fs,pdk-fs" /> + <project path="hardware/akm" name="platform/hardware/akm" groups="pdk" /> + <project path="hardware/broadcom/libbt" name="platform/hardware/broadcom/libbt" groups="pdk" /> + <project path="hardware/broadcom/wlan" name="platform/hardware/broadcom/wlan" groups="pdk,broadcom_wlan" /> + <project path="hardware/google/apf" name="platform/hardware/google/apf" groups="pdk" /> + <project path="hardware/google/easel" name="platform/hardware/google/easel" groups="pdk,easel" /> + <project path="hardware/google/interfaces" name="platform/hardware/google/interfaces" groups="pdk" /> + <project path="hardware/intel/audio_media" name="platform/hardware/intel/audio_media" groups="intel,pdk" /> + <project path="hardware/intel/bootstub" name="platform/hardware/intel/bootstub" groups="intel,pdk" /> + <project path="hardware/intel/common/libmix" name="platform/hardware/intel/common/libmix" groups="intel,pdk" /> + <project path="hardware/intel/common/libstagefrighthw" name="platform/hardware/intel/common/libstagefrighthw" groups="intel,pdk" /> + <project path="hardware/intel/common/libva" name="platform/hardware/intel/common/libva" groups="intel,pdk" /> + <project path="hardware/intel/common/libwsbm" name="platform/hardware/intel/common/libwsbm" groups="intel,pdk" /> + <project path="hardware/intel/common/omx-components" name="platform/hardware/intel/common/omx-components" groups="intel,pdk" /> + <project path="hardware/intel/common/utils" name="platform/hardware/intel/common/utils" groups="intel,pdk" /> + <project path="hardware/intel/common/wrs_omxil_core" name="platform/hardware/intel/common/wrs_omxil_core" groups="intel,pdk" /> + <project path="hardware/intel/img/hwcomposer" name="platform/hardware/intel/img/hwcomposer" groups="intel,pdk" /> + <project path="hardware/intel/img/psb_headers" name="platform/hardware/intel/img/psb_headers" groups="intel,pdk" /> + <project path="hardware/intel/img/psb_video" name="platform/hardware/intel/img/psb_video" groups="intel,pdk" /> + <project path="hardware/interfaces" name="platform/hardware/interfaces" groups="pdk" /> + <project path="hardware/invensense" name="platform/hardware/invensense" groups="invensense,pdk" /> + <project path="hardware/libhardware" name="platform/hardware/libhardware" groups="pdk" /> + <project path="hardware/libhardware_legacy" name="platform/hardware/libhardware_legacy" groups="pdk" /> + <project path="hardware/marvell/bt" name="platform/hardware/marvell/bt" groups="marvell_bt,pdk" /> + <project path="hardware/nxp/nfc" name="platform/hardware/nxp/nfc" groups="pdk" /> + <project path="hardware/nxp/secure_element" name="platform/hardware/nxp/secure_element" groups="pdk" /> + <project path="hardware/qcom/audio" name="platform/hardware/qcom/audio" groups="qcom,qcom_audio,pdk" /> + <project path="hardware/qcom/bootctrl" name="platform/hardware/qcom/bootctrl" groups="pdk" /> + <project path="hardware/qcom/bt" name="platform/hardware/qcom/bt" groups="qcom,pdk" /> + <project path="hardware/qcom/camera" name="platform/hardware/qcom/camera" groups="qcom_camera,pdk" /> + <project path="hardware/qcom/data/ipacfg-mgr" name="platform/hardware/qcom/data/ipacfg-mgr" groups="qcom,pdk" /> + <project path="hardware/qcom/display" name="platform/hardware/qcom/display" groups="pdk,qcom,qcom_display" /> + <project path="hardware/qcom/gps" name="platform/hardware/qcom/gps" groups="qcom,qcom_gps,pdk" /> + <project path="hardware/qcom/keymaster" name="platform/hardware/qcom/keymaster" groups="qcom,qcom_keymaster,pdk" /> + <project path="hardware/qcom/media" name="platform/hardware/qcom/media" groups="qcom,pdk" /> + <project path="hardware/qcom/msm8960" name="platform/hardware/qcom/msm8960" groups="qcom_msm8960,pdk" /> + <project path="hardware/qcom/msm8994" name="platform/hardware/qcom/msm8994" groups="qcom_msm8994,pdk" /> + <project path="hardware/qcom/msm8996" name="platform/hardware/qcom/msm8996" groups="qcom_msm8996,pdk" /> + <project path="hardware/qcom/msm8998" name="platform/hardware/qcom/msm8998" groups="qcom_msm8998,pdk" /> + <project path="hardware/qcom/msm8x09" name="platform/hardware/qcom/msm8x09" groups="qcom_msm8x09" /> + <project path="hardware/qcom/msm8x26" name="platform/hardware/qcom/msm8x26" groups="qcom_msm8x26,pdk" /> + <project path="hardware/qcom/msm8x27" name="platform/hardware/qcom/msm8x27" groups="qcom_msm8x27,pdk" /> + <project path="hardware/qcom/msm8x84" name="platform/hardware/qcom/msm8x84" groups="qcom_msm8x84,pdk" /> + <project path="hardware/qcom/neuralnetworks/hvxservice" name="platform/hardware/qcom/neuralnetworks/hvxservice" groups="wahoo" /> + <project path="hardware/qcom/power" name="platform/hardware/qcom/power" groups="qcom,pdk" /> + <project path="hardware/qcom/wlan" name="platform/hardware/qcom/wlan" groups="qcom_wlan,pdk" /> + <project path="hardware/ril" name="platform/hardware/ril" groups="pdk" /> + <project path="hardware/st/nfc" name="platform/hardware/st/nfc" groups="pdk" /> + <project path="kernel/configs" name="kernel/configs" groups="vts,pdk" /> + <project path="kernel/tests" name="kernel/tests" /> + <project path="libcore" name="platform/libcore" groups="pdk" /> + <project path="libnativehelper" name="platform/libnativehelper" groups="pdk" /> + <project path="packages/apps/BasicSmsReceiver" name="platform/packages/apps/BasicSmsReceiver" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/apps/Bluetooth" name="platform/packages/apps/Bluetooth" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/apps/Browser2" name="platform/packages/apps/Browser2" groups="pdk-fs" /> + <project path="packages/apps/Calendar" name="platform/packages/apps/Calendar" groups="pdk-fs" /> + <project path="packages/apps/Camera2" name="platform/packages/apps/Camera2" groups="pdk-fs" /> + <project path="packages/apps/Car/Dialer" name="platform/packages/apps/Car/Dialer" groups="pdk-fs" /> + <project path="packages/apps/Car/Hvac" name="platform/packages/apps/Car/Hvac" groups="pdk-fs" /> + <project path="packages/apps/Car/LatinIME" name="platform/packages/apps/Car/LatinIME" groups="pdk-fs" /> + <project path="packages/apps/Car/Launcher" name="platform/packages/apps/Car/Launcher" groups="pdk-fs" /> + <project path="packages/apps/Car/LensPicker" name="platform/packages/apps/Car/LensPicker" groups="pdk-fs" /> + <project path="packages/apps/Car/libs" name="platform/packages/apps/Car/libs" groups="pdk-fs" /> + <project path="packages/apps/Car/LocalMediaPlayer" name="platform/packages/apps/Car/LocalMediaPlayer" groups="pdk-fs" /> + <project path="packages/apps/Car/Media" name="platform/packages/apps/Car/Media" groups="pdk-fs" /> + <project path="packages/apps/Car/Messenger" name="platform/packages/apps/Car/Messenger" groups="pdk-fs" /> + <project path="packages/apps/Car/Overview" name="platform/packages/apps/Car/Overview" groups="pdk-fs" /> + <project path="packages/apps/Car/Radio" name="platform/packages/apps/Car/Radio" groups="pdk-fs" /> + <project path="packages/apps/Car/Settings" name="platform/packages/apps/Car/Settings" groups="pdk-fs" /> + <project path="packages/apps/Car/Stream" name="platform/packages/apps/Car/Stream" groups="pdk-fs" /> + <project path="packages/apps/Car/SystemUpdater" name="platform/packages/apps/Car/SystemUpdater" groups="pdk-fs" /> + <project path="packages/apps/CarrierConfig" name="platform/packages/apps/CarrierConfig" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/apps/CellBroadcastReceiver" name="platform/packages/apps/CellBroadcastReceiver" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/apps/CertInstaller" name="platform/packages/apps/CertInstaller" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/apps/Contacts" name="platform/packages/apps/Contacts" groups="pdk-fs" /> + <project path="packages/apps/DeskClock" name="platform/packages/apps/DeskClock" groups="pdk-fs" /> + <project path="packages/apps/DevCamera" name="platform/packages/apps/DevCamera" groups="pdk" /> + <project path="packages/apps/Dialer" name="platform/packages/apps/Dialer" groups="pdk-fs" /> + <project path="packages/apps/DocumentsUI" name="platform/packages/apps/DocumentsUI" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/apps/Email" name="platform/packages/apps/Email" groups="pdk-fs" /> + <project path="packages/apps/EmergencyInfo" name="platform/packages/apps/EmergencyInfo" groups="pdk-fs" /> + <project path="packages/apps/ExactCalculator" name="platform/packages/apps/ExactCalculator" groups="pdk-fs" /> + <project path="packages/apps/Gallery" name="platform/packages/apps/Gallery" groups="pdk-fs" /> + <project path="packages/apps/Gallery2" name="platform/packages/apps/Gallery2" groups="pdk-fs" /> + <project path="packages/apps/HTMLViewer" name="platform/packages/apps/HTMLViewer" groups="pdk-fs" /> + <project path="packages/apps/KeyChain" name="platform/packages/apps/KeyChain" groups="pdk-fs" /> + <project path="packages/apps/Launcher2" name="platform/packages/apps/Launcher2" groups="pdk-fs" /> + <project path="packages/apps/Launcher3" name="platform/packages/apps/Launcher3" groups="pdk-fs" /> + <project path="packages/apps/LegacyCamera" name="platform/packages/apps/LegacyCamera" groups="pdk-fs" /> + <project path="packages/apps/ManagedProvisioning" name="platform/packages/apps/ManagedProvisioning" groups="pdk-fs" /> + <project path="packages/apps/Messaging" name="platform/packages/apps/Messaging" groups="pdk-fs" /> + <project path="packages/apps/Music" name="platform/packages/apps/Music" groups="pdk-fs" /> + <project path="packages/apps/MusicFX" name="platform/packages/apps/MusicFX" groups="pdk-fs" /> + <project path="packages/apps/Nfc" name="platform/packages/apps/Nfc" groups="apps_nfc,pdk-fs" /> + <project path="packages/apps/OneTimeInitializer" name="platform/packages/apps/OneTimeInitializer" groups="pdk-fs" /> + <project path="packages/apps/PackageInstaller" name="platform/packages/apps/PackageInstaller" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/apps/PhoneCommon" name="platform/packages/apps/PhoneCommon" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/apps/Protips" name="platform/packages/apps/Protips" groups="pdk-fs" /> + <project path="packages/apps/Provision" name="platform/packages/apps/Provision" groups="pdk-fs" /> + <project path="packages/apps/QuickSearchBox" name="platform/packages/apps/QuickSearchBox" groups="pdk-fs" /> + <project path="packages/apps/SafetyRegulatoryInfo" name="platform/packages/apps/SafetyRegulatoryInfo" groups="pdk-fs" /> + <project path="packages/apps/SecureElement" name="platform/packages/apps/SecureElement" groups="apps_se,pdk-fs" /> + <project path="packages/apps/Settings" name="platform/packages/apps/Settings" groups="pdk-fs" /> + <project path="packages/apps/SoundRecorder" name="platform/packages/apps/SoundRecorder" groups="pdk-fs" /> + <project path="packages/apps/SpareParts" name="platform/packages/apps/SpareParts" groups="pdk-fs" /> + <project path="packages/apps/Stk" name="platform/packages/apps/Stk" groups="apps_stk,pdk-fs" /> + <project path="packages/apps/StorageManager" name="platform/packages/apps/StorageManager" groups="pdk-fs" /> + <project path="packages/apps/Tag" name="platform/packages/apps/Tag" groups="pdk-fs" /> + <project path="packages/apps/Terminal" name="platform/packages/apps/Terminal" groups="pdk-fs" /> + <project path="packages/apps/Test/connectivity" name="platform/packages/apps/Test/connectivity" groups="pdk" /> + <project path="packages/apps/TimeZoneData" name="platform/packages/apps/TimeZoneData" groups="pdk" /> + <project path="packages/apps/TimeZoneUpdater" name="platform/packages/apps/TimeZoneUpdater" groups="pdk" /> + <project path="packages/apps/Traceur" name="platform/packages/apps/Traceur" groups="pdk-fs" /> + <project path="packages/apps/TvSettings" name="platform/packages/apps/TvSettings" groups="pdk-fs" /> + <project path="packages/apps/TV" name="platform/packages/apps/TV" /> + <project path="packages/apps/UnifiedEmail" name="platform/packages/apps/UnifiedEmail" groups="pdk-fs" /> + <project path="packages/apps/WallpaperPicker" name="platform/packages/apps/WallpaperPicker" groups="pdk-fs" /> + <project path="packages/experimental" name="platform/packages/experimental" /> + <project path="packages/inputmethods/LatinIME" name="platform/packages/inputmethods/LatinIME" groups="pdk-fs" /> + <project path="packages/inputmethods/OpenWnn" name="platform/packages/inputmethods/OpenWnn" groups="pdk-fs" /> + <project path="packages/providers/ApplicationsProvider" name="platform/packages/providers/ApplicationsProvider" groups="pdk-fs" /> + <project path="packages/providers/BlockedNumberProvider" name="platform/packages/providers/BlockedNumberProvider" groups="pdk-fs" /> + <project path="packages/providers/BookmarkProvider" name="platform/packages/providers/BookmarkProvider" groups="pdk-fs" /> + <project path="packages/providers/CalendarProvider" name="platform/packages/providers/CalendarProvider" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/providers/CallLogProvider" name="platform/packages/providers/CallLogProvider" groups="pdk-fs" /> + <project path="packages/providers/ContactsProvider" name="platform/packages/providers/ContactsProvider" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/providers/DownloadProvider" name="platform/packages/providers/DownloadProvider" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/providers/MediaProvider" name="platform/packages/providers/MediaProvider" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/providers/PartnerBookmarksProvider" name="platform/packages/providers/PartnerBookmarksProvider" groups="pdk-fs" /> + <project path="packages/providers/TelephonyProvider" name="platform/packages/providers/TelephonyProvider" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/providers/TvProvider" name="platform/packages/providers/TvProvider" groups="pdk-fs" /> + <project path="packages/providers/UserDictionaryProvider" name="platform/packages/providers/UserDictionaryProvider" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/screensavers/Basic" name="platform/packages/screensavers/Basic" groups="pdk-fs" /> + <project path="packages/screensavers/PhotoTable" name="platform/packages/screensavers/PhotoTable" groups="pdk-fs" /> + <project path="packages/screensavers/WebView" name="platform/packages/screensavers/WebView" groups="pdk-fs" /> + <project path="packages/services/BuiltInPrintService" name="platform/packages/services/BuiltInPrintService" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/services/Car" name="platform/packages/services/Car" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/services/Mms" name="platform/packages/services/Mms" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/services/NetworkRecommendation" name="platform/packages/services/NetworkRecommendation" groups="pdk-fs" /> + <project path="packages/services/Telecomm" name="platform/packages/services/Telecomm" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/services/Telephony" name="platform/packages/services/Telephony" groups="pdk-cw-fs,pdk-fs" /> + <project path="packages/wallpapers/LivePicker" name="platform/packages/wallpapers/LivePicker" groups="pdk-fs" /> + <project path="pdk" name="platform/pdk" groups="pdk" /> + <project path="platform_testing" name="platform/platform_testing" groups="pdk-fs,pdk-cw-fs,cts" /> + <project path="prebuilts/abi-dumps/ndk" name="platform/prebuilts/abi-dumps/ndk" groups="pdk-fs" clone-depth="1" /> + <project path="prebuilts/abi-dumps/vndk" name="platform/prebuilts/abi-dumps/vndk" groups="pdk-fs" clone-depth="1" /> + <project path="prebuilts/android-emulator" name="platform/prebuilts/android-emulator" groups="pdk-fs" clone-depth="1" /> + <project path="prebuilts/build-tools" name="platform/prebuilts/build-tools" groups="pdk" clone-depth="1" /> + <project path="prebuilts/checkstyle" name="platform/prebuilts/checkstyle" groups="pdk" clone-depth="1" /> + <project path="prebuilts/clang-tools" name="platform/prebuilts/clang-tools" groups="pdk" clone-depth="1" /> + <project path="prebuilts/clang/host/darwin-x86" name="platform/prebuilts/clang/host/darwin-x86" groups="pdk,darwin" clone-depth="1" /> + <project path="prebuilts/clang/host/linux-x86" name="platform/prebuilts/clang/host/linux-x86" groups="pdk" clone-depth="1" /> + <project path="prebuilts/deqp" name="platform/prebuilts/deqp" groups="pdk-fs" clone-depth="1" /> + <project path="prebuilts/devtools" name="platform/prebuilts/devtools" groups="pdk-fs" clone-depth="1" /> + <project path="prebuilts/gcc/darwin-x86/aarch64/aarch64-linux-android-4.9" name="platform/prebuilts/gcc/darwin-x86/aarch64/aarch64-linux-android-4.9" groups="pdk,darwin,arm" clone-depth="1" /> + <project path="prebuilts/gcc/darwin-x86/arm/arm-linux-androideabi-4.9" name="platform/prebuilts/gcc/darwin-x86/arm/arm-linux-androideabi-4.9" groups="pdk,darwin,arm" clone-depth="1" /> + <project path="prebuilts/gcc/darwin-x86/host/i686-apple-darwin-4.2.1" name="platform/prebuilts/gcc/darwin-x86/host/i686-apple-darwin-4.2.1" groups="pdk,darwin" clone-depth="1" /> + <project path="prebuilts/gcc/darwin-x86/mips/mips64el-linux-android-4.9" name="platform/prebuilts/gcc/darwin-x86/mips/mips64el-linux-android-4.9" groups="pdk,darwin,mips" clone-depth="1" /> + <project path="prebuilts/gcc/darwin-x86/x86/x86_64-linux-android-4.9" name="platform/prebuilts/gcc/darwin-x86/x86/x86_64-linux-android-4.9" groups="pdk,darwin,x86" clone-depth="1" /> + <project path="prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9" name="platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9" groups="pdk,linux,arm" clone-depth="1" /> + <project path="prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9" name="platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9" groups="pdk,linux,arm" clone-depth="1" /> + <project path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8" groups="pdk,linux" clone-depth="1" /> + <project path="prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8" name="platform/prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8" groups="pdk-fs" clone-depth="1" /> + <project path="prebuilts/gcc/linux-x86/mips/mips64el-linux-android-4.9" name="platform/prebuilts/gcc/linux-x86/mips/mips64el-linux-android-4.9" groups="pdk,linux,mips" clone-depth="1" /> + <project path="prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9" name="platform/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9" groups="pdk,linux,x86" clone-depth="1" /> + <project path="prebuilts/gdb/darwin-x86" name="platform/prebuilts/gdb/darwin-x86" groups="darwin" clone-depth="1" /> + <project path="prebuilts/gdb/linux-x86" name="platform/prebuilts/gdb/linux-x86" groups="linux" clone-depth="1" /> + <project path="prebuilts/go/darwin-x86" name="platform/prebuilts/go/darwin-x86" groups="darwin,pdk,tradefed" clone-depth="1" /> + <project path="prebuilts/go/linux-x86" name="platform/prebuilts/go/linux-x86" groups="linux,pdk,tradefed" clone-depth="1" /> + <project path="prebuilts/gradle-plugin" name="platform/prebuilts/gradle-plugin" groups="pdk-cw-fs,pdk-fs" clone-depth="1" /> + <project path="prebuilts/jdk/jdk8" name="platform/prebuilts/jdk/jdk8" groups="pdk" clone-depth="1" /> + <project path="prebuilts/jdk/jdk9" name="platform/prebuilts/jdk/jdk9" groups="pdk" clone-depth="1" /> + <project path="prebuilts/libs/libedit" name="platform/prebuilts/libs/libedit" groups="pdk-cw-fs,pdk-fs" clone-depth="1" /> + <project path="prebuilts/maven_repo/android" name="platform/prebuilts/maven_repo/android" groups="pdk-cw-fs,pdk-fs" clone-depth="1" /> + <project path="prebuilts/maven_repo/bumptech" name="platform/prebuilts/maven_repo/bumptech" groups="pdk-cw-fs,pdk-fs" clone-depth="1" /> + <project path="prebuilts/maven_repo/google-play-service-client-libraries-3p" name="platform/prebuilts/maven_repo/google-play-service-client-libraries-3p" clone-depth="1" /> + <project path="prebuilts/misc" name="platform/prebuilts/misc" groups="pdk" clone-depth="1" /> + <project path="prebuilts/ndk" name="platform/prebuilts/ndk" groups="pdk" clone-depth="1" /> + <project path="prebuilts/python/darwin-x86/2.7.5" name="platform/prebuilts/python/darwin-x86/2.7.5" groups="darwin,pdk,pdk-cw-fs,pdk-fs" clone-depth="1" /> + <project path="prebuilts/python/linux-x86/2.7.5" name="platform/prebuilts/python/linux-x86/2.7.5" groups="linux,pdk,pdk-cw-fs,pdk-fs" clone-depth="1" /> + <project path="prebuilts/qemu-kernel" name="platform/prebuilts/qemu-kernel" groups="pdk" clone-depth="1" /> + <project path="prebuilts/r8" name="platform/prebuilts/r8" groups="pdk" clone-depth="1" /> + <project path="prebuilts/sdk" name="platform/prebuilts/sdk" groups="pdk" clone-depth="1" /> + <project path="prebuilts/tools" name="platform/prebuilts/tools" groups="pdk,tools" clone-depth="1" /> + <project path="sdk" name="platform/sdk" groups="pdk-cw-fs,pdk-fs" /> + <project path="system/bt" name="platform/system/bt" groups="pdk" /> + <project path="system/ca-certificates" name="platform/system/ca-certificates" groups="pdk" /> + <project path="system/chre" name="platform/system/chre" groups="pdk" /> + <project path="system/connectivity/wificond" name="platform/system/connectivity/wificond" groups="pdk" /> + <project path="system/connectivity/wifilogd" name="platform/system/connectivity/wifilogd" groups="pdk" /> + <project path="system/core" name="platform/system/core" groups="pdk" /> + <project path="system/extras" name="platform/system/extras" groups="pdk" /> + <project path="system/gatekeeper" name="platform/system/gatekeeper" groups="pdk" /> + <project path="system/hardware/interfaces" name="platform/system/hardware/interfaces" groups="pdk" /> + <project path="system/hwservicemanager" name="platform/system/hwservicemanager" groups="pdk" /> + <project path="system/iot/attestation" name="platform/system/iot/attestation" groups="pdk" /> + <project path="system/keymaster" name="platform/system/keymaster" groups="pdk" /> + <project path="system/libfmq" name="platform/system/libfmq" groups="pdk" /> + <project path="system/libhidl" name="platform/system/libhidl" groups="pdk" /> + <project path="system/libhwbinder" name="platform/system/libhwbinder" groups="pdk" /> + <project path="system/libufdt" name="platform/system/libufdt" groups="pdk" /> + <project path="system/libvintf" name="platform/system/libvintf" groups="pdk" /> + <project path="system/media" name="platform/system/media" groups="pdk" /> + <project path="system/netd" name="platform/system/netd" groups="pdk" /> + <project path="system/nfc" name="platform/system/nfc" groups="pdk" /> + <project path="system/nvram" name="platform/system/nvram" groups="pdk" /> + <project path="system/security" name="platform/system/security" groups="pdk" /> + <project path="system/sepolicy" name="platform/system/sepolicy" groups="pdk" /> + <project path="system/timezone" name="platform/system/timezone" groups="pdk" /> + <project path="system/tools/aidl" name="platform/system/tools/aidl" groups="pdk-cw-fs,pdk-fs" /> + <project path="system/tools/bpt" name="platform/system/tools/bpt" groups="pdk" /> + <project path="system/tools/hidl" name="platform/system/tools/hidl" groups="pdk" /> + <project path="system/update_engine" name="platform/system/update_engine" groups="pdk" /> + <project path="system/vold" name="platform/system/vold" groups="pdk" /> + <project path="test/framework" name="platform/test/framework" groups="vts,pdk" /> + <project path="test/mlts/benchmark" name="platform/test/mlts/benchmark" groups="pdk" /> + <project path="test/mlts/models" name="platform/test/mlts/models" groups="pdk" /> + <project path="test/sts" name="platform/test/sts" groups="sts,pdk" /> + <project path="test/vti/alert" name="platform/test/vti/alert" groups="vts,pdk" /> + <project path="test/vti/dashboard" name="platform/test/vti/dashboard" groups="vts,pdk" /> + <project path="test/vti/fuzz_test_serving" name="platform/test/vti/fuzz_test_serving" groups="vts,pdk" /> + <project path="test/vti/test_serving" name="platform/test/vti/test_serving" groups="vts,pdk" /> + <project path="test/vts" name="platform/test/vts" groups="vts,pdk" /> + <project path="test/vts-testcase/fuzz" name="platform/test/vts-testcase/fuzz" groups="vts,pdk" /> + <project path="test/vts-testcase/hal" name="platform/test/vts-testcase/hal" groups="vts,pdk" /> + <project path="test/vts-testcase/hal-trace" name="platform/test/vts-testcase/hal-trace" groups="vts,pdk" /> + <project path="test/vts-testcase/kernel" name="platform/test/vts-testcase/kernel" groups="vts,pdk" /> + <project path="test/vts-testcase/nbu" name="platform/test/vts-testcase/nbu" groups="vts,pdk" /> + <project path="test/vts-testcase/performance" name="platform/test/vts-testcase/performance" groups="vts,pdk" /> + <project path="test/vts-testcase/security" name="platform/test/vts-testcase/security" groups="vts,pdk" /> + <project path="test/vts-testcase/vndk" name="platform/test/vts-testcase/vndk" groups="vts,pdk" /> + <project path="toolchain/benchmark" name="toolchain/benchmark" /> + <project path="toolchain/binutils" name="toolchain/binutils" groups="pdk" /> + <project path="toolchain/pgo-profiles" name="toolchain/pgo-profiles" groups="pdk" /> + <project path="tools/acloud" name="platform/tools/acloud" groups="tools,vts,pdk,tradefed" /> + <project path="tools/adt/idea" name="platform/tools/adt/idea" groups="notdefault,tools" /> + <project path="tools/apksig" name="platform/tools/apksig" groups="pdk,tradefed" /> + <project path="tools/apkzlib" name="platform/tools/apkzlib" groups="pdk,tradefed" /> + <project path="tools/base" name="platform/tools/base" groups="notdefault,tools" /> + <project path="tools/build" name="platform/tools/build" groups="notdefault,tools" /> + <project path="tools/dexter" name="platform/tools/dexter" groups="tools,pdk-fs" /> + <project path="tools/external/fat32lib" name="platform/tools/external/fat32lib" groups="tools" /> + <project path="tools/external/gradle" name="platform/tools/external/gradle" groups="tools" clone-depth="1" /> + <project path="tools/idea" name="platform/tools/idea" groups="notdefault,tools" /> + <project path="tools/loganalysis" name="platform/tools/loganalysis" groups="nopresubmit,pdk,tradefed" /> + <project path="tools/metalava" name="platform/tools/metalava" groups="tools" /> + <project path="tools/motodev" name="platform/tools/motodev" groups="notdefault,motodev" /> + <project path="tools/repohooks" name="platform/tools/repohooks" groups="adt-infra,cts,developers,motodev,pdk,tools,tradefed" /> + <project path="tools/security" name="platform/tools/security" groups="pdk,tools" /> + <project path="tools/studio/cloud" name="platform/tools/studio/cloud" groups="notdefault,tools" /> + <project path="tools/swt" name="platform/tools/swt" groups="notdefault,tools" /> + <project path="tools/test/connectivity" name="platform/tools/test/connectivity" groups="pdk" /> + <project path="tools/test/graphicsbenchmark" name="platform/tools/test/graphicsbenchmark" groups="pdk" /> + <project path="tools/tradefederation/core" name="platform/tools/tradefederation" groups="pdk,tradefed" /> + <project path="tools/tradefederation/contrib" name="platform/tools/tradefederation/contrib" groups="pdk,tradefed" /> + + <repo-hooks in-project="platform/tools/repohooks" enabled-list="pre-upload" /> + +</manifest> diff --git a/spec/fixtures/project_export.tar.gz b/spec/fixtures/project_export.tar.gz Binary files differnew file mode 100644 index 00000000000..72ab2d71f35 --- /dev/null +++ b/spec/fixtures/project_export.tar.gz diff --git a/spec/fixtures/trace/sample_trace b/spec/fixtures/trace/sample_trace index c65cf05d5ca..7bfe3f83b7b 100644 --- a/spec/fixtures/trace/sample_trace +++ b/spec/fixtures/trace/sample_trace @@ -41,7 +41,7 @@ From https://gitlab.com/gitlab-org/gitlab-ce section_end:1522927113:get_sources [0Ksection_start:1522927113:restore_cache [0K[32;1mChecking cache for ruby-2.3.6-with-yarn...[0;m -Downloading cache.zip from http://runners-cache-5-internal.gitlab.com:444/runner/project/13083/ruby-2.3.6-with-yarn[0;m +Downloading cache.zip from http://runners-cache-5-internal.gitlab.com:444/runner/project/13083/ruby-2.3.6-with-yarn[0;m [32;1mSuccessfully extracted cache[0;m section_end:1522927128:restore_cache [0Ksection_start:1522927128:download_artifacts @@ -51,7 +51,7 @@ Downloading artifacts from coordinator... ok [0;m id[0;m=61303215 respon Downloading artifacts from coordinator... ok [0;m id[0;m=61303216 responseStatus[0;m=200 OK token[0;m=iy2yYbq8 [32;1mDownloading artifacts for setup-test-env (61303217)...[0;m Downloading artifacts from coordinator... ok [0;m id[0;m=61303217 responseStatus[0;m=200 OK token[0;m=ur1g79-4 -[0;33mWARNING: tmp/tests/gitlab-shell/.gitlab_shell_secret: chmod tmp/tests/gitlab-shell/.gitlab_shell_secret: no such file or directory (suppressing repeats)[0;m +[0;33mWARNING: tmp/tests/gitlab-shell/.gitlab_shell_secret: chmod tmp/tests/gitlab-shell/.gitlab_shell_secret: no such file or directory (suppressing repeats)[0;m section_end:1522927141:download_artifacts [0Ksection_start:1522927141:build_script [0K[32;1m$ bundle --version[0;m @@ -1486,7 +1486,7 @@ Gitlab::ImportExport::ProjectTreeSaver overrides the project description group members does not export group members if it has no permission - does not export group members as master + does not export group members as maintainer exports group members as group owner as admin exports group members as admin @@ -1690,7 +1690,7 @@ GroupsController and logged in as Developer behaves like member without ability to create subgroups renders the 404 page (PENDING: around hook at ./spec/spec_helper.rb:186 did not execute the example) - and logged in as Master + and logged in as Maintainer behaves like member without ability to create subgroups renders the 404 page (PENDING: around hook at ./spec/spec_helper.rb:186 did not execute the example) and can_create_group is false @@ -1706,7 +1706,7 @@ GroupsController and logged in as Developer behaves like member without ability to create subgroups renders the 404 page (PENDING: around hook at ./spec/spec_helper.rb:186 did not execute the example) - and logged in as Master + and logged in as Maintainer behaves like member without ability to create subgroups renders the 404 page (PENDING: around hook at ./spec/spec_helper.rb:186 did not execute the example) GET #activity @@ -2324,7 +2324,7 @@ Editing file blob shows blob editor with same branch with protected branch shows blob editor with patch branch - as master + as maintainer shows blob editor with same branch Boards::Lists::MoveService @@ -2880,7 +2880,7 @@ API::V3::Environments won't update the external_url if only the name is passed returns a 404 if the environment does not exist DELETE /projects/:id/environments/:environment_id - as a master + as a maintainer returns a 200 for an existing environment returns a 404 for non existing id a non member @@ -3001,11 +3001,11 @@ LfsFileLock #can_be_unlocked_by? when it's forced can be unlocked by the author - can be unlocked by a master + can be unlocked by a maintainer can't be unlocked by other user when it isn't forced can be unlocked by the author - can't be unlocked by a master + can't be unlocked by a maintainer can't be unlocked by other user Gitlab::Ci::Config::Entry::Boolean @@ -3069,7 +3069,7 @@ Pending: (Failures listed here are expected and do not affect your suite's statu # around hook at ./spec/spec_helper.rb:186 did not execute the example # ./spec/controllers/groups_controller_spec.rb:25 - 5) GroupsController GET #new when creating subgroups and can_create_group is true and logged in as Master behaves like member without ability to create subgroups renders the 404 page + 5) GroupsController GET #new when creating subgroups and can_create_group is true and logged in as Maintainer behaves like member without ability to create subgroups renders the 404 page # around hook at ./spec/spec_helper.rb:186 did not execute the example # ./spec/controllers/groups_controller_spec.rb:25 @@ -3089,7 +3089,7 @@ Pending: (Failures listed here are expected and do not affect your suite's statu # around hook at ./spec/spec_helper.rb:186 did not execute the example # ./spec/controllers/groups_controller_spec.rb:25 - 10) GroupsController GET #new when creating subgroups and can_create_group is false and logged in as Master behaves like member without ability to create subgroups renders the 404 page + 10) GroupsController GET #new when creating subgroups and can_create_group is false and logged in as Maintainer behaves like member without ability to create subgroups renders the 404 page # around hook at ./spec/spec_helper.rb:186 did not execute the example # ./spec/controllers/groups_controller_spec.rb:25 @@ -3237,7 +3237,7 @@ Pending: (Failures listed here are expected and do not affect your suite's statu # around hook at ./spec/spec_helper.rb:190 did not execute the example # ./spec/services/groups/transfer_service_spec.rb:212 - 47) Groups::TransferService#execute when transferring a subgroup into another group when the group is allowed to be transferred should update parent group to the new parent + 47) Groups::TransferService#execute when transferring a subgroup into another group when the group is allowed to be transferred should update parent group to the new parent # around hook at ./spec/spec_helper.rb:190 did not execute the example # ./spec/services/groups/transfer_service_spec.rb:216 @@ -3435,10 +3435,10 @@ section_end:1522927515:after_script section_end:1522927516:archive_cache [0Ksection_start:1522927516:upload_artifacts [0K[32;1mUploading artifacts...[0;m -coverage/: found 5 matching files [0;m -knapsack/: found 5 matching files [0;m -rspec_flaky/: found 4 matching files [0;m -[0;33mWARNING: tmp/capybara/: no matching files [0;m +coverage/: found 5 matching files [0;m +knapsack/: found 5 matching files [0;m +rspec_flaky/: found 4 matching files [0;m +[0;33mWARNING: tmp/capybara/: no matching files [0;m Uploading artifacts to coordinator... ok [0;m id[0;m=61303283 responseStatus[0;m=201 Created token[0;m=rusBKvxM section_end:1522927520:upload_artifacts [0K[32;1mJob succeeded diff --git a/spec/graphql/gitlab_schema_spec.rb b/spec/graphql/gitlab_schema_spec.rb index b892f6b44ed..515bbe78cb7 100644 --- a/spec/graphql/gitlab_schema_spec.rb +++ b/spec/graphql/gitlab_schema_spec.rb @@ -27,6 +27,12 @@ describe GitlabSchema do expect(described_class.query).to eq(::Types::QueryType.to_graphql) end + it 'paginates active record relations using `Gitlab::Graphql::Connections::KeysetConnection`' do + connection = GraphQL::Relay::BaseConnection::CONNECTION_IMPLEMENTATIONS[ActiveRecord::Relation.name] + + expect(connection).to eq(Gitlab::Graphql::Connections::KeysetConnection) + end + def field_instrumenters described_class.instrumenters[:field] end diff --git a/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb b/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb new file mode 100644 index 00000000000..ea7159eacf9 --- /dev/null +++ b/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe ResolvesPipelines do + include GraphqlHelpers + + subject(:resolver) do + Class.new(Resolvers::BaseResolver) do + include ResolvesPipelines + + def resolve(**args) + resolve_pipelines(object, args) + end + end + end + + let(:current_user) { create(:user) } + set(:project) { create(:project, :private) } + set(:pipeline) { create(:ci_pipeline, project: project) } + set(:failed_pipeline) { create(:ci_pipeline, :failed, project: project) } + set(:ref_pipeline) { create(:ci_pipeline, project: project, ref: 'awesome-feature') } + set(:sha_pipeline) { create(:ci_pipeline, project: project, sha: 'deadbeef') } + + before do + project.add_developer(current_user) + end + + it { is_expected.to have_graphql_arguments(:status, :ref, :sha) } + + it 'finds all pipelines' do + expect(resolve_pipelines).to contain_exactly(pipeline, failed_pipeline, ref_pipeline, sha_pipeline) + end + + it 'allows filtering by status' do + expect(resolve_pipelines(status: 'failed')).to contain_exactly(failed_pipeline) + end + + it 'allows filtering by ref' do + expect(resolve_pipelines(ref: 'awesome-feature')).to contain_exactly(ref_pipeline) + end + + it 'allows filtering by sha' do + expect(resolve_pipelines(sha: 'deadbeef')).to contain_exactly(sha_pipeline) + end + + it 'does not return any pipelines if the user does not have access' do + expect(resolve_pipelines({}, {})).to be_empty + end + + def resolve_pipelines(args = {}, context = { current_user: current_user }) + resolve(resolver, obj: project, args: args, ctx: context) + end +end diff --git a/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb b/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb new file mode 100644 index 00000000000..09b17bf6fc9 --- /dev/null +++ b/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe Resolvers::MergeRequestPipelinesResolver do + include GraphqlHelpers + + set(:merge_request) { create(:merge_request) } + set(:pipeline) do + create( + :ci_pipeline, + project: merge_request.source_project, + ref: merge_request.source_branch, + sha: merge_request.diff_head_sha + ) + end + set(:other_project_pipeline) { create(:ci_pipeline, project: merge_request.source_project) } + set(:other_pipeline) { create(:ci_pipeline) } + let(:current_user) { create(:user) } + + before do + merge_request.project.add_developer(current_user) + end + + def resolve_pipelines + resolve(described_class, obj: merge_request, ctx: { current_user: current_user }) + end + + it 'resolves only MRs for the passed merge request' do + expect(resolve_pipelines).to contain_exactly(pipeline) + end +end diff --git a/spec/graphql/resolvers/project_pipelines_resolver_spec.rb b/spec/graphql/resolvers/project_pipelines_resolver_spec.rb new file mode 100644 index 00000000000..407ca2f9d78 --- /dev/null +++ b/spec/graphql/resolvers/project_pipelines_resolver_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe Resolvers::ProjectPipelinesResolver do + include GraphqlHelpers + + set(:project) { create(:project) } + set(:pipeline) { create(:ci_pipeline, project: project) } + set(:other_pipeline) { create(:ci_pipeline) } + let(:current_user) { create(:user) } + + before do + project.add_developer(current_user) + end + + def resolve_pipelines + resolve(described_class, obj: project, ctx: { current_user: current_user }) + end + + it 'resolves only MRs for the passed merge request' do + expect(resolve_pipelines).to contain_exactly(pipeline) + end +end diff --git a/spec/graphql/types/ci/pipeline_type_spec.rb b/spec/graphql/types/ci/pipeline_type_spec.rb new file mode 100644 index 00000000000..ec1c689a4be --- /dev/null +++ b/spec/graphql/types/ci/pipeline_type_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe Types::Ci::PipelineType do + it { expect(described_class.graphql_name).to eq('Pipeline') } + + it { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Ci::Pipeline) } +end diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index 6e57122867a..c369953e3ea 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -1,5 +1,16 @@ require 'spec_helper' -describe Types::MergeRequestType do +describe GitlabSchema.types['MergeRequest'] do it { expect(described_class).to expose_permissions_using(Types::PermissionTypes::MergeRequest) } + + describe 'head pipeline' do + it 'has a head pipeline field' do + expect(described_class).to have_graphql_field(:head_pipeline) + end + + it 'authorizes the field' do + expect(described_class.fields['headPipeline']) + .to require_graphql_authorizations(:read_pipeline) + end + end end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index 7b5bc335511..49606c397b9 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -13,4 +13,6 @@ describe GitlabSchema.types['Project'] do .to require_graphql_authorizations(:read_merge_request) end end + + it { is_expected.to have_graphql_field(:pipelines) } end diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb index a3e010c3206..1c216b3fe97 100644 --- a/spec/helpers/blob_helper_spec.rb +++ b/spec/helpers/blob_helper_spec.rb @@ -65,9 +65,9 @@ describe BlobHelper do describe "#sanitize_svg_data" do let(:input_svg_path) { File.join(Rails.root, 'spec', 'fixtures', 'unsanitized.svg') } - let(:data) { open(input_svg_path).read } + let(:data) { File.read(input_svg_path) } let(:expected_svg_path) { File.join(Rails.root, 'spec', 'fixtures', 'sanitized.svg') } - let(:expected) { open(expected_svg_path).read } + let(:expected) { File.read(expected_svg_path) } it 'retains essential elements' do expect(sanitize_svg_data(data)).to eq(expected) diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb index 6c94bd4e504..115807f954b 100644 --- a/spec/helpers/groups_helper_spec.rb +++ b/spec/helpers/groups_helper_spec.rb @@ -206,8 +206,9 @@ describe GroupsHelper do let(:group) { create(:group, :public) } let(:user) { create(:user) } before do + group.add_owner(user) allow(helper).to receive(:current_user) { user } - allow(helper).to receive(:can?) { true } + allow(helper).to receive(:can?) { |*args| Ability.allowed?(*args) } helper.instance_variable_set(:@group, group) end @@ -231,7 +232,10 @@ describe GroupsHelper do cross_project_features = [:activity, :issues, :labels, :milestones, :merge_requests] - expect(helper).to receive(:can?).with(user, :read_cross_project) { false } + allow(Ability).to receive(:allowed?).and_call_original + cross_project_features.each do |feature| + expect(Ability).to receive(:allowed?).with(user, "read_group_#{feature}".to_sym, group) { false } + end expect(helper.group_sidebar_links).not_to include(*cross_project_features) end diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb index cddb49b320f..77410e0070c 100644 --- a/spec/helpers/issuables_helper_spec.rb +++ b/spec/helpers/issuables_helper_spec.rb @@ -163,6 +163,7 @@ describe IssuablesHelper do issuableRef: "##{issue.iid}", markdownPreviewPath: "/#{@project.full_path}/preview_markdown", markdownDocsPath: '/help/user/markdown', + markdownVersion: 11, issuableTemplates: [], projectPath: @project.path, projectNamespace: @project.namespace.path, diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb index 1a720aae55c..597648b064d 100644 --- a/spec/helpers/markup_helper_spec.rb +++ b/spec/helpers/markup_helper_spec.rb @@ -11,7 +11,7 @@ describe MarkupHelper do before do # Ensure the generated reference links aren't redacted - project.add_master(user) + project.add_maintainer(user) # Helper expects a @project instance variable helper.instance_variable_set(:@project, project) @@ -205,7 +205,9 @@ describe MarkupHelper do it "uses Wiki pipeline for markdown files" do allow(@wiki).to receive(:format).and_return(:markdown) - expect(helper).to receive(:markdown_unsafe).with('wiki content', pipeline: :wiki, project: project, project_wiki: @wiki, page_slug: "nested/page", issuable_state_filter_enabled: true) + expect(helper).to receive(:markdown_unsafe).with('wiki content', + pipeline: :wiki, project: project, project_wiki: @wiki, page_slug: "nested/page", + issuable_state_filter_enabled: true, markdown_engine: :redcarpet) helper.render_wiki_content(@wiki) end @@ -236,19 +238,32 @@ describe MarkupHelper do expect(helper.markup('foo.rst', content).encoding.name).to eq('UTF-8') end - it "delegates to #markdown_unsafe when file name corresponds to Markdown" do + it 'delegates to #markdown_unsafe when file name corresponds to Markdown' do expect(helper).to receive(:gitlab_markdown?).with('foo.md').and_return(true) expect(helper).to receive(:markdown_unsafe).and_return('NOEL') expect(helper.markup('foo.md', content)).to eq('NOEL') end - it "delegates to #asciidoc_unsafe when file name corresponds to AsciiDoc" do + it 'delegates to #asciidoc_unsafe when file name corresponds to AsciiDoc' do expect(helper).to receive(:asciidoc?).with('foo.adoc').and_return(true) expect(helper).to receive(:asciidoc_unsafe).and_return('NOEL') expect(helper.markup('foo.adoc', content)).to eq('NOEL') end + + it 'uses passed in rendered content' do + expect(helper).not_to receive(:gitlab_markdown?) + expect(helper).not_to receive(:markdown_unsafe) + + expect(helper.markup('foo.md', content, rendered: '<p>NOEL</p>')).to eq('<p>NOEL</p>') + end + + it 'defaults to Redcarpet' do + expect(helper).to receive(:markdown_unsafe).with(content, hash_including(markdown_engine: :redcarpet)).and_return('NOEL') + + expect(helper.markup('foo.md', content)).to eq('NOEL') + end end describe '#first_line_in_markdown' do diff --git a/spec/helpers/namespaces_helper_spec.rb b/spec/helpers/namespaces_helper_spec.rb index 460d3b6a7e4..343e140f5fb 100644 --- a/spec/helpers/namespaces_helper_spec.rb +++ b/spec/helpers/namespaces_helper_spec.rb @@ -28,6 +28,16 @@ describe NamespacesHelper do expect(options).not_to include(admin_group.name) expect(options).to include(user_group.name) + expect(options).to include(user.name) + end + + it 'returns only groups if groups_only option is true' do + allow(helper).to receive(:current_user).and_return(user) + + options = helper.namespaces_options(nil, groups_only: true) + + expect(options).not_to include(user.name) + expect(options).to include(user_group.name) end context 'when nested groups are available', :nested_groups do diff --git a/spec/helpers/notes_helper_spec.rb b/spec/helpers/notes_helper_spec.rb index b992bdb4a5e..21461e46cf4 100644 --- a/spec/helpers/notes_helper_spec.rb +++ b/spec/helpers/notes_helper_spec.rb @@ -6,18 +6,18 @@ describe NotesHelper do let(:owner) { create(:owner) } let(:group) { create(:group) } let(:project) { create(:project, namespace: group) } - let(:master) { create(:user) } + let(:maintainer) { create(:user) } let(:reporter) { create(:user) } let(:guest) { create(:user) } let(:owner_note) { create(:note, author: owner, project: project) } - let(:master_note) { create(:note, author: master, project: project) } + let(:maintainer_note) { create(:note, author: maintainer, project: project) } let(:reporter_note) { create(:note, author: reporter, project: project) } - let!(:notes) { [owner_note, master_note, reporter_note] } + let!(:notes) { [owner_note, maintainer_note, reporter_note] } before do group.add_owner(owner) - project.add_master(master) + project.add_maintainer(maintainer) project.add_reporter(reporter) project.add_guest(guest) end @@ -25,16 +25,16 @@ describe NotesHelper do describe "#notes_max_access_for_users" do it 'returns access levels' do expect(helper.note_max_access_for_user(owner_note)).to eq(Gitlab::Access::OWNER) - expect(helper.note_max_access_for_user(master_note)).to eq(Gitlab::Access::MASTER) + expect(helper.note_max_access_for_user(maintainer_note)).to eq(Gitlab::Access::MAINTAINER) expect(helper.note_max_access_for_user(reporter_note)).to eq(Gitlab::Access::REPORTER) end it 'handles access in different projects' do second_project = create(:project) - second_project.add_reporter(master) - other_note = create(:note, author: master, project: second_project) + second_project.add_reporter(maintainer) + other_note = create(:note, author: maintainer, project: second_project) - expect(helper.note_max_access_for_user(master_note)).to eq(Gitlab::Access::MASTER) + expect(helper.note_max_access_for_user(maintainer_note)).to eq(Gitlab::Access::MAINTAINER) expect(helper.note_max_access_for_user(other_note)).to eq(Gitlab::Access::REPORTER) end end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 80147b13739..beb6e8ea273 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -80,6 +80,7 @@ describe ProjectsHelper do before do allow(helper).to receive(:current_user).and_return(user) allow(helper).to receive(:can?).with(user, :read_cross_project) { true } + allow(user).to receive(:max_member_access_for_project).and_return(40) end it "includes the route" do @@ -125,6 +126,10 @@ describe ProjectsHelper do expect(helper.project_list_cache_key(project)).to include("pipeline-status/#{project.commit.sha}-success") end + + it "includes the user max member access" do + expect(helper.project_list_cache_key(project)).to include('access:40') + end end describe '#load_pipeline_status' do diff --git a/spec/helpers/time_helper_spec.rb b/spec/helpers/time_helper_spec.rb index 21f35585367..0b371d69ecf 100644 --- a/spec/helpers/time_helper_spec.rb +++ b/spec/helpers/time_helper_spec.rb @@ -4,10 +4,12 @@ describe TimeHelper do describe "#time_interval_in_words" do it "returns minutes and seconds" do intervals_in_words = { - 100 => "1 minute 40 seconds", - 100.32 => "1 minute 40 seconds", - 121 => "2 minutes 1 second", - 3721 => "62 minutes 1 second", + 60 => "1 minute", + 100 => "1 minute and 40 seconds", + 100.32 => "1 minute and 40 seconds", + 120 => "2 minutes", + 121 => "2 minutes and 1 second", + 3721 => "62 minutes and 1 second", 0 => "0 seconds" } diff --git a/spec/javascripts/diffs/components/changed_files_spec.js b/spec/javascripts/diffs/components/changed_files_spec.js index 2d57af6137c..f737e8fa38e 100644 --- a/spec/javascripts/diffs/components/changed_files_spec.js +++ b/spec/javascripts/diffs/components/changed_files_spec.js @@ -1,12 +1,17 @@ import Vue from 'vue'; -import $ from 'jquery'; +import Vuex from 'vuex'; import { mountComponentWithStore } from 'spec/helpers'; -import store from '~/diffs/store'; -import ChangedFiles from '~/diffs/components/changed_files.vue'; +import diffsModule from '~/diffs/store/modules'; +import changedFiles from '~/diffs/components/changed_files.vue'; describe('ChangedFiles', () => { - const Component = Vue.extend(ChangedFiles); - const createComponent = props => mountComponentWithStore(Component, { props, store }); + const Component = Vue.extend(changedFiles); + const store = new Vuex.Store({ + modules: { + diffs: diffsModule, + }, + }); + let vm; beforeEach(() => { @@ -14,6 +19,7 @@ describe('ChangedFiles', () => { <div id="dummy-element"></div> <div class="js-tabs-affix"></div> `); + const props = { diffFiles: [ { @@ -26,7 +32,8 @@ describe('ChangedFiles', () => { }, ], }; - vm = createComponent(props); + + vm = mountComponentWithStore(Component, { props, store }); }); describe('with single file added', () => { @@ -40,58 +47,56 @@ describe('ChangedFiles', () => { }); }); - describe('template', () => { - describe('diff view mode buttons', () => { - let inlineButton; - let parallelButton; + describe('diff view mode buttons', () => { + let inlineButton; + let parallelButton; - beforeEach(() => { - inlineButton = vm.$el.querySelector('.js-inline-diff-button'); - parallelButton = vm.$el.querySelector('.js-parallel-diff-button'); - }); + beforeEach(() => { + inlineButton = vm.$el.querySelector('.js-inline-diff-button'); + parallelButton = vm.$el.querySelector('.js-parallel-diff-button'); + }); + + it('should have Inline and Side-by-side buttons', () => { + expect(inlineButton).toBeDefined(); + expect(parallelButton).toBeDefined(); + }); + + it('should add active class to Inline button', done => { + vm.$store.state.diffs.diffViewType = 'inline'; + + vm.$nextTick(() => { + expect(inlineButton.classList.contains('active')).toEqual(true); + expect(parallelButton.classList.contains('active')).toEqual(false); - it('should have Inline and Side-by-side buttons', () => { - expect(inlineButton).toBeDefined(); - expect(parallelButton).toBeDefined(); + done(); }); + }); - it('should add active class to Inline button', done => { - vm.$store.state.diffs.diffViewType = 'inline'; + it('should toggle active state of buttons when diff view type changed', done => { + vm.$store.state.diffs.diffViewType = 'parallel'; - vm.$nextTick(() => { - expect(inlineButton.classList.contains('active')).toEqual(true); - expect(parallelButton.classList.contains('active')).toEqual(false); + vm.$nextTick(() => { + expect(inlineButton.classList.contains('active')).toEqual(false); + expect(parallelButton.classList.contains('active')).toEqual(true); - done(); - }); + done(); }); + }); - it('should toggle active state of buttons when diff view type changed', done => { - vm.$store.state.diffs.diffViewType = 'parallel'; + describe('clicking them', () => { + it('should toggle the diff view type', done => { + parallelButton.click(); vm.$nextTick(() => { expect(inlineButton.classList.contains('active')).toEqual(false); expect(parallelButton.classList.contains('active')).toEqual(true); - done(); - }); - }); - - describe('clicking them', () => { - it('should toggle the diff view type', done => { - $(parallelButton).click(); + inlineButton.click(); vm.$nextTick(() => { - expect(inlineButton.classList.contains('active')).toEqual(false); - expect(parallelButton.classList.contains('active')).toEqual(true); - - $(inlineButton).click(); - - vm.$nextTick(() => { - expect(inlineButton.classList.contains('active')).toEqual(true); - expect(parallelButton.classList.contains('active')).toEqual(false); - done(); - }); + expect(inlineButton.classList.contains('active')).toEqual(true); + expect(parallelButton.classList.contains('active')).toEqual(false); + done(); }); }); }); diff --git a/spec/javascripts/diffs/components/diff_file_header_spec.js b/spec/javascripts/diffs/components/diff_file_header_spec.js index d0f1700bee6..0f3a95da5bf 100644 --- a/spec/javascripts/diffs/components/diff_file_header_spec.js +++ b/spec/javascripts/diffs/components/diff_file_header_spec.js @@ -1,7 +1,10 @@ import Vue from 'vue'; +import Vuex from 'vuex'; +import diffsModule from '~/diffs/store/modules'; +import notesModule from '~/notes/stores/modules'; import DiffFileHeader from '~/diffs/components/diff_file_header.vue'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; -import mountComponent from 'spec/helpers/vue_mount_component_helper'; +import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; const discussionFixture = 'merge_requests/diff_discussion.json'; @@ -9,6 +12,12 @@ describe('diff_file_header', () => { let vm; let props; const Component = Vue.extend(DiffFileHeader); + const store = new Vuex.Store({ + modules: { + diffs: diffsModule, + notes: notesModule, + }, + }); beforeEach(() => { const diffDiscussionMock = getJSONFixture(discussionFixture)[0]; @@ -26,13 +35,13 @@ describe('diff_file_header', () => { describe('computed', () => { describe('icon', () => { beforeEach(() => { - props.diffFile.blob.icon = 'dummy icon'; + props.diffFile.blob.icon = 'file-text-o'; }); it('returns the blob icon for files', () => { props.diffFile.submodule = false; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.icon).toBe(props.diffFile.blob.icon); }); @@ -40,7 +49,7 @@ describe('diff_file_header', () => { it('returns the archive icon for submodules', () => { props.diffFile.submodule = true; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.icon).toBe('archive'); }); @@ -58,7 +67,7 @@ describe('diff_file_header', () => { it('returns the fileHash for files', () => { props.diffFile.submodule = false; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.titleLink).toBe(`#${props.diffFile.fileHash}`); }); @@ -66,7 +75,7 @@ describe('diff_file_header', () => { it('returns the submoduleTreeUrl for submodules', () => { props.diffFile.submodule = true; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.titleLink).toBe(props.diffFile.submoduleTreeUrl); }); @@ -77,7 +86,7 @@ describe('diff_file_header', () => { submoduleTreeUrl: null, }); - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.titleLink).toBe(props.diffFile.submoduleLink); }); @@ -94,7 +103,7 @@ describe('diff_file_header', () => { it('returns the filePath for files', () => { props.diffFile.submodule = false; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.filePath).toBe(props.diffFile.filePath); }); @@ -102,7 +111,7 @@ describe('diff_file_header', () => { it('appends the truncated blob id for submodules', () => { props.diffFile.submodule = true; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.filePath).toBe( `${props.diffFile.filePath} @ ${props.diffFile.blob.id.substr(0, 8)}`, @@ -114,7 +123,7 @@ describe('diff_file_header', () => { it('returns a link tag if fileHash is set', () => { props.diffFile.fileHash = 'some hash'; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.titleTag).toBe('a'); }); @@ -122,7 +131,7 @@ describe('diff_file_header', () => { it('returns a span tag if fileHash is not set', () => { props.diffFile.fileHash = null; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.titleTag).toBe('span'); }); @@ -137,7 +146,7 @@ describe('diff_file_header', () => { }); it('returns true if file is stored in LFS', () => { - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.isUsingLfs).toBe(true); }); @@ -145,7 +154,7 @@ describe('diff_file_header', () => { it('returns false if file is not stored externally', () => { props.diffFile.storedExternally = false; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.isUsingLfs).toBe(false); }); @@ -153,7 +162,7 @@ describe('diff_file_header', () => { it('returns false if file is not stored in LFS', () => { props.diffFile.externalStorage = 'not lfs'; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.isUsingLfs).toBe(false); }); @@ -163,7 +172,7 @@ describe('diff_file_header', () => { it('returns chevron-down if the diff is expanded', () => { props.expanded = true; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.collapseIcon).toBe('chevron-down'); }); @@ -171,49 +180,18 @@ describe('diff_file_header', () => { it('returns chevron-right if the diff is collapsed', () => { props.expanded = false; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.collapseIcon).toBe('chevron-right'); }); }); - describe('isDiscussionsExpanded', () => { - beforeEach(() => { - Object.assign(props, { - discussionsExpanded: true, - expanded: true, - }); - }); - - it('returns true if diff and discussion are expanded', () => { - vm = mountComponent(Component, props); - - expect(vm.isDiscussionsExpanded).toBe(true); - }); - - it('returns false if discussion is collapsed', () => { - props.discussionsExpanded = false; - - vm = mountComponent(Component, props); - - expect(vm.isDiscussionsExpanded).toBe(false); - }); - - it('returns false if diff is collapsed', () => { - props.expanded = false; - - vm = mountComponent(Component, props); - - expect(vm.isDiscussionsExpanded).toBe(false); - }); - }); - describe('viewFileButtonText', () => { it('contains the truncated content SHA', () => { const dummySha = 'deebd00f is no SHA'; props.diffFile.contentSha = dummySha; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.viewFileButtonText).not.toContain(dummySha); expect(vm.viewFileButtonText).toContain(dummySha.substr(0, 8)); @@ -225,7 +203,7 @@ describe('diff_file_header', () => { const dummySha = 'deadabba sings no more'; props.diffFile.diffRefs.baseSha = dummySha; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.viewReplacedFileButtonText).not.toContain(dummySha); expect(vm.viewReplacedFileButtonText).toContain(dummySha.substr(0, 8)); @@ -234,25 +212,25 @@ describe('diff_file_header', () => { }); describe('methods', () => { - describe('handleToggle', () => { + describe('handleToggleFile', () => { beforeEach(() => { spyOn(vm, '$emit').and.stub(); }); it('emits toggleFile if checkTarget is false', () => { - vm.handleToggle(null, false); + vm.handleToggleFile(null, false); expect(vm.$emit).toHaveBeenCalledWith('toggleFile'); }); it('emits toggleFile if checkTarget is true and event target is header', () => { - vm.handleToggle({ target: vm.$refs.header }, true); + vm.handleToggleFile({ target: vm.$refs.header }, true); expect(vm.$emit).toHaveBeenCalledWith('toggleFile'); }); it('does not emit toggleFile if checkTarget is true and event target is not header', () => { - vm.handleToggle({ target: 'not header' }, true); + vm.handleToggleFile({ target: 'not header' }, true); expect(vm.$emit).not.toHaveBeenCalled(); }); @@ -266,7 +244,7 @@ describe('diff_file_header', () => { it('is visible if collapsible is true', () => { props.collapsible = true; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(collapseToggle()).not.toBe(null); }); @@ -274,17 +252,17 @@ describe('diff_file_header', () => { it('is hidden if collapsible is false', () => { props.collapsible = false; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(collapseToggle()).toBe(null); }); }); - it('displays an icon in the title', () => { - vm = mountComponent(Component, props); - - const icon = vm.$el.querySelector(`i[class="fa fa-fw fa-${vm.icon}"]`); - expect(icon).not.toBe(null); + it('displays an file icon in the title', () => { + vm = mountComponentWithStore(Component, { props, store }); + expect(vm.$el.querySelector('svg.js-file-icon use').getAttribute('xlink:href')).toContain( + 'ruby', + ); }); describe('file paths', () => { @@ -293,7 +271,7 @@ describe('diff_file_header', () => { it('displays the path of a added file', () => { props.diffFile.renamedFile = false; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(filePaths()).toHaveLength(1); expect(filePaths()[0]).toHaveText(props.diffFile.filePath); @@ -303,7 +281,7 @@ describe('diff_file_header', () => { props.diffFile.renamedFile = false; props.diffFile.deletedFile = true; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(filePaths()).toHaveLength(1); expect(filePaths()[0]).toHaveText(`${props.diffFile.filePath} deleted`); @@ -312,7 +290,7 @@ describe('diff_file_header', () => { it('displays old and new path if the file was renamed', () => { props.diffFile.renamedFile = true; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(filePaths()).toHaveLength(2); expect(filePaths()[0]).toHaveText(props.diffFile.oldPath); @@ -321,7 +299,7 @@ describe('diff_file_header', () => { }); it('displays a copy to clipboard button', () => { - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); const button = vm.$el.querySelector('.btn-clipboard'); expect(button).not.toBe(null); @@ -332,7 +310,7 @@ describe('diff_file_header', () => { it('it displays old and new file mode if it changed', () => { props.diffFile.modeChanged = true; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); const { fileMode } = vm.$refs; expect(fileMode).not.toBe(undefined); @@ -343,7 +321,7 @@ describe('diff_file_header', () => { it('does not display the file mode if it has not changed', () => { props.diffFile.modeChanged = false; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); const { fileMode } = vm.$refs; expect(fileMode).toBe(undefined); @@ -359,7 +337,7 @@ describe('diff_file_header', () => { externalStorage: 'lfs', }); - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(lfsLabel()).not.toBe(null); expect(lfsLabel()).toHaveText('LFS'); @@ -368,7 +346,7 @@ describe('diff_file_header', () => { it('does not display the LFS label for files stored in repository', () => { props.diffFile.storedExternally = false; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(lfsLabel()).toBe(null); }); @@ -376,7 +354,7 @@ describe('diff_file_header', () => { describe('edit button', () => { it('should not render edit button if addMergeRequestButtons is not true', () => { - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.$el.querySelector('.js-edit-blob')).toEqual(null); }); @@ -384,7 +362,7 @@ describe('diff_file_header', () => { it('should show edit button when file is editable', () => { props.addMergeRequestButtons = true; props.diffFile.editPath = '/'; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.$el.querySelector('.js-edit-blob')).toContainText('Edit'); }); @@ -393,7 +371,7 @@ describe('diff_file_header', () => { props.addMergeRequestButtons = true; props.diffFile.deletedFile = true; props.diffFile.editPath = '/'; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.$el.querySelector('.js-edit-blob')).toEqual(null); }); @@ -413,7 +391,7 @@ describe('diff_file_header', () => { props.diffFile.externalUrl = url; props.diffFile.formattedExternalUrl = title; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.$el.querySelector(`a[href="${url}"]`)).not.toBe(null); expect(vm.$el.querySelector(`a[data-original-title="View on ${title}"]`)).not.toBe(null); @@ -423,11 +401,39 @@ describe('diff_file_header', () => { props.diffFile.externalUrl = ''; props.diffFile.formattedExternalUrl = title; - vm = mountComponent(Component, props); + vm = mountComponentWithStore(Component, { props, store }); expect(vm.$el.querySelector(`a[data-original-title="View on ${title}"]`)).toBe(null); }); }); }); + + describe('handles toggle discussions', () => { + it('dispatches toggleFileDiscussions when user clicks on toggle discussions button', () => { + const propsCopy = Object.assign({}, props); + propsCopy.diffFile.submodule = false; + propsCopy.diffFile.blob = { + id: '848ed9407c6730ff16edb3dd24485a0eea24292a', + path: 'lib/base.js', + name: 'base.js', + mode: '100644', + readableText: true, + icon: 'file-text-o', + }; + propsCopy.addMergeRequestButtons = true; + propsCopy.diffFile.deletedFile = true; + + vm = mountComponentWithStore(Component, { + props: propsCopy, + store, + }); + + spyOn(vm, 'toggleFileDiscussions'); + + vm.$el.querySelector('.js-btn-vue-toggle-comments').click(); + + expect(vm.toggleFileDiscussions).toHaveBeenCalled(); + }); + }); }); }); diff --git a/spec/javascripts/diffs/components/diff_file_spec.js b/spec/javascripts/diffs/components/diff_file_spec.js index 1c1edfac68c..9b994543e19 100644 --- a/spec/javascripts/diffs/components/diff_file_spec.js +++ b/spec/javascripts/diffs/components/diff_file_spec.js @@ -31,12 +31,12 @@ describe('DiffFile', () => { describe('collapsed', () => { it('should not have file content', done => { - expect(vm.$el.querySelectorAll('.diff-content.hidden').length).toEqual(0); + expect(vm.$el.querySelectorAll('.diff-content').length).toEqual(1); expect(vm.file.collapsed).toEqual(false); vm.file.collapsed = true; vm.$nextTick(() => { - expect(vm.$el.querySelectorAll('.diff-content.hidden').length).toEqual(1); + expect(vm.$el.querySelectorAll('.diff-content').length).toEqual(0); done(); }); diff --git a/spec/javascripts/diffs/components/inline_diff_view_spec.js b/spec/javascripts/diffs/components/inline_diff_view_spec.js index e1adf60962e..b02328dd359 100644 --- a/spec/javascripts/diffs/components/inline_diff_view_spec.js +++ b/spec/javascripts/diffs/components/inline_diff_view_spec.js @@ -13,7 +13,7 @@ describe('InlineDiffView', () => { beforeEach(() => { const diffFile = getDiffFileMock(); - store.dispatch('setInlineDiffViewType'); + store.dispatch('diffs/setInlineDiffViewType'); component = createComponentWithStore(Vue.extend(InlineDiffView), store, { diffFile, diffLines: diffFile.highlightedDiffLines, diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js index 6829c1e956a..c1560dac1a0 100644 --- a/spec/javascripts/diffs/store/actions_spec.js +++ b/spec/javascripts/diffs/store/actions_spec.js @@ -191,4 +191,48 @@ describe('DiffsStoreActions', () => { ); }); }); + + describe('toggleFileDiscussions', () => { + it('should dispatch collapseDiscussion when all discussions are expanded', () => { + const getters = { + getDiffFileDiscussions: jasmine.createSpy().and.returnValue([{ id: 1 }]), + diffHasAllExpandedDiscussions: jasmine.createSpy().and.returnValue(true), + diffHasAllCollpasedDiscussions: jasmine.createSpy().and.returnValue(false), + }; + + const dispatch = jasmine.createSpy('dispatch'); + + actions.toggleFileDiscussions({ getters, dispatch }); + + expect(dispatch).toHaveBeenCalledWith('collapseDiscussion', { discussionId: 1 }, { root: true }); + }); + + it('should dispatch expandDiscussion when all discussions are collapsed', () => { + const getters = { + getDiffFileDiscussions: jasmine.createSpy().and.returnValue([{ id: 1 }]), + diffHasAllExpandedDiscussions: jasmine.createSpy().and.returnValue(false), + diffHasAllCollpasedDiscussions: jasmine.createSpy().and.returnValue(true), + }; + + const dispatch = jasmine.createSpy(); + + actions.toggleFileDiscussions({ getters, dispatch }); + + expect(dispatch).toHaveBeenCalledWith('expandDiscussion', { discussionId: 1 }, { root: true }); + }); + + it('should dispatch expandDiscussion when some discussions are collapsed and others are expanded for the collapsed discussion', () => { + const getters = { + getDiffFileDiscussions: jasmine.createSpy().and.returnValue([{ expanded: false, id: 1 }]), + diffHasAllExpandedDiscussions: jasmine.createSpy().and.returnValue(false), + diffHasAllCollpasedDiscussions: jasmine.createSpy().and.returnValue(false), + }; + + const dispatch = jasmine.createSpy(); + + actions.toggleFileDiscussions({ getters, dispatch }); + + expect(dispatch).toHaveBeenCalledWith('expandDiscussion', { discussionId: 1 }, { root: true }); + }); + }); }); diff --git a/spec/javascripts/diffs/store/getters_spec.js b/spec/javascripts/diffs/store/getters_spec.js index 7945ddea911..919b612bb6a 100644 --- a/spec/javascripts/diffs/store/getters_spec.js +++ b/spec/javascripts/diffs/store/getters_spec.js @@ -1,24 +1,187 @@ -import getters from '~/diffs/store/getters'; +import * as getters from '~/diffs/store/getters'; +import state from '~/diffs/store/modules/diff_state'; import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '~/diffs/constants'; +import discussion from '../mock_data/diff_discussions'; + +describe('Diffs Module Getters', () => { + let localState; + let discussionMock; + let discussionMock1; + + const diffFileMock = { + fileHash: '9732849daca6ae818696d9575f5d1207d1a7f8bb', + }; + + beforeEach(() => { + localState = state(); + discussionMock = Object.assign({}, discussion); + discussionMock.diff_file.file_hash = diffFileMock.fileHash; + + discussionMock1 = Object.assign({}, discussion); + discussionMock1.diff_file.file_hash = diffFileMock.fileHash; + }); -describe('DiffsStoreGetters', () => { describe('isParallelView', () => { it('should return true if view set to parallel view', () => { - expect(getters.isParallelView({ diffViewType: PARALLEL_DIFF_VIEW_TYPE })).toBeTruthy(); + localState.diffViewType = PARALLEL_DIFF_VIEW_TYPE; + + expect(getters.isParallelView(localState)).toEqual(true); }); it('should return false if view not to parallel view', () => { - expect(getters.isParallelView({ diffViewType: 'foo' })).toBeFalsy(); + localState.diffViewType = INLINE_DIFF_VIEW_TYPE; + + expect(getters.isParallelView(localState)).toEqual(false); }); }); describe('isInlineView', () => { it('should return true if view set to inline view', () => { - expect(getters.isInlineView({ diffViewType: INLINE_DIFF_VIEW_TYPE })).toBeTruthy(); + localState.diffViewType = INLINE_DIFF_VIEW_TYPE; + + expect(getters.isInlineView(localState)).toEqual(true); }); it('should return false if view not to inline view', () => { - expect(getters.isInlineView({ diffViewType: PARALLEL_DIFF_VIEW_TYPE })).toBeFalsy(); + localState.diffViewType = PARALLEL_DIFF_VIEW_TYPE; + + expect(getters.isInlineView(localState)).toEqual(false); + }); + }); + + describe('areAllFilesCollapsed', () => { + it('returns true when all files are collapsed', () => { + localState.diffFiles = [{ collapsed: true }, { collapsed: true }]; + expect(getters.areAllFilesCollapsed(localState)).toEqual(true); + }); + + it('returns false when at least one file is not collapsed', () => { + localState.diffFiles = [{ collapsed: false }, { collapsed: true }]; + expect(getters.areAllFilesCollapsed(localState)).toEqual(false); + }); + }); + + describe('commitId', () => { + it('returns commit id when is set', () => { + const commitID = '800f7a91'; + localState.commit = { + id: commitID, + }; + + expect(getters.commitId(localState)).toEqual(commitID); + }); + + it('returns null when no commit is set', () => { + expect(getters.commitId(localState)).toEqual(null); + }); + }); + + describe('diffHasAllExpandedDiscussions', () => { + it('returns true when all discussions are expanded', () => { + expect( + getters.diffHasAllExpandedDiscussions(localState, { + getDiffFileDiscussions: () => [discussionMock, discussionMock], + })(diffFileMock), + ).toEqual(true); + }); + + it('returns false when there are no discussions', () => { + expect( + getters.diffHasAllExpandedDiscussions(localState, { + getDiffFileDiscussions: () => [], + })(diffFileMock), + ).toEqual(false); + }); + + it('returns false when one discussions is collapsed', () => { + discussionMock1.expanded = false; + + expect( + getters.diffHasAllExpandedDiscussions(localState, { + getDiffFileDiscussions: () => [discussionMock, discussionMock1], + })(diffFileMock), + ).toEqual(false); + }); + }); + + describe('diffHasAllCollpasedDiscussions', () => { + it('returns true when all discussions are collapsed', () => { + discussionMock.diff_file.file_hash = diffFileMock.fileHash; + discussionMock.expanded = false; + + expect( + getters.diffHasAllCollpasedDiscussions(localState, { + getDiffFileDiscussions: () => [discussionMock], + })(diffFileMock), + ).toEqual(true); + }); + + it('returns false when there are no discussions', () => { + expect( + getters.diffHasAllCollpasedDiscussions(localState, { + getDiffFileDiscussions: () => [], + })(diffFileMock), + ).toEqual(false); + }); + + it('returns false when one discussions is expanded', () => { + discussionMock1.expanded = false; + + expect( + getters.diffHasAllCollpasedDiscussions(localState, { + getDiffFileDiscussions: () => [discussionMock, discussionMock1], + })(diffFileMock), + ).toEqual(false); + }); + }); + + describe('diffHasExpandedDiscussions', () => { + it('returns true when one of the discussions is expanded', () => { + discussionMock1.expanded = false; + + expect( + getters.diffHasExpandedDiscussions(localState, { + getDiffFileDiscussions: () => [discussionMock, discussionMock], + })(diffFileMock), + ).toEqual(true); + }); + + it('returns false when there are no discussions', () => { + expect( + getters.diffHasExpandedDiscussions(localState, { getDiffFileDiscussions: () => [] })( + diffFileMock, + ), + ).toEqual(false); + }); + + it('returns false when no discussion is expanded', () => { + discussionMock.expanded = false; + discussionMock1.expanded = false; + + expect( + getters.diffHasExpandedDiscussions(localState, { + getDiffFileDiscussions: () => [discussionMock, discussionMock1], + })(diffFileMock), + ).toEqual(false); + }); + }); + + describe('getDiffFileDiscussions', () => { + it('returns an array with discussions when fileHash matches and the discussion belongs to a diff', () => { + discussionMock.diff_file.file_hash = diffFileMock.fileHash; + + expect( + getters.getDiffFileDiscussions(localState, {}, {}, { discussions: [discussionMock] })( + diffFileMock, + ).length, + ).toEqual(1); + }); + + it('returns an empty array when no discussions are found in the given diff', () => { + expect( + getters.getDiffFileDiscussions(localState, {}, {}, { discussions: [] })(diffFileMock) + .length, + ).toEqual(0); }); }); }); diff --git a/spec/javascripts/diffs/store/mutations_spec.js b/spec/javascripts/diffs/store/mutations_spec.js index 02836fcaeea..1af49f4985c 100644 --- a/spec/javascripts/diffs/store/mutations_spec.js +++ b/spec/javascripts/diffs/store/mutations_spec.js @@ -24,21 +24,6 @@ describe('DiffsStoreMutations', () => { }); }); - describe('SET_DIFF_FILES', () => { - it('should set diff files to state', () => { - const filePath = '/first-diff-file-path'; - const state = {}; - const diffFiles = { - a_mode: 1, - highlighted_diff_lines: [{ file_path: filePath }], - }; - - mutations[types.SET_DIFF_FILES](state, diffFiles); - expect(state.diffFiles.aMode).toEqual(1); - expect(state.diffFiles.highlightedDiffLines[0].filePath).toEqual(filePath); - }); - }); - describe('SET_DIFF_VIEW_TYPE', () => { it('should set diff view type properly', () => { const state = {}; diff --git a/spec/javascripts/diffs/store/utils_spec.js b/spec/javascripts/diffs/store/utils_spec.js index 5a024a0f2ad..32136d9ebff 100644 --- a/spec/javascripts/diffs/store/utils_spec.js +++ b/spec/javascripts/diffs/store/utils_spec.js @@ -176,4 +176,35 @@ describe('DiffsStoreUtils', () => { expect(linesWithReferences[1].metaData.newPos).toEqual(3); }); }); + + describe('trimFirstCharOfLineContent', () => { + it('trims the line when it starts with a space', () => { + expect(utils.trimFirstCharOfLineContent({ richText: ' diff' })).toEqual({ richText: 'diff' }); + }); + + it('trims the line when it starts with a +', () => { + expect(utils.trimFirstCharOfLineContent({ richText: '+diff' })).toEqual({ richText: 'diff' }); + }); + + it('trims the line when it starts with a -', () => { + expect(utils.trimFirstCharOfLineContent({ richText: '-diff' })).toEqual({ richText: 'diff' }); + }); + + it('does not trims the line when it starts with a letter', () => { + expect(utils.trimFirstCharOfLineContent({ richText: 'diff' })).toEqual({ richText: 'diff' }); + }); + + it('does not modify the provided object', () => { + const lineObj = { + richText: ' diff', + }; + + utils.trimFirstCharOfLineContent(lineObj); + expect(lineObj).toEqual({ richText: ' diff' }); + }); + + it('handles a undefined or null parameter', () => { + expect(utils.trimFirstCharOfLineContent()).toEqual({}); + }); + }); }); diff --git a/spec/javascripts/environments/environment_rollback_spec.js b/spec/javascripts/environments/environment_rollback_spec.js index eb8e49d81fe..79f33c5bc8a 100644 --- a/spec/javascripts/environments/environment_rollback_spec.js +++ b/spec/javascripts/environments/environment_rollback_spec.js @@ -18,7 +18,7 @@ describe('Rollback Component', () => { }, }).$mount(); - expect(component.$el.querySelector('span').textContent).toContain('Re-deploy'); + expect(component.$el).toHaveSpriteIcon('repeat'); }); it('Should render Rollback label when isLastDeployment is false', () => { @@ -30,6 +30,6 @@ describe('Rollback Component', () => { }, }).$mount(); - expect(component.$el.querySelector('span').textContent).toContain('Rollback'); + expect(component.$el).toHaveSpriteIcon('redo'); }); }); diff --git a/spec/javascripts/environments/environment_stop_spec.js b/spec/javascripts/environments/environment_stop_spec.js index 3f95faf466a..4d9caa57566 100644 --- a/spec/javascripts/environments/environment_stop_spec.js +++ b/spec/javascripts/environments/environment_stop_spec.js @@ -4,7 +4,6 @@ import stopComp from '~/environments/components/environment_stop.vue'; describe('Stop Component', () => { let StopComponent; let component; - const stopURL = '/stop'; beforeEach(() => { StopComponent = Vue.extend(stopComp); @@ -12,20 +11,13 @@ describe('Stop Component', () => { component = new StopComponent({ propsData: { - stopUrl: stopURL, + environment: {}, }, }).$mount(); }); - describe('computed', () => { - it('title', () => { - expect(component.title).toEqual('Stop'); - }); - }); - it('should render a button to stop the environment', () => { expect(component.$el.tagName).toEqual('BUTTON'); - expect(component.$el.getAttribute('data-original-title')).toEqual('Stop'); - expect(component.$el.getAttribute('aria-label')).toEqual('Stop'); + expect(component.$el.getAttribute('data-original-title')).toEqual('Stop environment'); }); }); diff --git a/spec/javascripts/fixtures/commit.rb b/spec/javascripts/fixtures/commit.rb index 351db6ba184..24ab8159a18 100644 --- a/spec/javascripts/fixtures/commit.rb +++ b/spec/javascripts/fixtures/commit.rb @@ -14,7 +14,7 @@ describe Projects::CommitController, '(JavaScript fixtures)', type: :controller end before do - project.add_master(user) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/javascripts/fixtures/groups.rb b/spec/javascripts/fixtures/groups.rb index 35be52fbf97..a2035ceae15 100644 --- a/spec/javascripts/fixtures/groups.rb +++ b/spec/javascripts/fixtures/groups.rb @@ -13,7 +13,7 @@ describe 'Groups (JavaScript fixtures)', type: :controller do end before do - group.add_master(admin) + group.add_maintainer(admin) sign_in(admin) end diff --git a/spec/javascripts/fixtures/merge_requests.rb b/spec/javascripts/fixtures/merge_requests.rb index ee60489eb7c..7257d0c8556 100644 --- a/spec/javascripts/fixtures/merge_requests.rb +++ b/spec/javascripts/fixtures/merge_requests.rb @@ -80,6 +80,13 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont render_discussions_json(merge_request, example.description) end + it 'merge_requests/resolved_diff_discussion.json' do |example| + note = create(:discussion_note_on_merge_request, :resolved, project: project, author: admin, position: position, noteable: merge_request) + create(:system_note, project: project, author: admin, noteable: merge_request, discussion_id: note.discussion.id) + + render_discussions_json(merge_request, example.description) + end + context 'with image diff' do let(:merge_request2) { create(:merge_request_with_diffs, :with_image_diffs, source_project: project, title: "Added images") } let(:image_path) { "files/images/ee_repo_logo.png" } diff --git a/spec/javascripts/fixtures/projects.rb b/spec/javascripts/fixtures/projects.rb index e8865b04874..57c78182abc 100644 --- a/spec/javascripts/fixtures/projects.rb +++ b/spec/javascripts/fixtures/projects.rb @@ -17,7 +17,7 @@ describe 'Projects (JavaScript fixtures)', type: :controller do end before do - project.add_master(admin) + project.add_maintainer(admin) sign_in(admin) end diff --git a/spec/javascripts/frequent_items/components/app_spec.js b/spec/javascripts/frequent_items/components/app_spec.js new file mode 100644 index 00000000000..834f919524d --- /dev/null +++ b/spec/javascripts/frequent_items/components/app_spec.js @@ -0,0 +1,251 @@ +import MockAdapter from 'axios-mock-adapter'; +import axios from '~/lib/utils/axios_utils'; +import Vue from 'vue'; +import appComponent from '~/frequent_items/components/app.vue'; +import eventHub from '~/frequent_items/event_hub'; +import store from '~/frequent_items/store'; +import { FREQUENT_ITEMS, HOUR_IN_MS } from '~/frequent_items/constants'; +import { getTopFrequentItems } from '~/frequent_items/utils'; +import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; +import { currentSession, mockFrequentProjects, mockSearchedProjects } from '../mock_data'; + +let session; +const createComponentWithStore = (namespace = 'projects') => { + session = currentSession[namespace]; + gon.api_version = session.apiVersion; + const Component = Vue.extend(appComponent); + + return mountComponentWithStore(Component, { + store, + props: { + namespace, + currentUserName: session.username, + currentItem: session.project || session.group, + }, + }); +}; + +describe('Frequent Items App Component', () => { + let vm; + let mock; + + beforeEach(() => { + mock = new MockAdapter(axios); + vm = createComponentWithStore(); + }); + + afterEach(() => { + mock.restore(); + vm.$destroy(); + }); + + describe('methods', () => { + describe('dropdownOpenHandler', () => { + it('should fetch frequent items when no search has been previously made on desktop', () => { + spyOn(vm, 'fetchFrequentItems'); + + vm.dropdownOpenHandler(); + + expect(vm.fetchFrequentItems).toHaveBeenCalledWith(); + }); + }); + + describe('logItemAccess', () => { + let storage; + + beforeEach(() => { + storage = {}; + + spyOn(window.localStorage, 'setItem').and.callFake((storageKey, value) => { + storage[storageKey] = value; + }); + + spyOn(window.localStorage, 'getItem').and.callFake(storageKey => { + if (storage[storageKey]) { + return storage[storageKey]; + } + + return null; + }); + }); + + it('should create a project store if it does not exist and adds a project', () => { + vm.logItemAccess(session.storageKey, session.project); + + const projects = JSON.parse(storage[session.storageKey]); + + expect(projects.length).toBe(1); + expect(projects[0].frequency).toBe(1); + expect(projects[0].lastAccessedOn).toBeDefined(); + }); + + it('should prevent inserting same report multiple times into store', () => { + vm.logItemAccess(session.storageKey, session.project); + vm.logItemAccess(session.storageKey, session.project); + + const projects = JSON.parse(storage[session.storageKey]); + + expect(projects.length).toBe(1); + }); + + it('should increase frequency of report if it was logged multiple times over the course of an hour', () => { + let projects; + const newTimestamp = Date.now() + HOUR_IN_MS + 1; + + vm.logItemAccess(session.storageKey, session.project); + projects = JSON.parse(storage[session.storageKey]); + + expect(projects[0].frequency).toBe(1); + + vm.logItemAccess(session.storageKey, { + ...session.project, + lastAccessedOn: newTimestamp, + }); + projects = JSON.parse(storage[session.storageKey]); + + expect(projects[0].frequency).toBe(2); + expect(projects[0].lastAccessedOn).not.toBe(session.project.lastAccessedOn); + }); + + it('should always update project metadata', () => { + let projects; + const oldProject = { + ...session.project, + }; + + const newProject = { + ...session.project, + name: 'New Name', + avatarUrl: 'new/avatar.png', + namespace: 'New / Namespace', + webUrl: 'http://localhost/new/web/url', + }; + + vm.logItemAccess(session.storageKey, oldProject); + projects = JSON.parse(storage[session.storageKey]); + + expect(projects[0].name).toBe(oldProject.name); + expect(projects[0].avatarUrl).toBe(oldProject.avatarUrl); + expect(projects[0].namespace).toBe(oldProject.namespace); + expect(projects[0].webUrl).toBe(oldProject.webUrl); + + vm.logItemAccess(session.storageKey, newProject); + projects = JSON.parse(storage[session.storageKey]); + + expect(projects[0].name).toBe(newProject.name); + expect(projects[0].avatarUrl).toBe(newProject.avatarUrl); + expect(projects[0].namespace).toBe(newProject.namespace); + expect(projects[0].webUrl).toBe(newProject.webUrl); + }); + + it('should not add more than 20 projects in store', () => { + for (let id = 0; id < FREQUENT_ITEMS.MAX_COUNT; id += 1) { + const project = { + ...session.project, + id, + }; + vm.logItemAccess(session.storageKey, project); + } + + const projects = JSON.parse(storage[session.storageKey]); + + expect(projects.length).toBe(FREQUENT_ITEMS.MAX_COUNT); + }); + }); + }); + + describe('created', () => { + it('should bind event listeners on eventHub', done => { + spyOn(eventHub, '$on'); + + createComponentWithStore().$mount(); + + Vue.nextTick(() => { + expect(eventHub.$on).toHaveBeenCalledWith('projects-dropdownOpen', jasmine.any(Function)); + done(); + }); + }); + }); + + describe('beforeDestroy', () => { + it('should unbind event listeners on eventHub', done => { + spyOn(eventHub, '$off'); + + vm.$mount(); + vm.$destroy(); + + Vue.nextTick(() => { + expect(eventHub.$off).toHaveBeenCalledWith('projects-dropdownOpen', jasmine.any(Function)); + done(); + }); + }); + }); + + describe('template', () => { + it('should render search input', () => { + expect(vm.$el.querySelector('.search-input-container')).toBeDefined(); + }); + + it('should render loading animation', done => { + vm.$store.dispatch('fetchSearchedItems'); + + Vue.nextTick(() => { + const loadingEl = vm.$el.querySelector('.loading-animation'); + + expect(loadingEl).toBeDefined(); + expect(loadingEl.classList.contains('prepend-top-20')).toBe(true); + expect(loadingEl.querySelector('i').getAttribute('aria-label')).toBe('Loading projects'); + done(); + }); + }); + + it('should render frequent projects list header', done => { + Vue.nextTick(() => { + const sectionHeaderEl = vm.$el.querySelector('.section-header'); + + expect(sectionHeaderEl).toBeDefined(); + expect(sectionHeaderEl.innerText.trim()).toBe('Frequently visited'); + done(); + }); + }); + + it('should render frequent projects list', done => { + const expectedResult = getTopFrequentItems(mockFrequentProjects); + spyOn(window.localStorage, 'getItem').and.callFake(() => + JSON.stringify(mockFrequentProjects), + ); + + expect(vm.$el.querySelectorAll('.frequent-items-list-container li').length).toBe(1); + + vm.fetchFrequentItems(); + Vue.nextTick(() => { + expect(vm.$el.querySelectorAll('.frequent-items-list-container li').length).toBe( + expectedResult.length, + ); + done(); + }); + }); + + it('should render searched projects list', done => { + mock.onGet(/\/api\/v4\/projects.json(.*)$/).replyOnce(200, mockSearchedProjects); + + expect(vm.$el.querySelectorAll('.frequent-items-list-container li').length).toBe(1); + + vm.$store.dispatch('setSearchQuery', 'gitlab'); + vm + .$nextTick() + .then(() => { + expect(vm.$el.querySelector('.loading-animation')).toBeDefined(); + }) + .then(vm.$nextTick) + .then(vm.$nextTick) + .then(() => { + expect(vm.$el.querySelectorAll('.frequent-items-list-container li').length).toBe( + mockSearchedProjects.length, + ); + }) + .then(done) + .catch(done.fail); + }); + }); +}); diff --git a/spec/javascripts/projects_dropdown/components/projects_list_item_spec.js b/spec/javascripts/frequent_items/components/frequent_items_list_item_spec.js index c193258474e..201aca77b10 100644 --- a/spec/javascripts/projects_dropdown/components/projects_list_item_spec.js +++ b/spec/javascripts/frequent_items/components/frequent_items_list_item_spec.js @@ -1,23 +1,21 @@ import Vue from 'vue'; - -import projectsListItemComponent from '~/projects_dropdown/components/projects_list_item.vue'; - +import frequentItemsListItemComponent from '~/frequent_items/components/frequent_items_list_item.vue'; import mountComponent from 'spec/helpers/vue_mount_component_helper'; -import { mockProject } from '../mock_data'; +import { mockProject } from '../mock_data'; // can also use 'mockGroup', but not useful to test here const createComponent = () => { - const Component = Vue.extend(projectsListItemComponent); + const Component = Vue.extend(frequentItemsListItemComponent); return mountComponent(Component, { - projectId: mockProject.id, - projectName: mockProject.name, + itemId: mockProject.id, + itemName: mockProject.name, namespace: mockProject.namespace, webUrl: mockProject.webUrl, avatarUrl: mockProject.avatarUrl, }); }; -describe('ProjectsListItemComponent', () => { +describe('FrequentItemsListItemComponent', () => { let vm; beforeEach(() => { @@ -32,22 +30,22 @@ describe('ProjectsListItemComponent', () => { describe('hasAvatar', () => { it('should return `true` or `false` if whether avatar is present or not', () => { vm.avatarUrl = 'path/to/avatar.png'; - expect(vm.hasAvatar).toBeTruthy(); + expect(vm.hasAvatar).toBe(true); vm.avatarUrl = null; - expect(vm.hasAvatar).toBeFalsy(); + expect(vm.hasAvatar).toBe(false); }); }); - describe('highlightedProjectName', () => { + describe('highlightedItemName', () => { it('should enclose part of project name in <b> & </b> which matches with `matcher` prop', () => { vm.matcher = 'lab'; - expect(vm.highlightedProjectName).toContain('<b>Lab</b>'); + expect(vm.highlightedItemName).toContain('<b>Lab</b>'); }); it('should return project name as it is if `matcher` is not available', () => { vm.matcher = null; - expect(vm.highlightedProjectName).toBe(mockProject.name); + expect(vm.highlightedItemName).toBe(mockProject.name); }); }); @@ -66,12 +64,12 @@ describe('ProjectsListItemComponent', () => { describe('template', () => { it('should render component element', () => { - expect(vm.$el.classList.contains('projects-list-item-container')).toBeTruthy(); + expect(vm.$el.classList.contains('frequent-items-list-item-container')).toBeTruthy(); expect(vm.$el.querySelectorAll('a').length).toBe(1); - expect(vm.$el.querySelectorAll('.project-item-avatar-container').length).toBe(1); - expect(vm.$el.querySelectorAll('.project-item-metadata-container').length).toBe(1); - expect(vm.$el.querySelectorAll('.project-title').length).toBe(1); - expect(vm.$el.querySelectorAll('.project-namespace').length).toBe(1); + expect(vm.$el.querySelectorAll('.frequent-items-item-avatar-container').length).toBe(1); + expect(vm.$el.querySelectorAll('.frequent-items-item-metadata-container').length).toBe(1); + expect(vm.$el.querySelectorAll('.frequent-items-item-title').length).toBe(1); + expect(vm.$el.querySelectorAll('.frequent-items-item-namespace').length).toBe(1); }); }); }); diff --git a/spec/javascripts/frequent_items/components/frequent_items_list_spec.js b/spec/javascripts/frequent_items/components/frequent_items_list_spec.js new file mode 100644 index 00000000000..3003b7ee000 --- /dev/null +++ b/spec/javascripts/frequent_items/components/frequent_items_list_spec.js @@ -0,0 +1,84 @@ +import Vue from 'vue'; +import frequentItemsListComponent from '~/frequent_items/components/frequent_items_list.vue'; +import mountComponent from 'spec/helpers/vue_mount_component_helper'; +import { mockFrequentProjects } from '../mock_data'; + +const createComponent = (namespace = 'projects') => { + const Component = Vue.extend(frequentItemsListComponent); + + return mountComponent(Component, { + namespace, + items: mockFrequentProjects, + isFetchFailed: false, + hasSearchQuery: false, + matcher: 'lab', + }); +}; + +describe('FrequentItemsListComponent', () => { + let vm; + + beforeEach(() => { + vm = createComponent(); + }); + + afterEach(() => { + vm.$destroy(); + }); + + describe('computed', () => { + describe('isListEmpty', () => { + it('should return `true` or `false` representing whether if `items` is empty or not with projects', () => { + vm.items = []; + expect(vm.isListEmpty).toBe(true); + + vm.items = mockFrequentProjects; + expect(vm.isListEmpty).toBe(false); + }); + }); + + describe('fetched item messages', () => { + it('should return appropriate empty list message based on value of `localStorageFailed` prop with projects', () => { + vm.isFetchFailed = true; + expect(vm.listEmptyMessage).toBe('This feature requires browser localStorage support'); + + vm.isFetchFailed = false; + expect(vm.listEmptyMessage).toBe('Projects you visit often will appear here'); + }); + }); + + describe('searched item messages', () => { + it('should return appropriate empty list message based on value of `searchFailed` prop with projects', () => { + vm.hasSearchQuery = true; + vm.isFetchFailed = true; + expect(vm.listEmptyMessage).toBe('Something went wrong on our end.'); + + vm.isFetchFailed = false; + expect(vm.listEmptyMessage).toBe('Sorry, no projects matched your search'); + }); + }); + }); + + describe('template', () => { + it('should render component element with list of projects', done => { + vm.items = mockFrequentProjects; + + Vue.nextTick(() => { + expect(vm.$el.classList.contains('frequent-items-list-container')).toBe(true); + expect(vm.$el.querySelectorAll('ul.list-unstyled').length).toBe(1); + expect(vm.$el.querySelectorAll('li.frequent-items-list-item-container').length).toBe(5); + done(); + }); + }); + + it('should render component element with empty message', done => { + vm.items = []; + + Vue.nextTick(() => { + expect(vm.$el.querySelectorAll('li.section-empty').length).toBe(1); + expect(vm.$el.querySelectorAll('li.frequent-items-list-item-container').length).toBe(0); + done(); + }); + }); + }); +}); diff --git a/spec/javascripts/frequent_items/components/frequent_items_search_input_spec.js b/spec/javascripts/frequent_items/components/frequent_items_search_input_spec.js new file mode 100644 index 00000000000..6a11038e70a --- /dev/null +++ b/spec/javascripts/frequent_items/components/frequent_items_search_input_spec.js @@ -0,0 +1,77 @@ +import Vue from 'vue'; +import searchComponent from '~/frequent_items/components/frequent_items_search_input.vue'; +import eventHub from '~/frequent_items/event_hub'; +import mountComponent from 'spec/helpers/vue_mount_component_helper'; + +const createComponent = (namespace = 'projects') => { + const Component = Vue.extend(searchComponent); + + return mountComponent(Component, { namespace }); +}; + +describe('FrequentItemsSearchInputComponent', () => { + let vm; + + beforeEach(() => { + vm = createComponent(); + }); + + afterEach(() => { + vm.$destroy(); + }); + + describe('methods', () => { + describe('setFocus', () => { + it('should set focus to search input', () => { + spyOn(vm.$refs.search, 'focus'); + + vm.setFocus(); + expect(vm.$refs.search.focus).toHaveBeenCalled(); + }); + }); + }); + + describe('mounted', () => { + it('should listen `dropdownOpen` event', done => { + spyOn(eventHub, '$on'); + const vmX = createComponent(); + + Vue.nextTick(() => { + expect(eventHub.$on).toHaveBeenCalledWith( + `${vmX.namespace}-dropdownOpen`, + jasmine.any(Function), + ); + done(); + }); + }); + }); + + describe('beforeDestroy', () => { + it('should unbind event listeners on eventHub', done => { + const vmX = createComponent(); + spyOn(eventHub, '$off'); + + vmX.$mount(); + vmX.$destroy(); + + Vue.nextTick(() => { + expect(eventHub.$off).toHaveBeenCalledWith( + `${vmX.namespace}-dropdownOpen`, + jasmine.any(Function), + ); + done(); + }); + }); + }); + + describe('template', () => { + it('should render component element', () => { + const inputEl = vm.$el.querySelector('input.form-control'); + + expect(vm.$el.classList.contains('search-input-container')).toBeTruthy(); + expect(inputEl).not.toBe(null); + expect(inputEl.getAttribute('placeholder')).toBe('Search your projects'); + expect(vm.$el.querySelector('.search-icon')).toBeDefined(); + }); + }); +}); diff --git a/spec/javascripts/frequent_items/mock_data.js b/spec/javascripts/frequent_items/mock_data.js new file mode 100644 index 00000000000..cf3602f42d6 --- /dev/null +++ b/spec/javascripts/frequent_items/mock_data.js @@ -0,0 +1,168 @@ +export const currentSession = { + groups: { + username: 'root', + storageKey: 'root/frequent-groups', + apiVersion: 'v4', + group: { + id: 1, + name: 'dummy-group', + full_name: 'dummy-parent-group', + webUrl: `${gl.TEST_HOST}/dummy-group`, + avatarUrl: null, + lastAccessedOn: Date.now(), + }, + }, + projects: { + username: 'root', + storageKey: 'root/frequent-projects', + apiVersion: 'v4', + project: { + id: 1, + name: 'dummy-project', + namespace: 'SampleGroup / Dummy-Project', + webUrl: `${gl.TEST_HOST}/samplegroup/dummy-project`, + avatarUrl: null, + lastAccessedOn: Date.now(), + }, + }, +}; + +export const mockNamespace = 'projects'; + +export const mockStorageKey = 'test-user/frequent-projects'; + +export const mockGroup = { + id: 1, + name: 'Sub451', + namespace: 'Commit451 / Sub451', + webUrl: `${gl.TEST_HOST}/Commit451/Sub451`, + avatarUrl: null, +}; + +export const mockRawGroup = { + id: 1, + name: 'Sub451', + full_name: 'Commit451 / Sub451', + web_url: `${gl.TEST_HOST}/Commit451/Sub451`, + avatar_url: null, +}; + +export const mockFrequentGroups = [ + { + id: 3, + name: 'Subgroup451', + full_name: 'Commit451 / Subgroup451', + webUrl: '/Commit451/Subgroup451', + avatarUrl: null, + frequency: 7, + lastAccessedOn: 1497979281815, + }, + { + id: 1, + name: 'Commit451', + full_name: 'Commit451', + webUrl: '/Commit451', + avatarUrl: null, + frequency: 3, + lastAccessedOn: 1497979281815, + }, +]; + +export const mockSearchedGroups = [mockRawGroup]; +export const mockProcessedSearchedGroups = [mockGroup]; + +export const mockProject = { + id: 1, + name: 'GitLab Community Edition', + namespace: 'gitlab-org / gitlab-ce', + webUrl: `${gl.TEST_HOST}/gitlab-org/gitlab-ce`, + avatarUrl: null, +}; + +export const mockRawProject = { + id: 1, + name: 'GitLab Community Edition', + name_with_namespace: 'gitlab-org / gitlab-ce', + web_url: `${gl.TEST_HOST}/gitlab-org/gitlab-ce`, + avatar_url: null, +}; + +export const mockFrequentProjects = [ + { + id: 1, + name: 'GitLab Community Edition', + namespace: 'gitlab-org / gitlab-ce', + webUrl: `${gl.TEST_HOST}/gitlab-org/gitlab-ce`, + avatarUrl: null, + frequency: 1, + lastAccessedOn: Date.now(), + }, + { + id: 2, + name: 'GitLab CI', + namespace: 'gitlab-org / gitlab-ci', + webUrl: `${gl.TEST_HOST}/gitlab-org/gitlab-ci`, + avatarUrl: null, + frequency: 9, + lastAccessedOn: Date.now(), + }, + { + id: 3, + name: 'Typeahead.Js', + namespace: 'twitter / typeahead-js', + webUrl: `${gl.TEST_HOST}/twitter/typeahead-js`, + avatarUrl: '/uploads/-/system/project/avatar/7/TWBS.png', + frequency: 2, + lastAccessedOn: Date.now(), + }, + { + id: 4, + name: 'Intel', + namespace: 'platform / hardware / bsp / intel', + webUrl: `${gl.TEST_HOST}/platform/hardware/bsp/intel`, + avatarUrl: null, + frequency: 3, + lastAccessedOn: Date.now(), + }, + { + id: 5, + name: 'v4.4', + namespace: 'platform / hardware / bsp / kernel / common / v4.4', + webUrl: `${gl.TEST_HOST}/platform/hardware/bsp/kernel/common/v4.4`, + avatarUrl: null, + frequency: 8, + lastAccessedOn: Date.now(), + }, +]; + +export const mockSearchedProjects = [mockRawProject]; +export const mockProcessedSearchedProjects = [mockProject]; + +export const unsortedFrequentItems = [ + { id: 1, frequency: 12, lastAccessedOn: 1491400843391 }, + { id: 2, frequency: 14, lastAccessedOn: 1488240890738 }, + { id: 3, frequency: 44, lastAccessedOn: 1497675908472 }, + { id: 4, frequency: 8, lastAccessedOn: 1497979281815 }, + { id: 5, frequency: 34, lastAccessedOn: 1488089211943 }, + { id: 6, frequency: 14, lastAccessedOn: 1493517292488 }, + { id: 7, frequency: 42, lastAccessedOn: 1486815299875 }, + { id: 8, frequency: 33, lastAccessedOn: 1500762279114 }, + { id: 10, frequency: 46, lastAccessedOn: 1483251641543 }, +]; + +/** + * This const has a specific order which tests authenticity + * of `getTopFrequentItems` method so + * DO NOT change order of items in this const. + */ +export const sortedFrequentItems = [ + { id: 10, frequency: 46, lastAccessedOn: 1483251641543 }, + { id: 3, frequency: 44, lastAccessedOn: 1497675908472 }, + { id: 7, frequency: 42, lastAccessedOn: 1486815299875 }, + { id: 5, frequency: 34, lastAccessedOn: 1488089211943 }, + { id: 8, frequency: 33, lastAccessedOn: 1500762279114 }, + { id: 6, frequency: 14, lastAccessedOn: 1493517292488 }, + { id: 2, frequency: 14, lastAccessedOn: 1488240890738 }, + { id: 1, frequency: 12, lastAccessedOn: 1491400843391 }, + { id: 4, frequency: 8, lastAccessedOn: 1497979281815 }, +]; diff --git a/spec/javascripts/frequent_items/store/actions_spec.js b/spec/javascripts/frequent_items/store/actions_spec.js new file mode 100644 index 00000000000..0a8525e77d6 --- /dev/null +++ b/spec/javascripts/frequent_items/store/actions_spec.js @@ -0,0 +1,225 @@ +import testAction from 'spec/helpers/vuex_action_helper'; +import MockAdapter from 'axios-mock-adapter'; +import axios from '~/lib/utils/axios_utils'; +import AccessorUtilities from '~/lib/utils/accessor'; +import * as actions from '~/frequent_items/store/actions'; +import * as types from '~/frequent_items/store/mutation_types'; +import state from '~/frequent_items/store/state'; +import { + mockNamespace, + mockStorageKey, + mockFrequentProjects, + mockSearchedProjects, +} from '../mock_data'; + +describe('Frequent Items Dropdown Store Actions', () => { + let mockedState; + let mock; + + beforeEach(() => { + mockedState = state(); + mock = new MockAdapter(axios); + + mockedState.namespace = mockNamespace; + mockedState.storageKey = mockStorageKey; + }); + + afterEach(() => { + mock.restore(); + }); + + describe('setNamespace', () => { + it('should set namespace', done => { + testAction( + actions.setNamespace, + mockNamespace, + mockedState, + [{ type: types.SET_NAMESPACE, payload: mockNamespace }], + [], + done, + ); + }); + }); + + describe('setStorageKey', () => { + it('should set storage key', done => { + testAction( + actions.setStorageKey, + mockStorageKey, + mockedState, + [{ type: types.SET_STORAGE_KEY, payload: mockStorageKey }], + [], + done, + ); + }); + }); + + describe('requestFrequentItems', () => { + it('should request frequent items', done => { + testAction( + actions.requestFrequentItems, + null, + mockedState, + [{ type: types.REQUEST_FREQUENT_ITEMS }], + [], + done, + ); + }); + }); + + describe('receiveFrequentItemsSuccess', () => { + it('should set frequent items', done => { + testAction( + actions.receiveFrequentItemsSuccess, + mockFrequentProjects, + mockedState, + [{ type: types.RECEIVE_FREQUENT_ITEMS_SUCCESS, payload: mockFrequentProjects }], + [], + done, + ); + }); + }); + + describe('receiveFrequentItemsError', () => { + it('should set frequent items error state', done => { + testAction( + actions.receiveFrequentItemsError, + null, + mockedState, + [{ type: types.RECEIVE_FREQUENT_ITEMS_ERROR }], + [], + done, + ); + }); + }); + + describe('fetchFrequentItems', () => { + it('should dispatch `receiveFrequentItemsSuccess`', done => { + mockedState.namespace = mockNamespace; + mockedState.storageKey = mockStorageKey; + + testAction( + actions.fetchFrequentItems, + null, + mockedState, + [], + [{ type: 'requestFrequentItems' }, { type: 'receiveFrequentItemsSuccess', payload: [] }], + done, + ); + }); + + it('should dispatch `receiveFrequentItemsError`', done => { + spyOn(AccessorUtilities, 'isLocalStorageAccessSafe').and.returnValue(false); + mockedState.namespace = mockNamespace; + mockedState.storageKey = mockStorageKey; + + testAction( + actions.fetchFrequentItems, + null, + mockedState, + [], + [{ type: 'requestFrequentItems' }, { type: 'receiveFrequentItemsError' }], + done, + ); + }); + }); + + describe('requestSearchedItems', () => { + it('should request searched items', done => { + testAction( + actions.requestSearchedItems, + null, + mockedState, + [{ type: types.REQUEST_SEARCHED_ITEMS }], + [], + done, + ); + }); + }); + + describe('receiveSearchedItemsSuccess', () => { + it('should set searched items', done => { + testAction( + actions.receiveSearchedItemsSuccess, + mockSearchedProjects, + mockedState, + [{ type: types.RECEIVE_SEARCHED_ITEMS_SUCCESS, payload: mockSearchedProjects }], + [], + done, + ); + }); + }); + + describe('receiveSearchedItemsError', () => { + it('should set searched items error state', done => { + testAction( + actions.receiveSearchedItemsError, + null, + mockedState, + [{ type: types.RECEIVE_SEARCHED_ITEMS_ERROR }], + [], + done, + ); + }); + }); + + describe('fetchSearchedItems', () => { + beforeEach(() => { + gon.api_version = 'v4'; + }); + + it('should dispatch `receiveSearchedItemsSuccess`', done => { + mock.onGet(/\/api\/v4\/projects.json(.*)$/).replyOnce(200, mockSearchedProjects); + + testAction( + actions.fetchSearchedItems, + null, + mockedState, + [], + [ + { type: 'requestSearchedItems' }, + { type: 'receiveSearchedItemsSuccess', payload: mockSearchedProjects }, + ], + done, + ); + }); + + it('should dispatch `receiveSearchedItemsError`', done => { + gon.api_version = 'v4'; + mock.onGet(/\/api\/v4\/projects.json(.*)$/).replyOnce(500); + + testAction( + actions.fetchSearchedItems, + null, + mockedState, + [], + [{ type: 'requestSearchedItems' }, { type: 'receiveSearchedItemsError' }], + done, + ); + }); + }); + + describe('setSearchQuery', () => { + it('should commit query and dispatch `fetchSearchedItems` when query is present', done => { + testAction( + actions.setSearchQuery, + { query: 'test' }, + mockedState, + [{ type: types.SET_SEARCH_QUERY, payload: { query: 'test' } }], + [{ type: 'fetchSearchedItems', payload: { query: 'test' } }], + done, + ); + }); + + it('should commit query and dispatch `fetchFrequentItems` when query is empty', done => { + testAction( + actions.setSearchQuery, + null, + mockedState, + [{ type: types.SET_SEARCH_QUERY, payload: null }], + [{ type: 'fetchFrequentItems' }], + done, + ); + }); + }); +}); diff --git a/spec/javascripts/frequent_items/store/getters_spec.js b/spec/javascripts/frequent_items/store/getters_spec.js new file mode 100644 index 00000000000..1cd12eb6832 --- /dev/null +++ b/spec/javascripts/frequent_items/store/getters_spec.js @@ -0,0 +1,24 @@ +import state from '~/frequent_items/store/state'; +import * as getters from '~/frequent_items/store/getters'; + +describe('Frequent Items Dropdown Store Getters', () => { + let mockedState; + + beforeEach(() => { + mockedState = state(); + }); + + describe('hasSearchQuery', () => { + it('should return `true` when search query is present', () => { + mockedState.searchQuery = 'test'; + + expect(getters.hasSearchQuery(mockedState)).toBe(true); + }); + + it('should return `false` when search query is empty', () => { + mockedState.searchQuery = ''; + + expect(getters.hasSearchQuery(mockedState)).toBe(false); + }); + }); +}); diff --git a/spec/javascripts/frequent_items/store/mutations_spec.js b/spec/javascripts/frequent_items/store/mutations_spec.js new file mode 100644 index 00000000000..d36964b2600 --- /dev/null +++ b/spec/javascripts/frequent_items/store/mutations_spec.js @@ -0,0 +1,117 @@ +import state from '~/frequent_items/store/state'; +import mutations from '~/frequent_items/store/mutations'; +import * as types from '~/frequent_items/store/mutation_types'; +import { + mockNamespace, + mockStorageKey, + mockFrequentProjects, + mockSearchedProjects, + mockProcessedSearchedProjects, + mockSearchedGroups, + mockProcessedSearchedGroups, +} from '../mock_data'; + +describe('Frequent Items dropdown mutations', () => { + let stateCopy; + + beforeEach(() => { + stateCopy = state(); + }); + + describe('SET_NAMESPACE', () => { + it('should set namespace', () => { + mutations[types.SET_NAMESPACE](stateCopy, mockNamespace); + + expect(stateCopy.namespace).toEqual(mockNamespace); + }); + }); + + describe('SET_STORAGE_KEY', () => { + it('should set storage key', () => { + mutations[types.SET_STORAGE_KEY](stateCopy, mockStorageKey); + + expect(stateCopy.storageKey).toEqual(mockStorageKey); + }); + }); + + describe('SET_SEARCH_QUERY', () => { + it('should set search query', () => { + const searchQuery = 'gitlab-ce'; + + mutations[types.SET_SEARCH_QUERY](stateCopy, searchQuery); + + expect(stateCopy.searchQuery).toEqual(searchQuery); + }); + }); + + describe('REQUEST_FREQUENT_ITEMS', () => { + it('should set view states when requesting frequent items', () => { + mutations[types.REQUEST_FREQUENT_ITEMS](stateCopy); + + expect(stateCopy.isLoadingItems).toEqual(true); + expect(stateCopy.hasSearchQuery).toEqual(false); + }); + }); + + describe('RECEIVE_FREQUENT_ITEMS_SUCCESS', () => { + it('should set view states when receiving frequent items', () => { + mutations[types.RECEIVE_FREQUENT_ITEMS_SUCCESS](stateCopy, mockFrequentProjects); + + expect(stateCopy.items).toEqual(mockFrequentProjects); + expect(stateCopy.isLoadingItems).toEqual(false); + expect(stateCopy.hasSearchQuery).toEqual(false); + expect(stateCopy.isFetchFailed).toEqual(false); + }); + }); + + describe('RECEIVE_FREQUENT_ITEMS_ERROR', () => { + it('should set items and view states when error occurs retrieving frequent items', () => { + mutations[types.RECEIVE_FREQUENT_ITEMS_ERROR](stateCopy); + + expect(stateCopy.items).toEqual([]); + expect(stateCopy.isLoadingItems).toEqual(false); + expect(stateCopy.hasSearchQuery).toEqual(false); + expect(stateCopy.isFetchFailed).toEqual(true); + }); + }); + + describe('REQUEST_SEARCHED_ITEMS', () => { + it('should set view states when requesting searched items', () => { + mutations[types.REQUEST_SEARCHED_ITEMS](stateCopy); + + expect(stateCopy.isLoadingItems).toEqual(true); + expect(stateCopy.hasSearchQuery).toEqual(true); + }); + }); + + describe('RECEIVE_SEARCHED_ITEMS_SUCCESS', () => { + it('should set items and view states when receiving searched items', () => { + mutations[types.RECEIVE_SEARCHED_ITEMS_SUCCESS](stateCopy, mockSearchedProjects); + + expect(stateCopy.items).toEqual(mockProcessedSearchedProjects); + expect(stateCopy.isLoadingItems).toEqual(false); + expect(stateCopy.hasSearchQuery).toEqual(true); + expect(stateCopy.isFetchFailed).toEqual(false); + }); + + it('should also handle the different `full_name` key for namespace in groups payload', () => { + mutations[types.RECEIVE_SEARCHED_ITEMS_SUCCESS](stateCopy, mockSearchedGroups); + + expect(stateCopy.items).toEqual(mockProcessedSearchedGroups); + expect(stateCopy.isLoadingItems).toEqual(false); + expect(stateCopy.hasSearchQuery).toEqual(true); + expect(stateCopy.isFetchFailed).toEqual(false); + }); + }); + + describe('RECEIVE_SEARCHED_ITEMS_ERROR', () => { + it('should set view states when error occurs retrieving searched items', () => { + mutations[types.RECEIVE_SEARCHED_ITEMS_ERROR](stateCopy); + + expect(stateCopy.items).toEqual([]); + expect(stateCopy.isLoadingItems).toEqual(false); + expect(stateCopy.hasSearchQuery).toEqual(true); + expect(stateCopy.isFetchFailed).toEqual(true); + }); + }); +}); diff --git a/spec/javascripts/frequent_items/utils_spec.js b/spec/javascripts/frequent_items/utils_spec.js new file mode 100644 index 00000000000..cd27d79b29a --- /dev/null +++ b/spec/javascripts/frequent_items/utils_spec.js @@ -0,0 +1,89 @@ +import bp from '~/breakpoints'; +import { isMobile, getTopFrequentItems, updateExistingFrequentItem } from '~/frequent_items/utils'; +import { HOUR_IN_MS, FREQUENT_ITEMS } from '~/frequent_items/constants'; +import { mockProject, unsortedFrequentItems, sortedFrequentItems } from './mock_data'; + +describe('Frequent Items utils spec', () => { + describe('isMobile', () => { + it('returns true when the screen is small ', () => { + spyOn(bp, 'getBreakpointSize').and.returnValue('sm'); + + expect(isMobile()).toBe(true); + }); + + it('returns true when the screen is extra-small ', () => { + spyOn(bp, 'getBreakpointSize').and.returnValue('xs'); + + expect(isMobile()).toBe(true); + }); + + it('returns false when the screen is larger than small ', () => { + spyOn(bp, 'getBreakpointSize').and.returnValue('md'); + + expect(isMobile()).toBe(false); + }); + }); + + describe('getTopFrequentItems', () => { + it('returns empty array if no items provided', () => { + const result = getTopFrequentItems(); + + expect(result.length).toBe(0); + }); + + it('returns correct amount of items for mobile', () => { + spyOn(bp, 'getBreakpointSize').and.returnValue('sm'); + const result = getTopFrequentItems(unsortedFrequentItems); + + expect(result.length).toBe(FREQUENT_ITEMS.LIST_COUNT_MOBILE); + }); + + it('returns correct amount of items for desktop', () => { + spyOn(bp, 'getBreakpointSize').and.returnValue('lg'); + const result = getTopFrequentItems(unsortedFrequentItems); + + expect(result.length).toBe(FREQUENT_ITEMS.LIST_COUNT_DESKTOP); + }); + + it('sorts frequent items in order of frequency and lastAccessedOn', () => { + spyOn(bp, 'getBreakpointSize').and.returnValue('lg'); + const result = getTopFrequentItems(unsortedFrequentItems); + const expectedResult = sortedFrequentItems.slice(0, FREQUENT_ITEMS.LIST_COUNT_DESKTOP); + + expect(result).toEqual(expectedResult); + }); + }); + + describe('updateExistingFrequentItem', () => { + let mockedProject; + + beforeEach(() => { + mockedProject = { + ...mockProject, + frequency: 1, + lastAccessedOn: 1497979281815, + }; + }); + + it('updates item if accessed over an hour ago', () => { + const newTimestamp = Date.now() + HOUR_IN_MS + 1; + const newItem = { + ...mockedProject, + lastAccessedOn: newTimestamp, + }; + const result = updateExistingFrequentItem(mockedProject, newItem); + + expect(result.frequency).toBe(mockedProject.frequency + 1); + }); + + it('does not update item if accessed within the hour', () => { + const newItem = { + ...mockedProject, + lastAccessedOn: mockedProject.lastAccessedOn + HOUR_IN_MS, + }; + const result = updateExistingFrequentItem(mockedProject, newItem); + + expect(result.frequency).toBe(mockedProject.frequency); + }); + }); +}); diff --git a/spec/javascripts/helpers/vuex_action_helper.js b/spec/javascripts/helpers/vuex_action_helper.js index d6ab0aeeed7..4ca7015184e 100644 --- a/spec/javascripts/helpers/vuex_action_helper.js +++ b/spec/javascripts/helpers/vuex_action_helper.js @@ -1,71 +1,103 @@ +const noop = () => {}; + /** - * helper for testing action with expected mutations inspired in + * Helper for testing action with expected mutations inspired in * https://vuex.vuejs.org/en/testing.html * + * @param {Function} action to be tested + * @param {Object} payload will be provided to the action + * @param {Object} state will be provided to the action + * @param {Array} [expectedMutations=[]] mutations expected to be committed + * @param {Array} [expectedActions=[]] actions expected to be dispatched + * @param {Function} [done=noop] to be executed after the tests + * @return {Promise} + * * @example * testAction( * actions.actionName, // action - * { }, // mocked response - * state, // state + * { }, // mocked payload + * state, //state + * // expected mutations * [ * { type: types.MUTATION} - * { type: types.MUTATION_1, payload: {}} - * ], // mutations + * { type: types.MUTATION_1, payload: jasmine.any(Number)} + * ], + * // expected actions * [ - * { type: 'actionName', payload: {}}, - * { type: 'actionName1', payload: {}} - * ] //actions + * { type: 'actionName', payload: {param: 'foobar'}}, + * { type: 'actionName1'} + * ] * done, * ); + * + * @example + * testAction( + * actions.actionName, // action + * { }, // mocked payload + * state, //state + * [ { type: types.MUTATION} ], // expected mutations + * [], // expected actions + * ).then(done) + * .catch(done.fail); */ -export default (action, payload, state, expectedMutations, expectedActions, done) => { - let mutationsCount = 0; - let actionsCount = 0; +export default ( + action, + payload, + state, + expectedMutations = [], + expectedActions = [], + done = noop, +) => { + const mutations = []; + const actions = []; // mock commit const commit = (type, mutationPayload) => { - const mutation = expectedMutations[mutationsCount]; - - expect(mutation.type).toEqual(type); + const mutation = { type }; - if (mutation.payload) { - expect(mutation.payload).toEqual(mutationPayload); + if (typeof mutationPayload !== 'undefined') { + mutation.payload = mutationPayload; } - mutationsCount += 1; - if (mutationsCount >= expectedMutations.length) { - done(); - } + mutations.push(mutation); }; // mock dispatch const dispatch = (type, actionPayload) => { - const actionExpected = expectedActions[actionsCount]; - - expect(actionExpected.type).toEqual(type); + const dispatchedAction = { type }; - if (actionExpected.payload) { - expect(actionExpected.payload).toEqual(actionPayload); + if (typeof actionPayload !== 'undefined') { + dispatchedAction.payload = actionPayload; } - actionsCount += 1; - if (actionsCount >= expectedActions.length) { - done(); - } + actions.push(dispatchedAction); }; - // call the action with mocked store and arguments - action({ commit, state, dispatch, rootState: state }, payload); - - // check if no mutations should have been dispatched - if (expectedMutations.length === 0) { - expect(mutationsCount).toEqual(0); + const validateResults = () => { + expect({ + mutations, + actions, + }).toEqual({ + mutations: expectedMutations, + actions: expectedActions, + }); done(); - } + }; - // check if no mutations should have been dispatched - if (expectedActions.length === 0) { - expect(actionsCount).toEqual(0); - done(); - } + return new Promise((resolve, reject) => { + try { + const result = action({ commit, state, dispatch, rootState: state }, payload); + resolve(result); + } catch (e) { + reject(e); + } + }) + .catch(error => { + validateResults(); + throw error; + }) + .then(data => { + validateResults(); + return data; + }); }; diff --git a/spec/javascripts/helpers/vuex_action_helper_spec.js b/spec/javascripts/helpers/vuex_action_helper_spec.js new file mode 100644 index 00000000000..8d6ad6750c0 --- /dev/null +++ b/spec/javascripts/helpers/vuex_action_helper_spec.js @@ -0,0 +1,141 @@ +import MockAdapter from 'axios-mock-adapter'; +import { TEST_HOST } from 'spec/test_constants'; +import axios from '~/lib/utils/axios_utils'; +import testAction from './vuex_action_helper'; + +describe('VueX test helper (testAction)', () => { + let originalExpect; + let assertion; + let mock; + const noop = () => {}; + + beforeAll(() => { + mock = new MockAdapter(axios); + /* + In order to test the helper properly, we need to overwrite the jasmine `expect` helper. + We test that the testAction helper properly passes the dispatched actions/committed mutations + to the jasmine helper. + */ + originalExpect = expect; + assertion = null; + global.expect = actual => ({ + toEqual: () => { + originalExpect(actual).toEqual(assertion); + }, + }); + }); + + afterAll(() => { + mock.restore(); + global.expect = originalExpect; + }); + + it('should properly pass on state and payload', () => { + const exampleState = { FOO: 12, BAR: 3 }; + const examplePayload = { BAZ: 73, BIZ: 55 }; + + const action = ({ state }, payload) => { + originalExpect(state).toEqual(exampleState); + originalExpect(payload).toEqual(examplePayload); + }; + + assertion = { mutations: [], actions: [] }; + + testAction(action, examplePayload, exampleState); + }); + + describe('should work with synchronous actions', () => { + it('committing mutation', () => { + const action = ({ commit }) => { + commit('MUTATION'); + }; + + assertion = { mutations: [{ type: 'MUTATION' }], actions: [] }; + + testAction(action, null, {}, assertion.mutations, assertion.actions, noop); + }); + + it('dispatching action', () => { + const action = ({ dispatch }) => { + dispatch('ACTION'); + }; + + assertion = { actions: [{ type: 'ACTION' }], mutations: [] }; + + testAction(action, null, {}, assertion.mutations, assertion.actions, noop); + }); + + it('work with jasmine done once finished', done => { + assertion = { mutations: [], actions: [] }; + + testAction(noop, null, {}, assertion.mutations, assertion.actions, done); + }); + + it('provide promise interface', done => { + assertion = { mutations: [], actions: [] }; + + testAction(noop, null, {}, assertion.mutations, assertion.actions) + .then(done) + .catch(done.fail); + }); + }); + + describe('should work with promise based actions (fetch action)', () => { + let lastError; + const data = { FOO: 'BAR' }; + + const promiseAction = ({ commit, dispatch }) => { + dispatch('ACTION'); + + return axios + .get(TEST_HOST) + .catch(error => { + commit('ERROR'); + lastError = error; + throw error; + }) + .then(() => { + commit('SUCCESS'); + return data; + }); + }; + + beforeEach(() => { + lastError = null; + }); + + it('work with jasmine done once finished', done => { + mock.onGet(TEST_HOST).replyOnce(200, 42); + + assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] }; + + testAction(promiseAction, null, {}, assertion.mutations, assertion.actions, done); + }); + + it('return original data of successful promise while checking actions/mutations', done => { + mock.onGet(TEST_HOST).replyOnce(200, 42); + + assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] }; + + testAction(promiseAction, null, {}, assertion.mutations, assertion.actions) + .then(res => { + originalExpect(res).toEqual(data); + done(); + }) + .catch(done.fail); + }); + + it('return original error of rejected promise while checking actions/mutations', done => { + mock.onGet(TEST_HOST).replyOnce(500, ''); + + assertion = { mutations: [{ type: 'ERROR' }], actions: [{ type: 'ACTION' }] }; + + testAction(promiseAction, null, {}, assertion.mutations, assertion.actions) + .then(done.fail) + .catch(error => { + originalExpect(error).toBe(lastError); + done(); + }); + }); + }); +}); diff --git a/spec/javascripts/helpers/wait_for_promises.js b/spec/javascripts/helpers/wait_for_promises.js new file mode 100644 index 00000000000..1d2b53fc770 --- /dev/null +++ b/spec/javascripts/helpers/wait_for_promises.js @@ -0,0 +1 @@ +export default () => new Promise(resolve => requestAnimationFrame(resolve)); diff --git a/spec/javascripts/ide/components/ide_status_bar_spec.js b/spec/javascripts/ide/components/ide_status_bar_spec.js index 770dca9cb0f..9895682f388 100644 --- a/spec/javascripts/ide/components/ide_status_bar_spec.js +++ b/spec/javascripts/ide/components/ide_status_bar_spec.js @@ -13,6 +13,7 @@ describe('ideStatusBar', () => { store.state.currentProjectId = 'abcproject'; store.state.projects.abcproject = projectData; + store.state.currentBranchId = 'master'; vm = createComponentWithStore(Component, store).$mount(); }); @@ -60,4 +61,29 @@ describe('ideStatusBar', () => { expect(vm.getCommitPath('abc123de')).toBe('/commit/abc123de'); }); }); + + describe('pipeline status', () => { + it('opens right sidebar on clicking icon', done => { + spyOn(vm, 'setRightPane'); + Vue.set(vm.$store.state.pipelines, 'latestPipeline', { + details: { + status: { + text: 'success', + details_path: 'test', + icon: 'success', + }, + }, + }); + + vm + .$nextTick() + .then(() => { + vm.$el.querySelector('.ide-status-pipeline button').click(); + + expect(vm.setRightPane).toHaveBeenCalledWith('pipelines-list'); + }) + .then(done) + .catch(done.fail); + }); + }); }); diff --git a/spec/javascripts/ide/components/merge_requests/info_spec.js b/spec/javascripts/ide/components/merge_requests/info_spec.js new file mode 100644 index 00000000000..98a29e5128b --- /dev/null +++ b/spec/javascripts/ide/components/merge_requests/info_spec.js @@ -0,0 +1,51 @@ +import Vue from 'vue'; +import '~/behaviors/markdown/render_gfm'; +import { createStore } from '~/ide/stores'; +import Info from '~/ide/components/merge_requests/info.vue'; +import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper'; + +describe('IDE merge request details', () => { + let Component; + let vm; + + beforeAll(() => { + Component = Vue.extend(Info); + }); + + beforeEach(() => { + const store = createStore(); + store.state.currentProjectId = 'gitlab-ce'; + store.state.currentMergeRequestId = 1; + store.state.projects['gitlab-ce'] = { + mergeRequests: { + 1: { + iid: 1, + title: 'Testing', + title_html: '<span class="title-html">Testing</span>', + description: 'Description', + description_html: '<p class="description-html">Description HTML</p>', + }, + }, + }; + + vm = createComponentWithStore(Component, store).$mount(); + }); + + afterEach(() => { + vm.$destroy(); + }); + + it('renders merge request IID', () => { + expect(vm.$el.querySelector('.detail-page-header').textContent).toContain('!1'); + }); + + it('renders title as HTML', () => { + expect(vm.$el.querySelector('.title-html')).not.toBe(null); + expect(vm.$el.querySelector('.title').textContent).toContain('Testing'); + }); + + it('renders description as HTML', () => { + expect(vm.$el.querySelector('.description-html')).not.toBe(null); + expect(vm.$el.querySelector('.description').textContent).toContain('Description HTML'); + }); +}); diff --git a/spec/javascripts/ide/components/new_dropdown/button_spec.js b/spec/javascripts/ide/components/new_dropdown/button_spec.js new file mode 100644 index 00000000000..ef083d06ba7 --- /dev/null +++ b/spec/javascripts/ide/components/new_dropdown/button_spec.js @@ -0,0 +1,49 @@ +import Vue from 'vue'; +import mountComponent from 'spec/helpers/vue_mount_component_helper'; +import Button from '~/ide/components/new_dropdown/button.vue'; + +describe('IDE new entry dropdown button component', () => { + let Component; + let vm; + + beforeAll(() => { + Component = Vue.extend(Button); + }); + + beforeEach(() => { + vm = mountComponent(Component, { + label: 'Testing', + icon: 'doc-new', + }); + + spyOn(vm, '$emit'); + }); + + afterEach(() => { + vm.$destroy(); + }); + + it('renders button with label', () => { + expect(vm.$el.textContent).toContain('Testing'); + }); + + it('renders icon', () => { + expect(vm.$el.querySelector('.ic-doc-new')).not.toBe(null); + }); + + it('emits click event', () => { + vm.$el.click(); + + expect(vm.$emit).toHaveBeenCalledWith('click'); + }); + + it('hides label if showLabel is false', done => { + vm.showLabel = false; + + vm.$nextTick(() => { + expect(vm.$el.textContent).not.toContain('Testing'); + + done(); + }); + }); +}); diff --git a/spec/javascripts/ide/components/new_dropdown/index_spec.js b/spec/javascripts/ide/components/new_dropdown/index_spec.js index 7b637f37eba..4d704b80209 100644 --- a/spec/javascripts/ide/components/new_dropdown/index_spec.js +++ b/spec/javascripts/ide/components/new_dropdown/index_spec.js @@ -13,6 +13,7 @@ describe('new dropdown component', () => { vm = createComponentWithStore(component, store, { branch: 'master', path: '', + mouseOver: false, }); vm.$store.state.currentProjectId = 'abcproject'; @@ -21,6 +22,8 @@ describe('new dropdown component', () => { tree: [], }; + spyOn(vm, 'openNewEntryModal'); + vm.$mount(); }); @@ -31,50 +34,23 @@ describe('new dropdown component', () => { }); it('renders new file, upload and new directory links', () => { - expect(vm.$el.querySelectorAll('a')[0].textContent.trim()).toBe('New file'); - expect(vm.$el.querySelectorAll('a')[1].textContent.trim()).toBe('Upload file'); - expect(vm.$el.querySelectorAll('a')[2].textContent.trim()).toBe('New directory'); + const buttons = vm.$el.querySelectorAll('.dropdown-menu button'); + expect(buttons[0].textContent.trim()).toBe('New file'); + expect(buttons[1].textContent.trim()).toBe('Upload file'); + expect(buttons[2].textContent.trim()).toBe('New directory'); }); describe('createNewItem', () => { it('sets modalType to blob when new file is clicked', () => { - vm.$el.querySelectorAll('a')[0].click(); + vm.$el.querySelectorAll('.dropdown-menu button')[0].click(); - expect(vm.modalType).toBe('blob'); + expect(vm.openNewEntryModal).toHaveBeenCalledWith({ type: 'blob', path: '' }); }); it('sets modalType to tree when new directory is clicked', () => { - vm.$el.querySelectorAll('a')[2].click(); - - expect(vm.modalType).toBe('tree'); - }); - - it('opens modal when link is clicked', done => { - vm.$el.querySelectorAll('a')[0].click(); - - Vue.nextTick(() => { - expect(vm.$el.querySelector('.modal')).not.toBeNull(); - - done(); - }); - }); - }); - - describe('hideModal', () => { - beforeAll(done => { - vm.openModal = true; - Vue.nextTick(done); - }); - - it('closes modal after toggling', done => { - vm.hideModal(); + vm.$el.querySelectorAll('.dropdown-menu button')[2].click(); - Vue.nextTick() - .then(() => { - expect(vm.$el.querySelector('.modal')).toBeNull(); - }) - .then(done) - .catch(done.fail); + expect(vm.openNewEntryModal).toHaveBeenCalledWith({ type: 'tree', path: '' }); }); }); diff --git a/spec/javascripts/ide/components/new_dropdown/modal_spec.js b/spec/javascripts/ide/components/new_dropdown/modal_spec.js index f362ed4db65..6dcc5880677 100644 --- a/spec/javascripts/ide/components/new_dropdown/modal_spec.js +++ b/spec/javascripts/ide/components/new_dropdown/modal_spec.js @@ -1,6 +1,7 @@ import Vue from 'vue'; +import { createStore } from '~/ide/stores'; import modal from '~/ide/components/new_dropdown/modal.vue'; -import createComponent from 'spec/helpers/vue_mount_component_helper'; +import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; describe('new file modal component', () => { const Component = Vue.extend(modal); @@ -13,13 +14,15 @@ describe('new file modal component', () => { ['tree', 'blob'].forEach(type => { describe(type, () => { beforeEach(() => { - vm = createComponent(Component, { + const store = createStore(); + store.state.newEntryModal = { type, - branchId: 'master', path: '', - }); + }; + + vm = createComponentWithStore(Component, store).$mount(); - vm.entryName = 'testing'; + vm.name = 'testing'; }); it(`sets modal title as ${type}`, () => { @@ -40,12 +43,11 @@ describe('new file modal component', () => { describe('createEntryInStore', () => { it('$emits create', () => { - spyOn(vm, '$emit'); + spyOn(vm, 'createTempEntry'); vm.createEntryInStore(); - expect(vm.$emit).toHaveBeenCalledWith('create', { - branchId: 'master', + expect(vm.createTempEntry).toHaveBeenCalledWith({ name: 'testing', type, }); @@ -53,22 +55,4 @@ describe('new file modal component', () => { }); }); }); - - it('focuses field on mount', () => { - document.body.innerHTML += '<div class="js-test"></div>'; - - vm = createComponent( - Component, - { - type: 'tree', - branchId: 'master', - path: '', - }, - '.js-test', - ); - - expect(document.activeElement).toBe(vm.$refs.fieldName); - - vm.$el.remove(); - }); }); diff --git a/spec/javascripts/ide/components/new_dropdown/upload_spec.js b/spec/javascripts/ide/components/new_dropdown/upload_spec.js index 2bc5d701601..9c76500cfe5 100644 --- a/spec/javascripts/ide/components/new_dropdown/upload_spec.js +++ b/spec/javascripts/ide/components/new_dropdown/upload_spec.js @@ -9,7 +9,6 @@ describe('new dropdown upload', () => { const Component = Vue.extend(upload); vm = createComponent(Component, { - branchId: 'master', path: '', }); @@ -65,7 +64,6 @@ describe('new dropdown upload', () => { expect(vm.$emit).toHaveBeenCalledWith('create', { name: file.name, - branchId: 'master', type: 'blob', content: target.result, base64: false, @@ -77,7 +75,6 @@ describe('new dropdown upload', () => { expect(vm.$emit).toHaveBeenCalledWith('create', { name: file.name, - branchId: 'master', type: 'blob', content: binaryTarget.result.split('base64,')[1], base64: true, diff --git a/spec/javascripts/ide/components/panes/right_spec.js b/spec/javascripts/ide/components/panes/right_spec.js new file mode 100644 index 00000000000..99879fb0930 --- /dev/null +++ b/spec/javascripts/ide/components/panes/right_spec.js @@ -0,0 +1,72 @@ +import Vue from 'vue'; +import '~/behaviors/markdown/render_gfm'; +import { createStore } from '~/ide/stores'; +import RightPane from '~/ide/components/panes/right.vue'; +import { rightSidebarViews } from '~/ide/constants'; +import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper'; + +describe('IDE right pane', () => { + let Component; + let vm; + + beforeAll(() => { + Component = Vue.extend(RightPane); + }); + + beforeEach(() => { + const store = createStore(); + + vm = createComponentWithStore(Component, store).$mount(); + }); + + afterEach(() => { + vm.$destroy(); + }); + + describe('active', () => { + it('renders merge request button as active', done => { + vm.$store.state.rightPane = rightSidebarViews.mergeRequestInfo; + vm.$store.state.currentMergeRequestId = '123'; + vm.$store.state.currentProjectId = 'gitlab-ce'; + vm.$store.state.currentMergeRequestId = 1; + vm.$store.state.projects['gitlab-ce'] = { + mergeRequests: { + 1: { + iid: 1, + title: 'Testing', + title_html: '<span class="title-html">Testing</span>', + description: 'Description', + description_html: '<p class="description-html">Description HTML</p>', + }, + }, + }; + + vm.$nextTick(() => { + expect(vm.$el.querySelector('.ide-sidebar-link.active')).not.toBe(null); + expect( + vm.$el.querySelector('.ide-sidebar-link.active').getAttribute('data-original-title'), + ).toBe('Merge Request'); + + done(); + }); + }); + }); + + describe('click', () => { + beforeEach(() => { + spyOn(vm, 'setRightPane'); + }); + + it('sets view to merge request', done => { + vm.$store.state.currentMergeRequestId = '123'; + + vm.$nextTick(() => { + vm.$el.querySelector('.ide-sidebar-link').click(); + + expect(vm.setRightPane).toHaveBeenCalledWith(rightSidebarViews.mergeRequestInfo); + + done(); + }); + }); + }); +}); diff --git a/spec/javascripts/ide/mock_data.js b/spec/javascripts/ide/mock_data.js index 80bf664d491..4bbda4c8e80 100644 --- a/spec/javascripts/ide/mock_data.js +++ b/spec/javascripts/ide/mock_data.js @@ -9,6 +9,9 @@ export const projectData = { master: { treeId: 'abcproject/master', can_push: true, + commit: { + id: '123', + }, }, }, mergeRequests: {}, diff --git a/spec/javascripts/ide/stores/actions/file_spec.js b/spec/javascripts/ide/stores/actions/file_spec.js index 58d3ffc6d94..f570c0b16bd 100644 --- a/spec/javascripts/ide/stores/actions/file_spec.js +++ b/spec/javascripts/ide/stores/actions/file_spec.js @@ -601,10 +601,7 @@ describe('IDE store file actions', () => { actions.unstageChange, 'path', store.state, - [ - { type: types.UNSTAGE_CHANGE, payload: 'path' }, - { type: types.SET_LAST_COMMIT_MSG, payload: '' }, - ], + [{ type: types.UNSTAGE_CHANGE, payload: 'path' }], [], done, ); diff --git a/spec/javascripts/ide/stores/actions/merge_request_spec.js b/spec/javascripts/ide/stores/actions/merge_request_spec.js index c99ccc70c6a..90c28c769f7 100644 --- a/spec/javascripts/ide/stores/actions/merge_request_spec.js +++ b/spec/javascripts/ide/stores/actions/merge_request_spec.js @@ -39,7 +39,9 @@ describe('IDE store merge request actions', () => { store .dispatch('getMergeRequestData', { projectId: 'abcproject', mergeRequestId: 1 }) .then(() => { - expect(service.getProjectMergeRequestData).toHaveBeenCalledWith('abcproject', 1); + expect(service.getProjectMergeRequestData).toHaveBeenCalledWith('abcproject', 1, { + render_html: true, + }); done(); }) diff --git a/spec/javascripts/ide/stores/actions/project_spec.js b/spec/javascripts/ide/stores/actions/project_spec.js index ca79edafb7e..6a85968e199 100644 --- a/spec/javascripts/ide/stores/actions/project_spec.js +++ b/spec/javascripts/ide/stores/actions/project_spec.js @@ -73,6 +73,7 @@ describe('IDE store project actions', () => { branchId: store.state.currentBranchId, }, store.state, + // mutations [ { type: 'SET_BRANCH_COMMIT', @@ -82,17 +83,9 @@ describe('IDE store project actions', () => { commit: { id: '123' }, }, }, - ], // mutations - [ - { - type: 'getLastCommitPipeline', - payload: { - projectId: 'abc/def', - projectIdNumber: store.state.projects['abc/def'].id, - branchId: 'master', - }, - }, - ], // action + ], + // action + [], done, ); }); diff --git a/spec/javascripts/ide/stores/actions/tree_spec.js b/spec/javascripts/ide/stores/actions/tree_spec.js index 6860e6cdb91..9f098eded08 100644 --- a/spec/javascripts/ide/stores/actions/tree_spec.js +++ b/spec/javascripts/ide/stores/actions/tree_spec.js @@ -192,11 +192,8 @@ describe('Multi-file store tree actions', () => { showTreeEntry, 'grandparent/parent/child.txt', store.state, - [ - { type: types.SET_TREE_OPEN, payload: 'grandparent/parent' }, - { type: types.SET_TREE_OPEN, payload: 'grandparent' }, - ], - [{ type: 'showTreeEntry' }], + [{ type: types.SET_TREE_OPEN, payload: 'grandparent/parent' }], + [{ type: 'showTreeEntry', payload: 'grandparent/parent' }], done, ); }); diff --git a/spec/javascripts/ide/stores/modules/merge_requests/actions_spec.js b/spec/javascripts/ide/stores/modules/merge_requests/actions_spec.js index fa4c18931e5..d063f1ea860 100644 --- a/spec/javascripts/ide/stores/modules/merge_requests/actions_spec.js +++ b/spec/javascripts/ide/stores/modules/merge_requests/actions_spec.js @@ -2,7 +2,7 @@ import MockAdapter from 'axios-mock-adapter'; import axios from '~/lib/utils/axios_utils'; import state from '~/ide/stores/modules/merge_requests/state'; import * as types from '~/ide/stores/modules/merge_requests/mutation_types'; -import actions, { +import { requestMergeRequests, receiveMergeRequestsError, receiveMergeRequestsSuccess, @@ -41,28 +41,26 @@ describe('IDE merge requests actions', () => { }); describe('receiveMergeRequestsError', () => { - let flashSpy; - - beforeEach(() => { - flashSpy = spyOnDependency(actions, 'flash'); - }); - it('should should commit error', done => { testAction( receiveMergeRequestsError, - 'created', + { type: 'created', search: '' }, mockedState, [{ type: types.RECEIVE_MERGE_REQUESTS_ERROR, payload: 'created' }], - [], + [ + { + type: 'setErrorMessage', + payload: { + text: 'Error loading merge requests.', + action: jasmine.any(Function), + actionText: 'Please try again', + actionPayload: { type: 'created', search: '' }, + }, + }, + ], done, ); }); - - it('creates flash message', () => { - receiveMergeRequestsError({ commit() {} }, 'created'); - - expect(flashSpy).toHaveBeenCalled(); - }); }); describe('receiveMergeRequestsSuccess', () => { @@ -124,21 +122,6 @@ describe('IDE merge requests actions', () => { }); }); - it('dispatches request', done => { - testAction( - fetchMergeRequests, - { type: 'created' }, - mockedState, - [], - [ - { type: 'requestMergeRequests' }, - { type: 'resetMergeRequests' }, - { type: 'receiveMergeRequestsSuccess' }, - ], - done, - ); - }); - it('dispatches success with received data', done => { testAction( fetchMergeRequests, @@ -146,8 +129,8 @@ describe('IDE merge requests actions', () => { mockedState, [], [ - { type: 'requestMergeRequests' }, - { type: 'resetMergeRequests' }, + { type: 'requestMergeRequests', payload: 'created' }, + { type: 'resetMergeRequests', payload: 'created' }, { type: 'receiveMergeRequestsSuccess', payload: { type: 'created', data: mergeRequests }, @@ -170,9 +153,9 @@ describe('IDE merge requests actions', () => { mockedState, [], [ - { type: 'requestMergeRequests' }, - { type: 'resetMergeRequests' }, - { type: 'receiveMergeRequestsError' }, + { type: 'requestMergeRequests', payload: 'created' }, + { type: 'resetMergeRequests', payload: 'created' }, + { type: 'receiveMergeRequestsError', payload: { type: 'created', search: '' } }, ], done, ); diff --git a/spec/javascripts/ide/stores/modules/pipelines/actions_spec.js b/spec/javascripts/ide/stores/modules/pipelines/actions_spec.js index f47e69d6e5b..91edb388791 100644 --- a/spec/javascripts/ide/stores/modules/pipelines/actions_spec.js +++ b/spec/javascripts/ide/stores/modules/pipelines/actions_spec.js @@ -1,7 +1,7 @@ import Visibility from 'visibilityjs'; import MockAdapter from 'axios-mock-adapter'; import axios from '~/lib/utils/axios_utils'; -import actions, { +import { requestLatestPipeline, receiveLatestPipelineError, receiveLatestPipelineSuccess, @@ -59,7 +59,7 @@ describe('IDE pipelines actions', () => { it('commits error', done => { testAction( receiveLatestPipelineError, - null, + { status: 404 }, mockedState, [{ type: types.RECEIVE_LASTEST_PIPELINE_ERROR }], [{ type: 'stopPipelinePolling' }], @@ -67,12 +67,26 @@ describe('IDE pipelines actions', () => { ); }); - it('creates flash message', () => { - const flashSpy = spyOnDependency(actions, 'flash'); - - receiveLatestPipelineError({ commit() {}, dispatch() {} }); - - expect(flashSpy).toHaveBeenCalled(); + it('dispatches setErrorMessage is not 404', done => { + testAction( + receiveLatestPipelineError, + { status: 500 }, + mockedState, + [{ type: types.RECEIVE_LASTEST_PIPELINE_ERROR }], + [ + { + type: 'setErrorMessage', + payload: { + text: 'An error occured whilst fetching the latest pipline.', + action: jasmine.any(Function), + actionText: 'Please try again', + actionPayload: null, + }, + }, + { type: 'stopPipelinePolling' }, + ], + done, + ); }); }); @@ -181,7 +195,10 @@ describe('IDE pipelines actions', () => { new Promise(resolve => requestAnimationFrame(resolve)) .then(() => { - expect(dispatch.calls.argsFor(1)).toEqual(['receiveLatestPipelineError']); + expect(dispatch.calls.argsFor(1)).toEqual([ + 'receiveLatestPipelineError', + jasmine.anything(), + ]); }) .then(done) .catch(done.fail); @@ -199,21 +216,23 @@ describe('IDE pipelines actions', () => { it('commits error', done => { testAction( receiveJobsError, - 1, + { id: 1 }, mockedState, [{ type: types.RECEIVE_JOBS_ERROR, payload: 1 }], - [], + [ + { + type: 'setErrorMessage', + payload: { + text: 'An error occured whilst loading the pipelines jobs.', + action: jasmine.anything(), + actionText: 'Please try again', + actionPayload: { id: 1 }, + }, + }, + ], done, ); }); - - it('creates flash message', () => { - const flashSpy = spyOnDependency(actions, 'flash'); - - receiveJobsError({ commit() {} }, 1); - - expect(flashSpy).toHaveBeenCalled(); - }); }); describe('receiveJobsSuccess', () => { @@ -268,7 +287,7 @@ describe('IDE pipelines actions', () => { [], [ { type: 'requestJobs', payload: stage.id }, - { type: 'receiveJobsError', payload: stage.id }, + { type: 'receiveJobsError', payload: stage }, ], done, ); @@ -296,7 +315,7 @@ describe('IDE pipelines actions', () => { 'job', mockedState, [{ type: types.SET_DETAIL_JOB, payload: 'job' }], - [{ type: 'setRightPane' }], + [{ type: 'setRightPane', payload: 'jobs-detail' }], done, ); }); @@ -306,7 +325,7 @@ describe('IDE pipelines actions', () => { setDetailJob, null, mockedState, - [{ type: types.SET_DETAIL_JOB }], + [{ type: types.SET_DETAIL_JOB, payload: null }], [{ type: 'setRightPane', payload: rightSidebarViews.pipelines }], done, ); @@ -317,7 +336,7 @@ describe('IDE pipelines actions', () => { setDetailJob, 'job', mockedState, - [{ type: types.SET_DETAIL_JOB }], + [{ type: types.SET_DETAIL_JOB, payload: 'job' }], [{ type: 'setRightPane', payload: rightSidebarViews.jobsDetail }], done, ); @@ -337,18 +356,20 @@ describe('IDE pipelines actions', () => { null, mockedState, [{ type: types.RECEIVE_JOB_TRACE_ERROR }], - [], + [ + { + type: 'setErrorMessage', + payload: { + text: 'An error occured whilst fetching the job trace.', + action: jasmine.any(Function), + actionText: 'Please try again', + actionPayload: null, + }, + }, + ], done, ); }); - - it('creates flash message', () => { - const flashSpy = spyOnDependency(actions, 'flash'); - - receiveJobTraceError({ commit() {} }); - - expect(flashSpy).toHaveBeenCalled(); - }); }); describe('receiveJobTraceSuccess', () => { diff --git a/spec/javascripts/issuable_time_tracker_spec.js b/spec/javascripts/issuable_time_tracker_spec.js deleted file mode 100644 index 5add150f874..00000000000 --- a/spec/javascripts/issuable_time_tracker_spec.js +++ /dev/null @@ -1,201 +0,0 @@ -/* eslint-disable no-unused-vars, func-call-spacing, no-spaced-func, semi, quotes, space-infix-ops, max-len */ - -import $ from 'jquery'; -import Vue from 'vue'; - -import timeTracker from '~/sidebar/components/time_tracking/time_tracker.vue'; - -function initTimeTrackingComponent(opts) { - setFixtures(` - <div> - <div id="mock-container"></div> - </div> - `); - - this.initialData = { - time_estimate: opts.timeEstimate, - time_spent: opts.timeSpent, - human_time_estimate: opts.timeEstimateHumanReadable, - human_time_spent: opts.timeSpentHumanReadable, - rootPath: '/', - }; - - const TimeTrackingComponent = Vue.extend(timeTracker); - this.timeTracker = new TimeTrackingComponent({ - el: '#mock-container', - propsData: this.initialData, - }); -} - -describe('Issuable Time Tracker', function() { - describe('Initialization', function() { - beforeEach(function() { - initTimeTrackingComponent.call(this, { timeEstimate: 100000, timeSpent: 5000, timeEstimateHumanReadable: '2h 46m', timeSpentHumanReadable: '1h 23m' }); - }); - - it('should return something defined', function() { - expect(this.timeTracker).toBeDefined(); - }); - - it ('should correctly set timeEstimate', function(done) { - Vue.nextTick(() => { - expect(this.timeTracker.timeEstimate).toBe(this.initialData.time_estimate); - done(); - }); - }); - it ('should correctly set time_spent', function(done) { - Vue.nextTick(() => { - expect(this.timeTracker.timeSpent).toBe(this.initialData.time_spent); - done(); - }); - }); - }); - - describe('Content Display', function() { - describe('Panes', function() { - describe('Comparison pane', function() { - beforeEach(function() { - initTimeTrackingComponent.call(this, { timeEstimate: 100000, timeSpent: 5000, timeEstimateHumanReadable: '', timeSpentHumanReadable: '' }); - }); - - it('should show the "Comparison" pane when timeEstimate and time_spent are truthy', function(done) { - Vue.nextTick(() => { - const $comparisonPane = this.timeTracker.$el.querySelector('.time-tracking-comparison-pane'); - expect(this.timeTracker.showComparisonState).toBe(true); - done(); - }); - }); - - describe('Remaining meter', function() { - it('should display the remaining meter with the correct width', function(done) { - Vue.nextTick(() => { - const meterWidth = this.timeTracker.$el.querySelector('.time-tracking-comparison-pane .meter-fill').style.width; - const correctWidth = '5%'; - - expect(meterWidth).toBe(correctWidth); - done(); - }) - }); - - it('should display the remaining meter with the correct background color when within estimate', function(done) { - Vue.nextTick(() => { - const styledMeter = $(this.timeTracker.$el).find('.time-tracking-comparison-pane .within_estimate .meter-fill'); - expect(styledMeter.length).toBe(1); - done() - }); - }); - - it('should display the remaining meter with the correct background color when over estimate', function(done) { - this.timeTracker.time_estimate = 100000; - this.timeTracker.time_spent = 20000000; - Vue.nextTick(() => { - const styledMeter = $(this.timeTracker.$el).find('.time-tracking-comparison-pane .over_estimate .meter-fill'); - expect(styledMeter.length).toBe(1); - done(); - }); - }); - }); - }); - - describe("Estimate only pane", function() { - beforeEach(function() { - initTimeTrackingComponent.call(this, { timeEstimate: 100000, timeSpent: 0, timeEstimateHumanReadable: '2h 46m', timeSpentHumanReadable: '' }); - }); - - it('should display the human readable version of time estimated', function(done) { - Vue.nextTick(() => { - const estimateText = this.timeTracker.$el.querySelector('.time-tracking-estimate-only-pane').innerText; - const correctText = 'Estimated: 2h 46m'; - - expect(estimateText).toBe(correctText); - done(); - }); - }); - }); - - describe('Spent only pane', function() { - beforeEach(function() { - initTimeTrackingComponent.call(this, { timeEstimate: 0, timeSpent: 5000, timeEstimateHumanReadable: '2h 46m', timeSpentHumanReadable: '1h 23m' }); - }); - - it('should display the human readable version of time spent', function(done) { - Vue.nextTick(() => { - const spentText = this.timeTracker.$el.querySelector('.time-tracking-spend-only-pane').innerText; - const correctText = 'Spent: 1h 23m'; - - expect(spentText).toBe(correctText); - done(); - }); - }); - }); - - describe('No time tracking pane', function() { - beforeEach(function() { - initTimeTrackingComponent.call(this, { timeEstimate: 0, timeSpent: 0, timeEstimateHumanReadable: '', timeSpentHumanReadable: '' }); - }); - - it('should only show the "No time tracking" pane when both timeEstimate and time_spent are falsey', function(done) { - Vue.nextTick(() => { - const $noTrackingPane = this.timeTracker.$el.querySelector('.time-tracking-no-tracking-pane'); - const noTrackingText =$noTrackingPane.innerText; - const correctText = 'No estimate or time spent'; - - expect(this.timeTracker.showNoTimeTrackingState).toBe(true); - expect($noTrackingPane).toBeVisible(); - expect(noTrackingText).toBe(correctText); - done(); - }); - }); - }); - - describe("Help pane", function() { - beforeEach(function() { - initTimeTrackingComponent.call(this, { timeEstimate: 0, timeSpent: 0 }); - }); - - it('should not show the "Help" pane by default', function(done) { - Vue.nextTick(() => { - const $helpPane = this.timeTracker.$el.querySelector('.time-tracking-help-state'); - - expect(this.timeTracker.showHelpState).toBe(false); - expect($helpPane).toBeNull(); - done(); - }); - }); - - it('should show the "Help" pane when help button is clicked', function(done) { - Vue.nextTick(() => { - $(this.timeTracker.$el).find('.help-button').click(); - - setTimeout(() => { - const $helpPane = this.timeTracker.$el.querySelector('.time-tracking-help-state'); - expect(this.timeTracker.showHelpState).toBe(true); - expect($helpPane).toBeVisible(); - done(); - }, 10); - }); - }); - - it('should not show the "Help" pane when help button is clicked and then closed', function(done) { - Vue.nextTick(() => { - $(this.timeTracker.$el).find('.help-button').click(); - - setTimeout(() => { - - $(this.timeTracker.$el).find('.close-help-button').click(); - - setTimeout(() => { - const $helpPane = this.timeTracker.$el.querySelector('.time-tracking-help-state'); - - expect(this.timeTracker.showHelpState).toBe(false); - expect($helpPane).toBeNull(); - - done(); - }, 1000); - }, 1000); - }); - }); - }); - }); - }); -}); diff --git a/spec/javascripts/job_spec.js b/spec/javascripts/job_spec.js index 79e375aa02e..2fcb5566ebc 100644 --- a/spec/javascripts/job_spec.js +++ b/spec/javascripts/job_spec.js @@ -5,6 +5,7 @@ import { numberToHumanSize } from '~/lib/utils/number_utils'; import '~/lib/utils/datetime_utility'; import Job from '~/job'; import '~/breakpoints'; +import waitForPromises from 'spec/helpers/wait_for_promises'; describe('Job', () => { const JOB_URL = `${gl.TEST_HOST}/frontend-fixtures/builds-project/-/jobs/1`; @@ -12,10 +13,6 @@ describe('Job', () => { let response; let job; - function waitForPromise() { - return new Promise(resolve => requestAnimationFrame(resolve)); - } - preloadFixtures('builds/build-with-artifacts.html.raw'); beforeEach(() => { @@ -49,7 +46,7 @@ describe('Job', () => { beforeEach(function (done) { job = new Job(); - waitForPromise() + waitForPromises() .then(done) .catch(done.fail); }); @@ -93,7 +90,7 @@ describe('Job', () => { job = new Job(); - waitForPromise() + waitForPromises() .then(() => { expect($('#build-trace .js-build-output').text()).toMatch(/Update/); expect(job.state).toBe('newstate'); @@ -107,7 +104,7 @@ describe('Job', () => { }; }) .then(() => jasmine.clock().tick(4001)) - .then(waitForPromise) + .then(waitForPromises) .then(() => { expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/); expect(job.state).toBe('finalstate'); @@ -126,7 +123,7 @@ describe('Job', () => { job = new Job(); - waitForPromise() + waitForPromises() .then(() => { expect($('#build-trace .js-build-output').text()).toMatch(/Update/); @@ -137,7 +134,7 @@ describe('Job', () => { }; }) .then(() => jasmine.clock().tick(4001)) - .then(waitForPromise) + .then(waitForPromises) .then(() => { expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/); expect($('#build-trace .js-build-output').text()).toMatch(/Different/); @@ -160,7 +157,7 @@ describe('Job', () => { job = new Job(); - waitForPromise() + waitForPromises() .then(() => { expect(document.querySelector('.js-truncated-info').classList).not.toContain('hidden'); }) @@ -181,7 +178,7 @@ describe('Job', () => { job = new Job(); - waitForPromise() + waitForPromises() .then(() => { expect( document.querySelector('.js-truncated-info-size').textContent.trim(), @@ -203,7 +200,7 @@ describe('Job', () => { job = new Job(); - waitForPromise() + waitForPromises() .then(() => { expect( document.querySelector('.js-truncated-info-size').textContent.trim(), @@ -219,7 +216,7 @@ describe('Job', () => { }; }) .then(() => jasmine.clock().tick(4001)) - .then(waitForPromise) + .then(waitForPromises) .then(() => { expect( document.querySelector('.js-truncated-info-size').textContent.trim(), @@ -258,7 +255,7 @@ describe('Job', () => { job = new Job(); - waitForPromise() + waitForPromises() .then(() => { expect(document.querySelector('.js-truncated-info').classList).toContain('hidden'); }) @@ -280,7 +277,7 @@ describe('Job', () => { job = new Job(); - waitForPromise() + waitForPromises() .then(done) .catch(done.fail); }); diff --git a/spec/javascripts/monitoring/dashboard_spec.js b/spec/javascripts/monitoring/dashboard_spec.js index eba6dcf47c5..997163c7602 100644 --- a/spec/javascripts/monitoring/dashboard_spec.js +++ b/spec/javascripts/monitoring/dashboard_spec.js @@ -2,7 +2,7 @@ import Vue from 'vue'; import MockAdapter from 'axios-mock-adapter'; import Dashboard from '~/monitoring/components/dashboard.vue'; import axios from '~/lib/utils/axios_utils'; -import { metricsGroupsAPIResponse, mockApiEndpoint } from './mock_data'; +import { metricsGroupsAPIResponse, mockApiEndpoint, environmentData } from './mock_data'; describe('Dashboard', () => { let DashboardComponent; @@ -20,6 +20,8 @@ describe('Dashboard', () => { emptyLoadingSvgPath: '/path/to/loading.svg', emptyNoDataSvgPath: '/path/to/no-data.svg', emptyUnableToConnectSvgPath: '/path/to/unable-to-connect.svg', + environmentsEndpoint: '/root/hello-prometheus/environments/35', + currentEnvironmentName: 'production', }; beforeEach(() => { @@ -50,7 +52,7 @@ describe('Dashboard', () => { mock.restore(); }); - it('shows up a loading state', (done) => { + it('shows up a loading state', done => { const component = new DashboardComponent({ el: document.querySelector('.prometheus-graphs'), propsData: { ...propsData, hasMetrics: true }, @@ -62,7 +64,7 @@ describe('Dashboard', () => { }); }); - it('hides the legend when showLegend is false', (done) => { + it('hides the legend when showLegend is false', done => { const component = new DashboardComponent({ el: document.querySelector('.prometheus-graphs'), propsData: { ...propsData, hasMetrics: true, showLegend: false }, @@ -76,7 +78,7 @@ describe('Dashboard', () => { }); }); - it('hides the group panels when showPanels is false', (done) => { + it('hides the group panels when showPanels is false', done => { const component = new DashboardComponent({ el: document.querySelector('.prometheus-graphs'), propsData: { ...propsData, hasMetrics: true, showPanels: false }, @@ -89,5 +91,40 @@ describe('Dashboard', () => { done(); }); }); + + it('renders the dropdown with a number of environments', done => { + const component = new DashboardComponent({ + el: document.querySelector('.prometheus-graphs'), + propsData: { ...propsData, hasMetrics: true, showPanels: false }, + }); + + component.store.storeEnvironmentsData(environmentData); + + setTimeout(() => { + const dropdownMenuEnvironments = component.$el.querySelectorAll('.dropdown-menu ul li a'); + expect(dropdownMenuEnvironments.length).toEqual(component.store.environmentsData.length); + done(); + }); + }); + + it('renders the dropdown with a single is-active element', done => { + const component = new DashboardComponent({ + el: document.querySelector('.prometheus-graphs'), + propsData: { ...propsData, hasMetrics: true, showPanels: false }, + }); + + component.store.storeEnvironmentsData(environmentData); + + setTimeout(() => { + const dropdownIsActiveElement = component.$el.querySelectorAll( + '.dropdown-menu ul li a.is-active', + ); + expect(dropdownIsActiveElement.length).toEqual(1); + expect(dropdownIsActiveElement[0].textContent.trim()).toEqual( + component.currentEnvironmentName, + ); + done(); + }); + }); }); }); diff --git a/spec/javascripts/monitoring/mock_data.js b/spec/javascripts/monitoring/mock_data.js index 799d03f6b57..10808315372 100644 --- a/spec/javascripts/monitoring/mock_data.js +++ b/spec/javascripts/monitoring/mock_data.js @@ -6542,3 +6542,44 @@ export function convertDatesMultipleSeries(multipleSeries) { }); return convertedMultiple; } + +export const environmentData = [ + { + name: 'production', + size: 1, + latest: { + id: 34, + name: 'production', + state: 'available', + external_url: 'http://root-autodevops-deploy.my-fake-domain.com', + environment_type: null, + stop_action: false, + metrics_path: '/root/hello-prometheus/environments/34/metrics', + environment_path: '/root/hello-prometheus/environments/34', + stop_path: '/root/hello-prometheus/environments/34/stop', + terminal_path: '/root/hello-prometheus/environments/34/terminal', + folder_path: '/root/hello-prometheus/environments/folders/production', + created_at: '2018-06-29T16:53:38.301Z', + updated_at: '2018-06-29T16:57:09.825Z', + }, + }, + { + name: 'review', + size: 1, + latest: { + id: 35, + name: 'review/noop-branch', + state: 'available', + external_url: 'http://root-autodevops-deploy-review-noop-branc-die93w.my-fake-domain.com', + environment_type: 'review', + stop_action: true, + metrics_path: '/root/hello-prometheus/environments/35/metrics', + environment_path: '/root/hello-prometheus/environments/35', + stop_path: '/root/hello-prometheus/environments/35/stop', + terminal_path: '/root/hello-prometheus/environments/35/terminal', + folder_path: '/root/hello-prometheus/environments/folders/review', + created_at: '2018-07-03T18:39:41.702Z', + updated_at: '2018-07-03T18:44:54.010Z', + }, + }, +]; diff --git a/spec/javascripts/notes/components/discussion_counter_spec.js b/spec/javascripts/notes/components/discussion_counter_spec.js index 7b2302e6f47..a3869cc6498 100644 --- a/spec/javascripts/notes/components/discussion_counter_spec.js +++ b/spec/javascripts/notes/components/discussion_counter_spec.js @@ -32,12 +32,12 @@ describe('DiscussionCounter component', () => { { ...discussionMock, id: discussionMock.id, - notes: [{ ...discussionMock.notes[0], resolved: true }], + notes: [{ ...discussionMock.notes[0], resolvable: true, resolved: true }], }, { ...discussionMock, id: discussionMock.id + 1, - notes: [{ ...discussionMock.notes[0], resolved: false }], + notes: [{ ...discussionMock.notes[0], resolvable: true, resolved: false }], }, ]; const firstDiscussionId = discussionMock.id + 1; diff --git a/spec/javascripts/notes/components/noteable_discussion_spec.js b/spec/javascripts/notes/components/noteable_discussion_spec.js index 058ddb6202f..7da931fd9cb 100644 --- a/spec/javascripts/notes/components/noteable_discussion_spec.js +++ b/spec/javascripts/notes/components/noteable_discussion_spec.js @@ -4,22 +4,23 @@ import noteableDiscussion from '~/notes/components/noteable_discussion.vue'; import '~/behaviors/markdown/render_gfm'; import { noteableDataMock, discussionMock, notesDataMock } from '../mock_data'; +const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json'; + describe('noteable_discussion component', () => { + const Component = Vue.extend(noteableDiscussion); let store; let vm; - beforeEach(() => { - const Component = Vue.extend(noteableDiscussion); + preloadFixtures(discussionWithTwoUnresolvedNotes); + beforeEach(() => { store = createStore(); store.dispatch('setNoteableData', noteableDataMock); store.dispatch('setNotesData', notesDataMock); vm = new Component({ store, - propsData: { - discussion: discussionMock, - }, + propsData: { discussion: discussionMock }, }).$mount(); }); @@ -84,7 +85,9 @@ describe('noteable_discussion component', () => { }); it('is true if there are two unresolved discussions', done => { - spyOnProperty(vm, 'unresolvedDiscussions').and.returnValue([{}, {}]); + const discussion = getJSONFixture(discussionWithTwoUnresolvedNotes)[0]; + discussion.notes[0].resolved = false; + vm.$store.dispatch('setInitialNotes', [discussion, discussion]); Vue.nextTick() .then(() => { @@ -105,12 +108,12 @@ describe('noteable_discussion component', () => { { ...discussionMock, id: discussionMock.id + 1, - notes: [{ ...discussionMock.notes[0], resolved: true }], + notes: [{ ...discussionMock.notes[0], resolvable: true, resolved: true }], }, { ...discussionMock, id: discussionMock.id + 2, - notes: [{ ...discussionMock.notes[0], resolved: false }], + notes: [{ ...discussionMock.notes[0], resolvable: true, resolved: false }], }, ]; const nextDiscussionId = discussionMock.id + 2; diff --git a/spec/javascripts/notes/mock_data.js b/spec/javascripts/notes/mock_data.js index 547efa32694..be2a8ba67fe 100644 --- a/spec/javascripts/notes/mock_data.js +++ b/spec/javascripts/notes/mock_data.js @@ -165,6 +165,7 @@ export const note = { report_abuse_path: '/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F7%23note_546&user_id=1', path: '/gitlab-org/gitlab-ce/notes/546', + cached_markdown_version: 11, }; export const discussionMock = { @@ -303,6 +304,7 @@ export const discussionMock = { }, ], individual_note: false, + resolvable: true, }; export const loggedOutnoteableData = { diff --git a/spec/javascripts/notes/stores/actions_spec.js b/spec/javascripts/notes/stores/actions_spec.js index 71ef3aa9b03..b66e8e1ceb3 100644 --- a/spec/javascripts/notes/stores/actions_spec.js +++ b/spec/javascripts/notes/stores/actions_spec.js @@ -128,6 +128,19 @@ describe('Actions Notes Store', () => { }); }); + describe('collapseDiscussion', () => { + it('should commit collapse discussion', done => { + testAction( + actions.collapseDiscussion, + { discussionId: discussionMock.id }, + { notes: [discussionMock] }, + [{ type: 'COLLAPSE_DISCUSSION', payload: { discussionId: discussionMock.id } }], + [], + done, + ); + }); + }); + describe('async methods', () => { const interceptor = (request, next) => { next( diff --git a/spec/javascripts/notes/stores/getters_spec.js b/spec/javascripts/notes/stores/getters_spec.js index 815cc09621f..41599e00122 100644 --- a/spec/javascripts/notes/stores/getters_spec.js +++ b/spec/javascripts/notes/stores/getters_spec.js @@ -7,9 +7,13 @@ import { collapseNotesMock, } from '../mock_data'; +const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json'; + describe('Getters Notes Store', () => { let state; + preloadFixtures(discussionWithTwoUnresolvedNotes); + beforeEach(() => { state = { discussions: [individualNote], @@ -22,12 +26,26 @@ describe('Getters Notes Store', () => { noteableData: noteableDataMock, }; }); + describe('discussions', () => { it('should return all discussions in the store', () => { expect(getters.discussions(state)).toEqual([individualNote]); }); }); + describe('resolvedDiscussionsById', () => { + it('ignores unresolved system notes', () => { + const [discussion] = getJSONFixture(discussionWithTwoUnresolvedNotes); + discussion.notes[0].resolved = true; + discussion.notes[1].resolved = false; + state.discussions.push(discussion); + + expect(getters.resolvedDiscussionsById(state)).toEqual({ + [discussion.id]: discussion, + }); + }); + }); + describe('Collapsed notes', () => { const stateCollapsedNotes = { discussions: collapseNotesMock, diff --git a/spec/javascripts/notes/stores/mutation_spec.js b/spec/javascripts/notes/stores/mutation_spec.js index ccc7328447b..a15ff1a5888 100644 --- a/spec/javascripts/notes/stores/mutation_spec.js +++ b/spec/javascripts/notes/stores/mutation_spec.js @@ -74,6 +74,20 @@ describe('Notes Store mutations', () => { }); }); + describe('COLLAPSE_DISCUSSION', () => { + it('should collpase an expanded discussion', () => { + const discussion = Object.assign({}, discussionMock, { expanded: true }); + + const state = { + discussions: [discussion], + }; + + mutations.COLLAPSE_DISCUSSION(state, { discussionId: discussion.id }); + + expect(state.discussions[0].expanded).toEqual(false); + }); + }); + describe('REMOVE_PLACEHOLDER_NOTES', () => { it('should remove all placeholder notes in indivudal notes and discussion', () => { const placeholderNote = Object.assign({}, individualNote, { isPlaceholderNote: true }); diff --git a/spec/javascripts/profile/add_ssh_key_validation_spec.js b/spec/javascripts/profile/add_ssh_key_validation_spec.js new file mode 100644 index 00000000000..c71a2885acc --- /dev/null +++ b/spec/javascripts/profile/add_ssh_key_validation_spec.js @@ -0,0 +1,69 @@ +import AddSshKeyValidation from '../../../app/assets/javascripts/profile/add_ssh_key_validation'; + +describe('AddSshKeyValidation', () => { + describe('submit', () => { + it('returns true if isValid is true', () => { + const addSshKeyValidation = new AddSshKeyValidation({}); + spyOn(AddSshKeyValidation, 'isPublicKey').and.returnValue(true); + + expect(addSshKeyValidation.submit()).toBeTruthy(); + }); + + it('calls preventDefault and toggleWarning if isValid is false', () => { + const addSshKeyValidation = new AddSshKeyValidation({}); + const event = jasmine.createSpyObj('event', ['preventDefault']); + spyOn(AddSshKeyValidation, 'isPublicKey').and.returnValue(false); + spyOn(addSshKeyValidation, 'toggleWarning'); + + addSshKeyValidation.submit(event); + + expect(event.preventDefault).toHaveBeenCalled(); + expect(addSshKeyValidation.toggleWarning).toHaveBeenCalledWith(true); + }); + }); + + describe('toggleWarning', () => { + it('shows warningElement and hides originalSubmitElement if isVisible is true', () => { + const warningElement = document.createElement('div'); + const originalSubmitElement = document.createElement('div'); + warningElement.classList.add('hide'); + + const addSshKeyValidation = new AddSshKeyValidation( + {}, + warningElement, + originalSubmitElement, + ); + addSshKeyValidation.toggleWarning(true); + + expect(warningElement.classList.contains('hide')).toBeFalsy(); + expect(originalSubmitElement.classList.contains('hide')).toBeTruthy(); + }); + + it('hides warningElement and shows originalSubmitElement if isVisible is false', () => { + const warningElement = document.createElement('div'); + const originalSubmitElement = document.createElement('div'); + originalSubmitElement.classList.add('hide'); + + const addSshKeyValidation = new AddSshKeyValidation( + {}, + warningElement, + originalSubmitElement, + ); + addSshKeyValidation.toggleWarning(false); + + expect(warningElement.classList.contains('hide')).toBeTruthy(); + expect(originalSubmitElement.classList.contains('hide')).toBeFalsy(); + }); + }); + + describe('isPublicKey', () => { + it('returns false if probably invalid public ssh key', () => { + expect(AddSshKeyValidation.isPublicKey('nope')).toBeFalsy(); + }); + + it('returns true if probably valid public ssh key', () => { + expect(AddSshKeyValidation.isPublicKey('ssh-')).toBeTruthy(); + expect(AddSshKeyValidation.isPublicKey('ecdsa-sha2-')).toBeTruthy(); + }); + }); +}); diff --git a/spec/javascripts/projects_dropdown/components/app_spec.js b/spec/javascripts/projects_dropdown/components/app_spec.js deleted file mode 100644 index 38b31c3d727..00000000000 --- a/spec/javascripts/projects_dropdown/components/app_spec.js +++ /dev/null @@ -1,349 +0,0 @@ -import Vue from 'vue'; - -import bp from '~/breakpoints'; -import appComponent from '~/projects_dropdown/components/app.vue'; -import eventHub from '~/projects_dropdown/event_hub'; -import ProjectsStore from '~/projects_dropdown/store/projects_store'; -import ProjectsService from '~/projects_dropdown/service/projects_service'; - -import mountComponent from 'spec/helpers/vue_mount_component_helper'; -import { currentSession, mockProject, mockRawProject } from '../mock_data'; - -const createComponent = () => { - gon.api_version = currentSession.apiVersion; - const Component = Vue.extend(appComponent); - const store = new ProjectsStore(); - const service = new ProjectsService(currentSession.username); - - return mountComponent(Component, { - store, - service, - currentUserName: currentSession.username, - currentProject: currentSession.project, - }); -}; - -const returnServicePromise = (data, failed) => - new Promise((resolve, reject) => { - if (failed) { - reject(data); - } else { - resolve({ - json() { - return data; - }, - }); - } - }); - -describe('AppComponent', () => { - describe('computed', () => { - let vm; - - beforeEach(() => { - vm = createComponent(); - }); - - afterEach(() => { - vm.$destroy(); - }); - - describe('frequentProjects', () => { - it('should return list of frequently accessed projects from store', () => { - expect(vm.frequentProjects).toBeDefined(); - expect(vm.frequentProjects.length).toBe(0); - - vm.store.setFrequentProjects([mockProject]); - expect(vm.frequentProjects).toBeDefined(); - expect(vm.frequentProjects.length).toBe(1); - }); - }); - - describe('searchProjects', () => { - it('should return list of frequently accessed projects from store', () => { - expect(vm.searchProjects).toBeDefined(); - expect(vm.searchProjects.length).toBe(0); - - vm.store.setSearchedProjects([mockRawProject]); - expect(vm.searchProjects).toBeDefined(); - expect(vm.searchProjects.length).toBe(1); - }); - }); - }); - - describe('methods', () => { - let vm; - - beforeEach(() => { - vm = createComponent(); - }); - - afterEach(() => { - vm.$destroy(); - }); - - describe('toggleFrequentProjectsList', () => { - it('should toggle props which control visibility of Frequent Projects list from state passed', () => { - vm.toggleFrequentProjectsList(true); - expect(vm.isLoadingProjects).toBeFalsy(); - expect(vm.isSearchListVisible).toBeFalsy(); - expect(vm.isFrequentsListVisible).toBeTruthy(); - - vm.toggleFrequentProjectsList(false); - expect(vm.isLoadingProjects).toBeTruthy(); - expect(vm.isSearchListVisible).toBeTruthy(); - expect(vm.isFrequentsListVisible).toBeFalsy(); - }); - }); - - describe('toggleSearchProjectsList', () => { - it('should toggle props which control visibility of Searched Projects list from state passed', () => { - vm.toggleSearchProjectsList(true); - expect(vm.isLoadingProjects).toBeFalsy(); - expect(vm.isFrequentsListVisible).toBeFalsy(); - expect(vm.isSearchListVisible).toBeTruthy(); - - vm.toggleSearchProjectsList(false); - expect(vm.isLoadingProjects).toBeTruthy(); - expect(vm.isFrequentsListVisible).toBeTruthy(); - expect(vm.isSearchListVisible).toBeFalsy(); - }); - }); - - describe('toggleLoader', () => { - it('should toggle props which control visibility of list loading animation from state passed', () => { - vm.toggleLoader(true); - expect(vm.isFrequentsListVisible).toBeFalsy(); - expect(vm.isSearchListVisible).toBeFalsy(); - expect(vm.isLoadingProjects).toBeTruthy(); - - vm.toggleLoader(false); - expect(vm.isFrequentsListVisible).toBeTruthy(); - expect(vm.isSearchListVisible).toBeTruthy(); - expect(vm.isLoadingProjects).toBeFalsy(); - }); - }); - - describe('fetchFrequentProjects', () => { - it('should set props for loading animation to `true` while frequent projects list is being loaded', () => { - spyOn(vm, 'toggleLoader'); - - vm.fetchFrequentProjects(); - expect(vm.isLocalStorageFailed).toBeFalsy(); - expect(vm.toggleLoader).toHaveBeenCalledWith(true); - }); - - it('should set props for loading animation to `false` and props for frequent projects list to `true` once data is loaded', () => { - const mockData = [mockProject]; - - spyOn(vm.service, 'getFrequentProjects').and.returnValue(mockData); - spyOn(vm.store, 'setFrequentProjects'); - spyOn(vm, 'toggleFrequentProjectsList'); - - vm.fetchFrequentProjects(); - expect(vm.service.getFrequentProjects).toHaveBeenCalled(); - expect(vm.store.setFrequentProjects).toHaveBeenCalledWith(mockData); - expect(vm.toggleFrequentProjectsList).toHaveBeenCalledWith(true); - }); - - it('should set props for failure message to `true` when method fails to fetch frequent projects list', () => { - spyOn(vm.service, 'getFrequentProjects').and.returnValue(null); - spyOn(vm.store, 'setFrequentProjects'); - spyOn(vm, 'toggleFrequentProjectsList'); - - expect(vm.isLocalStorageFailed).toBeFalsy(); - - vm.fetchFrequentProjects(); - expect(vm.service.getFrequentProjects).toHaveBeenCalled(); - expect(vm.store.setFrequentProjects).toHaveBeenCalledWith([]); - expect(vm.toggleFrequentProjectsList).toHaveBeenCalledWith(true); - expect(vm.isLocalStorageFailed).toBeTruthy(); - }); - - it('should set props for search results list to `true` if search query was already made previously', () => { - spyOn(bp, 'getBreakpointSize').and.returnValue('md'); - spyOn(vm.service, 'getFrequentProjects'); - spyOn(vm, 'toggleSearchProjectsList'); - - vm.searchQuery = 'test'; - vm.fetchFrequentProjects(); - expect(vm.service.getFrequentProjects).not.toHaveBeenCalled(); - expect(vm.toggleSearchProjectsList).toHaveBeenCalledWith(true); - }); - - it('should set props for frequent projects list to `true` if search query was already made but screen size is less than 768px', () => { - spyOn(bp, 'getBreakpointSize').and.returnValue('sm'); - spyOn(vm, 'toggleSearchProjectsList'); - spyOn(vm.service, 'getFrequentProjects'); - - vm.searchQuery = 'test'; - vm.fetchFrequentProjects(); - expect(vm.service.getFrequentProjects).toHaveBeenCalled(); - expect(vm.toggleSearchProjectsList).not.toHaveBeenCalled(); - }); - }); - - describe('fetchSearchedProjects', () => { - const searchQuery = 'test'; - - it('should perform search with provided search query', done => { - const mockData = [mockRawProject]; - spyOn(vm, 'toggleLoader'); - spyOn(vm, 'toggleSearchProjectsList'); - spyOn(vm.service, 'getSearchedProjects').and.returnValue(returnServicePromise(mockData)); - spyOn(vm.store, 'setSearchedProjects'); - - vm.fetchSearchedProjects(searchQuery); - setTimeout(() => { - expect(vm.searchQuery).toBe(searchQuery); - expect(vm.toggleLoader).toHaveBeenCalledWith(true); - expect(vm.service.getSearchedProjects).toHaveBeenCalledWith(searchQuery); - expect(vm.toggleSearchProjectsList).toHaveBeenCalledWith(true); - expect(vm.store.setSearchedProjects).toHaveBeenCalledWith(mockData); - done(); - }, 0); - }); - - it('should update props for showing search failure', done => { - spyOn(vm, 'toggleSearchProjectsList'); - spyOn(vm.service, 'getSearchedProjects').and.returnValue(returnServicePromise({}, true)); - - vm.fetchSearchedProjects(searchQuery); - setTimeout(() => { - expect(vm.searchQuery).toBe(searchQuery); - expect(vm.service.getSearchedProjects).toHaveBeenCalledWith(searchQuery); - expect(vm.isSearchFailed).toBeTruthy(); - expect(vm.toggleSearchProjectsList).toHaveBeenCalledWith(true); - done(); - }, 0); - }); - }); - - describe('logCurrentProjectAccess', () => { - it('should log current project access via service', done => { - spyOn(vm.service, 'logProjectAccess'); - - vm.currentProject = mockProject; - vm.logCurrentProjectAccess(); - - setTimeout(() => { - expect(vm.service.logProjectAccess).toHaveBeenCalledWith(mockProject); - done(); - }, 1); - }); - }); - - describe('handleSearchClear', () => { - it('should show frequent projects list when search input is cleared', () => { - spyOn(vm.store, 'clearSearchedProjects'); - spyOn(vm, 'toggleFrequentProjectsList'); - - vm.handleSearchClear(); - - expect(vm.toggleFrequentProjectsList).toHaveBeenCalledWith(true); - expect(vm.store.clearSearchedProjects).toHaveBeenCalled(); - expect(vm.searchQuery).toBe(''); - }); - }); - - describe('handleSearchFailure', () => { - it('should show failure message within dropdown', () => { - spyOn(vm, 'toggleSearchProjectsList'); - - vm.handleSearchFailure(); - expect(vm.toggleSearchProjectsList).toHaveBeenCalledWith(true); - expect(vm.isSearchFailed).toBeTruthy(); - }); - }); - }); - - describe('created', () => { - it('should bind event listeners on eventHub', done => { - spyOn(eventHub, '$on'); - - createComponent().$mount(); - - Vue.nextTick(() => { - expect(eventHub.$on).toHaveBeenCalledWith('dropdownOpen', jasmine.any(Function)); - expect(eventHub.$on).toHaveBeenCalledWith('searchProjects', jasmine.any(Function)); - expect(eventHub.$on).toHaveBeenCalledWith('searchCleared', jasmine.any(Function)); - expect(eventHub.$on).toHaveBeenCalledWith('searchFailed', jasmine.any(Function)); - done(); - }); - }); - }); - - describe('beforeDestroy', () => { - it('should unbind event listeners on eventHub', done => { - const vm = createComponent(); - spyOn(eventHub, '$off'); - - vm.$mount(); - vm.$destroy(); - - Vue.nextTick(() => { - expect(eventHub.$off).toHaveBeenCalledWith('dropdownOpen', jasmine.any(Function)); - expect(eventHub.$off).toHaveBeenCalledWith('searchProjects', jasmine.any(Function)); - expect(eventHub.$off).toHaveBeenCalledWith('searchCleared', jasmine.any(Function)); - expect(eventHub.$off).toHaveBeenCalledWith('searchFailed', jasmine.any(Function)); - done(); - }); - }); - }); - - describe('template', () => { - let vm; - - beforeEach(() => { - vm = createComponent(); - }); - - afterEach(() => { - vm.$destroy(); - }); - - it('should render search input', () => { - expect(vm.$el.querySelector('.search-input-container')).toBeDefined(); - }); - - it('should render loading animation', done => { - vm.toggleLoader(true); - Vue.nextTick(() => { - const loadingEl = vm.$el.querySelector('.loading-animation'); - - expect(loadingEl).toBeDefined(); - expect(loadingEl.classList.contains('prepend-top-20')).toBeTruthy(); - expect(loadingEl.querySelector('i').getAttribute('aria-label')).toBe('Loading projects'); - done(); - }); - }); - - it('should render frequent projects list header', done => { - vm.toggleFrequentProjectsList(true); - Vue.nextTick(() => { - const sectionHeaderEl = vm.$el.querySelector('.section-header'); - - expect(sectionHeaderEl).toBeDefined(); - expect(sectionHeaderEl.innerText.trim()).toBe('Frequently visited'); - done(); - }); - }); - - it('should render frequent projects list', done => { - vm.toggleFrequentProjectsList(true); - Vue.nextTick(() => { - expect(vm.$el.querySelector('.projects-list-frequent-container')).toBeDefined(); - done(); - }); - }); - - it('should render searched projects list', done => { - vm.toggleSearchProjectsList(true); - Vue.nextTick(() => { - expect(vm.$el.querySelector('.section-header')).toBe(null); - expect(vm.$el.querySelector('.projects-list-search-container')).toBeDefined(); - done(); - }); - }); - }); -}); diff --git a/spec/javascripts/projects_dropdown/components/projects_list_frequent_spec.js b/spec/javascripts/projects_dropdown/components/projects_list_frequent_spec.js deleted file mode 100644 index 2bafb4e81ca..00000000000 --- a/spec/javascripts/projects_dropdown/components/projects_list_frequent_spec.js +++ /dev/null @@ -1,72 +0,0 @@ -import Vue from 'vue'; - -import projectsListFrequentComponent from '~/projects_dropdown/components/projects_list_frequent.vue'; - -import mountComponent from 'spec/helpers/vue_mount_component_helper'; -import { mockFrequents } from '../mock_data'; - -const createComponent = () => { - const Component = Vue.extend(projectsListFrequentComponent); - - return mountComponent(Component, { - projects: mockFrequents, - localStorageFailed: false, - }); -}; - -describe('ProjectsListFrequentComponent', () => { - let vm; - - beforeEach(() => { - vm = createComponent(); - }); - - afterEach(() => { - vm.$destroy(); - }); - - describe('computed', () => { - describe('isListEmpty', () => { - it('should return `true` or `false` representing whether if `projects` is empty of not', () => { - vm.projects = []; - expect(vm.isListEmpty).toBeTruthy(); - - vm.projects = mockFrequents; - expect(vm.isListEmpty).toBeFalsy(); - }); - }); - - describe('listEmptyMessage', () => { - it('should return appropriate empty list message based on value of `localStorageFailed` prop', () => { - vm.localStorageFailed = true; - expect(vm.listEmptyMessage).toBe('This feature requires browser localStorage support'); - - vm.localStorageFailed = false; - expect(vm.listEmptyMessage).toBe('Projects you visit often will appear here'); - }); - }); - }); - - describe('template', () => { - it('should render component element with list of projects', (done) => { - vm.projects = mockFrequents; - - Vue.nextTick(() => { - expect(vm.$el.classList.contains('projects-list-frequent-container')).toBeTruthy(); - expect(vm.$el.querySelectorAll('ul.list-unstyled').length).toBe(1); - expect(vm.$el.querySelectorAll('li.projects-list-item-container').length).toBe(5); - done(); - }); - }); - - it('should render component element with empty message', (done) => { - vm.projects = []; - - Vue.nextTick(() => { - expect(vm.$el.querySelectorAll('li.section-empty').length).toBe(1); - expect(vm.$el.querySelectorAll('li.projects-list-item-container').length).toBe(0); - done(); - }); - }); - }); -}); diff --git a/spec/javascripts/projects_dropdown/components/projects_list_search_spec.js b/spec/javascripts/projects_dropdown/components/projects_list_search_spec.js deleted file mode 100644 index c4b86d77034..00000000000 --- a/spec/javascripts/projects_dropdown/components/projects_list_search_spec.js +++ /dev/null @@ -1,84 +0,0 @@ -import Vue from 'vue'; - -import projectsListSearchComponent from '~/projects_dropdown/components/projects_list_search.vue'; - -import mountComponent from 'spec/helpers/vue_mount_component_helper'; -import { mockProject } from '../mock_data'; - -const createComponent = () => { - const Component = Vue.extend(projectsListSearchComponent); - - return mountComponent(Component, { - projects: [mockProject], - matcher: 'lab', - searchFailed: false, - }); -}; - -describe('ProjectsListSearchComponent', () => { - let vm; - - beforeEach(() => { - vm = createComponent(); - }); - - afterEach(() => { - vm.$destroy(); - }); - - describe('computed', () => { - describe('isListEmpty', () => { - it('should return `true` or `false` representing whether if `projects` is empty of not', () => { - vm.projects = []; - expect(vm.isListEmpty).toBeTruthy(); - - vm.projects = [mockProject]; - expect(vm.isListEmpty).toBeFalsy(); - }); - }); - - describe('listEmptyMessage', () => { - it('should return appropriate empty list message based on value of `searchFailed` prop', () => { - vm.searchFailed = true; - expect(vm.listEmptyMessage).toBe('Something went wrong on our end.'); - - vm.searchFailed = false; - expect(vm.listEmptyMessage).toBe('Sorry, no projects matched your search'); - }); - }); - }); - - describe('template', () => { - it('should render component element with list of projects', (done) => { - vm.projects = [mockProject]; - - Vue.nextTick(() => { - expect(vm.$el.classList.contains('projects-list-search-container')).toBeTruthy(); - expect(vm.$el.querySelectorAll('ul.list-unstyled').length).toBe(1); - expect(vm.$el.querySelectorAll('li.projects-list-item-container').length).toBe(1); - done(); - }); - }); - - it('should render component element with empty message', (done) => { - vm.projects = []; - - Vue.nextTick(() => { - expect(vm.$el.querySelectorAll('li.section-empty').length).toBe(1); - expect(vm.$el.querySelectorAll('li.projects-list-item-container').length).toBe(0); - done(); - }); - }); - - it('should render component element with failure message', (done) => { - vm.searchFailed = true; - vm.projects = []; - - Vue.nextTick(() => { - expect(vm.$el.querySelectorAll('li.section-empty.section-failure').length).toBe(1); - expect(vm.$el.querySelectorAll('li.projects-list-item-container').length).toBe(0); - done(); - }); - }); - }); -}); diff --git a/spec/javascripts/projects_dropdown/components/search_spec.js b/spec/javascripts/projects_dropdown/components/search_spec.js deleted file mode 100644 index 427f5024e3a..00000000000 --- a/spec/javascripts/projects_dropdown/components/search_spec.js +++ /dev/null @@ -1,100 +0,0 @@ -import Vue from 'vue'; - -import searchComponent from '~/projects_dropdown/components/search.vue'; -import eventHub from '~/projects_dropdown/event_hub'; - -import mountComponent from 'spec/helpers/vue_mount_component_helper'; - -const createComponent = () => { - const Component = Vue.extend(searchComponent); - - return mountComponent(Component); -}; - -describe('SearchComponent', () => { - describe('methods', () => { - let vm; - - beforeEach(() => { - vm = createComponent(); - }); - - afterEach(() => { - vm.$destroy(); - }); - - describe('setFocus', () => { - it('should set focus to search input', () => { - spyOn(vm.$refs.search, 'focus'); - - vm.setFocus(); - expect(vm.$refs.search.focus).toHaveBeenCalled(); - }); - }); - - describe('emitSearchEvents', () => { - it('should emit `searchProjects` event via eventHub when `searchQuery` present', () => { - const searchQuery = 'test'; - spyOn(eventHub, '$emit'); - vm.searchQuery = searchQuery; - vm.emitSearchEvents(); - expect(eventHub.$emit).toHaveBeenCalledWith('searchProjects', searchQuery); - }); - - it('should emit `searchCleared` event via eventHub when `searchQuery` is cleared', () => { - spyOn(eventHub, '$emit'); - vm.searchQuery = ''; - vm.emitSearchEvents(); - expect(eventHub.$emit).toHaveBeenCalledWith('searchCleared'); - }); - }); - }); - - describe('mounted', () => { - it('should listen `dropdownOpen` event', (done) => { - spyOn(eventHub, '$on'); - createComponent(); - - Vue.nextTick(() => { - expect(eventHub.$on).toHaveBeenCalledWith('dropdownOpen', jasmine.any(Function)); - done(); - }); - }); - }); - - describe('beforeDestroy', () => { - it('should unbind event listeners on eventHub', (done) => { - const vm = createComponent(); - spyOn(eventHub, '$off'); - - vm.$mount(); - vm.$destroy(); - - Vue.nextTick(() => { - expect(eventHub.$off).toHaveBeenCalledWith('dropdownOpen', jasmine.any(Function)); - done(); - }); - }); - }); - - describe('template', () => { - let vm; - - beforeEach(() => { - vm = createComponent(); - }); - - afterEach(() => { - vm.$destroy(); - }); - - it('should render component element', () => { - const inputEl = vm.$el.querySelector('input.form-control'); - - expect(vm.$el.classList.contains('search-input-container')).toBeTruthy(); - expect(inputEl).not.toBe(null); - expect(inputEl.getAttribute('placeholder')).toBe('Search your projects'); - expect(vm.$el.querySelector('.search-icon')).toBeDefined(); - }); - }); -}); diff --git a/spec/javascripts/projects_dropdown/mock_data.js b/spec/javascripts/projects_dropdown/mock_data.js deleted file mode 100644 index d6a79fb8ac1..00000000000 --- a/spec/javascripts/projects_dropdown/mock_data.js +++ /dev/null @@ -1,96 +0,0 @@ -export const currentSession = { - username: 'root', - storageKey: 'root/frequent-projects', - apiVersion: 'v4', - project: { - id: 1, - name: 'dummy-project', - namespace: 'SamepleGroup / Dummy-Project', - webUrl: 'http://127.0.0.1/samplegroup/dummy-project', - avatarUrl: null, - lastAccessedOn: Date.now(), - }, -}; - -export const mockProject = { - id: 1, - name: 'GitLab Community Edition', - namespace: 'gitlab-org / gitlab-ce', - webUrl: 'http://127.0.0.1:3000/gitlab-org/gitlab-ce', - avatarUrl: null, -}; - -export const mockRawProject = { - id: 1, - name: 'GitLab Community Edition', - name_with_namespace: 'gitlab-org / gitlab-ce', - web_url: 'http://127.0.0.1:3000/gitlab-org/gitlab-ce', - avatar_url: null, -}; - -export const mockFrequents = [ - { - id: 1, - name: 'GitLab Community Edition', - namespace: 'gitlab-org / gitlab-ce', - webUrl: 'http://127.0.0.1:3000/gitlab-org/gitlab-ce', - avatarUrl: null, - }, - { - id: 2, - name: 'GitLab CI', - namespace: 'gitlab-org / gitlab-ci', - webUrl: 'http://127.0.0.1:3000/gitlab-org/gitlab-ci', - avatarUrl: null, - }, - { - id: 3, - name: 'Typeahead.Js', - namespace: 'twitter / typeahead-js', - webUrl: 'http://127.0.0.1:3000/twitter/typeahead-js', - avatarUrl: '/uploads/-/system/project/avatar/7/TWBS.png', - }, - { - id: 4, - name: 'Intel', - namespace: 'platform / hardware / bsp / intel', - webUrl: 'http://127.0.0.1:3000/platform/hardware/bsp/intel', - avatarUrl: null, - }, - { - id: 5, - name: 'v4.4', - namespace: 'platform / hardware / bsp / kernel / common / v4.4', - webUrl: 'http://localhost:3000/platform/hardware/bsp/kernel/common/v4.4', - avatarUrl: null, - }, -]; - -export const unsortedFrequents = [ - { id: 1, frequency: 12, lastAccessedOn: 1491400843391 }, - { id: 2, frequency: 14, lastAccessedOn: 1488240890738 }, - { id: 3, frequency: 44, lastAccessedOn: 1497675908472 }, - { id: 4, frequency: 8, lastAccessedOn: 1497979281815 }, - { id: 5, frequency: 34, lastAccessedOn: 1488089211943 }, - { id: 6, frequency: 14, lastAccessedOn: 1493517292488 }, - { id: 7, frequency: 42, lastAccessedOn: 1486815299875 }, - { id: 8, frequency: 33, lastAccessedOn: 1500762279114 }, - { id: 10, frequency: 46, lastAccessedOn: 1483251641543 }, -]; - -/** - * This const has a specific order which tests authenticity - * of `ProjectsService.getTopFrequentProjects` method so - * DO NOT change order of items in this const. - */ -export const sortedFrequents = [ - { id: 10, frequency: 46, lastAccessedOn: 1483251641543 }, - { id: 3, frequency: 44, lastAccessedOn: 1497675908472 }, - { id: 7, frequency: 42, lastAccessedOn: 1486815299875 }, - { id: 5, frequency: 34, lastAccessedOn: 1488089211943 }, - { id: 8, frequency: 33, lastAccessedOn: 1500762279114 }, - { id: 6, frequency: 14, lastAccessedOn: 1493517292488 }, - { id: 2, frequency: 14, lastAccessedOn: 1488240890738 }, - { id: 1, frequency: 12, lastAccessedOn: 1491400843391 }, - { id: 4, frequency: 8, lastAccessedOn: 1497979281815 }, -]; diff --git a/spec/javascripts/projects_dropdown/service/projects_service_spec.js b/spec/javascripts/projects_dropdown/service/projects_service_spec.js deleted file mode 100644 index cfd1bb7d24f..00000000000 --- a/spec/javascripts/projects_dropdown/service/projects_service_spec.js +++ /dev/null @@ -1,179 +0,0 @@ -import Vue from 'vue'; -import VueResource from 'vue-resource'; - -import bp from '~/breakpoints'; -import ProjectsService from '~/projects_dropdown/service/projects_service'; -import { FREQUENT_PROJECTS } from '~/projects_dropdown/constants'; -import { currentSession, unsortedFrequents, sortedFrequents } from '../mock_data'; - -Vue.use(VueResource); - -FREQUENT_PROJECTS.MAX_COUNT = 3; - -describe('ProjectsService', () => { - let service; - - beforeEach(() => { - gon.api_version = currentSession.apiVersion; - gon.current_user_id = 1; - service = new ProjectsService(currentSession.username); - }); - - describe('contructor', () => { - it('should initialize default properties of class', () => { - expect(service.isLocalStorageAvailable).toBeTruthy(); - expect(service.currentUserName).toBe(currentSession.username); - expect(service.storageKey).toBe(currentSession.storageKey); - expect(service.projectsPath).toBeDefined(); - }); - }); - - describe('getSearchedProjects', () => { - it('should return promise from VueResource HTTP GET', () => { - spyOn(service.projectsPath, 'get').and.stub(); - - const searchQuery = 'lab'; - const queryParams = { - simple: true, - per_page: 20, - membership: true, - order_by: 'last_activity_at', - search: searchQuery, - }; - - service.getSearchedProjects(searchQuery); - expect(service.projectsPath.get).toHaveBeenCalledWith(queryParams); - }); - }); - - describe('logProjectAccess', () => { - let storage; - - beforeEach(() => { - storage = {}; - - spyOn(window.localStorage, 'setItem').and.callFake((storageKey, value) => { - storage[storageKey] = value; - }); - - spyOn(window.localStorage, 'getItem').and.callFake((storageKey) => { - if (storage[storageKey]) { - return storage[storageKey]; - } - - return null; - }); - }); - - it('should create a project store if it does not exist and adds a project', () => { - service.logProjectAccess(currentSession.project); - - const projects = JSON.parse(storage[currentSession.storageKey]); - expect(projects.length).toBe(1); - expect(projects[0].frequency).toBe(1); - expect(projects[0].lastAccessedOn).toBeDefined(); - }); - - it('should prevent inserting same report multiple times into store', () => { - service.logProjectAccess(currentSession.project); - service.logProjectAccess(currentSession.project); - - const projects = JSON.parse(storage[currentSession.storageKey]); - expect(projects.length).toBe(1); - }); - - it('should increase frequency of report if it was logged multiple times over the course of an hour', () => { - let projects; - spyOn(Math, 'abs').and.returnValue(3600001); // this will lead to `diff` > 1; - service.logProjectAccess(currentSession.project); - - projects = JSON.parse(storage[currentSession.storageKey]); - expect(projects[0].frequency).toBe(1); - - service.logProjectAccess(currentSession.project); - projects = JSON.parse(storage[currentSession.storageKey]); - expect(projects[0].frequency).toBe(2); - expect(projects[0].lastAccessedOn).not.toBe(currentSession.project.lastAccessedOn); - }); - - it('should always update project metadata', () => { - let projects; - const oldProject = { - ...currentSession.project, - }; - - const newProject = { - ...currentSession.project, - name: 'New Name', - avatarUrl: 'new/avatar.png', - namespace: 'New / Namespace', - webUrl: 'http://localhost/new/web/url', - }; - - service.logProjectAccess(oldProject); - projects = JSON.parse(storage[currentSession.storageKey]); - expect(projects[0].name).toBe(oldProject.name); - expect(projects[0].avatarUrl).toBe(oldProject.avatarUrl); - expect(projects[0].namespace).toBe(oldProject.namespace); - expect(projects[0].webUrl).toBe(oldProject.webUrl); - - service.logProjectAccess(newProject); - projects = JSON.parse(storage[currentSession.storageKey]); - expect(projects[0].name).toBe(newProject.name); - expect(projects[0].avatarUrl).toBe(newProject.avatarUrl); - expect(projects[0].namespace).toBe(newProject.namespace); - expect(projects[0].webUrl).toBe(newProject.webUrl); - }); - - it('should not add more than 20 projects in store', () => { - for (let i = 1; i <= 5; i += 1) { - const project = Object.assign(currentSession.project, { id: i }); - service.logProjectAccess(project); - } - - const projects = JSON.parse(storage[currentSession.storageKey]); - expect(projects.length).toBe(3); - }); - }); - - describe('getTopFrequentProjects', () => { - let storage = {}; - - beforeEach(() => { - storage[currentSession.storageKey] = JSON.stringify(unsortedFrequents); - - spyOn(window.localStorage, 'getItem').and.callFake((storageKey) => { - if (storage[storageKey]) { - return storage[storageKey]; - } - - return null; - }); - }); - - it('should return top 5 frequently accessed projects for desktop screens', () => { - spyOn(bp, 'getBreakpointSize').and.returnValue('md'); - const frequentProjects = service.getTopFrequentProjects(); - - expect(frequentProjects.length).toBe(5); - frequentProjects.forEach((project, index) => { - expect(project.id).toBe(sortedFrequents[index].id); - }); - }); - - it('should return top 3 frequently accessed projects for mobile screens', () => { - spyOn(bp, 'getBreakpointSize').and.returnValue('sm'); - const frequentProjects = service.getTopFrequentProjects(); - - expect(frequentProjects.length).toBe(3); - frequentProjects.forEach((project, index) => { - expect(project.id).toBe(sortedFrequents[index].id); - }); - }); - - it('should return empty array if there are no projects available in store', () => { - storage = {}; - expect(service.getTopFrequentProjects().length).toBe(0); - }); - }); -}); diff --git a/spec/javascripts/projects_dropdown/store/projects_store_spec.js b/spec/javascripts/projects_dropdown/store/projects_store_spec.js deleted file mode 100644 index e57399d37cd..00000000000 --- a/spec/javascripts/projects_dropdown/store/projects_store_spec.js +++ /dev/null @@ -1,41 +0,0 @@ -import ProjectsStore from '~/projects_dropdown/store/projects_store'; -import { mockProject, mockRawProject } from '../mock_data'; - -describe('ProjectsStore', () => { - let store; - - beforeEach(() => { - store = new ProjectsStore(); - }); - - describe('setFrequentProjects', () => { - it('should set frequent projects list to state', () => { - store.setFrequentProjects([mockProject]); - - expect(store.getFrequentProjects().length).toBe(1); - expect(store.getFrequentProjects()[0].id).toBe(mockProject.id); - }); - }); - - describe('setSearchedProjects', () => { - it('should set searched projects list to state', () => { - store.setSearchedProjects([mockRawProject]); - - const processedProjects = store.getSearchedProjects(); - expect(processedProjects.length).toBe(1); - expect(processedProjects[0].id).toBe(mockRawProject.id); - expect(processedProjects[0].namespace).toBe(mockRawProject.name_with_namespace); - expect(processedProjects[0].webUrl).toBe(mockRawProject.web_url); - expect(processedProjects[0].avatarUrl).toBe(mockRawProject.avatar_url); - }); - }); - - describe('clearSearchedProjects', () => { - it('should clear searched projects list from state', () => { - store.setSearchedProjects([mockRawProject]); - expect(store.getSearchedProjects().length).toBe(1); - store.clearSearchedProjects(); - expect(store.getSearchedProjects().length).toBe(0); - }); - }); -}); diff --git a/spec/javascripts/sidebar/components/time_tracking/time_tracker_spec.js b/spec/javascripts/sidebar/components/time_tracking/time_tracker_spec.js new file mode 100644 index 00000000000..b58de607ece --- /dev/null +++ b/spec/javascripts/sidebar/components/time_tracking/time_tracker_spec.js @@ -0,0 +1,243 @@ +import $ from 'jquery'; +import Vue from 'vue'; + +import TimeTracker from '~/sidebar/components/time_tracking/time_tracker.vue'; + +import mountComponent from 'spec/helpers/vue_mount_component_helper'; + +describe('Issuable Time Tracker', () => { + let initialData; + let vm; + + const initTimeTrackingComponent = opts => { + setFixtures(` + <div> + <div id="mock-container"></div> + </div> + `); + + initialData = { + time_estimate: opts.timeEstimate, + time_spent: opts.timeSpent, + human_time_estimate: opts.timeEstimateHumanReadable, + human_time_spent: opts.timeSpentHumanReadable, + rootPath: '/', + }; + + const TimeTrackingComponent = Vue.extend({ + ...TimeTracker, + components: { + ...TimeTracker.components, + transition: { + // disable animations + template: '<div><slot></slot></div>', + }, + }, + }); + vm = mountComponent(TimeTrackingComponent, initialData, '#mock-container'); + }; + + afterEach(() => { + vm.$destroy(); + }); + + describe('Initialization', () => { + beforeEach(() => { + initTimeTrackingComponent({ + timeEstimate: 100000, + timeSpent: 5000, + timeEstimateHumanReadable: '2h 46m', + timeSpentHumanReadable: '1h 23m', + }); + }); + + it('should return something defined', () => { + expect(vm).toBeDefined(); + }); + + it('should correctly set timeEstimate', done => { + Vue.nextTick(() => { + expect(vm.timeEstimate).toBe(initialData.time_estimate); + done(); + }); + }); + + it('should correctly set time_spent', done => { + Vue.nextTick(() => { + expect(vm.timeSpent).toBe(initialData.time_spent); + done(); + }); + }); + }); + + describe('Content Display', () => { + describe('Panes', () => { + describe('Comparison pane', () => { + beforeEach(() => { + initTimeTrackingComponent({ + timeEstimate: 100000, + timeSpent: 5000, + timeEstimateHumanReadable: '', + timeSpentHumanReadable: '', + }); + }); + + it('should show the "Comparison" pane when timeEstimate and time_spent are truthy', done => { + Vue.nextTick(() => { + expect(vm.showComparisonState).toBe(true); + const $comparisonPane = vm.$el.querySelector('.time-tracking-comparison-pane'); + expect($comparisonPane).toBeVisible(); + done(); + }); + }); + + describe('Remaining meter', () => { + it('should display the remaining meter with the correct width', done => { + Vue.nextTick(() => { + const meterWidth = vm.$el.querySelector('.time-tracking-comparison-pane .meter-fill') + .style.width; + const correctWidth = '5%'; + + expect(meterWidth).toBe(correctWidth); + done(); + }); + }); + + it('should display the remaining meter with the correct background color when within estimate', done => { + Vue.nextTick(() => { + const styledMeter = $(vm.$el).find( + '.time-tracking-comparison-pane .within_estimate .meter-fill', + ); + expect(styledMeter.length).toBe(1); + done(); + }); + }); + + it('should display the remaining meter with the correct background color when over estimate', done => { + vm.time_estimate = 100000; + vm.time_spent = 20000000; + Vue.nextTick(() => { + const styledMeter = $(vm.$el).find( + '.time-tracking-comparison-pane .over_estimate .meter-fill', + ); + expect(styledMeter.length).toBe(1); + done(); + }); + }); + }); + }); + + describe('Estimate only pane', () => { + beforeEach(() => { + initTimeTrackingComponent({ + timeEstimate: 100000, + timeSpent: 0, + timeEstimateHumanReadable: '2h 46m', + timeSpentHumanReadable: '', + }); + }); + + it('should display the human readable version of time estimated', done => { + Vue.nextTick(() => { + const estimateText = vm.$el.querySelector('.time-tracking-estimate-only-pane') + .innerText; + const correctText = 'Estimated: 2h 46m'; + + expect(estimateText).toBe(correctText); + done(); + }); + }); + }); + + describe('Spent only pane', () => { + beforeEach(() => { + initTimeTrackingComponent({ + timeEstimate: 0, + timeSpent: 5000, + timeEstimateHumanReadable: '2h 46m', + timeSpentHumanReadable: '1h 23m', + }); + }); + + it('should display the human readable version of time spent', done => { + Vue.nextTick(() => { + const spentText = vm.$el.querySelector('.time-tracking-spend-only-pane').innerText; + const correctText = 'Spent: 1h 23m'; + + expect(spentText).toBe(correctText); + done(); + }); + }); + }); + + describe('No time tracking pane', () => { + beforeEach(() => { + initTimeTrackingComponent({ + timeEstimate: 0, + timeSpent: 0, + timeEstimateHumanReadable: '', + timeSpentHumanReadable: '', + }); + }); + + it('should only show the "No time tracking" pane when both timeEstimate and time_spent are falsey', done => { + Vue.nextTick(() => { + const $noTrackingPane = vm.$el.querySelector('.time-tracking-no-tracking-pane'); + const noTrackingText = $noTrackingPane.innerText; + const correctText = 'No estimate or time spent'; + + expect(vm.showNoTimeTrackingState).toBe(true); + expect($noTrackingPane).toBeVisible(); + expect(noTrackingText).toBe(correctText); + done(); + }); + }); + }); + + describe('Help pane', () => { + const helpButton = () => vm.$el.querySelector('.help-button'); + const closeHelpButton = () => vm.$el.querySelector('.close-help-button'); + const helpPane = () => vm.$el.querySelector('.time-tracking-help-state'); + + beforeEach(done => { + initTimeTrackingComponent({ timeEstimate: 0, timeSpent: 0 }); + + Vue.nextTick() + .then(done) + .catch(done.fail); + }); + + it('should not show the "Help" pane by default', () => { + expect(vm.showHelpState).toBe(false); + expect(helpPane()).toBeNull(); + }); + + it('should show the "Help" pane when help button is clicked', done => { + helpButton().click(); + + Vue.nextTick() + .then(() => { + expect(vm.showHelpState).toBe(true); + expect(helpPane()).toBeVisible(); + }) + .then(done) + .catch(done.fail); + }); + + it('should not show the "Help" pane when help button is clicked and then closed', done => { + helpButton().click(); + + Vue.nextTick() + .then(() => closeHelpButton().click()) + .then(() => Vue.nextTick()) + .then(() => { + expect(vm.showHelpState).toBe(false); + expect(helpPane()).toBeNull(); + }) + .then(done) + .catch(done.fail); + }); + }); + }); + }); +}); diff --git a/spec/javascripts/smart_interval_spec.js b/spec/javascripts/smart_interval_spec.js index 60153672214..d9b6dd1d487 100644 --- a/spec/javascripts/smart_interval_spec.js +++ b/spec/javascripts/smart_interval_spec.js @@ -1,12 +1,12 @@ import $ from 'jquery'; import _ from 'underscore'; import SmartInterval from '~/smart_interval'; +import waitForPromises from 'spec/helpers/wait_for_promises'; describe('SmartInterval', function () { const DEFAULT_MAX_INTERVAL = 100; const DEFAULT_STARTING_INTERVAL = 5; const DEFAULT_SHORT_TIMEOUT = 75; - const DEFAULT_LONG_TIMEOUT = 1000; const DEFAULT_INCREMENT_FACTOR = 2; function createDefaultSmartInterval(config) { @@ -27,52 +27,65 @@ describe('SmartInterval', function () { return new SmartInterval(defaultParams); } + beforeEach(() => { + jasmine.clock().install(); + }); + + afterEach(() => { + jasmine.clock().uninstall(); + }); + describe('Increment Interval', function () { - beforeEach(function () { - this.smartInterval = createDefaultSmartInterval(); - }); + it('should increment the interval delay', (done) => { + const smartInterval = createDefaultSmartInterval(); - it('should increment the interval delay', function (done) { - const interval = this.smartInterval; - setTimeout(() => { - const intervalConfig = this.smartInterval.cfg; - const iterationCount = 4; - const maxIntervalAfterIterations = intervalConfig.startingInterval * - (intervalConfig.incrementByFactorOf ** (iterationCount - 1)); // 40 - const currentInterval = interval.getCurrentInterval(); - - // Provide some flexibility for performance of testing environment - expect(currentInterval).toBeGreaterThan(intervalConfig.startingInterval); - expect(currentInterval <= maxIntervalAfterIterations).toBeTruthy(); - - done(); - }, DEFAULT_SHORT_TIMEOUT); // 4 iterations, increment by 2x = (5 + 10 + 20 + 40) + jasmine.clock().tick(DEFAULT_SHORT_TIMEOUT); + + waitForPromises() + .then(() => { + const intervalConfig = smartInterval.cfg; + const iterationCount = 4; + const maxIntervalAfterIterations = intervalConfig.startingInterval * + (intervalConfig.incrementByFactorOf ** iterationCount); + const currentInterval = smartInterval.getCurrentInterval(); + + // Provide some flexibility for performance of testing environment + expect(currentInterval).toBeGreaterThan(intervalConfig.startingInterval); + expect(currentInterval).toBeLessThanOrEqual(maxIntervalAfterIterations); + }) + .then(done) + .catch(done.fail); }); - it('should not increment past maxInterval', function (done) { - const interval = this.smartInterval; + it('should not increment past maxInterval', (done) => { + const smartInterval = createDefaultSmartInterval({ maxInterval: DEFAULT_STARTING_INTERVAL }); - setTimeout(() => { - const currentInterval = interval.getCurrentInterval(); - expect(currentInterval).toBe(interval.cfg.maxInterval); + jasmine.clock().tick(DEFAULT_STARTING_INTERVAL); + jasmine.clock().tick(DEFAULT_STARTING_INTERVAL * DEFAULT_INCREMENT_FACTOR); - done(); - }, DEFAULT_LONG_TIMEOUT); + waitForPromises() + .then(() => { + const currentInterval = smartInterval.getCurrentInterval(); + expect(currentInterval).toBe(smartInterval.cfg.maxInterval); + }) + .then(done) + .catch(done.fail); }); - it('does not increment while waiting for callback', function () { - jasmine.clock().install(); - + it('does not increment while waiting for callback', done => { const smartInterval = createDefaultSmartInterval({ callback: () => new Promise($.noop), }); jasmine.clock().tick(DEFAULT_SHORT_TIMEOUT); - const oneInterval = smartInterval.cfg.startingInterval * DEFAULT_INCREMENT_FACTOR; - expect(smartInterval.getCurrentInterval()).toEqual(oneInterval); - - jasmine.clock().uninstall(); + waitForPromises() + .then(() => { + const oneInterval = smartInterval.cfg.startingInterval * DEFAULT_INCREMENT_FACTOR; + expect(smartInterval.getCurrentInterval()).toEqual(oneInterval); + }) + .then(done) + .catch(done.fail); }); }); @@ -84,34 +97,39 @@ describe('SmartInterval', function () { it('should cancel an interval', function (done) { const interval = this.smartInterval; - setTimeout(() => { - interval.cancel(); + jasmine.clock().tick(DEFAULT_SHORT_TIMEOUT); - const { intervalId } = interval.state; - const currentInterval = interval.getCurrentInterval(); - const intervalLowerLimit = interval.cfg.startingInterval; + interval.cancel(); - expect(intervalId).toBeUndefined(); - expect(currentInterval).toBe(intervalLowerLimit); + waitForPromises() + .then(() => { + const { intervalId } = interval.state; + const currentInterval = interval.getCurrentInterval(); + const intervalLowerLimit = interval.cfg.startingInterval; - done(); - }, DEFAULT_SHORT_TIMEOUT); + expect(intervalId).toBeUndefined(); + expect(currentInterval).toBe(intervalLowerLimit); + }) + .then(done) + .catch(done.fail); }); it('should resume an interval', function (done) { const interval = this.smartInterval; - setTimeout(() => { - interval.cancel(); - - interval.resume(); + jasmine.clock().tick(DEFAULT_SHORT_TIMEOUT); - const { intervalId } = interval.state; + interval.cancel(); - expect(intervalId).toBeTruthy(); + interval.resume(); - done(); - }, DEFAULT_SHORT_TIMEOUT); + waitForPromises() + .then(() => { + const { intervalId } = interval.state; + expect(intervalId).toBeTruthy(); + }) + .then(done) + .catch(done.fail); }); }); @@ -126,64 +144,79 @@ describe('SmartInterval', function () { it('should pause when page is not visible', function (done) { const interval = this.smartInterval; - setTimeout(() => { - expect(interval.state.intervalId).toBeTruthy(); + jasmine.clock().tick(DEFAULT_SHORT_TIMEOUT); + + waitForPromises() + .then(() => { + expect(interval.state.intervalId).toBeTruthy(); - // simulates triggering of visibilitychange event - interval.handleVisibilityChange({ target: { visibilityState: 'hidden' } }); + // simulates triggering of visibilitychange event + interval.handleVisibilityChange({ target: { visibilityState: 'hidden' } }); - expect(interval.state.intervalId).toBeUndefined(); - done(); - }, DEFAULT_SHORT_TIMEOUT); + expect(interval.state.intervalId).toBeUndefined(); + }) + .then(done) + .catch(done.fail); }); - it('should change to the hidden interval when page is not visible', function (done) { + it('should change to the hidden interval when page is not visible', done => { const HIDDEN_INTERVAL = 1500; const interval = createDefaultSmartInterval({ hiddenInterval: HIDDEN_INTERVAL }); - setTimeout(() => { - expect(interval.state.intervalId).toBeTruthy(); - expect(interval.getCurrentInterval() >= DEFAULT_STARTING_INTERVAL && - interval.getCurrentInterval() <= DEFAULT_MAX_INTERVAL).toBeTruthy(); + jasmine.clock().tick(DEFAULT_SHORT_TIMEOUT); + + waitForPromises() + .then(() => { + expect(interval.state.intervalId).toBeTruthy(); + expect(interval.getCurrentInterval() >= DEFAULT_STARTING_INTERVAL && + interval.getCurrentInterval() <= DEFAULT_MAX_INTERVAL).toBeTruthy(); - // simulates triggering of visibilitychange event - interval.handleVisibilityChange({ target: { visibilityState: 'hidden' } }); + // simulates triggering of visibilitychange event + interval.handleVisibilityChange({ target: { visibilityState: 'hidden' } }); - expect(interval.state.intervalId).toBeTruthy(); - expect(interval.getCurrentInterval()).toBe(HIDDEN_INTERVAL); - done(); - }, DEFAULT_SHORT_TIMEOUT); + expect(interval.state.intervalId).toBeTruthy(); + expect(interval.getCurrentInterval()).toBe(HIDDEN_INTERVAL); + }) + .then(done) + .catch(done.fail); }); it('should resume when page is becomes visible at the previous interval', function (done) { const interval = this.smartInterval; - setTimeout(() => { - expect(interval.state.intervalId).toBeTruthy(); + jasmine.clock().tick(DEFAULT_SHORT_TIMEOUT); - // simulates triggering of visibilitychange event - interval.handleVisibilityChange({ target: { visibilityState: 'hidden' } }); + waitForPromises() + .then(() => { + expect(interval.state.intervalId).toBeTruthy(); - expect(interval.state.intervalId).toBeUndefined(); + // simulates triggering of visibilitychange event + interval.handleVisibilityChange({ target: { visibilityState: 'hidden' } }); - // simulates triggering of visibilitychange event - interval.handleVisibilityChange({ target: { visibilityState: 'visible' } }); + expect(interval.state.intervalId).toBeUndefined(); - expect(interval.state.intervalId).toBeTruthy(); + // simulates triggering of visibilitychange event + interval.handleVisibilityChange({ target: { visibilityState: 'visible' } }); - done(); - }, DEFAULT_SHORT_TIMEOUT); + expect(interval.state.intervalId).toBeTruthy(); + }) + .then(done) + .catch(done.fail); }); it('should cancel on page unload', function (done) { const interval = this.smartInterval; - setTimeout(() => { - $(document).triggerHandler('beforeunload'); - expect(interval.state.intervalId).toBeUndefined(); - expect(interval.getCurrentInterval()).toBe(interval.cfg.startingInterval); - done(); - }, DEFAULT_SHORT_TIMEOUT); + jasmine.clock().tick(DEFAULT_SHORT_TIMEOUT); + + waitForPromises() + .then(() => { + $(document).triggerHandler('beforeunload'); + expect(interval.state.intervalId).toBeUndefined(); + expect(interval.getCurrentInterval()).toBe(interval.cfg.startingInterval); + }) + .then(done) + .catch(done.fail); }); it('should execute callback before first interval', function () { diff --git a/spec/javascripts/test_bundle.js b/spec/javascripts/test_bundle.js index 0eff98bcc9d..a0ca8f8b4c3 100644 --- a/spec/javascripts/test_bundle.js +++ b/spec/javascripts/test_bundle.js @@ -166,13 +166,13 @@ if (process.env.BABEL_ENV === 'coverage') { ]; describe('Uncovered files', function() { - const sourceFiles = require.context('~', true, /\.js$/); + const sourceFiles = require.context('~', true, /\.(js|vue)$/); $.holdReady(true); sourceFiles.keys().forEach(function(path) { // ignore if there is a matching spec file - if (testsContext.keys().indexOf(`${path.replace(/\.js$/, '')}_spec`) > -1) { + if (testsContext.keys().indexOf(`${path.replace(/\.(js|vue)$/, '')}_spec`) > -1) { return; } diff --git a/spec/javascripts/vue_mr_widget/components/deployment_spec.js b/spec/javascripts/vue_mr_widget/components/deployment_spec.js index c82ba61a5b1..50c2b0e2bd0 100644 --- a/spec/javascripts/vue_mr_widget/components/deployment_spec.js +++ b/spec/javascripts/vue_mr_widget/components/deployment_spec.js @@ -153,7 +153,7 @@ describe('Deployment component', () => { it('renders external URL', () => { expect(el.querySelector('.js-deploy-url').getAttribute('href')).toEqual(deploymentMockData.external_url); - expect(el.querySelector('.js-deploy-url').innerText).toContain(deploymentMockData.external_url_formatted); + expect(el.querySelector('.js-deploy-url').innerText).toContain('View app'); }); it('renders stop button', () => { diff --git a/spec/javascripts/vue_mr_widget/components/mr_widget_header_spec.js b/spec/javascripts/vue_mr_widget/components/mr_widget_header_spec.js index 3d36e46d863..61b7bd2c226 100644 --- a/spec/javascripts/vue_mr_widget/components/mr_widget_header_spec.js +++ b/spec/javascripts/vue_mr_widget/components/mr_widget_header_spec.js @@ -145,7 +145,7 @@ describe('MRWidgetHeader', () => { it('renders web ide button', () => { const button = vm.$el.querySelector('.js-web-ide'); - expect(button.textContent.trim()).toEqual('Web IDE'); + expect(button.textContent.trim()).toEqual('Open in Web IDE'); expect(button.getAttribute('href')).toEqual('/-/ide/projectabc'); }); @@ -154,7 +154,7 @@ describe('MRWidgetHeader', () => { const button = vm.$el.querySelector('.js-web-ide'); - expect(button.textContent.trim()).toEqual('Web IDE'); + expect(button.textContent.trim()).toEqual('Open in Web IDE'); expect(button.getAttribute('href')).toEqual('/-/ide/projectabc'); }); @@ -253,8 +253,8 @@ describe('MRWidgetHeader', () => { }); it('renders diverged commits info', () => { - expect(vm.$el.querySelector('.diverged-commits-count').textContent.trim()).toEqual( - '(12 commits behind)', + expect(vm.$el.querySelector('.diverged-commits-count').textContent).toMatch( + /(mr-widget-refactor[\s\S]+?is 12 commits behind[\s\S]+?master)/, ); }); }); diff --git a/spec/javascripts/vue_shared/components/markdown/header_spec.js b/spec/javascripts/vue_shared/components/markdown/header_spec.js index 02117638b63..488575df401 100644 --- a/spec/javascripts/vue_shared/components/markdown/header_spec.js +++ b/spec/javascripts/vue_shared/components/markdown/header_spec.js @@ -51,7 +51,7 @@ describe('Markdown field header component', () => { spyOn(vm, '$emit'); $(document).triggerHandler('markdown-preview:show', [ - $('<form><textarea class="markdown-area"></textarea></textarea></form>'), + $('<form><div class="js-vue-markdown-field"><textarea class="markdown-area"></textarea></div></form>'), ]); expect(vm.$emit).not.toHaveBeenCalled(); diff --git a/spec/lib/banzai/filter/markdown_filter_spec.rb b/spec/lib/banzai/filter/markdown_filter_spec.rb index ab14d77d552..a515d07b072 100644 --- a/spec/lib/banzai/filter/markdown_filter_spec.rb +++ b/spec/lib/banzai/filter/markdown_filter_spec.rb @@ -3,17 +3,61 @@ require 'spec_helper' describe Banzai::Filter::MarkdownFilter do include FilterSpecHelper - context 'code block' do - it 'adds language to lang attribute when specified' do - result = filter("```html\nsome code\n```") + describe 'markdown engine from context' do + it 'defaults to CommonMark' do + expect_any_instance_of(Banzai::Filter::MarkdownEngines::CommonMark).to receive(:render).and_return('test') - expect(result).to start_with("<pre><code lang=\"html\">") + filter('test') end - it 'does not add language to lang attribute when not specified' do - result = filter("```\nsome code\n```") + it 'uses Redcarpet' do + expect_any_instance_of(Banzai::Filter::MarkdownEngines::Redcarpet).to receive(:render).and_return('test') - expect(result).to start_with("<pre><code>") + filter('test', { markdown_engine: :redcarpet }) + end + + it 'uses CommonMark' do + expect_any_instance_of(Banzai::Filter::MarkdownEngines::CommonMark).to receive(:render).and_return('test') + + filter('test', { markdown_engine: :common_mark }) + end + end + + describe 'code block' do + context 'using CommonMark' do + before do + stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :common_mark) + end + + it 'adds language to lang attribute when specified' do + result = filter("```html\nsome code\n```") + + expect(result).to start_with("<pre><code lang=\"html\">") + end + + it 'does not add language to lang attribute when not specified' do + result = filter("```\nsome code\n```") + + expect(result).to start_with("<pre><code>") + end + end + + context 'using Redcarpet' do + before do + stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :redcarpet) + end + + it 'adds language to lang attribute when specified' do + result = filter("```html\nsome code\n```") + + expect(result).to start_with("\n<pre><code lang=\"html\">") + end + + it 'does not add language to lang attribute when not specified' do + result = filter("```\nsome code\n```") + + expect(result).to start_with("\n<pre><code>") + end end end end diff --git a/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb index a1dd72c498f..55c41e55437 100644 --- a/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb @@ -210,6 +210,13 @@ describe Banzai::Filter::MergeRequestReferenceFilter do .to eq reference end + it 'commit ref tag is valid' do + doc = reference_filter("See #{reference}") + commit_ref_tag = doc.css('a').first.css('span.gfm.gfm-commit') + + expect(commit_ref_tag.text).to eq(commit.short_id) + end + it 'has valid text' do doc = reference_filter("See #{reference}") diff --git a/spec/lib/banzai/filter/redactor_filter_spec.rb b/spec/lib/banzai/filter/redactor_filter_spec.rb index 9a2e521fdcf..919825a6102 100644 --- a/spec/lib/banzai/filter/redactor_filter_spec.rb +++ b/spec/lib/banzai/filter/redactor_filter_spec.rb @@ -46,7 +46,7 @@ describe Banzai::Filter::RedactorFilter do it 'allows permitted Project references' do user = create(:user) project = create(:project) - project.add_master(user) + project.add_maintainer(user) link = reference_link(project: project.id, reference_type: 'test') doc = filter(link, current_user: user) diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb index e13406d1972..8947e2ac4fb 100644 --- a/spec/lib/extracts_path_spec.rb +++ b/spec/lib/extracts_path_spec.rb @@ -203,4 +203,30 @@ describe ExtractsPath do expect(extract_ref_without_atom('foo.atom')).to eq(nil) end end + + describe '#lfs_blob_ids' do + shared_examples '#lfs_blob_ids' do + let(:tag) { @project.repository.add_tag(@project.owner, 'my-annotated-tag', 'master', 'test tag') } + let(:ref) { tag.target } + let(:params) { { ref: ref, path: 'README.md' } } + + before do + @project = create(:project, :repository) + end + + it 'handles annotated tags' do + assign_ref_vars + + expect(lfs_blob_ids).to eq([]) + end + end + + context 'when gitaly is enabled' do + it_behaves_like '#lfs_blob_ids' + end + + context 'when gitaly is disabled', :skip_gitaly_mock do + it_behaves_like '#lfs_blob_ids' + end + end end diff --git a/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb b/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb index a251ab323d8..64c994a268f 100644 --- a/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb +++ b/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb @@ -4,28 +4,32 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, schema: 20180 describe '#perform' do context 'when diff files can be deleted' do let(:merge_request) { create(:merge_request, :merged) } - let(:merge_request_diff) do + let!(:merge_request_diff) do merge_request.create_merge_request_diff merge_request.merge_request_diffs.first end + let(:perform) do + described_class.new.perform(MergeRequestDiff.pluck(:id)) + end + it 'deletes all merge request diff files' do - expect { described_class.new.perform(merge_request_diff.id) } + expect { perform } .to change { merge_request_diff.merge_request_diff_files.count } .from(20).to(0) end it 'updates state to without_files' do - expect { described_class.new.perform(merge_request_diff.id) } + expect { perform } .to change { merge_request_diff.reload.state } .from('collected').to('without_files') end it 'rollsback if something goes wrong' do - expect(MergeRequestDiffFile).to receive_message_chain(:where, :delete_all) + expect(described_class::MergeRequestDiffFile).to receive_message_chain(:where, :delete_all) .and_raise - expect { described_class.new.perform(merge_request_diff.id) } + expect { perform } .to raise_error merge_request_diff.reload @@ -35,35 +39,35 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, schema: 20180 end end - it 'deletes no merge request diff files when MR is not merged' do - merge_request = create(:merge_request, :opened) - merge_request.create_merge_request_diff - merge_request_diff = merge_request.merge_request_diffs.first - - expect { described_class.new.perform(merge_request_diff.id) } - .not_to change { merge_request_diff.merge_request_diff_files.count } - .from(20) - end - - it 'deletes no merge request diff files when diff is marked as "without_files"' do + it 'reschedules itself when should_wait_deadtuple_vacuum' do merge_request = create(:merge_request, :merged) - merge_request.create_merge_request_diff - merge_request_diff = merge_request.merge_request_diffs.first + first_diff = merge_request.merge_request_diff + second_diff = merge_request.create_merge_request_diff - merge_request_diff.clean! + Sidekiq::Testing.fake! do + worker = described_class.new + allow(worker).to receive(:should_wait_deadtuple_vacuum?) { true } - expect { described_class.new.perform(merge_request_diff.id) } - .not_to change { merge_request_diff.merge_request_diff_files.count } - .from(20) + worker.perform([first_diff.id, second_diff.id]) + + expect(described_class.name.demodulize).to be_scheduled_delayed_migration(5.minutes, [first_diff.id, second_diff.id]) + expect(BackgroundMigrationWorker.jobs.size).to eq(1) + end end + end - it 'deletes no merge request diff files when diff is the latest' do - merge_request = create(:merge_request, :merged) - merge_request_diff = merge_request.merge_request_diff + describe '#should_wait_deadtuple_vacuum?' do + it 'returns true when hitting merge_request_diff_files hits DEAD_TUPLES_THRESHOLD', :postgresql do + worker = described_class.new + threshold_query_result = [{ "n_dead_tup" => described_class::DEAD_TUPLES_THRESHOLD.to_s }] + normal_query_result = [{ "n_dead_tup" => '3' }] + + allow(worker) + .to receive(:execute_statement) + .with(/SELECT n_dead_tup */) + .and_return(threshold_query_result, normal_query_result) - expect { described_class.new.perform(merge_request_diff.id) } - .not_to change { merge_request_diff.merge_request_diff_files.count } - .from(20) + expect(worker.should_wait_deadtuple_vacuum?).to be(true) end end end diff --git a/spec/lib/gitlab/background_migration/fix_cross_project_label_links_spec.rb b/spec/lib/gitlab/background_migration/fix_cross_project_label_links_spec.rb new file mode 100644 index 00000000000..20af63bc6c8 --- /dev/null +++ b/spec/lib/gitlab/background_migration/fix_cross_project_label_links_spec.rb @@ -0,0 +1,109 @@ +require 'spec_helper' + +describe Gitlab::BackgroundMigration::FixCrossProjectLabelLinks, :migration, schema: 20180702120647 do + let(:namespaces_table) { table(:namespaces) } + let(:projects_table) { table(:projects) } + let(:issues_table) { table(:issues) } + let(:merge_requests_table) { table(:merge_requests) } + let(:labels_table) { table(:labels) } + let(:label_links_table) { table(:label_links) } + + let!(:group1) { namespaces_table.create(id: 10, type: 'Group', name: 'group1', path: 'group1') } + let!(:group2) { namespaces_table.create(id: 20, type: 'Group', name: 'group2', path: 'group2') } + + let!(:project1) { projects_table.create(id: 1, name: 'project1', path: 'group1/project1', namespace_id: 10) } + let!(:project2) { projects_table.create(id: 3, name: 'project2', path: 'group1/project2', namespace_id: 20) } + + let!(:label1) { labels_table.create(id: 1, title: 'bug', color: 'red', group_id: 10, type: 'GroupLabel') } + let!(:label2) { labels_table.create(id: 2, title: 'bug', color: 'red', group_id: 20, type: 'GroupLabel') } + + def create_merge_request(id, project_id) + merge_requests_table.create(id: id, + target_project_id: project_id, + target_branch: 'master', + source_project_id: project_id, + source_branch: 'mr name', + title: "mr name#{id}") + end + + def create_issue(id, project_id) + issues_table.create(id: id, title: "issue#{id}", project_id: project_id) + end + + def create_resource(target_type, id, project_id) + target_type == 'Issue' ? create_issue(id, project_id) : create_merge_request(id, project_id) + end + + shared_examples_for 'resource with cross-project labels' do + it 'updates only cross-project label links which exist in the local project or group' do + create_resource(target_type, 1, 1) + create_resource(target_type, 2, 3) + labels_table.create(id: 3, title: 'bug', color: 'red', project_id: 3, type: 'ProjectLabel') + link = label_links_table.create(label_id: 2, target_type: target_type, target_id: 1) + link2 = label_links_table.create(label_id: 3, target_type: target_type, target_id: 2) + + subject.perform(1, 100) + + expect(link.reload.label_id).to eq(1) + expect(link2.reload.label_id).to eq(3) + end + + it 'ignores cross-project label links if label color is different' do + labels_table.create(id: 3, title: 'bug', color: 'green', group_id: 20, type: 'GroupLabel') + create_resource(target_type, 1, 1) + link = label_links_table.create(label_id: 3, target_type: target_type, target_id: 1) + + subject.perform(1, 100) + + expect(link.reload.label_id).to eq(3) + end + + it 'ignores cross-project label links if label name is different' do + labels_table.create(id: 3, title: 'bug1', color: 'red', group_id: 20, type: 'GroupLabel') + create_resource(target_type, 1, 1) + link = label_links_table.create(label_id: 3, target_type: target_type, target_id: 1) + + subject.perform(1, 100) + + expect(link.reload.label_id).to eq(3) + end + + context 'with nested group' do + before do + namespaces_table.create(id: 11, type: 'Group', name: 'subgroup1', path: 'group1/subgroup1', parent_id: 10) + projects_table.create(id: 2, name: 'subproject1', path: 'group1/subgroup1/subproject1', namespace_id: 11) + create_resource(target_type, 1, 2) + end + + it 'ignores label links referencing ancestor group labels', :nested_groups do + labels_table.create(id: 4, title: 'bug', color: 'red', project_id: 2, type: 'ProjectLabel') + label_links_table.create(label_id: 4, target_type: target_type, target_id: 1) + link = label_links_table.create(label_id: 1, target_type: target_type, target_id: 1) + + subject.perform(1, 100) + + expect(link.reload.label_id).to eq(1) + end + + it 'checks also issues and MRs in subgroups', :nested_groups do + link = label_links_table.create(label_id: 2, target_type: target_type, target_id: 1) + + subject.perform(1, 100) + + expect(link.reload.label_id).to eq(1) + end + end + end + + context 'resource is Issue' do + it_behaves_like 'resource with cross-project labels' do + let(:target_type) { 'Issue' } + end + end + + context 'resource is Merge Request' do + it_behaves_like 'resource with cross-project labels' do + let(:target_type) { 'MergeRequest' } + end + end +end diff --git a/spec/lib/gitlab/background_migration/move_personal_snippet_files_spec.rb b/spec/lib/gitlab/background_migration/move_personal_snippet_files_spec.rb index ee60e498b59..2e77e80ee46 100644 --- a/spec/lib/gitlab/background_migration/move_personal_snippet_files_spec.rb +++ b/spec/lib/gitlab/background_migration/move_personal_snippet_files_spec.rb @@ -7,7 +7,7 @@ describe Gitlab::BackgroundMigration::MovePersonalSnippetFiles do let(:snippet) do snippet = create(:personal_snippet) create_upload_for_snippet(snippet) - snippet.update_attributes!(description: markdown_linking_file(snippet)) + snippet.update!(description: markdown_linking_file(snippet)) snippet end diff --git a/spec/lib/gitlab/background_migration/schedule_diff_files_deletion_spec.rb b/spec/lib/gitlab/background_migration/schedule_diff_files_deletion_spec.rb new file mode 100644 index 00000000000..fb5093b0bd1 --- /dev/null +++ b/spec/lib/gitlab/background_migration/schedule_diff_files_deletion_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe Gitlab::BackgroundMigration::ScheduleDiffFilesDeletion, :migration, schema: 20180619121030 do + describe '#perform' do + let(:merge_request_diffs) { table(:merge_request_diffs) } + let(:merge_requests) { table(:merge_requests) } + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + + before do + stub_const("#{described_class.name}::DIFF_BATCH_SIZE", 3) + + namespaces.create!(id: 1, name: 'gitlab', path: 'gitlab') + projects.create!(id: 1, namespace_id: 1, name: 'gitlab', path: 'gitlab') + + merge_requests.create!(id: 1, target_project_id: 1, source_project_id: 1, target_branch: 'feature', source_branch: 'master', state: 'merged') + + merge_request_diffs.create!(id: 1, merge_request_id: 1, state: 'collected') + merge_request_diffs.create!(id: 2, merge_request_id: 1, state: 'empty') + merge_request_diffs.create!(id: 3, merge_request_id: 1, state: 'without_files') + merge_request_diffs.create!(id: 4, merge_request_id: 1, state: 'collected') + merge_request_diffs.create!(id: 5, merge_request_id: 1, state: 'collected') + merge_request_diffs.create!(id: 6, merge_request_id: 1, state: 'collected') + merge_request_diffs.create!(id: 7, merge_request_id: 1, state: 'collected') + + merge_requests.update(1, latest_merge_request_diff_id: 7) + end + + it 'correctly schedules diff file deletion workers' do + Sidekiq::Testing.fake! do + Timecop.freeze do + described_class.new.perform + + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(5.minutes, [1, 4, 5]) + + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(10.minutes, [6]) + + expect(BackgroundMigrationWorker.jobs.size).to eq(2) + end + end + end + end +end diff --git a/spec/lib/gitlab/checks/change_access_spec.rb b/spec/lib/gitlab/checks/change_access_spec.rb index 1cb8143a9e9..7c04aa27971 100644 --- a/spec/lib/gitlab/checks/change_access_spec.rb +++ b/spec/lib/gitlab/checks/change_access_spec.rb @@ -54,7 +54,7 @@ describe Gitlab::Checks::ChangeAccess do context 'as maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end context 'deletion' do @@ -144,7 +144,7 @@ describe Gitlab::Checks::ChangeAccess do context 'if the user is allowed to delete protected branches' do before do - project.add_master(user) + project.add_maintainer(user) end context 'through the web interface' do diff --git a/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb b/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb index 6a52ae01b2f..e327399d82d 100644 --- a/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb +++ b/spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb @@ -2,13 +2,21 @@ require 'spec_helper' describe Gitlab::Ci::Build::Artifacts::Metadata do def metadata(path = '', **opts) - described_class.new(metadata_file_path, path, **opts) + described_class.new(metadata_file_stream, path, **opts) end let(:metadata_file_path) do Rails.root + 'spec/fixtures/ci_build_artifacts_metadata.gz' end + let(:metadata_file_stream) do + File.open(metadata_file_path) if metadata_file_path + end + + after do + metadata_file_stream&.close + end + context 'metadata file exists' do describe '#find_entries! empty string' do subject { metadata('').find_entries! } @@ -86,11 +94,21 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do end context 'metadata file does not exist' do - let(:metadata_file_path) { '' } + let(:metadata_file_path) { nil } + + describe '#find_entries!' do + it 'raises error' do + expect { metadata.find_entries! }.to raise_error(described_class::InvalidStreamError, /Invalid stream/) + end + end + end + + context 'metadata file is invalid' do + let(:metadata_file_path) { Rails.root + 'spec/fixtures/ci_build_artifacts.zip' } describe '#find_entries!' do it 'raises error' do - expect { metadata.find_entries! }.to raise_error(Errno::ENOENT) + expect { metadata.find_entries! }.to raise_error(described_class::InvalidStreamError, /not in gzip format/) end end end diff --git a/spec/lib/gitlab/ci/pipeline/chain/validate/abilities_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/validate/abilities_spec.rb index a973ccda8de..8ba56d73838 100644 --- a/spec/lib/gitlab/ci/pipeline/chain/validate/abilities_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/chain/validate/abilities_spec.rb @@ -99,9 +99,9 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Abilities do end end - context 'when user is a master' do + context 'when user is a maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it { is_expected.to be_truthy } diff --git a/spec/lib/gitlab/ci/status/build/play_spec.rb b/spec/lib/gitlab/ci/status/build/play_spec.rb index e2bb378f663..02f8c4c114b 100644 --- a/spec/lib/gitlab/ci/status/build/play_spec.rb +++ b/spec/lib/gitlab/ci/status/build/play_spec.rb @@ -46,7 +46,7 @@ describe Gitlab::Ci::Status::Build::Play do context 'when user can not push to the branch' do before do build.project.add_developer(user) - create(:protected_branch, :masters_can_push, + create(:protected_branch, :maintainers_can_push, name: build.ref, project: project) end diff --git a/spec/lib/gitlab/ci/status/stage/common_spec.rb b/spec/lib/gitlab/ci/status/stage/common_spec.rb index 6ec35f8da7e..bb2d0a2c75c 100644 --- a/spec/lib/gitlab/ci/status/stage/common_spec.rb +++ b/spec/lib/gitlab/ci/status/stage/common_spec.rb @@ -27,7 +27,7 @@ describe Gitlab::Ci::Status::Stage::Common do context 'when user has permission to read pipeline' do before do - project.add_master(user) + project.add_maintainer(user) end it 'has details' do diff --git a/spec/lib/gitlab/closing_issue_extractor_spec.rb b/spec/lib/gitlab/closing_issue_extractor_spec.rb index 8d4862932b2..3a0688b7cbb 100644 --- a/spec/lib/gitlab/closing_issue_extractor_spec.rb +++ b/spec/lib/gitlab/closing_issue_extractor_spec.rb @@ -15,7 +15,7 @@ describe Gitlab::ClosingIssueExtractor do before do project.add_developer(project.creator) project.add_developer(project2.creator) - project2.add_master(project.creator) + project2.add_maintainer(project.creator) end describe "#closed_by_message" do @@ -298,7 +298,7 @@ describe Gitlab::ClosingIssueExtractor do context 'with an external issue tracker reference' do it 'extracts the referenced issue' do jira_project = create(:jira_project, name: 'JIRA_EXT1') - jira_project.add_master(jira_project.creator) + jira_project.add_maintainer(jira_project.creator) jira_issue = ExternalIssue.new("#{jira_project.name}-1", project: jira_project) closing_issue_extractor = described_class.new(jira_project, jira_project.creator) message = "Resolve #{jira_issue.to_reference}" diff --git a/spec/lib/gitlab/cycle_analytics/permissions_spec.rb b/spec/lib/gitlab/cycle_analytics/permissions_spec.rb index 6de4bd3dc7c..f670c7f6c75 100644 --- a/spec/lib/gitlab/cycle_analytics/permissions_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/permissions_spec.rb @@ -36,9 +36,9 @@ describe Gitlab::CycleAnalytics::Permissions do end end - context 'user is master' do + context 'user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it 'has permissions to issue stage' do diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb index b411aaa19da..0a8c77b0ad9 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb @@ -281,7 +281,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, : it "doesn't break when the namespace was renamed" do subject.rename_namespace(namespace) - namespace.update_attributes!(path: 'renamed-afterwards') + namespace.update!(path: 'renamed-afterwards') expect { subject.revert_renames }.not_to raise_error end diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb index b4896d69077..d4d7a83921c 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects_spec.rb @@ -169,7 +169,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de it "doesn't break when the project was renamed" do subject.rename_project(project) - project.update_attributes!(path: 'renamed-afterwards') + project.update!(path: 'renamed-afterwards') expect { subject.revert_renames }.not_to raise_error end diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb index 8bb246aa4bd..782e4e45a91 100644 --- a/spec/lib/gitlab/database_spec.rb +++ b/spec/lib/gitlab/database_spec.rb @@ -357,6 +357,35 @@ describe Gitlab::Database do end end + describe '.db_read_only?' do + context 'when using PostgreSQL' do + before do + allow(ActiveRecord::Base.connection).to receive(:execute).and_call_original + expect(described_class).to receive(:postgresql?).and_return(true) + end + + it 'detects a read only database' do + allow(ActiveRecord::Base.connection).to receive(:execute).with('SELECT pg_is_in_recovery()').and_return([{ "pg_is_in_recovery" => "t" }]) + + expect(described_class.db_read_only?).to be_truthy + end + + it 'detects a read write database' do + allow(ActiveRecord::Base.connection).to receive(:execute).with('SELECT pg_is_in_recovery()').and_return([{ "pg_is_in_recovery" => "f" }]) + + expect(described_class.db_read_only?).to be_falsey + end + end + + context 'when using MySQL' do + before do + expect(described_class).to receive(:postgresql?).and_return(false) + end + + it { expect(described_class.db_read_only?).to be_falsey } + end + end + describe '#sanitize_timestamp' do let(:max_timestamp) { Time.at((1 << 31) - 1) } diff --git a/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb b/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb index f48ee8924e8..79287021981 100644 --- a/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb +++ b/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb @@ -20,6 +20,15 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do diff_files end + it 'it uses a different cache key if diff line keys change' do + mr_diff = described_class.new(merge_request.merge_request_diff, diff_options: nil) + key = mr_diff.cache_key + + stub_const('Gitlab::Diff::Line::SERIALIZE_KEYS', [:foo]) + + expect(mr_diff.cache_key).not_to eq(key) + end + shared_examples 'initializes a DiffCollection' do it 'returns a valid instance of a DiffCollection' do expect(diff_files).to be_a(Gitlab::Git::DiffCollection) diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb index 5dfbb8e71f8..ebeb05d6e02 100644 --- a/spec/lib/gitlab/diff/file_spec.rb +++ b/spec/lib/gitlab/diff/file_spec.rb @@ -26,6 +26,21 @@ describe Gitlab::Diff::File do end end + describe '#diff_lines_for_serializer' do + it 'includes bottom match line if not in the end' do + expect(diff_file.diff_lines_for_serializer.last.type).to eq('match') + end + + context 'when deleted' do + let(:commit) { project.commit('d59c60028b053793cecfb4022de34602e1a9218e') } + let(:diff_file) { commit.diffs.diff_file_with_old_path('files/js/commit.js.coffee') } + + it 'does not include bottom match line' do + expect(diff_file.diff_lines_for_serializer.last.type).not_to eq('match') + end + end + end + describe '#mode_changed?' do it { expect(diff_file.mode_changed?).to be_falsey } end diff --git a/spec/lib/gitlab/exclusive_lease_helpers_spec.rb b/spec/lib/gitlab/exclusive_lease_helpers_spec.rb new file mode 100644 index 00000000000..2e3656b52fb --- /dev/null +++ b/spec/lib/gitlab/exclusive_lease_helpers_spec.rb @@ -0,0 +1,76 @@ +require 'spec_helper' + +describe Gitlab::ExclusiveLeaseHelpers, :clean_gitlab_redis_shared_state do + include ::ExclusiveLeaseHelpers + + let(:class_instance) { (Class.new { include ::Gitlab::ExclusiveLeaseHelpers }).new } + let(:unique_key) { SecureRandom.hex(10) } + + describe '#in_lock' do + subject { class_instance.in_lock(unique_key, **options) { } } + + let(:options) { {} } + + context 'when the lease is not obtained yet' do + before do + stub_exclusive_lease(unique_key, 'uuid') + end + + it 'calls the given block' do + expect { |b| class_instance.in_lock(unique_key, &b) }.to yield_control.once + end + + it 'calls the given block continuously' do + expect { |b| class_instance.in_lock(unique_key, &b) }.to yield_control.once + expect { |b| class_instance.in_lock(unique_key, &b) }.to yield_control.once + expect { |b| class_instance.in_lock(unique_key, &b) }.to yield_control.once + end + + it 'cancels the exclusive lease after the block' do + expect_to_cancel_exclusive_lease(unique_key, 'uuid') + + subject + end + end + + context 'when the lease is obtained already' do + let!(:lease) { stub_exclusive_lease_taken(unique_key) } + + it 'retries to obtain a lease and raises an error' do + expect(lease).to receive(:try_obtain).exactly(11).times + + expect { subject }.to raise_error('Failed to obtain a lock') + end + + context 'when ttl is specified' do + let(:options) { { ttl: 10.minutes } } + + it 'receives the specified argument' do + expect(Gitlab::ExclusiveLease).to receive(:new).with(unique_key, { timeout: 10.minutes } ) + + expect { subject }.to raise_error('Failed to obtain a lock') + end + end + + context 'when retry count is specified' do + let(:options) { { retries: 3 } } + + it 'retries for the specified times' do + expect(lease).to receive(:try_obtain).exactly(4).times + + expect { subject }.to raise_error('Failed to obtain a lock') + end + end + + context 'when sleep second is specified' do + let(:options) { { retries: 0, sleep_sec: 0.05.seconds } } + + it 'receives the specified argument' do + expect(class_instance).to receive(:sleep).with(0.05.seconds).once + + expect { subject }.to raise_error('Failed to obtain a lock') + end + end + end + end +end diff --git a/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb b/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb index 13df8531b63..ef52a25f47e 100644 --- a/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb +++ b/spec/lib/gitlab/gfm/uploads_rewriter_spec.rb @@ -20,37 +20,55 @@ describe Gitlab::Gfm::UploadsRewriter do "Text and #{image_uploader.markdown_link} and #{zip_uploader.markdown_link}" end - describe '#rewrite' do - let!(:new_text) { rewriter.rewrite(new_project) } + shared_examples "files are accessible" do + describe '#rewrite' do + let!(:new_text) { rewriter.rewrite(new_project) } - let(:old_files) { [image_uploader, zip_uploader].map(&:file) } - let(:new_files) do - described_class.new(new_text, new_project, user).files - end + let(:old_files) { [image_uploader, zip_uploader] } + let(:new_files) do + described_class.new(new_text, new_project, user).files + end - let(:old_paths) { old_files.map(&:path) } - let(:new_paths) { new_files.map(&:path) } + let(:old_paths) { old_files.map(&:path) } + let(:new_paths) { new_files.map(&:path) } - it 'rewrites content' do - expect(new_text).not_to eq text - expect(new_text.length).to eq text.length - end + it 'rewrites content' do + expect(new_text).not_to eq text + expect(new_text.length).to eq text.length + end - it 'copies files' do - expect(new_files).to all(exist) - expect(old_paths).not_to match_array new_paths - expect(old_paths).to all(include(old_project.disk_path)) - expect(new_paths).to all(include(new_project.disk_path)) - end + it 'copies files' do + expect(new_files).to all(exist) + expect(old_paths).not_to match_array new_paths + expect(old_paths).to all(include(old_project.disk_path)) + expect(new_paths).to all(include(new_project.disk_path)) + end - it 'does not remove old files' do - expect(old_files).to all(exist) + it 'does not remove old files' do + expect(old_files).to all(exist) + end + + it 'generates a new secret for each file' do + expect(new_paths).not_to include image_uploader.secret + expect(new_paths).not_to include zip_uploader.secret + end end + end - it 'generates a new secret for each file' do - expect(new_paths).not_to include image_uploader.secret - expect(new_paths).not_to include zip_uploader.secret + context "file are stored locally" do + include_examples "files are accessible" + end + + context "files are stored remotely" do + before do + stub_uploads_object_storage(FileUploader) + + old_files.each do |file| + file.migrate!(ObjectStorage::Store::REMOTE) + end end + + include_examples "files are accessible" end describe '#needs_rewrite?' do diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb index b6061df349d..034b89a46fa 100644 --- a/spec/lib/gitlab/git/blob_spec.rb +++ b/spec/lib/gitlab/git/blob_spec.rb @@ -178,77 +178,67 @@ describe Gitlab::Git::Blob, seed_helper: true do end describe '.batch' do - shared_examples 'loading blobs in batch' do - let(:blob_references) do - [ - [SeedRepo::Commit::ID, "files/ruby/popen.rb"], - [SeedRepo::Commit::ID, 'six'] - ] - end + let(:blob_references) do + [ + [SeedRepo::Commit::ID, "files/ruby/popen.rb"], + [SeedRepo::Commit::ID, 'six'] + ] + end - subject { described_class.batch(repository, blob_references) } + subject { described_class.batch(repository, blob_references) } - it { expect(subject.size).to eq(blob_references.size) } + it { expect(subject.size).to eq(blob_references.size) } - context 'first blob' do - let(:blob) { subject[0] } + context 'first blob' do + let(:blob) { subject[0] } - it { expect(blob.id).to eq(SeedRepo::RubyBlob::ID) } - it { expect(blob.name).to eq(SeedRepo::RubyBlob::NAME) } - it { expect(blob.path).to eq("files/ruby/popen.rb") } - it { expect(blob.commit_id).to eq(SeedRepo::Commit::ID) } - it { expect(blob.data[0..10]).to eq(SeedRepo::RubyBlob::CONTENT[0..10]) } - it { expect(blob.size).to eq(669) } - it { expect(blob.mode).to eq("100644") } - end + it { expect(blob.id).to eq(SeedRepo::RubyBlob::ID) } + it { expect(blob.name).to eq(SeedRepo::RubyBlob::NAME) } + it { expect(blob.path).to eq("files/ruby/popen.rb") } + it { expect(blob.commit_id).to eq(SeedRepo::Commit::ID) } + it { expect(blob.data[0..10]).to eq(SeedRepo::RubyBlob::CONTENT[0..10]) } + it { expect(blob.size).to eq(669) } + it { expect(blob.mode).to eq("100644") } + end - context 'second blob' do - let(:blob) { subject[1] } + context 'second blob' do + let(:blob) { subject[1] } - it { expect(blob.id).to eq('409f37c4f05865e4fb208c771485f211a22c4c2d') } - it { expect(blob.data).to eq('') } - it 'does not mark the blob as binary' do - expect(blob).not_to be_binary - end + it { expect(blob.id).to eq('409f37c4f05865e4fb208c771485f211a22c4c2d') } + it { expect(blob.data).to eq('') } + it 'does not mark the blob as binary' do + expect(blob).not_to be_binary end + end - context 'limiting' do - subject { described_class.batch(repository, blob_references, blob_size_limit: blob_size_limit) } + context 'limiting' do + subject { described_class.batch(repository, blob_references, blob_size_limit: blob_size_limit) } - context 'positive' do - let(:blob_size_limit) { 10 } + context 'positive' do + let(:blob_size_limit) { 10 } - it { expect(subject.first.data.size).to eq(10) } - end + it { expect(subject.first.data.size).to eq(10) } + end - context 'zero' do - let(:blob_size_limit) { 0 } + context 'zero' do + let(:blob_size_limit) { 0 } - it 'only loads the metadata' do - expect(subject.first.size).not_to be(0) - expect(subject.first.data).to eq('') - end + it 'only loads the metadata' do + expect(subject.first.size).not_to be(0) + expect(subject.first.data).to eq('') end + end - context 'negative' do - let(:blob_size_limit) { -1 } + context 'negative' do + let(:blob_size_limit) { -1 } - it 'ignores MAX_DATA_DISPLAY_SIZE' do - stub_const('Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE', 100) + it 'ignores MAX_DATA_DISPLAY_SIZE' do + stub_const('Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE', 100) - expect(subject.first.data.size).to eq(669) - end + expect(subject.first.data.size).to eq(669) end end end - - context 'when Gitaly list_blobs_by_sha_path feature is enabled' do - it_behaves_like 'loading blobs in batch' - end - - context 'when Gitaly list_blobs_by_sha_path feature is disabled', :disable_gitaly do - it_behaves_like 'loading blobs in batch' - end end describe '.batch_metadata' do @@ -294,58 +284,48 @@ describe Gitlab::Git::Blob, seed_helper: true do ) end - shared_examples 'fetching batch of LFS pointers' do - it 'returns a list of Gitlab::Git::Blob' do - blobs = described_class.batch_lfs_pointers(repository, [lfs_blob.id]) - - expect(blobs.count).to eq(1) - expect(blobs).to all( be_a(Gitlab::Git::Blob) ) - expect(blobs).to be_an(Array) - end - - it 'accepts blob IDs as a lazy enumerator' do - blobs = described_class.batch_lfs_pointers(repository, [lfs_blob.id].lazy) - - expect(blobs.count).to eq(1) - expect(blobs).to all( be_a(Gitlab::Git::Blob) ) - end + it 'returns a list of Gitlab::Git::Blob' do + blobs = described_class.batch_lfs_pointers(repository, [lfs_blob.id]) - it 'handles empty list of IDs gracefully' do - blobs_1 = described_class.batch_lfs_pointers(repository, [].lazy) - blobs_2 = described_class.batch_lfs_pointers(repository, []) + expect(blobs.count).to eq(1) + expect(blobs).to all( be_a(Gitlab::Git::Blob) ) + expect(blobs).to be_an(Array) + end - expect(blobs_1).to eq([]) - expect(blobs_2).to eq([]) - end + it 'accepts blob IDs as a lazy enumerator' do + blobs = described_class.batch_lfs_pointers(repository, [lfs_blob.id].lazy) - it 'silently ignores tree objects' do - blobs = described_class.batch_lfs_pointers(repository, [tree_object.oid]) + expect(blobs.count).to eq(1) + expect(blobs).to all( be_a(Gitlab::Git::Blob) ) + end - expect(blobs).to eq([]) - end + it 'handles empty list of IDs gracefully' do + blobs_1 = described_class.batch_lfs_pointers(repository, [].lazy) + blobs_2 = described_class.batch_lfs_pointers(repository, []) - it 'silently ignores non lfs objects' do - blobs = described_class.batch_lfs_pointers(repository, [non_lfs_blob.id]) + expect(blobs_1).to eq([]) + expect(blobs_2).to eq([]) + end - expect(blobs).to eq([]) - end + it 'silently ignores tree objects' do + blobs = described_class.batch_lfs_pointers(repository, [tree_object.oid]) - it 'avoids loading large blobs into memory' do - # This line could call `lookup` on `repository`, so do here before mocking. - non_lfs_blob_id = non_lfs_blob.id + expect(blobs).to eq([]) + end - expect(repository).not_to receive(:lookup) + it 'silently ignores non lfs objects' do + blobs = described_class.batch_lfs_pointers(repository, [non_lfs_blob.id]) - described_class.batch_lfs_pointers(repository, [non_lfs_blob_id]) - end + expect(blobs).to eq([]) end - context 'when Gitaly batch_lfs_pointers is enabled' do - it_behaves_like 'fetching batch of LFS pointers' - end + it 'avoids loading large blobs into memory' do + # This line could call `lookup` on `repository`, so do here before mocking. + non_lfs_blob_id = non_lfs_blob.id + + expect(repository).not_to receive(:lookup) - context 'when Gitaly batch_lfs_pointers is disabled', :disable_gitaly do - it_behaves_like 'fetching batch of LFS pointers' + described_class.batch_lfs_pointers(repository, [non_lfs_blob_id]) end end @@ -532,8 +512,8 @@ describe Gitlab::Git::Blob, seed_helper: true do subject { blob.load_all_data!(repository) } it 'loads missing data' do - expect(Gitlab::GitalyClient).to receive(:migrate) - .with(:git_blob_load_all_data).and_return(full_data) + expect(repository.gitaly_blob_client).to receive(:get_blob) + .and_return(double(:response, data: full_data)) subject @@ -544,8 +524,7 @@ describe Gitlab::Git::Blob, seed_helper: true do let(:blob) { Gitlab::Git::Blob.new(name: 'test', size: 4, data: full_data) } it "doesn't perform any loading" do - expect(Gitlab::GitalyClient).not_to receive(:migrate) - .with(:git_blob_load_all_data) + expect(repository.gitaly_blob_client).not_to receive(:get_blob) subject diff --git a/spec/lib/gitlab/git/branch_spec.rb b/spec/lib/gitlab/git/branch_spec.rb index ec1a684cfbc..a8c5627e678 100644 --- a/spec/lib/gitlab/git/branch_spec.rb +++ b/spec/lib/gitlab/git/branch_spec.rb @@ -2,6 +2,11 @@ require "spec_helper" describe Gitlab::Git::Branch, seed_helper: true do let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '') } + let(:rugged) do + Gitlab::GitalyClient::StorageSettings.allow_disk_access do + repository.rugged + end + end subject { repository.branches } @@ -124,6 +129,7 @@ describe Gitlab::Git::Branch, seed_helper: true do it { expect(repository.branches.size).to eq(SeedRepo::Repo::BRANCHES.size) } def create_commit - repository.create_commit(params.merge(committer: committer.merge(time: Time.now))) + params[:message].delete!("\r") + Rugged::Commit.create(rugged, params.merge(committer: committer.merge(time: Time.now))) end end diff --git a/spec/lib/gitlab/git/diff_spec.rb b/spec/lib/gitlab/git/diff_spec.rb index 3bb0b5be15b..7c3d2af819b 100644 --- a/spec/lib/gitlab/git/diff_spec.rb +++ b/spec/lib/gitlab/git/diff_spec.rb @@ -27,6 +27,7 @@ EOT too_large: false } + # TODO use a Gitaly diff object instead @rugged_diff = Gitlab::GitalyClient::StorageSettings.allow_disk_access do repository.rugged.diff("5937ac0a7beb003549fc5fd26fc247adbce4a52e^", "5937ac0a7beb003549fc5fd26fc247adbce4a52e", paths: [".gitmodules"]).patches.first @@ -266,8 +267,12 @@ EOT describe '#submodule?' do before do - commit = repository.lookup('5937ac0a7beb003549fc5fd26fc247adbce4a52e') - @diffs = commit.parents[0].diff(commit).patches + # TODO use a Gitaly diff object instead + rugged_commit = Gitlab::GitalyClient::StorageSettings.allow_disk_access do + repository.lookup('5937ac0a7beb003549fc5fd26fc247adbce4a52e') + end + + @diffs = rugged_commit.parents[0].diff(rugged_commit).patches end it { expect(described_class.new(@diffs[0]).submodule?).to eq(false) } diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 6ec4b90d70c..64b08dd9c4b 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -611,21 +611,6 @@ describe Gitlab::Git::Repository, seed_helper: true do end end - describe "#remove_remote" do - before(:all) do - @repo = Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '') - @repo.remove_remote("expendable") - end - - it "should remove the remote" do - expect(@repo.rugged.remotes).not_to include("expendable") - end - - after(:all) do - ensure_seeds - end - end - describe "#remote_update" do before(:all) do @repo = Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '') @@ -633,7 +618,9 @@ describe Gitlab::Git::Repository, seed_helper: true do end it "should add the remote" do - expect(@repo.rugged.remotes["expendable"].url).to( + rugged = Gitlab::GitalyClient::StorageSettings.allow_disk_access { @repo.rugged } + + expect(rugged.remotes["expendable"].url).to( eq(TEST_NORMAL_REPO_PATH) ) end @@ -1157,6 +1144,13 @@ describe Gitlab::Git::Repository, seed_helper: true do @repo.rugged.config['core.autocrlf'] = true end + around do |example| + # OK because autocrlf is only used in gitaly-ruby + Gitlab::GitalyClient::StorageSettings.allow_disk_access do + example.run + end + end + it 'return the value of the autocrlf option' do expect(@repo.autocrlf).to be(true) end @@ -1172,6 +1166,13 @@ describe Gitlab::Git::Repository, seed_helper: true do @repo.rugged.config['core.autocrlf'] = false end + around do |example| + # OK because autocrlf= is only used in gitaly-ruby + Gitlab::GitalyClient::StorageSettings.allow_disk_access do + example.run + end + end + it 'should set the autocrlf option to the provided option' do @repo.autocrlf = :input @@ -1186,50 +1187,17 @@ describe Gitlab::Git::Repository, seed_helper: true do end describe '#find_branch' do - shared_examples 'finding a branch' do - it 'should return a Branch for master' do - branch = repository.find_branch('master') - - expect(branch).to be_a_kind_of(Gitlab::Git::Branch) - expect(branch.name).to eq('master') - end - - it 'should handle non-existent branch' do - branch = repository.find_branch('this-is-garbage') + it 'should return a Branch for master' do + branch = repository.find_branch('master') - expect(branch).to eq(nil) - end + expect(branch).to be_a_kind_of(Gitlab::Git::Branch) + expect(branch.name).to eq('master') end - context 'when Gitaly find_branch feature is enabled' do - it_behaves_like 'finding a branch' - end - - context 'when Gitaly find_branch feature is disabled', :skip_gitaly_mock do - it_behaves_like 'finding a branch' - - context 'force_reload is true' do - it 'should reload Rugged::Repository' do - expect(Rugged::Repository).to receive(:new).twice.and_call_original - - repository.find_branch('master') - branch = repository.find_branch('master', force_reload: true) - - expect(branch).to be_a_kind_of(Gitlab::Git::Branch) - expect(branch.name).to eq('master') - end - end - - context 'force_reload is false' do - it 'should not reload Rugged::Repository' do - expect(Rugged::Repository).to receive(:new).once.and_call_original + it 'should handle non-existent branch' do + branch = repository.find_branch('this-is-garbage') - branch = repository.find_branch('master', force_reload: false) - - expect(branch).to be_a_kind_of(Gitlab::Git::Branch) - expect(branch.name).to eq('master') - end - end + expect(branch).to eq(nil) end end @@ -1402,94 +1370,84 @@ describe Gitlab::Git::Repository, seed_helper: true do end describe "#copy_gitattributes" do - shared_examples 'applying git attributes' do - let(:attributes_path) { File.join(SEED_STORAGE_PATH, TEST_REPO_PATH, 'info/attributes') } - - after do - FileUtils.rm_rf(attributes_path) if Dir.exist?(attributes_path) - end - - it "raises an error with invalid ref" do - expect { repository.copy_gitattributes("invalid") }.to raise_error(Gitlab::Git::Repository::InvalidRef) - end + let(:attributes_path) { File.join(SEED_STORAGE_PATH, TEST_REPO_PATH, 'info/attributes') } - context 'when forcing encoding issues' do - let(:branch_name) { "ʕ•ᴥ•ʔ" } + after do + FileUtils.rm_rf(attributes_path) if Dir.exist?(attributes_path) + end - before do - repository.create_branch(branch_name, "master") - end + it "raises an error with invalid ref" do + expect { repository.copy_gitattributes("invalid") }.to raise_error(Gitlab::Git::Repository::InvalidRef) + end - after do - repository.rm_branch(branch_name, user: build(:admin)) - end + context 'when forcing encoding issues' do + let(:branch_name) { "ʕ•ᴥ•ʔ" } - it "doesn't raise with a valid unicode ref" do - expect { repository.copy_gitattributes(branch_name) }.not_to raise_error + before do + repository.create_branch(branch_name, "master") + end - repository - end + after do + repository.rm_branch(branch_name, user: build(:admin)) end - context "with no .gitattrbutes" do - before do - repository.copy_gitattributes("master") - end + it "doesn't raise with a valid unicode ref" do + expect { repository.copy_gitattributes(branch_name) }.not_to raise_error - it "does not have an info/attributes" do - expect(File.exist?(attributes_path)).to be_falsey - end + repository end + end - context "with .gitattrbutes" do - before do - repository.copy_gitattributes("gitattributes") - end + context "with no .gitattrbutes" do + before do + repository.copy_gitattributes("master") + end - it "has an info/attributes" do - expect(File.exist?(attributes_path)).to be_truthy - end + it "does not have an info/attributes" do + expect(File.exist?(attributes_path)).to be_falsey + end + end - it "has the same content in info/attributes as .gitattributes" do - contents = File.open(attributes_path, "rb") { |f| f.read } - expect(contents).to eq("*.md binary\n") - end + context "with .gitattrbutes" do + before do + repository.copy_gitattributes("gitattributes") end - context "with updated .gitattrbutes" do - before do - repository.copy_gitattributes("gitattributes") - repository.copy_gitattributes("gitattributes-updated") - end + it "has an info/attributes" do + expect(File.exist?(attributes_path)).to be_truthy + end - it "has an info/attributes" do - expect(File.exist?(attributes_path)).to be_truthy - end + it "has the same content in info/attributes as .gitattributes" do + contents = File.open(attributes_path, "rb") { |f| f.read } + expect(contents).to eq("*.md binary\n") + end + end - it "has the updated content in info/attributes" do - contents = File.read(attributes_path) - expect(contents).to eq("*.txt binary\n") - end + context "with updated .gitattrbutes" do + before do + repository.copy_gitattributes("gitattributes") + repository.copy_gitattributes("gitattributes-updated") end - context "with no .gitattrbutes in HEAD but with previous info/attributes" do - before do - repository.copy_gitattributes("gitattributes") - repository.copy_gitattributes("master") - end + it "has an info/attributes" do + expect(File.exist?(attributes_path)).to be_truthy + end - it "does not have an info/attributes" do - expect(File.exist?(attributes_path)).to be_falsey - end + it "has the updated content in info/attributes" do + contents = File.read(attributes_path) + expect(contents).to eq("*.txt binary\n") end end - context 'when gitaly is enabled' do - it_behaves_like 'applying git attributes' - end + context "with no .gitattrbutes in HEAD but with previous info/attributes" do + before do + repository.copy_gitattributes("gitattributes") + repository.copy_gitattributes("master") + end - context 'when gitaly is disabled', :disable_gitaly do - it_behaves_like 'applying git attributes' + it "does not have an info/attributes" do + expect(File.exist?(attributes_path)).to be_falsey + end end end @@ -1726,59 +1684,51 @@ describe Gitlab::Git::Repository, seed_helper: true do end describe '#fetch_source_branch!' do - shared_examples '#fetch_source_branch!' do - let(:local_ref) { 'refs/merge-requests/1/head' } - let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '') } - let(:source_repository) { Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '') } - - after do - ensure_seeds - end + let(:local_ref) { 'refs/merge-requests/1/head' } + let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '') } + let(:source_repository) { Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '') } - context 'when the branch exists' do - context 'when the commit does not exist locally' do - let(:source_branch) { 'new-branch-for-fetch-source-branch' } - let(:source_rugged) { Gitlab::GitalyClient::StorageSettings.allow_disk_access { source_repository.rugged } } - let(:new_oid) { new_commit_edit_old_file(source_rugged).oid } + after do + ensure_seeds + end - before do - source_rugged.branches.create(source_branch, new_oid) - end + context 'when the branch exists' do + context 'when the commit does not exist locally' do + let(:source_branch) { 'new-branch-for-fetch-source-branch' } + let(:source_rugged) { Gitlab::GitalyClient::StorageSettings.allow_disk_access { source_repository.rugged } } + let(:new_oid) { new_commit_edit_old_file(source_rugged).oid } - it 'writes the ref' do - expect(repository.fetch_source_branch!(source_repository, source_branch, local_ref)).to eq(true) - expect(repository.commit(local_ref).sha).to eq(new_oid) - end + before do + source_rugged.branches.create(source_branch, new_oid) end - context 'when the commit exists locally' do - let(:source_branch) { 'master' } - let(:expected_oid) { SeedRepo::LastCommit::ID } - - it 'writes the ref' do - # Sanity check: the commit should already exist - expect(repository.commit(expected_oid)).not_to be_nil - - expect(repository.fetch_source_branch!(source_repository, source_branch, local_ref)).to eq(true) - expect(repository.commit(local_ref).sha).to eq(expected_oid) - end + it 'writes the ref' do + expect(repository.fetch_source_branch!(source_repository, source_branch, local_ref)).to eq(true) + expect(repository.commit(local_ref).sha).to eq(new_oid) end end - context 'when the branch does not exist' do - let(:source_branch) { 'definitely-not-master' } + context 'when the commit exists locally' do + let(:source_branch) { 'master' } + let(:expected_oid) { SeedRepo::LastCommit::ID } + + it 'writes the ref' do + # Sanity check: the commit should already exist + expect(repository.commit(expected_oid)).not_to be_nil - it 'does not write the ref' do - expect(repository.fetch_source_branch!(source_repository, source_branch, local_ref)).to eq(false) - expect(repository.commit(local_ref)).to be_nil + expect(repository.fetch_source_branch!(source_repository, source_branch, local_ref)).to eq(true) + expect(repository.commit(local_ref).sha).to eq(expected_oid) end end end - it_behaves_like '#fetch_source_branch!' + context 'when the branch does not exist' do + let(:source_branch) { 'definitely-not-master' } - context 'without gitaly', :skip_gitaly_mock do - it_behaves_like '#fetch_source_branch!' + it 'does not write the ref' do + expect(repository.fetch_source_branch!(source_repository, source_branch, local_ref)).to eq(false) + expect(repository.commit(local_ref)).to be_nil + end end end @@ -1866,6 +1816,54 @@ describe Gitlab::Git::Repository, seed_helper: true do end end + describe '#set_config' do + let(:repository) { Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '') } + let(:rugged) { repository_rugged } + let(:entries) do + { + 'test.foo1' => 'bla bla', + 'test.foo2' => 1234, + 'test.foo3' => true + } + end + + it 'can set config settings' do + expect(repository.set_config(entries)).to be_nil + + expect(rugged.config['test.foo1']).to eq('bla bla') + expect(rugged.config['test.foo2']).to eq('1234') + expect(rugged.config['test.foo3']).to eq('true') + end + + after do + entries.keys.each { |k| rugged.config.delete(k) } + end + end + + describe '#delete_config' do + let(:repository) { Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '') } + let(:rugged) { repository_rugged } + let(:entries) do + { + 'test.foo1' => 'bla bla', + 'test.foo2' => 1234, + 'test.foo3' => true + } + end + + it 'can delete config settings' do + entries.each do |key, value| + rugged.config[key] = value + end + + expect(repository.delete_config(*%w[does.not.exist test.foo1 test.foo2])).to be_nil + + config_keys = rugged.config.each_key.to_a + expect(config_keys).not_to include('test.foo1') + expect(config_keys).not_to include('test.foo2') + end + end + describe '#merge' do let(:repository) do Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '') @@ -1971,21 +1969,15 @@ describe Gitlab::Git::Repository, seed_helper: true do end end - context 'with gitaly' do - it "calls Gitaly's OperationService" do - expect_any_instance_of(Gitlab::GitalyClient::OperationService) - .to receive(:user_ff_branch).with(user, source_sha, target_branch) - .and_return(nil) - - subject - end + it "calls Gitaly's OperationService" do + expect_any_instance_of(Gitlab::GitalyClient::OperationService) + .to receive(:user_ff_branch).with(user, source_sha, target_branch) + .and_return(nil) - it_behaves_like '#ff_merge' + subject end - context 'without gitaly', :skip_gitaly_mock do - it_behaves_like '#ff_merge' - end + it_behaves_like '#ff_merge' end describe '#delete_all_refs_except' do @@ -2018,54 +2010,61 @@ describe Gitlab::Git::Repository, seed_helper: true do let(:repository) do Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '') end + let(:rugged) do + Gitlab::GitalyClient::StorageSettings.allow_disk_access { repository.rugged } + end let(:remote_name) { 'my-remote' } + let(:url) { 'http://my-repo.git' } after do ensure_seeds end describe '#add_remote' do - let(:url) { 'http://my-repo.git' } let(:mirror_refmap) { '+refs/*:refs/*' } - it 'creates a new remote via Gitaly' do - expect_any_instance_of(Gitlab::GitalyClient::RemoteService) - .to receive(:add_remote).with(remote_name, url, mirror_refmap) + shared_examples 'add_remote' do + it 'added the remote' do + begin + rugged.remotes.delete(remote_name) + rescue Rugged::ConfigError + end - repository.add_remote(remote_name, url, mirror_refmap: mirror_refmap) + repository.add_remote(remote_name, url, mirror_refmap: mirror_refmap) + + expect(rugged.remotes[remote_name]).not_to be_nil + expect(rugged.config["remote.#{remote_name}.mirror"]).to eq('true') + expect(rugged.config["remote.#{remote_name}.prune"]).to eq('true') + expect(rugged.config["remote.#{remote_name}.fetch"]).to eq(mirror_refmap) + end end - context 'with Gitaly disabled', :skip_gitaly_mock do - it 'creates a new remote via Rugged' do - expect_any_instance_of(Rugged::RemoteCollection).to receive(:create) - .with(remote_name, url) - expect_any_instance_of(Rugged::Config).to receive(:[]=) - .with("remote.#{remote_name}.mirror", true) - expect_any_instance_of(Rugged::Config).to receive(:[]=) - .with("remote.#{remote_name}.prune", true) - expect_any_instance_of(Rugged::Config).to receive(:[]=) - .with("remote.#{remote_name}.fetch", mirror_refmap) + context 'using Gitaly' do + it_behaves_like 'add_remote' + end - repository.add_remote(remote_name, url, mirror_refmap: mirror_refmap) - end + context 'with Gitaly disabled', :disable_gitaly do + it_behaves_like 'add_remote' end end describe '#remove_remote' do - it 'removes the remote via Gitaly' do - expect_any_instance_of(Gitlab::GitalyClient::RemoteService) - .to receive(:remove_remote).with(remote_name) + shared_examples 'remove_remote' do + it 'removes the remote' do + rugged.remotes.create(remote_name, url) - repository.remove_remote(remote_name) + repository.remove_remote(remote_name) + + expect(rugged.remotes[remote_name]).to be_nil + end end - context 'with Gitaly disabled', :skip_gitaly_mock do - it 'removes the remote via Rugged' do - expect_any_instance_of(Rugged::RemoteCollection).to receive(:delete) - .with(remote_name) + context 'using Gitaly' do + it_behaves_like 'remove_remote' + end - repository.remove_remote(remote_name) - end + context 'with Gitaly disabled', :disable_gitaly do + it_behaves_like 'remove_remote' end end end @@ -2257,20 +2256,25 @@ describe Gitlab::Git::Repository, seed_helper: true do let(:worktree_path) { File.join(repository_path, 'worktrees', 'delete-me') } it 'cleans up the files' do - repository.with_worktree(worktree_path, 'master', env: ENV) do - FileUtils.touch(worktree_path, mtime: Time.now - 8.hours) - # git rev-list --all will fail in git 2.16 if HEAD is pointing to a non-existent object, - # but the HEAD must be 40 characters long or git will ignore it. - File.write(File.join(worktree_path, 'HEAD'), Gitlab::Git::BLANK_SHA) + create_worktree = %W[git -C #{repository_path} worktree add --detach #{worktree_path} master] + raise 'preparation failed' unless system(*create_worktree, err: '/dev/null') - # git 2.16 fails with "fatal: bad object HEAD" - expect { repository.rev_list(including: :all) }.to raise_error(Gitlab::Git::Repository::GitError) + FileUtils.touch(worktree_path, mtime: Time.now - 8.hours) + # git rev-list --all will fail in git 2.16 if HEAD is pointing to a non-existent object, + # but the HEAD must be 40 characters long or git will ignore it. + File.write(File.join(worktree_path, 'HEAD'), Gitlab::Git::BLANK_SHA) - repository.clean_stale_repository_files + # git 2.16 fails with "fatal: bad object HEAD" + expect(rev_list_all).to be false - expect { repository.rev_list(including: :all) }.not_to raise_error - expect(File.exist?(worktree_path)).to be_falsey - end + repository.clean_stale_repository_files + + expect(rev_list_all).to be true + expect(File.exist?(worktree_path)).to be_falsey + end + + def rev_list_all + system(*%W[git -C #{repository_path} rev-list --all], out: '/dev/null', err: '/dev/null') end it 'increments a counter upon an error' do @@ -2308,92 +2312,95 @@ describe Gitlab::Git::Repository, seed_helper: true do expect { subject }.to raise_error(Gitlab::Git::CommandError, 'error') end end + end - describe '#squash' do - let(:squash_id) { '1' } - let(:branch_name) { 'fix' } - let(:start_sha) { '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' } - let(:end_sha) { '12d65c8dd2b2676fa3ac47d955accc085a37a9c1' } + describe '#squash' do + let(:squash_id) { '1' } + let(:branch_name) { 'fix' } + let(:start_sha) { '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' } + let(:end_sha) { '12d65c8dd2b2676fa3ac47d955accc085a37a9c1' } - subject do - opts = { - branch: branch_name, - start_sha: start_sha, - end_sha: end_sha, - author: user, - message: 'Squash commit message' - } + subject do + opts = { + branch: branch_name, + start_sha: start_sha, + end_sha: end_sha, + author: user, + message: 'Squash commit message' + } - repository.squash(user, squash_id, opts) + repository.squash(user, squash_id, opts) + end + + # Should be ported to gitaly-ruby rspec suite https://gitlab.com/gitlab-org/gitaly/issues/1234 + skip 'sparse checkout' do + let(:expected_files) { %w(files files/js files/js/application.js) } + + it 'checks out only the files in the diff' do + allow(repository).to receive(:with_worktree).and_wrap_original do |m, *args| + m.call(*args) do + worktree_path = args[0] + files_pattern = File.join(worktree_path, '**', '*') + expected = expected_files.map do |path| + File.expand_path(path, worktree_path) + end + + expect(Dir[files_pattern]).to eq(expected) + end + end + + subject end - context 'sparse checkout', :skip_gitaly_mock do - let(:expected_files) { %w(files files/js files/js/application.js) } + context 'when the diff contains a rename' do + let(:repo) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '').rugged } + let(:end_sha) { new_commit_move_file(repo).oid } + + after do + # Erase our commits so other tests get the original repo + repo = Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '').rugged + repo.references.update('refs/heads/master', SeedRepo::LastCommit::ID) + end - it 'checks out only the files in the diff' do + it 'does not include the renamed file in the sparse checkout' do allow(repository).to receive(:with_worktree).and_wrap_original do |m, *args| m.call(*args) do worktree_path = args[0] files_pattern = File.join(worktree_path, '**', '*') - expected = expected_files.map do |path| - File.expand_path(path, worktree_path) - end - expect(Dir[files_pattern]).to eq(expected) + expect(Dir[files_pattern]).not_to include('CHANGELOG') + expect(Dir[files_pattern]).not_to include('encoding/CHANGELOG') end end subject end - - context 'when the diff contains a rename' do - let(:repo) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '').rugged } - let(:end_sha) { new_commit_move_file(repo).oid } - - after do - # Erase our commits so other tests get the original repo - repo = Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '').rugged - repo.references.update('refs/heads/master', SeedRepo::LastCommit::ID) - end - - it 'does not include the renamed file in the sparse checkout' do - allow(repository).to receive(:with_worktree).and_wrap_original do |m, *args| - m.call(*args) do - worktree_path = args[0] - files_pattern = File.join(worktree_path, '**', '*') - - expect(Dir[files_pattern]).not_to include('CHANGELOG') - expect(Dir[files_pattern]).not_to include('encoding/CHANGELOG') - end - end - - subject - end - end end + end - context 'with an ASCII-8BIT diff', :skip_gitaly_mock do - let(:diff) { "diff --git a/README.md b/README.md\nindex faaf198..43c5edf 100644\n--- a/README.md\n+++ b/README.md\n@@ -1,4 +1,4 @@\n-testme\n+✓ testme\n ======\n \n Sample repo for testing gitlab features\n" } + # Should be ported to gitaly-ruby rspec suite https://gitlab.com/gitlab-org/gitaly/issues/1234 + skip 'with an ASCII-8BIT diff' do + let(:diff) { "diff --git a/README.md b/README.md\nindex faaf198..43c5edf 100644\n--- a/README.md\n+++ b/README.md\n@@ -1,4 +1,4 @@\n-testme\n+✓ testme\n ======\n \n Sample repo for testing gitlab features\n" } - it 'applies a ASCII-8BIT diff' do - allow(repository).to receive(:run_git!).and_call_original - allow(repository).to receive(:run_git!).with(%W(diff --binary #{start_sha}...#{end_sha})).and_return(diff.force_encoding('ASCII-8BIT')) + it 'applies a ASCII-8BIT diff' do + allow(repository).to receive(:run_git!).and_call_original + allow(repository).to receive(:run_git!).with(%W(diff --binary #{start_sha}...#{end_sha})).and_return(diff.force_encoding('ASCII-8BIT')) - expect(subject).to match(/\h{40}/) - end + expect(subject).to match(/\h{40}/) end + end - context 'with trailing whitespace in an invalid patch', :skip_gitaly_mock do - let(:diff) { "diff --git a/README.md b/README.md\nindex faaf198..43c5edf 100644\n--- a/README.md\n+++ b/README.md\n@@ -1,4 +1,4 @@\n-testme\n+ \n ====== \n \n Sample repo for testing gitlab features\n" } + # Should be ported to gitaly-ruby rspec suite https://gitlab.com/gitlab-org/gitaly/issues/1234 + skip 'with trailing whitespace in an invalid patch' do + let(:diff) { "diff --git a/README.md b/README.md\nindex faaf198..43c5edf 100644\n--- a/README.md\n+++ b/README.md\n@@ -1,4 +1,4 @@\n-testme\n+ \n ====== \n \n Sample repo for testing gitlab features\n" } - it 'does not include whitespace warnings in the error' do - allow(repository).to receive(:run_git!).and_call_original - allow(repository).to receive(:run_git!).with(%W(diff --binary #{start_sha}...#{end_sha})).and_return(diff.force_encoding('ASCII-8BIT')) + it 'does not include whitespace warnings in the error' do + allow(repository).to receive(:run_git!).and_call_original + allow(repository).to receive(:run_git!).with(%W(diff --binary #{start_sha}...#{end_sha})).and_return(diff.force_encoding('ASCII-8BIT')) - expect { subject }.to raise_error do |error| - expect(error).to be_a(described_class::GitError) - expect(error.message).not_to include('trailing whitespace') - end + expect { subject }.to raise_error do |error| + expect(error).to be_a(described_class::GitError) + expect(error.message).not_to include('trailing whitespace') end end end diff --git a/spec/lib/gitlab/git/rev_list_spec.rb b/spec/lib/gitlab/git/rev_list_spec.rb index b752c3e8341..d9d405e1ccc 100644 --- a/spec/lib/gitlab/git/rev_list_spec.rb +++ b/spec/lib/gitlab/git/rev_list_spec.rb @@ -32,65 +32,4 @@ describe Gitlab::Git::RevList do expect(rev_list.new_refs).to eq(%w[sha1 sha2]) end end - - context '#new_objects' do - it 'fetches list of newly pushed objects using rev-list' do - stub_popen_rev_list('newrev', '--not', '--all', '--objects', output: "sha1\nsha2") - - expect { |b| rev_list.new_objects(&b) }.to yield_with_args(%w[sha1 sha2]) - end - - it 'can skip pathless objects' do - stub_popen_rev_list('newrev', '--not', '--all', '--objects', output: "sha1\nsha2 path/to/file") - - expect { |b| rev_list.new_objects(require_path: true, &b) }.to yield_with_args(%w[sha2]) - end - - it 'can handle non utf-8 paths' do - non_utf_char = [0x89].pack("c*").force_encoding("UTF-8") - stub_popen_rev_list('newrev', '--not', '--all', '--objects', output: "sha2 πå†h/†ø/ƒîlé#{non_utf_char}\nsha1") - - rev_list.new_objects(require_path: true) do |object_ids| - expect(object_ids.force).to eq(%w[sha2]) - end - end - - it 'can yield a lazy enumerator' do - stub_popen_rev_list('newrev', '--not', '--all', '--objects', output: "sha1\nsha2") - - rev_list.new_objects do |object_ids| - expect(object_ids).to be_a Enumerator::Lazy - end - end - - it 'returns the result of the block when given' do - stub_popen_rev_list('newrev', '--not', '--all', '--objects', output: "sha1\nsha2") - - objects = rev_list.new_objects do |object_ids| - object_ids.first - end - - expect(objects).to eq 'sha1' - end - - it 'can accept list of references to exclude' do - stub_popen_rev_list('newrev', '--not', 'master', '--objects', output: "sha1\nsha2") - - expect { |b| rev_list.new_objects(not_in: ['master'], &b) }.to yield_with_args(%w[sha1 sha2]) - end - - it 'handles empty list of references to exclude as listing all known objects' do - stub_popen_rev_list('newrev', '--objects', output: "sha1\nsha2") - - expect { |b| rev_list.new_objects(not_in: [], &b) }.to yield_with_args(%w[sha1 sha2]) - end - end - - context '#all_objects' do - it 'fetches list of all pushed objects using rev-list' do - stub_popen_rev_list('--all', '--objects', output: "sha1\nsha2") - - expect { |b| rev_list.all_objects(&b) }.to yield_with_args(%w[sha1 sha2]) - end - end end diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index ff32025253a..dbd64c4bec0 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -13,14 +13,6 @@ describe Gitlab::GitAccess do let(:authentication_abilities) { %i[read_project download_code push_code] } let(:redirected_path) { nil } let(:auth_result_type) { nil } - - let(:access) do - described_class.new(actor, project, - protocol, authentication_abilities: authentication_abilities, - namespace_path: namespace_path, project_path: project_path, - redirected_path: redirected_path, auth_result_type: auth_result_type) - end - let(:changes) { '_any' } let(:push_access_check) { access.check('git-receive-pack', changes) } let(:pull_access_check) { access.check('git-upload-pack', changes) } @@ -48,7 +40,7 @@ describe Gitlab::GitAccess do before do disable_protocol('http') - project.add_master(user) + project.add_maintainer(user) end it 'blocks http push and pull' do @@ -113,7 +105,7 @@ describe Gitlab::GitAccess do context 'when actor is a User' do context 'when the User can read the project' do before do - project.add_master(user) + project.add_maintainer(user) end it 'allows push and pull access' do @@ -254,7 +246,7 @@ describe Gitlab::GitAccess do shared_examples '#check with a key that is not valid' do before do - project.add_master(user) + project.add_maintainer(user) end context 'key is too small' do @@ -307,7 +299,7 @@ describe Gitlab::GitAccess do describe '#add_project_moved_message!', :clean_gitlab_redis_shared_state do before do - project.add_master(user) + project.add_maintainer(user) end context 'when a redirect was not followed to find the project' do @@ -335,7 +327,7 @@ describe Gitlab::GitAccess do describe '#check_authentication_abilities!' do before do - project.add_master(user) + project.add_maintainer(user) end context 'when download' do @@ -381,7 +373,7 @@ describe Gitlab::GitAccess do describe '#check_command_disabled!' do before do - project.add_master(user) + project.add_maintainer(user) end context 'over http' do @@ -529,8 +521,8 @@ describe Gitlab::GitAccess do end describe '#check_download_access!' do - it 'allows masters to pull' do - project.add_master(user) + it 'allows maintainers to pull' do + project.add_maintainer(user) expect { pull_access_check }.not_to raise_error end @@ -542,7 +534,7 @@ describe Gitlab::GitAccess do end it 'disallows blocked users to pull' do - project.add_master(user) + project.add_maintainer(user) user.block expect { pull_access_check }.to raise_unauthorized('Your account has been blocked.') @@ -724,10 +716,11 @@ describe Gitlab::GitAccess do end describe '#check_push_access!' do + let(:unprotected_branch) { 'unprotected_branch' } + before do merge_into_protected_branch end - let(:unprotected_branch) { 'unprotected_branch' } let(:changes) do { push_new_branch: "#{Gitlab::Git::BLANK_SHA} 570e7b2ab refs/heads/wow", @@ -741,26 +734,18 @@ describe Gitlab::GitAccess do merge_into_protected_branch: "0b4bc9a #{merge_into_protected_branch} refs/heads/feature" } end - def stub_git_hooks - # Running the `pre-receive` hook is expensive, and not necessary for this test. - allow_any_instance_of(Gitlab::Git::HooksService).to receive(:execute) do |service, &block| - block.call(service) - end - end - def merge_into_protected_branch @protected_branch_merge_commit ||= begin Gitlab::GitalyClient::StorageSettings.allow_disk_access do - stub_git_hooks project.repository.add_branch(user, unprotected_branch, 'feature') - target_branch = project.repository.lookup('feature') + rugged = project.repository.rugged + target_branch = rugged.rev_parse('feature') source_branch = project.repository.create_file( user, 'filename', 'This is the file content', message: 'This is a good commit message', branch_name: unprotected_branch) - rugged = project.repository.rugged author = { email: "email@example.com", time: Time.now, name: "Example Git User" } merge_index = rugged.merge_commits(target_branch, source_branch) @@ -785,7 +770,7 @@ describe Gitlab::GitAccess do aggregate_failures do matrix.each do |action, allowed| - check = -> { access.send(:check_push_access!, changes[action]) } + check = -> { push_changes(changes[action]) } if allowed expect(&check).not_to raise_error, @@ -812,7 +797,7 @@ describe Gitlab::GitAccess do merge_into_protected_branch: true }, - master: { + maintainer: { push_new_branch: true, push_master: true, push_protected_branch: true, @@ -917,7 +902,7 @@ describe Gitlab::GitAccess do end run_permission_checks(permissions_matrix.deep_merge(developer: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false }, - master: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false }, + maintainer: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false }, admin: { push_protected_branch: false, push_all: false, merge_into_protected_branch: false })) end end @@ -989,7 +974,7 @@ describe Gitlab::GitAccess do let(:project) { create(:project, :repository, :read_only) } it 'denies push access' do - project.add_master(user) + project.add_maintainer(user) expect { push_access_check }.to raise_unauthorized('The repository is temporarily read-only. Please try again later.') end @@ -1119,9 +1104,9 @@ describe Gitlab::GitAccess do it_behaves_like 'access after accepting terms' end - describe 'as a master of the project' do + describe 'as a maintainer of the project' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'access after accepting terms' @@ -1152,6 +1137,17 @@ describe Gitlab::GitAccess do private + def access + described_class.new(actor, project, protocol, + authentication_abilities: authentication_abilities, + namespace_path: namespace_path, project_path: project_path, + redirected_path: redirected_path, auth_result_type: auth_result_type) + end + + def push_changes(changes) + access.check('git-receive-pack', changes) + end + def raise_unauthorized(message) raise_error(Gitlab::GitAccess::UnauthorizedError, message) end diff --git a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb index 7951cbe7b1d..54f2ea33f90 100644 --- a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb @@ -17,7 +17,7 @@ describe Gitlab::GitalyClient::CommitService do repository: repository_message, left_commit_id: 'cfe32cf61b73a0d5e9f13e774abde7ff789b1660', right_commit_id: commit.id, - collapse_diffs: true, + collapse_diffs: false, enforce_limits: true, **Gitlab::Git::DiffCollection.collection_limits.to_h ) @@ -35,7 +35,7 @@ describe Gitlab::GitalyClient::CommitService do repository: repository_message, left_commit_id: Gitlab::Git::EMPTY_TREE_ID, right_commit_id: initial_commit.id, - collapse_diffs: true, + collapse_diffs: false, enforce_limits: true, **Gitlab::Git::DiffCollection.collection_limits.to_h ) diff --git a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb index 9709f1f5646..031d1e87dc1 100644 --- a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb @@ -53,6 +53,47 @@ describe Gitlab::GitalyClient::OperationService do end end + describe '#user_update_branch' do + let(:branch_name) { 'my-branch' } + let(:newrev) { '01e' } + let(:oldrev) { '01d' } + let(:request) do + Gitaly::UserUpdateBranchRequest.new( + repository: repository.gitaly_repository, + branch_name: branch_name, + newrev: newrev, + oldrev: oldrev, + user: gitaly_user + ) + end + let(:response) { Gitaly::UserUpdateBranchResponse.new } + + subject { client.user_update_branch(branch_name, user, newrev, oldrev) } + + it 'sends a user_update_branch message' do + expect_any_instance_of(Gitaly::OperationService::Stub) + .to receive(:user_update_branch).with(request, kind_of(Hash)) + .and_return(response) + + subject + end + + context "when pre_receive_error is present" do + let(:response) do + Gitaly::UserUpdateBranchResponse.new(pre_receive_error: "something failed") + end + + it "throws a PreReceive exception" do + expect_any_instance_of(Gitaly::OperationService::Stub) + .to receive(:user_update_branch).with(request, kind_of(Hash)) + .and_return(response) + + expect { subject }.to raise_error( + Gitlab::Git::PreReceiveError, "something failed") + end + end + end + describe '#user_delete_branch' do let(:branch_name) { 'my-branch' } let(:request) do diff --git a/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb index 51fad6c6838..b2e544e6fed 100644 --- a/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb @@ -27,9 +27,9 @@ describe Gitlab::GithubImport::Importer::PullRequestsImporter do milestone: double(:milestone, number: 4), user: double(:user, id: 4, login: 'alice'), assignee: double(:user, id: 4, login: 'alice'), - created_at: Time.zone.now, - updated_at: Time.zone.now, - merged_at: Time.zone.now + created_at: 1.second.ago, + updated_at: 1.second.ago, + merged_at: 1.second.ago ) end diff --git a/spec/lib/gitlab/google_code_import/importer_spec.rb b/spec/lib/gitlab/google_code_import/importer_spec.rb index 017facd0f5e..031f57dbc65 100644 --- a/spec/lib/gitlab/google_code_import/importer_spec.rb +++ b/spec/lib/gitlab/google_code_import/importer_spec.rb @@ -15,7 +15,7 @@ describe Gitlab::GoogleCodeImport::Importer do subject { described_class.new(project) } before do - project.add_master(project.creator) + project.add_maintainer(project.creator) project.create_import_data(data: import_data) end diff --git a/spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb b/spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb index 6fbffc38444..1a2c6ef25c4 100644 --- a/spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb +++ b/spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb @@ -141,7 +141,7 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do expect(invalid_gpg_signature.reload.verification_status).to eq 'unverified_key' # InvalidGpgSignatureUpdater is called by the after_update hook - user.update_attributes!(email: GpgHelpers::User1.emails.first) + user.update!(email: GpgHelpers::User1.emails.first) expect(invalid_gpg_signature.reload).to have_attributes( project: project, @@ -166,7 +166,7 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do ) # InvalidGpgSignatureUpdater is called by the after_update hook - user.update_attributes!(email: 'still.unrelated@example.com') + user.update!(email: 'still.unrelated@example.com') expect(invalid_gpg_signature.reload).to have_attributes( project: project, diff --git a/spec/lib/gitlab/graphql/connections/keyset_connection_spec.rb b/spec/lib/gitlab/graphql/connections/keyset_connection_spec.rb new file mode 100644 index 00000000000..96615ae80de --- /dev/null +++ b/spec/lib/gitlab/graphql/connections/keyset_connection_spec.rb @@ -0,0 +1,112 @@ +require 'spec_helper' + +describe Gitlab::Graphql::Connections::KeysetConnection do + let(:nodes) { Project.all.order(id: :asc) } + let(:arguments) { {} } + subject(:connection) do + described_class.new(nodes, arguments, max_page_size: 3) + end + + def encoded_property(value) + Base64.strict_encode64(value.to_s) + end + + describe '#cursor_from_nodes' do + let(:project) { create(:project) } + + it 'returns an encoded ID' do + expect(connection.cursor_from_node(project)) + .to eq(encoded_property(project.id)) + end + + context 'when an order was specified' do + let(:nodes) { Project.order(:updated_at) } + + it 'returns the encoded value of the order' do + expect(connection.cursor_from_node(project)) + .to eq(encoded_property(project.updated_at)) + end + end + end + + describe '#sliced_nodes' do + let(:projects) { create_list(:project, 4) } + + context 'when before is passed' do + let(:arguments) { { before: encoded_property(projects[1].id) } } + + it 'only returns the project before the selected one' do + expect(subject.sliced_nodes).to contain_exactly(projects.first) + end + + context 'when the sort order is descending' do + let(:nodes) { Project.all.order(id: :desc) } + + it 'returns the correct nodes' do + expect(subject.sliced_nodes).to contain_exactly(*projects[2..-1]) + end + end + end + + context 'when after is passed' do + let(:arguments) { { after: encoded_property(projects[1].id) } } + + it 'only returns the project before the selected one' do + expect(subject.sliced_nodes).to contain_exactly(*projects[2..-1]) + end + + context 'when the sort order is descending' do + let(:nodes) { Project.all.order(id: :desc) } + + it 'returns the correct nodes' do + expect(subject.sliced_nodes).to contain_exactly(projects.first) + end + end + end + + context 'when both before and after are passed' do + let(:arguments) do + { + after: encoded_property(projects[1].id), + before: encoded_property(projects[3].id) + } + end + + it 'returns the expected set' do + expect(subject.sliced_nodes).to contain_exactly(projects[2]) + end + end + end + + describe '#paged_nodes' do + let!(:projects) { create_list(:project, 5) } + + it 'returns the collection limited to max page size' do + expect(subject.paged_nodes.size).to eq(3) + end + + context 'when `first` is passed' do + let(:arguments) { { first: 2 } } + + it 'returns only the first elements' do + expect(subject.paged_nodes).to contain_exactly(projects.first, projects.second) + end + end + + context 'when `last` is passed' do + let(:arguments) { { last: 2 } } + + it 'returns only the last elements' do + expect(subject.paged_nodes).to contain_exactly(projects[3], projects[4]) + end + end + + context 'when both are passed' do + let(:arguments) { { first: 2, last: 2 } } + + it 'raises an error' do + expect { subject.paged_nodes }.to raise_error(Gitlab::Graphql::Errors::ArgumentError) + end + end + end +end diff --git a/spec/lib/gitlab/ci/trace/http_io_spec.rb b/spec/lib/gitlab/http_io_spec.rb index 5474e2f518c..788bddb8f59 100644 --- a/spec/lib/gitlab/ci/trace/http_io_spec.rb +++ b/spec/lib/gitlab/http_io_spec.rb @@ -1,11 +1,14 @@ require 'spec_helper' -describe Gitlab::Ci::Trace::HttpIO do +describe Gitlab::HttpIO do include HttpIOHelpers let(:http_io) { described_class.new(url, size) } - let(:url) { remote_trace_url } - let(:size) { remote_trace_size } + + let(:url) { 'http://object-storage/trace' } + let(:file_path) { expand_fixture_path('trace/sample_trace') } + let(:file_body) { File.read(file_path).force_encoding(Encoding::BINARY) } + let(:size) { File.size(file_path) } describe '#close' do subject { http_io.close } @@ -86,10 +89,10 @@ describe Gitlab::Ci::Trace::HttpIO do describe '#each_line' do subject { http_io.each_line } - let(:string_io) { StringIO.new(remote_trace_body) } + let(:string_io) { StringIO.new(file_body) } before do - stub_remote_trace_206 + stub_remote_url_206(url, file_path) end it 'yields lines' do @@ -99,7 +102,7 @@ describe Gitlab::Ci::Trace::HttpIO do context 'when buckets on GCS' do context 'when BUFFER_SIZE is larger than file size' do before do - stub_remote_trace_200 + stub_remote_url_200(url, file_path) set_larger_buffer_size_than(size) end @@ -117,7 +120,7 @@ describe Gitlab::Ci::Trace::HttpIO do context 'when there are no network issue' do before do - stub_remote_trace_206 + stub_remote_url_206(url, file_path) end context 'when read whole size' do @@ -129,7 +132,7 @@ describe Gitlab::Ci::Trace::HttpIO do end it 'reads a trace' do - is_expected.to eq(remote_trace_body) + is_expected.to eq(file_body) end end @@ -139,7 +142,7 @@ describe Gitlab::Ci::Trace::HttpIO do end it 'reads a trace' do - is_expected.to eq(remote_trace_body) + is_expected.to eq(file_body) end end end @@ -153,7 +156,7 @@ describe Gitlab::Ci::Trace::HttpIO do end it 'reads a trace' do - is_expected.to eq(remote_trace_body[0, length]) + is_expected.to eq(file_body[0, length]) end end @@ -163,7 +166,7 @@ describe Gitlab::Ci::Trace::HttpIO do end it 'reads a trace' do - is_expected.to eq(remote_trace_body[0, length]) + is_expected.to eq(file_body[0, length]) end end end @@ -177,7 +180,7 @@ describe Gitlab::Ci::Trace::HttpIO do end it 'reads a trace' do - is_expected.to eq(remote_trace_body) + is_expected.to eq(file_body) end end @@ -187,7 +190,7 @@ describe Gitlab::Ci::Trace::HttpIO do end it 'reads a trace' do - is_expected.to eq(remote_trace_body) + is_expected.to eq(file_body) end end end @@ -221,11 +224,11 @@ describe Gitlab::Ci::Trace::HttpIO do let(:length) { nil } before do - stub_remote_trace_500 + stub_remote_url_500(url) end it 'reads a trace' do - expect { subject }.to raise_error(Gitlab::Ci::Trace::HttpIO::FailedToGetChunkError) + expect { subject }.to raise_error(Gitlab::HttpIO::FailedToGetChunkError) end end end @@ -233,15 +236,15 @@ describe Gitlab::Ci::Trace::HttpIO do describe '#readline' do subject { http_io.readline } - let(:string_io) { StringIO.new(remote_trace_body) } + let(:string_io) { StringIO.new(file_body) } before do - stub_remote_trace_206 + stub_remote_url_206(url, file_path) end shared_examples 'all line matching' do it 'reads a line' do - (0...remote_trace_body.lines.count).each do + (0...file_body.lines.count).each do expect(http_io.readline).to eq(string_io.readline) end end @@ -251,11 +254,11 @@ describe Gitlab::Ci::Trace::HttpIO do let(:length) { nil } before do - stub_remote_trace_500 + stub_remote_url_500(url) end it 'reads a trace' do - expect { subject }.to raise_error(Gitlab::Ci::Trace::HttpIO::FailedToGetChunkError) + expect { subject }.to raise_error(Gitlab::HttpIO::FailedToGetChunkError) end end diff --git a/spec/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy_object_storage_spec.rb b/spec/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy_object_storage_spec.rb new file mode 100644 index 00000000000..5059d68e54b --- /dev/null +++ b/spec/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy_object_storage_spec.rb @@ -0,0 +1,105 @@ +require 'spec_helper' + +describe Gitlab::ImportExport::AfterExportStrategies::BaseAfterExportStrategy do + let!(:service) { described_class.new } + let!(:project) { create(:project, :with_object_export) } + let(:shared) { project.import_export_shared } + let!(:user) { create(:user) } + + describe '#execute' do + before do + allow(service).to receive(:strategy_execute) + stub_feature_flags(import_export_object_storage: true) + end + + it 'returns if project exported file is not found' do + allow(project).to receive(:export_project_object_exists?).and_return(false) + + expect(service).not_to receive(:strategy_execute) + + service.execute(user, project) + end + + it 'creates a lock file in the export dir' do + allow(service).to receive(:delete_after_export_lock) + + service.execute(user, project) + + expect(lock_path_exist?).to be_truthy + end + + context 'when the method succeeds' do + it 'removes the lock file' do + service.execute(user, project) + + expect(lock_path_exist?).to be_falsey + end + end + + context 'when the method fails' do + before do + allow(service).to receive(:strategy_execute).and_call_original + end + + context 'when validation fails' do + before do + allow(service).to receive(:invalid?).and_return(true) + end + + it 'does not create the lock file' do + expect(service).not_to receive(:create_or_update_after_export_lock) + + service.execute(user, project) + end + + it 'does not execute main logic' do + expect(service).not_to receive(:strategy_execute) + + service.execute(user, project) + end + + it 'logs validation errors in shared context' do + expect(service).to receive(:log_validation_errors) + + service.execute(user, project) + end + end + + context 'when an exception is raised' do + it 'removes the lock' do + expect { service.execute(user, project) }.to raise_error(NotImplementedError) + + expect(lock_path_exist?).to be_falsey + end + end + end + end + + describe '#log_validation_errors' do + it 'add the message to the shared context' do + errors = %w(test_message test_message2) + + allow(service).to receive(:invalid?).and_return(true) + allow(service.errors).to receive(:full_messages).and_return(errors) + + expect(shared).to receive(:add_error_message).twice.and_call_original + + service.execute(user, project) + + expect(shared.errors).to eq errors + end + end + + describe '#to_json' do + it 'adds the current strategy class to the serialized attributes' do + params = { param1: 1 } + result = params.merge(klass: described_class.to_s).to_json + + expect(described_class.new(params).to_json).to eq result + end + end + + def lock_path_exist? + File.exist?(described_class.lock_file_path(project)) + end +end diff --git a/spec/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy_spec.rb b/spec/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy_spec.rb index ed54d87de4a..566b7f46c87 100644 --- a/spec/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy_spec.rb +++ b/spec/lib/gitlab/import_export/after_export_strategies/base_after_export_strategy_spec.rb @@ -9,6 +9,7 @@ describe Gitlab::ImportExport::AfterExportStrategies::BaseAfterExportStrategy do describe '#execute' do before do allow(service).to receive(:strategy_execute) + stub_feature_flags(import_export_object_storage: false) end it 'returns if project exported file is not found' do diff --git a/spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb b/spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb index 5fe57d9987b..7f2e0a4ee2c 100644 --- a/spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb +++ b/spec/lib/gitlab/import_export/after_export_strategies/web_upload_strategy_spec.rb @@ -24,13 +24,34 @@ describe Gitlab::ImportExport::AfterExportStrategies::WebUploadStrategy do end describe '#execute' do - it 'removes the exported project file after the upload' do - allow(strategy).to receive(:send_file) - allow(strategy).to receive(:handle_response_error) + context 'without object storage' do + before do + stub_feature_flags(import_export_object_storage: false) + end + + it 'removes the exported project file after the upload' do + allow(strategy).to receive(:send_file) + allow(strategy).to receive(:handle_response_error) + + expect(project).to receive(:remove_exported_project_file) + + strategy.execute(user, project) + end + end + + context 'with object storage' do + before do + stub_feature_flags(import_export_object_storage: true) + end - expect(project).to receive(:remove_exported_project_file) + it 'removes the exported project file after the upload' do + allow(strategy).to receive(:send_file) + allow(strategy).to receive(:handle_response_error) - strategy.execute(user, project) + expect(project).to receive(:remove_exported_project_file) + + strategy.execute(user, project) + end end end end diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 2ea66479c1b..084ce3066d6 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -293,6 +293,7 @@ project: - deploy_tokens - settings - ci_cd_settings +- import_export_upload award_emoji: - awardable - user diff --git a/spec/lib/gitlab/import_export/members_mapper_spec.rb b/spec/lib/gitlab/import_export/members_mapper_spec.rb index 246f009ad27..67e4c289906 100644 --- a/spec/lib/gitlab/import_export/members_mapper_spec.rb +++ b/spec/lib/gitlab/import_export/members_mapper_spec.rb @@ -111,7 +111,7 @@ describe Gitlab::ImportExport::MembersMapper do end it 'maps the project member if it already exists' do - project.add_master(user2) + project.add_maintainer(user2) expect(members_mapper.map[exported_user_id]).to eq(user2.id) end diff --git a/spec/lib/gitlab/import_export/project_tree_saver_spec.rb b/spec/lib/gitlab/import_export/project_tree_saver_spec.rb index 2b8a11ce8f9..fec8a2af9ab 100644 --- a/spec/lib/gitlab/import_export/project_tree_saver_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_saver_spec.rb @@ -9,7 +9,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver do let!(:project) { setup_project } before do - project.add_master(user) + project.add_maintainer(user) allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) allow_any_instance_of(MergeRequest).to receive(:source_branch_sha).and_return('ABCD') allow_any_instance_of(MergeRequest).to receive(:target_branch_sha).and_return('DCBA') @@ -217,8 +217,8 @@ describe Gitlab::ImportExport::ProjectTreeSaver do expect(member_emails).not_to include('group@member.com') end - it 'does not export group members as master' do - Group.first.add_master(user) + it 'does not export group members as maintainer' do + Group.first.add_maintainer(user) expect(member_emails).not_to include('group@member.com') end diff --git a/spec/lib/gitlab/import_export/repo_saver_spec.rb b/spec/lib/gitlab/import_export/repo_saver_spec.rb index 187ec8fcfa2..5a646b4aac8 100644 --- a/spec/lib/gitlab/import_export/repo_saver_spec.rb +++ b/spec/lib/gitlab/import_export/repo_saver_spec.rb @@ -9,7 +9,7 @@ describe Gitlab::ImportExport::RepoSaver do let(:bundler) { described_class.new(project: project, shared: shared) } before do - project.add_master(user) + project.add_maintainer(user) allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) end diff --git a/spec/lib/gitlab/import_export/saver_spec.rb b/spec/lib/gitlab/import_export/saver_spec.rb new file mode 100644 index 00000000000..02f1a4b81aa --- /dev/null +++ b/spec/lib/gitlab/import_export/saver_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' +require 'fileutils' + +describe Gitlab::ImportExport::Saver do + let!(:project) { create(:project, :public, name: 'project') } + let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" } + let(:shared) { project.import_export_shared } + subject { described_class.new(project: project, shared: shared) } + + before do + allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) + + FileUtils.mkdir_p(shared.export_path) + FileUtils.touch("#{shared.export_path}/tmp.bundle") + end + + after do + FileUtils.rm_rf(export_path) + end + + context 'local archive' do + it 'saves the repo to disk' do + stub_feature_flags(import_export_object_storage: false) + + subject.save + + expect(shared.errors).to be_empty + expect(Dir.empty?(shared.archive_path)).to be false + end + end + + context 'object storage' do + it 'saves the repo using object storage' do + stub_feature_flags(import_export_object_storage: true) + stub_uploads_object_storage(ImportExportUploader) + + subject.save + + expect(ImportExportUpload.find_by(project: project).export_file.url) + .to match(%r[\/uploads\/-\/system\/import_export_upload\/export_file.*]) + end + end +end diff --git a/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb b/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb index 24bc231d5a0..441aa1defe6 100644 --- a/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb +++ b/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb @@ -10,7 +10,7 @@ describe Gitlab::ImportExport::WikiRepoSaver do let!(:project_wiki) { ProjectWiki.new(project, user) } before do - project.add_master(user) + project.add_maintainer(user) allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) project_wiki.wiki project_wiki.create_page("index", "test content") diff --git a/spec/lib/gitlab/import_sources_spec.rb b/spec/lib/gitlab/import_sources_spec.rb index 10341486512..25827423914 100644 --- a/spec/lib/gitlab/import_sources_spec.rb +++ b/spec/lib/gitlab/import_sources_spec.rb @@ -12,7 +12,8 @@ describe Gitlab::ImportSources do 'FogBugz' => 'fogbugz', 'Repo by URL' => 'git', 'GitLab export' => 'gitlab_project', - 'Gitea' => 'gitea' + 'Gitea' => 'gitea', + 'Manifest file' => 'manifest' } expect(described_class.options).to eq(expected) @@ -31,6 +32,7 @@ describe Gitlab::ImportSources do git gitlab_project gitea + manifest ) expect(described_class.values).to eq(expected) @@ -63,7 +65,8 @@ describe Gitlab::ImportSources do 'fogbugz' => Gitlab::FogbugzImport::Importer, 'git' => nil, 'gitlab_project' => Gitlab::ImportExport::Importer, - 'gitea' => Gitlab::LegacyGithubImport::Importer + 'gitea' => Gitlab::LegacyGithubImport::Importer, + 'manifest' => nil } import_sources.each do |name, klass| @@ -82,7 +85,8 @@ describe Gitlab::ImportSources do 'fogbugz' => 'FogBugz', 'git' => 'Repo by URL', 'gitlab_project' => 'GitLab export', - 'gitea' => 'Gitea' + 'gitea' => 'Gitea', + 'manifest' => 'Manifest file' } import_sources.each do |name, title| diff --git a/spec/lib/gitlab/kubernetes_spec.rb b/spec/lib/gitlab/kubernetes_spec.rb index 34b33772578..5c03a2ce7d3 100644 --- a/spec/lib/gitlab/kubernetes_spec.rb +++ b/spec/lib/gitlab/kubernetes_spec.rb @@ -70,4 +70,19 @@ describe Gitlab::Kubernetes do it { is_expected.to eq(YAML.load_file(path)) } end end + + describe '#add_terminal_auth' do + it 'adds authentication parameters to a hash' do + terminal = { original: 'value' } + + add_terminal_auth(terminal, token: 'foo', max_session_time: 0, ca_pem: 'bar') + + expect(terminal).to eq( + original: 'value', + headers: { 'Authorization' => ['Bearer foo'] }, + max_session_time: 0, + ca_pem: 'bar' + ) + end + end end diff --git a/spec/lib/gitlab/manifest_import/manifest_spec.rb b/spec/lib/gitlab/manifest_import/manifest_spec.rb new file mode 100644 index 00000000000..ab305fb2316 --- /dev/null +++ b/spec/lib/gitlab/manifest_import/manifest_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe Gitlab::ManifestImport::Manifest, :postgresql do + let(:file) { File.open(Rails.root.join('spec/fixtures/aosp_manifest.xml')) } + let(:manifest) { described_class.new(file) } + + describe '#valid?' do + context 'valid file' do + it { expect(manifest.valid?).to be true } + end + + context 'missing or invalid attributes' do + let(:file) { Tempfile.new('foo') } + + before do + content = <<~EOS + <manifest> + <remote review="invalid-url" /> + <project name="platform/build"/> + </manifest> + EOS + + file.write(content) + file.rewind + end + + it { expect(manifest.valid?).to be false } + + describe 'errors' do + before do + manifest.valid? + end + + it { expect(manifest.errors).to include('Make sure a <remote> tag is present and is valid.') } + it { expect(manifest.errors).to include('Make sure every <project> tag has name and path attributes.') } + end + end + end + + describe '#projects' do + it { expect(manifest.projects.size).to eq(660) } + it { expect(manifest.projects[0][:name]).to eq('platform/build') } + it { expect(manifest.projects[0][:path]).to eq('build/make') } + it { expect(manifest.projects[0][:url]).to eq('https://android-review.googlesource.com/platform/build') } + end +end diff --git a/spec/lib/gitlab/manifest_import/project_creator_spec.rb b/spec/lib/gitlab/manifest_import/project_creator_spec.rb new file mode 100644 index 00000000000..1d01d437535 --- /dev/null +++ b/spec/lib/gitlab/manifest_import/project_creator_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +describe Gitlab::ManifestImport::ProjectCreator, :postgresql do + let(:group) { create(:group) } + let(:user) { create(:user) } + let(:repository) do + { + path: 'device/common', + url: 'https://android-review.googlesource.com/device/common' + } + end + + before do + group.add_owner(user) + end + + subject { described_class.new(repository, group, user) } + + describe '#execute' do + it { expect(subject.execute).to be_a(Project) } + it { expect { subject.execute }.to change { Project.count }.by(1) } + it { expect { subject.execute }.to change { Group.count }.by(1) } + + it 'creates project with valid full path and import url' do + subject.execute + + project = Project.last + + expect(project.full_path).to eq(File.join(group.path, 'device/common')) + expect(project.import_url).to eq('https://android-review.googlesource.com/device/common') + end + end +end diff --git a/spec/lib/gitlab/middleware/go_spec.rb b/spec/lib/gitlab/middleware/go_spec.rb index b24c9882c0c..7a3a9ab875b 100644 --- a/spec/lib/gitlab/middleware/go_spec.rb +++ b/spec/lib/gitlab/middleware/go_spec.rb @@ -79,7 +79,7 @@ describe Gitlab::Middleware::Go do let(:current_user) { project.creator } before do - project.team.add_master(current_user) + project.team.add_maintainer(current_user) end shared_examples 'authenticated' do diff --git a/spec/lib/gitlab/middleware/multipart_spec.rb b/spec/lib/gitlab/middleware/multipart_spec.rb index a2ba91dae80..f788f8ee276 100644 --- a/spec/lib/gitlab/middleware/multipart_spec.rb +++ b/spec/lib/gitlab/middleware/multipart_spec.rb @@ -7,18 +7,47 @@ describe Gitlab::Middleware::Multipart do let(:middleware) { described_class.new(app) } let(:original_filename) { 'filename' } - it 'opens top-level files' do - Tempfile.open('top-level') do |tempfile| - env = post_env({ 'file' => tempfile.path }, { 'file.name' => original_filename }, Gitlab::Workhorse.secret, 'gitlab-workhorse') + shared_examples_for 'multipart upload files' do + it 'opens top-level files' do + Tempfile.open('top-level') do |tempfile| + env = post_env({ 'file' => tempfile.path }, { 'file.name' => original_filename, 'file.path' => tempfile.path, 'file.remote_id' => remote_id }, Gitlab::Workhorse.secret, 'gitlab-workhorse') + expect_uploaded_file(tempfile, %w(file)) + + middleware.call(env) + end + end + + it 'opens files one level deep' do + Tempfile.open('one-level') do |tempfile| + in_params = { 'user' => { 'avatar' => { '.name' => original_filename, '.path' => tempfile.path, '.remote_id' => remote_id } } } + env = post_env({ 'user[avatar]' => tempfile.path }, in_params, Gitlab::Workhorse.secret, 'gitlab-workhorse') + + expect_uploaded_file(tempfile, %w(user avatar)) + + middleware.call(env) + end + end + + it 'opens files two levels deep' do + Tempfile.open('two-levels') do |tempfile| + in_params = { 'project' => { 'milestone' => { 'themesong' => { '.name' => original_filename, '.path' => tempfile.path, '.remote_id' => remote_id } } } } + env = post_env({ 'project[milestone][themesong]' => tempfile.path }, in_params, Gitlab::Workhorse.secret, 'gitlab-workhorse') + + expect_uploaded_file(tempfile, %w(project milestone themesong)) + + middleware.call(env) + end + end + + def expect_uploaded_file(tempfile, path, remote: false) expect(app).to receive(:call) do |env| - file = Rack::Request.new(env).params['file'] + file = Rack::Request.new(env).params.dig(*path) expect(file).to be_a(::UploadedFile) expect(file.path).to eq(tempfile.path) expect(file.original_filename).to eq(original_filename) + expect(file.remote_id).to eq(remote_id) end - - middleware.call(env) end end @@ -34,32 +63,39 @@ describe Gitlab::Middleware::Multipart do expect { middleware.call(env) }.to raise_error(JWT::InvalidIssuerError) end - it 'opens files one level deep' do - Tempfile.open('one-level') do |tempfile| - in_params = { 'user' => { 'avatar' => { '.name' => original_filename } } } - env = post_env({ 'user[avatar]' => tempfile.path }, in_params, Gitlab::Workhorse.secret, 'gitlab-workhorse') + context 'with remote file' do + let(:remote_id) { 'someid' } - expect(app).to receive(:call) do |env| - file = Rack::Request.new(env).params['user']['avatar'] - expect(file).to be_a(::UploadedFile) - expect(file.path).to eq(tempfile.path) - expect(file.original_filename).to eq(original_filename) - end + it_behaves_like 'multipart upload files' + end - middleware.call(env) - end + context 'with local file' do + let(:remote_id) { nil } + + it_behaves_like 'multipart upload files' end - it 'opens files two levels deep' do + it 'allows symlinks for uploads dir' do Tempfile.open('two-levels') do |tempfile| - in_params = { 'project' => { 'milestone' => { 'themesong' => { '.name' => original_filename } } } } - env = post_env({ 'project[milestone][themesong]' => tempfile.path }, in_params, Gitlab::Workhorse.secret, 'gitlab-workhorse') + symlinked_dir = '/some/dir/uploads' + symlinked_path = File.join(symlinked_dir, File.basename(tempfile.path)) + env = post_env({ 'file' => symlinked_path }, { 'file.name' => original_filename, 'file.path' => symlinked_path }, Gitlab::Workhorse.secret, 'gitlab-workhorse') + + allow(FileUploader).to receive(:root).and_return(symlinked_dir) + allow(UploadedFile).to receive(:allowed_paths).and_return([symlinked_dir, Gitlab.config.uploads.storage_path]) + allow(File).to receive(:realpath).and_call_original + allow(File).to receive(:realpath).with(symlinked_dir).and_return(Dir.tmpdir) + allow(File).to receive(:realpath).with(symlinked_path).and_return(tempfile.path) + allow(File).to receive(:exist?).and_call_original + allow(File).to receive(:exist?).with(symlinked_dir).and_return(true) + + # override Dir.tmpdir because this dir is in the list of allowed paths + # and it would match FileUploader.root path (which in this test is linked + # to /tmp too) + allow(Dir).to receive(:tmpdir).and_return(File.join(Dir.tmpdir, 'tmpsubdir')) expect(app).to receive(:call) do |env| - file = Rack::Request.new(env).params['project']['milestone']['themesong'] - expect(file).to be_a(::UploadedFile) - expect(file.path).to eq(tempfile.path) - expect(file.original_filename).to eq(original_filename) + expect(Rack::Request.new(env).params['file']).to be_a(::UploadedFile) end middleware.call(env) diff --git a/spec/lib/gitlab/middleware/read_only_spec.rb b/spec/lib/gitlab/middleware/read_only_spec.rb index 5c398bc2063..8fbeaa065fa 100644 --- a/spec/lib/gitlab/middleware/read_only_spec.rb +++ b/spec/lib/gitlab/middleware/read_only_spec.rb @@ -4,28 +4,6 @@ describe Gitlab::Middleware::ReadOnly do include Rack::Test::Methods using RSpec::Parameterized::TableSyntax - RSpec::Matchers.define :be_a_redirect do - match do |response| - response.status == 301 - end - end - - RSpec::Matchers.define :disallow_request do - match do |middleware| - alert = middleware.env['rack.session'].to_hash - .dig('flash', 'flashes', 'alert') - - alert&.include?('You cannot perform write operations') - end - end - - RSpec::Matchers.define :disallow_request_in_json do - match do |response| - json_response = JSON.parse(response.body) - response.body.include?('You cannot perform write operations') && json_response.key?('message') - end - end - let(:rack_stack) do rack = Rack::Builder.new do use ActionDispatch::Session::CacheStore @@ -66,38 +44,38 @@ describe Gitlab::Middleware::ReadOnly do it 'expects PATCH requests to be disallowed' do response = request.patch('/test_request') - expect(response).to be_a_redirect + expect(response).to be_redirect expect(subject).to disallow_request end it 'expects PUT requests to be disallowed' do response = request.put('/test_request') - expect(response).to be_a_redirect + expect(response).to be_redirect expect(subject).to disallow_request end it 'expects POST requests to be disallowed' do response = request.post('/test_request') - expect(response).to be_a_redirect + expect(response).to be_redirect expect(subject).to disallow_request end it 'expects a internal POST request to be allowed after a disallowed request' do response = request.post('/test_request') - expect(response).to be_a_redirect + expect(response).to be_redirect response = request.post("/api/#{API::API.version}/internal") - expect(response).not_to be_a_redirect + expect(response).not_to be_redirect end it 'expects DELETE requests to be disallowed' do response = request.delete('/test_request') - expect(response).to be_a_redirect + expect(response).to be_redirect expect(subject).to disallow_request end @@ -105,7 +83,7 @@ describe Gitlab::Middleware::ReadOnly do expect(Rails.application.routes).to receive(:recognize_path).and_call_original response = request.post('/root/gitlab-ce/new/master/app/info/lfs/objects/batch') - expect(response).to be_a_redirect + expect(response).to be_redirect expect(subject).to disallow_request end @@ -120,19 +98,19 @@ describe Gitlab::Middleware::ReadOnly do expect(Rails.application.routes).not_to receive(:recognize_path) response = request.post("/api/#{API::API.version}/internal") - expect(response).not_to be_a_redirect + expect(response).not_to be_redirect expect(subject).not_to disallow_request end it 'expects requests to sidekiq admin to be allowed' do response = request.post('/admin/sidekiq') - expect(response).not_to be_a_redirect + expect(response).not_to be_redirect expect(subject).not_to disallow_request response = request.get('/admin/sidekiq') - expect(response).not_to be_a_redirect + expect(response).not_to be_redirect expect(subject).not_to disallow_request end @@ -150,7 +128,7 @@ describe Gitlab::Middleware::ReadOnly do expect(Rails.application.routes).to receive(:recognize_path).and_call_original response = request.post(path) - expect(response).not_to be_a_redirect + expect(response).not_to be_redirect expect(subject).not_to disallow_request end end diff --git a/spec/lib/gitlab/project_authorizations_spec.rb b/spec/lib/gitlab/project_authorizations_spec.rb index f3cd6961e94..00c62c7bf96 100644 --- a/spec/lib/gitlab/project_authorizations_spec.rb +++ b/spec/lib/gitlab/project_authorizations_spec.rb @@ -41,7 +41,7 @@ describe Gitlab::ProjectAuthorizations do it 'includes the correct access levels' do mapping = map_access_levels(authorizations) - expect(mapping[owned_project.id]).to eq(Gitlab::Access::MASTER) + expect(mapping[owned_project.id]).to eq(Gitlab::Access::MAINTAINER) expect(mapping[other_project.id]).to eq(Gitlab::Access::REPORTER) expect(mapping[group_project.id]).to eq(Gitlab::Access::DEVELOPER) end @@ -62,11 +62,11 @@ describe Gitlab::ProjectAuthorizations do end it 'uses the greatest access level when a user is a member of a nested group' do - nested_group.add_master(user) + nested_group.add_maintainer(user) mapping = map_access_levels(authorizations) - expect(mapping[nested_project.id]).to eq(Gitlab::Access::MASTER) + expect(mapping[nested_project.id]).to eq(Gitlab::Access::MAINTAINER) end end end diff --git a/spec/lib/gitlab/project_search_results_spec.rb b/spec/lib/gitlab/project_search_results_spec.rb index 50224bde722..767a3092c73 100644 --- a/spec/lib/gitlab/project_search_results_spec.rb +++ b/spec/lib/gitlab/project_search_results_spec.rb @@ -385,7 +385,7 @@ describe Gitlab::ProjectSearchResults do let!(:private_project) { create(:project, :private, :repository, creator: creator, namespace: creator.namespace) } let(:team_master) do user = create(:user, username: 'private-project-master') - private_project.add_master(user) + private_project.add_maintainer(user) user end let(:team_reporter) do diff --git a/spec/lib/gitlab/sanitizers/svg_spec.rb b/spec/lib/gitlab/sanitizers/svg_spec.rb index 030c2063ab2..df46a874528 100644 --- a/spec/lib/gitlab/sanitizers/svg_spec.rb +++ b/spec/lib/gitlab/sanitizers/svg_spec.rb @@ -7,9 +7,9 @@ describe Gitlab::Sanitizers::SVG do describe '.clean' do let(:input_svg_path) { File.join(Rails.root, 'spec', 'fixtures', 'unsanitized.svg') } - let(:data) { open(input_svg_path).read } + let(:data) { File.read(input_svg_path) } let(:sanitized_svg_path) { File.join(Rails.root, 'spec', 'fixtures', 'sanitized.svg') } - let(:sanitized) { open(sanitized_svg_path).read } + let(:sanitized) { File.read(sanitized_svg_path) } it 'delegates sanitization to scrubber' do expect_any_instance_of(Gitlab::Sanitizers::SVG::Scrubber).to receive(:scrub).at_least(:once) diff --git a/spec/lib/gitlab/shell_spec.rb b/spec/lib/gitlab/shell_spec.rb index c435f988cdd..f8bf896950e 100644 --- a/spec/lib/gitlab/shell_spec.rb +++ b/spec/lib/gitlab/shell_spec.rb @@ -403,46 +403,36 @@ describe Gitlab::Shell do end describe '#create_repository' do - shared_examples '#create_repository' do - let(:repository_storage) { 'default' } - let(:repository_storage_path) do - Gitlab::GitalyClient::StorageSettings.allow_disk_access do - Gitlab.config.repositories.storages[repository_storage].legacy_disk_path - end - end - let(:repo_name) { 'project/path' } - let(:created_path) { File.join(repository_storage_path, repo_name + '.git') } - - after do - FileUtils.rm_rf(created_path) + let(:repository_storage) { 'default' } + let(:repository_storage_path) do + Gitlab::GitalyClient::StorageSettings.allow_disk_access do + Gitlab.config.repositories.storages[repository_storage].legacy_disk_path end + end + let(:repo_name) { 'project/path' } + let(:created_path) { File.join(repository_storage_path, repo_name + '.git') } - it 'creates a repository' do - expect(gitlab_shell.create_repository(repository_storage, repo_name)).to be_truthy - - expect(File.stat(created_path).mode & 0o777).to eq(0o770) + after do + FileUtils.rm_rf(created_path) + end - hooks_path = File.join(created_path, 'hooks') - expect(File.lstat(hooks_path)).to be_symlink - expect(File.realpath(hooks_path)).to eq(gitlab_shell_hooks_path) - end + it 'creates a repository' do + expect(gitlab_shell.create_repository(repository_storage, repo_name)).to be_truthy - it 'returns false when the command fails' do - FileUtils.mkdir_p(File.dirname(created_path)) - # This file will block the creation of the repo's .git directory. That - # should cause #create_repository to fail. - FileUtils.touch(created_path) + expect(File.stat(created_path).mode & 0o777).to eq(0o770) - expect(gitlab_shell.create_repository(repository_storage, repo_name)).to be_falsy - end + hooks_path = File.join(created_path, 'hooks') + expect(File.lstat(hooks_path)).to be_symlink + expect(File.realpath(hooks_path)).to eq(gitlab_shell_hooks_path) end - context 'with gitaly' do - it_behaves_like '#create_repository' - end + it 'returns false when the command fails' do + FileUtils.mkdir_p(File.dirname(created_path)) + # This file will block the creation of the repo's .git directory. That + # should cause #create_repository to fail. + FileUtils.touch(created_path) - context 'without gitaly', :skip_gitaly_mock do - it_behaves_like '#create_repository' + expect(gitlab_shell.create_repository(repository_storage, repo_name)).to be_falsy end end @@ -513,22 +503,12 @@ describe Gitlab::Shell do end end - shared_examples 'fetch_remote' do |gitaly_on| + describe '#fetch_remote' do def fetch_remote(ssh_auth = nil, prune = true) gitlab_shell.fetch_remote(repository.raw_repository, 'remote-name', ssh_auth: ssh_auth, prune: prune) end - def expect_gitlab_projects(fail = false, options = {}) - expect(gitlab_projects).to receive(:fetch_remote).with( - 'remote-name', - timeout, - options - ).and_return(!fail) - - allow(gitlab_projects).to receive(:output).and_return('error') if fail - end - - def expect_gitaly_call(fail, options = {}) + def expect_call(fail, options = {}) receive_fetch_remote = if fail receive(:fetch_remote).and_raise(GRPC::NotFound) @@ -539,16 +519,6 @@ describe Gitlab::Shell do expect_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive_fetch_remote end - if gitaly_on - def expect_call(fail, options = {}) - expect_gitaly_call(fail, options) - end - else - def expect_call(fail, options = {}) - expect_gitlab_projects(fail, options) - end - end - def build_ssh_auth(opts = {}) defaults = { ssh_import?: true, @@ -634,14 +604,6 @@ describe Gitlab::Shell do expect(fetch_remote(ssh_auth)).to be_truthy end end - end - - describe '#fetch_remote local', :skip_gitaly_mock do - it_should_behave_like 'fetch_remote', false - end - - describe '#fetch_remote gitaly' do - it_should_behave_like 'fetch_remote', true context 'gitaly call' do let(:remote_name) { 'remote-name' } @@ -683,25 +645,6 @@ describe Gitlab::Shell do end.to raise_error(Gitlab::Shell::Error, "error") end end - - context 'without gitaly', :disable_gitaly do - it 'returns true when the command succeeds' do - expect(gitlab_projects).to receive(:import_project).with(import_url, timeout) { true } - - result = gitlab_shell.import_repository(project.repository_storage, project.disk_path, import_url) - - expect(result).to be_truthy - end - - it 'raises an exception when the command fails' do - allow(gitlab_projects).to receive(:output) { 'error' } - expect(gitlab_projects).to receive(:import_project) { false } - - expect do - gitlab_shell.import_repository(project.repository_storage, project.disk_path, import_url) - end.to raise_error(Gitlab::Shell::Error, "error") - end - end end end diff --git a/spec/lib/gitlab/slash_commands/issue_move_spec.rb b/spec/lib/gitlab/slash_commands/issue_move_spec.rb index d41441c9472..9a990e1fad7 100644 --- a/spec/lib/gitlab/slash_commands/issue_move_spec.rb +++ b/spec/lib/gitlab/slash_commands/issue_move_spec.rb @@ -27,7 +27,7 @@ describe Gitlab::SlashCommands::IssueMove, service: true do set(:other_project) { create(:project, namespace: project.namespace) } before do - [project, other_project].each { |prj| prj.add_master(user) } + [project, other_project].each { |prj| prj.add_maintainer(user) } end subject { described_class.new(project, chat_name) } diff --git a/spec/lib/gitlab/slash_commands/issue_new_spec.rb b/spec/lib/gitlab/slash_commands/issue_new_spec.rb index 8e7df946529..724c76ade6e 100644 --- a/spec/lib/gitlab/slash_commands/issue_new_spec.rb +++ b/spec/lib/gitlab/slash_commands/issue_new_spec.rb @@ -8,7 +8,7 @@ describe Gitlab::SlashCommands::IssueNew do let(:regex_match) { described_class.match("issue create bird is the word") } before do - project.add_master(user) + project.add_maintainer(user) end subject do diff --git a/spec/lib/gitlab/slash_commands/issue_search_spec.rb b/spec/lib/gitlab/slash_commands/issue_search_spec.rb index 189e9592f1b..47787307990 100644 --- a/spec/lib/gitlab/slash_commands/issue_search_spec.rb +++ b/spec/lib/gitlab/slash_commands/issue_search_spec.rb @@ -22,7 +22,7 @@ describe Gitlab::SlashCommands::IssueSearch do context 'the user has access' do before do - project.add_master(user) + project.add_maintainer(user) end it 'returns all results' do diff --git a/spec/lib/gitlab/slash_commands/issue_show_spec.rb b/spec/lib/gitlab/slash_commands/issue_show_spec.rb index b1db1638237..5c4ba2736ba 100644 --- a/spec/lib/gitlab/slash_commands/issue_show_spec.rb +++ b/spec/lib/gitlab/slash_commands/issue_show_spec.rb @@ -9,7 +9,7 @@ describe Gitlab::SlashCommands::IssueShow do let(:regex_match) { described_class.match("issue show #{issue.iid}") } before do - project.add_master(user) + project.add_maintainer(user) end subject do diff --git a/spec/lib/gitlab/url_sanitizer_spec.rb b/spec/lib/gitlab/url_sanitizer_spec.rb index fc8991fd31f..758a9bc5a2b 100644 --- a/spec/lib/gitlab/url_sanitizer_spec.rb +++ b/spec/lib/gitlab/url_sanitizer_spec.rb @@ -92,6 +92,7 @@ describe Gitlab::UrlSanitizer do context 'credentials in URL' do where(:url, :credentials) do 'http://foo:bar@example.com' | { user: 'foo', password: 'bar' } + 'http://foo:bar:baz@example.com' | { user: 'foo', password: 'bar:baz' } 'http://:bar@example.com' | { user: nil, password: 'bar' } 'http://foo:@example.com' | { user: 'foo', password: nil } 'http://foo@example.com' | { user: 'foo', password: nil } diff --git a/spec/lib/gitlab/user_access_spec.rb b/spec/lib/gitlab/user_access_spec.rb index 0469d984a40..9da06bb40f4 100644 --- a/spec/lib/gitlab/user_access_spec.rb +++ b/spec/lib/gitlab/user_access_spec.rb @@ -9,8 +9,8 @@ describe Gitlab::UserAccess do describe '#can_push_to_branch?' do describe 'push to none protected branch' do - it 'returns true if user is a master' do - project.add_master(user) + it 'returns true if user is a maintainer' do + project.add_maintainer(user) expect(access.can_push_to_branch?('random_branch')).to be_truthy end @@ -38,8 +38,8 @@ describe Gitlab::UserAccess do expect(access.can_push_to_branch?('master')).to be_truthy end - it 'returns true if user is master' do - empty_project.add_master(user) + it 'returns true if user is maintainer' do + empty_project.add_maintainer(user) expect(project_access.can_push_to_branch?('master')).to be_truthy end @@ -83,8 +83,8 @@ describe Gitlab::UserAccess do expect(access.can_push_to_branch?(branch.name)).to be_truthy end - it 'returns true if user is a master' do - project.add_master(user) + it 'returns true if user is a maintainer' do + project.add_maintainer(user) expect(access.can_push_to_branch?(branch.name)).to be_truthy end @@ -113,8 +113,8 @@ describe Gitlab::UserAccess do @branch = create :protected_branch, :developers_can_push, project: project end - it 'returns true if user is a master' do - project.add_master(user) + it 'returns true if user is a maintainer' do + project.add_maintainer(user) expect(access.can_push_to_branch?(@branch.name)).to be_truthy end @@ -170,8 +170,8 @@ describe Gitlab::UserAccess do @branch = create :protected_branch, :developers_can_merge, project: project end - it 'returns true if user is a master' do - project.add_master(user) + it 'returns true if user is a maintainer' do + project.add_maintainer(user) expect(access.can_merge_to_branch?(@branch.name)).to be_truthy end @@ -192,8 +192,8 @@ describe Gitlab::UserAccess do describe '#can_create_tag?' do describe 'push to none protected tag' do - it 'returns true if user is a master' do - project.add_user(user, :master) + it 'returns true if user is a maintainer' do + project.add_user(user, :maintainer) expect(access.can_create_tag?('random_tag')).to be_truthy end @@ -215,8 +215,8 @@ describe Gitlab::UserAccess do let(:tag) { create(:protected_tag, project: project, name: "test") } let(:not_existing_tag) { create :protected_tag, project: project } - it 'returns true if user is a master' do - project.add_user(user, :master) + it 'returns true if user is a maintainer' do + project.add_user(user, :maintainer) expect(access.can_create_tag?(tag.name)).to be_truthy end @@ -239,8 +239,8 @@ describe Gitlab::UserAccess do @tag = create(:protected_tag, :developers_can_create, project: project) end - it 'returns true if user is a master' do - project.add_user(user, :master) + it 'returns true if user is a maintainer' do + project.add_user(user, :maintainer) expect(access.can_create_tag?(@tag.name)).to be_truthy end @@ -261,8 +261,8 @@ describe Gitlab::UserAccess do describe '#can_delete_branch?' do describe 'delete unprotected branch' do - it 'returns true if user is a master' do - project.add_user(user, :master) + it 'returns true if user is a maintainer' do + project.add_user(user, :maintainer) expect(access.can_delete_branch?('random_branch')).to be_truthy end @@ -283,8 +283,8 @@ describe Gitlab::UserAccess do describe 'delete protected branch' do let(:branch) { create(:protected_branch, project: project, name: "test") } - it 'returns true if user is a master' do - project.add_user(user, :master) + it 'returns true if user is a maintainer' do + project.add_user(user, :maintainer) expect(access.can_delete_branch?(branch.name)).to be_truthy end diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb index 660671cefaf..23869f3d2da 100644 --- a/spec/lib/gitlab/workhorse_spec.rb +++ b/spec/lib/gitlab/workhorse_spec.rb @@ -36,22 +36,20 @@ describe Gitlab::Workhorse do allow(described_class).to receive(:git_archive_cache_disabled?).and_return(cache_disabled) end - context 'when Gitaly workhorse_archive feature is enabled' do - it 'sets the header correctly' do - key, command, params = decode_workhorse_header(subject) + it 'sets the header correctly' do + key, command, params = decode_workhorse_header(subject) - expect(key).to eq('Gitlab-Workhorse-Send-Data') - expect(command).to eq('git-archive') - expect(params).to include(gitaly_params) - end + expect(key).to eq('Gitlab-Workhorse-Send-Data') + expect(command).to eq('git-archive') + expect(params).to include(gitaly_params) + end - context 'when archive caching is disabled' do - let(:cache_disabled) { true } + context 'when archive caching is disabled' do + let(:cache_disabled) { true } - it 'tells workhorse not to use the cache' do - _, _, params = decode_workhorse_header(subject) - expect(params).to include({ 'DisableCache' => true }) - end + it 'tells workhorse not to use the cache' do + _, _, params = decode_workhorse_header(subject) + expect(params).to include({ 'DisableCache' => true }) end end @@ -70,34 +68,22 @@ describe Gitlab::Workhorse do let(:diff_refs) { double(base_sha: "base", head_sha: "head") } subject { described_class.send_git_patch(repository, diff_refs) } - context 'when Gitaly workhorse_send_git_patch feature is enabled' do - it 'sets the header correctly' do - key, command, params = decode_workhorse_header(subject) - - expect(key).to eq("Gitlab-Workhorse-Send-Data") - expect(command).to eq("git-format-patch") - expect(params).to eq({ - 'GitalyServer' => { - address: Gitlab::GitalyClient.address(project.repository_storage), - token: Gitlab::GitalyClient.token(project.repository_storage) - }, - 'RawPatchRequest' => Gitaly::RawPatchRequest.new( - repository: repository.gitaly_repository, - left_commit_id: 'base', - right_commit_id: 'head' - ).to_json - }.deep_stringify_keys) - end - end - - context 'when Gitaly workhorse_send_git_patch feature is disabled', :disable_gitaly do - it 'sets the header correctly' do - key, command, params = decode_workhorse_header(subject) + it 'sets the header correctly' do + key, command, params = decode_workhorse_header(subject) - expect(key).to eq("Gitlab-Workhorse-Send-Data") - expect(command).to eq("git-format-patch") - expect(params).to eq("RepoPath" => repository.path_to_repo, "ShaFrom" => "base", "ShaTo" => "head") - end + expect(key).to eq("Gitlab-Workhorse-Send-Data") + expect(command).to eq("git-format-patch") + expect(params).to eq({ + 'GitalyServer' => { + address: Gitlab::GitalyClient.address(project.repository_storage), + token: Gitlab::GitalyClient.token(project.repository_storage) + }, + 'RawPatchRequest' => Gitaly::RawPatchRequest.new( + repository: repository.gitaly_repository, + left_commit_id: 'base', + right_commit_id: 'head' + ).to_json + }.deep_stringify_keys) end end @@ -143,34 +129,22 @@ describe Gitlab::Workhorse do let(:diff_refs) { double(base_sha: "base", head_sha: "head") } subject { described_class.send_git_diff(repository, diff_refs) } - context 'when Gitaly workhorse_send_git_diff feature is enabled' do - it 'sets the header correctly' do - key, command, params = decode_workhorse_header(subject) - - expect(key).to eq("Gitlab-Workhorse-Send-Data") - expect(command).to eq("git-diff") - expect(params).to eq({ - 'GitalyServer' => { - address: Gitlab::GitalyClient.address(project.repository_storage), - token: Gitlab::GitalyClient.token(project.repository_storage) - }, - 'RawDiffRequest' => Gitaly::RawDiffRequest.new( - repository: repository.gitaly_repository, - left_commit_id: 'base', - right_commit_id: 'head' - ).to_json - }.deep_stringify_keys) - end - end - - context 'when Gitaly workhorse_send_git_diff feature is disabled', :disable_gitaly do - it 'sets the header correctly' do - key, command, params = decode_workhorse_header(subject) + it 'sets the header correctly' do + key, command, params = decode_workhorse_header(subject) - expect(key).to eq("Gitlab-Workhorse-Send-Data") - expect(command).to eq("git-diff") - expect(params).to eq("RepoPath" => repository.path_to_repo, "ShaFrom" => "base", "ShaTo" => "head") - end + expect(key).to eq("Gitlab-Workhorse-Send-Data") + expect(command).to eq("git-diff") + expect(params).to eq({ + 'GitalyServer' => { + address: Gitlab::GitalyClient.address(project.repository_storage), + token: Gitlab::GitalyClient.token(project.repository_storage) + }, + 'RawDiffRequest' => Gitaly::RawDiffRequest.new( + repository: repository.gitaly_repository, + left_commit_id: 'base', + right_commit_id: 'head' + ).to_json + }.deep_stringify_keys) end end @@ -189,7 +163,7 @@ describe Gitlab::Workhorse do end it 'accepts a trailing newline' do - open(described_class.secret_path, 'a') { |f| f.write "\n" } + File.open(described_class.secret_path, 'a') { |f| f.write "\n" } expect(subject.length).to eq(32) end @@ -425,34 +399,22 @@ describe Gitlab::Workhorse do subject { described_class.send_git_blob(repository, blob) } - context 'when Gitaly workhorse_raw_show feature is enabled' do - it 'sets the header correctly' do - key, command, params = decode_workhorse_header(subject) - - expect(key).to eq('Gitlab-Workhorse-Send-Data') - expect(command).to eq('git-blob') - expect(params).to eq({ - 'GitalyServer' => { - address: Gitlab::GitalyClient.address(project.repository_storage), - token: Gitlab::GitalyClient.token(project.repository_storage) - }, - 'GetBlobRequest' => { - repository: repository.gitaly_repository.to_h, - oid: blob.id, - limit: -1 - } - }.deep_stringify_keys) - end - end - - context 'when Gitaly workhorse_raw_show feature is disabled', :disable_gitaly do - it 'sets the header correctly' do - key, command, params = decode_workhorse_header(subject) + it 'sets the header correctly' do + key, command, params = decode_workhorse_header(subject) - expect(key).to eq('Gitlab-Workhorse-Send-Data') - expect(command).to eq('git-blob') - expect(params).to eq('RepoPath' => repository.path_to_repo, 'BlobId' => blob.id) - end + expect(key).to eq('Gitlab-Workhorse-Send-Data') + expect(command).to eq('git-blob') + expect(params).to eq({ + 'GitalyServer' => { + address: Gitlab::GitalyClient.address(project.repository_storage), + token: Gitlab::GitalyClient.token(project.repository_storage) + }, + 'GetBlobRequest' => { + repository: repository.gitaly_repository.to_h, + oid: blob.id, + limit: -1 + } + }.deep_stringify_keys) end end diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index a9a45367b4a..581132b6672 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -314,6 +314,17 @@ describe Notify do end end + describe 'that are new with a description' do + subject { described_class.new_merge_request_email(merge_request.assignee_id, merge_request.id) } + + it_behaves_like 'it should show Gmail Actions View Merge request link' + it_behaves_like "an unsubscribeable thread" + + it 'contains the description' do + is_expected.to have_body_text(merge_request.description) + end + end + describe 'that have been relabeled' do subject { described_class.relabeled_merge_request_email(recipient.id, merge_request.id, %w[foo bar baz], current_user.id) } @@ -541,7 +552,7 @@ describe Notify do describe 'project access requested' do let(:project) do create(:project, :public, :access_requestable) do |project| - project.add_master(project.owner) + project.add_maintainer(project.owner) end end @@ -616,8 +627,8 @@ describe Notify do end describe 'project invitation' do - let(:master) { create(:user).tap { |u| project.add_master(u) } } - let(:project_member) { invite_to_project(project, inviter: master) } + let(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } } + let(:project_member) { invite_to_project(project, inviter: maintainer) } subject { described_class.member_invited_email('project', project_member.id, project_member.invite_token) } @@ -636,9 +647,9 @@ describe Notify do describe 'project invitation accepted' do let(:invited_user) { create(:user, name: 'invited user') } - let(:master) { create(:user).tap { |u| project.add_master(u) } } + let(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } } let(:project_member) do - invitee = invite_to_project(project, inviter: master) + invitee = invite_to_project(project, inviter: maintainer) invitee.accept_invite!(invited_user) invitee end @@ -659,14 +670,14 @@ describe Notify do end describe 'project invitation declined' do - let(:master) { create(:user).tap { |u| project.add_master(u) } } + let(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } } let(:project_member) do - invitee = invite_to_project(project, inviter: master) + invitee = invite_to_project(project, inviter: maintainer) invitee.decline_invite! invitee end - subject { described_class.member_invite_declined_email('project', project.id, project_member.invite_email, master.id) } + subject { described_class.member_invite_declined_email('project', project.id, project_member.invite_email, maintainer.id) } it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' diff --git a/spec/mailers/previews/devise_mailer_preview.rb b/spec/mailers/previews/devise_mailer_preview.rb deleted file mode 100644 index d6588efc486..00000000000 --- a/spec/mailers/previews/devise_mailer_preview.rb +++ /dev/null @@ -1,30 +0,0 @@ -class DeviseMailerPreview < ActionMailer::Preview - def confirmation_instructions_for_signup - DeviseMailer.confirmation_instructions(unsaved_user, 'faketoken', {}) - end - - def confirmation_instructions_for_new_email - user = User.last - user.unconfirmed_email = 'unconfirmed@example.com' - - DeviseMailer.confirmation_instructions(user, 'faketoken', {}) - end - - def reset_password_instructions - DeviseMailer.reset_password_instructions(unsaved_user, 'faketoken', {}) - end - - def unlock_instructions - DeviseMailer.unlock_instructions(unsaved_user, 'faketoken', {}) - end - - def password_change - DeviseMailer.password_change(unsaved_user, {}) - end - - private - - def unsaved_user - User.new(name: 'Jane Doe', email: 'jdoe@example.com') - end -end diff --git a/spec/mailers/previews/email_rejection_mailer_preview.rb b/spec/mailers/previews/email_rejection_mailer_preview.rb deleted file mode 100644 index 639e8471232..00000000000 --- a/spec/mailers/previews/email_rejection_mailer_preview.rb +++ /dev/null @@ -1,5 +0,0 @@ -class EmailRejectionMailerPreview < ActionMailer::Preview - def rejection - EmailRejectionMailer.rejection("some rejection reason", "From: someone@example.com\nraw email here").message - end -end diff --git a/spec/mailers/previews/notify_preview.rb b/spec/mailers/previews/notify_preview.rb deleted file mode 100644 index e32fd0bd120..00000000000 --- a/spec/mailers/previews/notify_preview.rb +++ /dev/null @@ -1,170 +0,0 @@ -class NotifyPreview < ActionMailer::Preview - def note_merge_request_email_for_individual_note - note_email(:note_merge_request_email) do - note = <<-MD.strip_heredoc - This is an individual note on a merge request :smiley: - - In this notification email, we expect to see: - - - The note contents (that's what you're looking at) - - A link to view this note on Gitlab - - An explanation for why the user is receiving this notification - MD - - create_note(noteable_type: 'merge_request', noteable_id: merge_request.id, note: note) - end - end - - def note_merge_request_email_for_discussion - note_email(:note_merge_request_email) do - note = <<-MD.strip_heredoc - This is a new discussion on a merge request :smiley: - - In this notification email, we expect to see: - - - A line saying who started this discussion - - The note contents (that's what you're looking at) - - A link to view this discussion on Gitlab - - An explanation for why the user is receiving this notification - MD - - create_note(noteable_type: 'merge_request', noteable_id: merge_request.id, type: 'DiscussionNote', note: note) - end - end - - def note_merge_request_email_for_diff_discussion - note_email(:note_merge_request_email) do - note = <<-MD.strip_heredoc - This is a new discussion on a merge request :smiley: - - In this notification email, we expect to see: - - - A line saying who started this discussion and on what file - - The diff - - The note contents (that's what you're looking at) - - A link to view this discussion on Gitlab - - An explanation for why the user is receiving this notification - MD - - position = Gitlab::Diff::Position.new( - old_path: "files/ruby/popen.rb", - new_path: "files/ruby/popen.rb", - old_line: nil, - new_line: 14, - diff_refs: merge_request.diff_refs - ) - - create_note(noteable_type: 'merge_request', noteable_id: merge_request.id, type: 'DiffNote', position: position, note: note) - end - end - - def closed_issue_email - Notify.closed_issue_email(user.id, issue.id, user.id).message - end - - def issue_status_changed_email - Notify.issue_status_changed_email(user.id, issue.id, 'closed', user.id).message - end - - def closed_merge_request_email - Notify.closed_merge_request_email(user.id, issue.id, user.id).message - end - - def merge_request_status_email - Notify.merge_request_status_email(user.id, merge_request.id, 'closed', user.id).message - end - - def merged_merge_request_email - Notify.merged_merge_request_email(user.id, merge_request.id, user.id).message - end - - def member_access_denied_email - Notify.member_access_denied_email('project', project.id, user.id).message - end - - def member_access_granted_email - Notify.member_access_granted_email('project', user.id).message - end - - def member_access_requested_email - Notify.member_access_requested_email('group', user.id, 'some@example.com').message - end - - def member_invite_accepted_email - Notify.member_invite_accepted_email('project', user.id).message - end - - def member_invite_declined_email - Notify.member_invite_declined_email( - 'project', - project.id, - 'invite@example.com', - user.id - ).message - end - - def member_invited_email - Notify.member_invited_email('project', user.id, '1234').message - end - - def pages_domain_enabled_email - cleanup do - pages_domain = PagesDomain.new(domain: 'my.example.com', project: project, verified_at: Time.now, enabled_until: 1.week.from_now) - - Notify.pages_domain_enabled_email(pages_domain, user).message - end - end - - def pipeline_success_email - Notify.pipeline_success_email(pipeline, pipeline.user.try(:email)) - end - - def pipeline_failed_email - Notify.pipeline_failed_email(pipeline, pipeline.user.try(:email)) - end - - private - - def project - @project ||= Project.find_by_full_path('gitlab-org/gitlab-test') - end - - def issue - @merge_request ||= project.issues.first - end - - def merge_request - @merge_request ||= project.merge_requests.first - end - - def pipeline - @pipeline = Ci::Pipeline.last - end - - def user - @user ||= User.last - end - - def create_note(params) - Notes::CreateService.new(project, user, params).execute - end - - def note_email(method) - cleanup do - note = yield - - Notify.public_send(method, user.id, note) - end - end - - def cleanup - email = nil - - ActiveRecord::Base.transaction do - email = yield - raise ActiveRecord::Rollback - end - - email - end -end diff --git a/spec/mailers/previews/repository_check_mailer_preview.rb b/spec/mailers/previews/repository_check_mailer_preview.rb deleted file mode 100644 index 19d4eab1805..00000000000 --- a/spec/mailers/previews/repository_check_mailer_preview.rb +++ /dev/null @@ -1,5 +0,0 @@ -class RepositoryCheckMailerPreview < ActionMailer::Preview - def notify - RepositoryCheckMailer.notify(3).message - end -end diff --git a/spec/migrations/enqueue_delete_diff_files_workers_spec.rb b/spec/migrations/enqueue_delete_diff_files_workers_spec.rb index 686027822b8..6bae870920c 100644 --- a/spec/migrations/enqueue_delete_diff_files_workers_spec.rb +++ b/spec/migrations/enqueue_delete_diff_files_workers_spec.rb @@ -2,47 +2,16 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20180619121030_enqueue_delete_diff_files_workers.rb') describe EnqueueDeleteDiffFilesWorkers, :migration, :sidekiq do - let(:merge_request_diffs) { table(:merge_request_diffs) } - let(:merge_requests) { table(:merge_requests) } - let(:namespaces) { table(:namespaces) } - let(:projects) { table(:projects) } - - before do - stub_const("#{described_class.name}::BATCH_SIZE", 2) - - namespaces.create!(id: 1, name: 'gitlab', path: 'gitlab') - projects.create!(id: 1, namespace_id: 1, name: 'gitlab', path: 'gitlab') - - merge_requests.create!(id: 1, target_project_id: 1, source_project_id: 1, target_branch: 'feature', source_branch: 'master', state: 'merged') - - merge_request_diffs.create!(id: 1, merge_request_id: 1, state: 'collected') - merge_request_diffs.create!(id: 2, merge_request_id: 1, state: 'without_files') - merge_request_diffs.create!(id: 3, merge_request_id: 1, state: 'collected') - merge_request_diffs.create!(id: 4, merge_request_id: 1, state: 'collected') - merge_request_diffs.create!(id: 5, merge_request_id: 1, state: 'empty') - merge_request_diffs.create!(id: 6, merge_request_id: 1, state: 'collected') - - merge_requests.update(1, latest_merge_request_diff_id: 6) - end - - it 'correctly schedules diff file deletion workers' do + it 'correctly schedules diff files deletion schedulers' do Sidekiq::Testing.fake! do - Timecop.freeze do - migrate! + expect(BackgroundMigrationWorker) + .to receive(:perform_async) + .with(described_class::SCHEDULER) + .and_call_original - # 1st batch - expect(described_class::MIGRATION).to be_scheduled_delayed_migration(8.minutes, 1) - expect(described_class::MIGRATION).to be_scheduled_delayed_migration(9.minutes, 3) - # 2nd batch - expect(described_class::MIGRATION).to be_scheduled_delayed_migration(16.minutes, 4) - expect(described_class::MIGRATION).to be_scheduled_delayed_migration(17.minutes, 6) - expect(BackgroundMigrationWorker.jobs.size).to eq(4) - end - end - end + migrate! - it 'migrates the data' do - expect { migrate! }.to change { merge_request_diffs.where(state: 'without_files').count } - .from(1).to(4) + expect(BackgroundMigrationWorker.jobs.size).to eq(1) + end end end diff --git a/spec/migrations/issues_moved_to_id_foreign_key_spec.rb b/spec/migrations/issues_moved_to_id_foreign_key_spec.rb index dd2b08099f2..495e86ee888 100644 --- a/spec/migrations/issues_moved_to_id_foreign_key_spec.rb +++ b/spec/migrations/issues_moved_to_id_foreign_key_spec.rb @@ -14,7 +14,7 @@ describe IssuesMovedToIdForeignKey, :migration, schema: 20171114150259 do it 'removes the orphaned moved_to_id' do subject.down - issue_third.update_attributes(moved_to_id: 100000) + issue_third.update(moved_to_id: 100000) subject.up diff --git a/spec/migrations/migrate_gcp_clusters_to_new_clusters_architectures_spec.rb b/spec/migrations/migrate_gcp_clusters_to_new_clusters_architectures_spec.rb index df009cec25c..ba4c66057d4 100644 --- a/spec/migrations/migrate_gcp_clusters_to_new_clusters_architectures_spec.rb +++ b/spec/migrations/migrate_gcp_clusters_to_new_clusters_architectures_spec.rb @@ -12,7 +12,7 @@ describe MigrateGcpClustersToNewClustersArchitectures, :migration do class KubernetesService < ActiveRecord::Base self.table_name = 'services' - serialize :properties, JSON # rubocop:disable Cop/ActiveRecordSerialize + serialize :properties, JSON default_value_for :active, true default_value_for :type, 'KubernetesService' @@ -175,7 +175,7 @@ describe MigrateGcpClustersToNewClustersArchitectures, :migration do end end - def tr(s) - s.delete("'") + def tr(str) + str.delete("'") end end diff --git a/spec/models/ci/build_metadata_spec.rb b/spec/models/ci/build_metadata_spec.rb index 7e75d5a5411..6dba132184c 100644 --- a/spec/models/ci/build_metadata_spec.rb +++ b/spec/models/ci/build_metadata_spec.rb @@ -30,7 +30,7 @@ describe Ci::BuildMetadata do context 'when runner is assigned to the job' do before do - build.update_attributes(runner: runner) + build.update(runner: runner) end context 'when runner timeout is lower than project timeout' do diff --git a/spec/models/ci/build_runner_session_spec.rb b/spec/models/ci/build_runner_session_spec.rb new file mode 100644 index 00000000000..7183957aa50 --- /dev/null +++ b/spec/models/ci/build_runner_session_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe Ci::BuildRunnerSession, model: true do + let!(:build) { create(:ci_build, :with_runner_session) } + + subject { build.runner_session } + + it { is_expected.to belong_to(:build) } + + it { is_expected.to validate_presence_of(:build) } + it { is_expected.to validate_presence_of(:url).with_message('must be a valid URL') } + + describe '#terminal_specification' do + let(:terminal_specification) { subject.terminal_specification } + + it 'returns empty hash if no url' do + subject.url = '' + + expect(terminal_specification).to be_empty + end + + context 'when url is present' do + it 'returns ca_pem nil if empty certificate' do + subject.certificate = '' + + expect(terminal_specification[:ca_pem]).to be_nil + end + + it 'adds Authorization header if authorization is present' do + subject.authorization = 'whatever' + + expect(terminal_specification[:headers]).to include(Authorization: 'whatever') + end + end + end +end diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 6758adc59eb..3c96fe76829 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -19,6 +19,7 @@ describe Ci::Build do it { is_expected.to belong_to(:erased_by) } it { is_expected.to have_many(:deployments) } it { is_expected.to have_many(:trace_sections)} + it { is_expected.to have_one(:runner_session)} it { is_expected.to validate_presence_of(:ref) } it { is_expected.to respond_to(:has_trace?) } it { is_expected.to respond_to(:trace) } @@ -42,6 +43,20 @@ describe Ci::Build do end end + describe 'status' do + context 'when transitioning to any state from running' do + it 'removes runner_session' do + %w(success drop cancel).each do |event| + build = FactoryBot.create(:ci_build, :running, :with_runner_session, pipeline: pipeline) + + build.fire_events!(event) + + expect(build.reload.runner_session).to be_nil + end + end + end + end + describe '.manual_actions' do let!(:manual_but_created) { create(:ci_build, :manual, status: :created, pipeline: pipeline) } let!(:manual_but_succeeded) { create(:ci_build, :manual, status: :success, pipeline: pipeline) } @@ -171,18 +186,18 @@ describe Ci::Build do let(:runner) { create(:ci_runner, :project, projects: [build.project]) } before do - runner.update_attributes(contacted_at: 1.second.ago) + runner.update(contacted_at: 1.second.ago) end it { is_expected.to be_truthy } it 'that is inactive' do - runner.update_attributes(active: false) + runner.update(active: false) is_expected.to be_falsey end it 'that is not online' do - runner.update_attributes(contacted_at: nil) + runner.update(contacted_at: nil) is_expected.to be_falsey end @@ -246,7 +261,7 @@ describe Ci::Build do context 'artifacts metadata does not exist' do before do - build.update_attributes(legacy_artifacts_metadata: nil) + build.update(legacy_artifacts_metadata: nil) end it { is_expected.to be_falsy } @@ -499,6 +514,22 @@ describe Ci::Build do end end + describe '#has_old_trace?' do + subject { build.has_old_trace? } + + context 'when old trace exists' do + before do + build.update_column(:trace, 'old trace') + end + + it { is_expected.to be_truthy } + end + + context 'when old trace does not exist' do + it { is_expected.to be_falsy } + end + end + describe '#trace=' do it "expect to fail trace=" do expect { build.trace = "new" }.to raise_error(NotImplementedError) @@ -518,16 +549,32 @@ describe Ci::Build do end describe '#erase_old_trace!' do - subject { build.send(:read_attribute, :trace) } + subject { build.erase_old_trace! } - before do - build.send(:write_attribute, :trace, 'old trace') + context 'when old trace exists' do + before do + build.update_column(:trace, 'old trace') + end + + it "erases old trace" do + subject + + expect(build.old_trace).to be_nil + end + + it "executes UPDATE query" do + recorded = ActiveRecord::QueryRecorder.new { subject } + + expect(recorded.log.select { |l| l.match?(/UPDATE.*ci_builds/) }.count).to eq(1) + end end - it "expect to receive data from database" do - build.erase_old_trace! + context 'when old trace does not exist' do + it 'does not execute UPDATE query' do + recorded = ActiveRecord::QueryRecorder.new { subject } - is_expected.to be_nil + expect(recorded.log.select { |l| l.match?(/UPDATE.*ci_builds/) }.count).to eq(0) + end end end @@ -1488,7 +1535,7 @@ describe Ci::Build do expect(ProjectStatistics) .not_to receive(:increment_statistic) - build.project.update_attributes(pending_delete: true) + build.project.update(pending_delete: true) build.project.destroy! end end @@ -1615,7 +1662,7 @@ describe Ci::Build do end before do - build.update_attributes(user: user) + build.update(user: user) end it { user_variables.each { |v| is_expected.to include(v) } } @@ -1693,7 +1740,7 @@ describe Ci::Build do context 'when build started manually' do before do - build.update_attributes(when: :manual) + build.update(when: :manual) end let(:manual_variable) do @@ -1709,7 +1756,7 @@ describe Ci::Build do end before do - build.update_attributes(tag: true) + build.update(tag: true) end it { is_expected.to include(tag_variable) } @@ -2605,4 +2652,93 @@ describe Ci::Build do end end end + + describe '#has_terminal?' do + let(:states) { described_class.state_machines[:status].states.keys - [:running] } + + subject { build.has_terminal? } + + it 'returns true if the build is running and it has a runner_session_url' do + build.build_runner_session(url: 'whatever') + build.status = :running + + expect(subject).to be_truthy + end + + context 'returns false' do + it 'when runner_session_url is empty' do + build.status = :running + + expect(subject).to be_falsey + end + + context 'unless the build is running' do + before do + build.build_runner_session(url: 'whatever') + end + + it do + states.each do |state| + build.status = state + + is_expected.to be_falsey + end + end + end + end + end + + describe '#artifacts_metadata_entry' do + set(:build) { create(:ci_build, project: project) } + let(:path) { 'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif' } + + before do + stub_artifacts_object_storage + end + + subject { build.artifacts_metadata_entry(path) } + + context 'when using local storage' do + let!(:metadata) { create(:ci_job_artifact, :metadata, job: build) } + + context 'for existing file' do + it 'does exist' do + is_expected.to be_exists + end + end + + context 'for non-existing file' do + let(:path) { 'invalid-file' } + + it 'does not exist' do + is_expected.not_to be_exists + end + end + end + + context 'when using remote storage' do + include HttpIOHelpers + + let!(:metadata) { create(:ci_job_artifact, :remote_store, :metadata, job: build) } + let(:file_path) { expand_fixture_path('ci_build_artifacts_metadata.gz') } + + before do + stub_remote_url_206(metadata.file.url, file_path) + end + + context 'for existing file' do + it 'does exist' do + is_expected.to be_exists + end + end + + context 'for non-existing file' do + let(:path) { 'invalid-file' } + + it 'does not exist' do + is_expected.not_to be_exists + end + end + end + end end diff --git a/spec/models/ci/build_trace_chunk_spec.rb b/spec/models/ci/build_trace_chunk_spec.rb index 464897de306..774a638b430 100644 --- a/spec/models/ci/build_trace_chunk_spec.rb +++ b/spec/models/ci/build_trace_chunk_spec.rb @@ -14,6 +14,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do before do stub_feature_flags(ci_enable_live_trace: true) + stub_artifacts_object_storage end context 'FastDestroyAll' do @@ -37,6 +38,22 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do end end + describe '.all_stores' do + subject { described_class.all_stores } + + it 'returns a correctly ordered array' do + is_expected.to eq(%w[redis database fog]) + end + + it 'returns redis store as the the lowest precedence' do + expect(subject.first).to eq('redis') + end + + it 'returns fog store as the the highest precedence' do + expect(subject.last).to eq('fog') + end + end + describe '#data' do subject { build_trace_chunk.data } @@ -44,181 +61,269 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do let(:data_store) { :redis } before do - build_trace_chunk.send(:redis_set_data, 'Sample data in redis') + build_trace_chunk.send(:unsafe_set_data!, 'Sample data in redis') end it { is_expected.to eq('Sample data in redis') } end context 'when data_store is database' do - let(:data_store) { :db } - let(:raw_data) { 'Sample data in db' } + let(:data_store) { :database } + let(:raw_data) { 'Sample data in database' } - it { is_expected.to eq('Sample data in db') } + it { is_expected.to eq('Sample data in database') } end - end - - describe '#set_data' do - subject { build_trace_chunk.send(:set_data, value) } - let(:value) { 'Sample data' } + context 'when data_store is fog' do + let(:data_store) { :fog } - context 'when value bytesize is bigger than CHUNK_SIZE' do - let(:value) { 'a' * (described_class::CHUNK_SIZE + 1) } + before do + build_trace_chunk.send(:unsafe_set_data!, 'Sample data in fog') + end - it { expect { subject }.to raise_error('too much data') } + it { is_expected.to eq('Sample data in fog') } end + end - context 'when data_store is redis' do - let(:data_store) { :redis } + describe '#append' do + subject { build_trace_chunk.append(new_data, offset) } - it do - expect(build_trace_chunk.send(:redis_data)).to be_nil + let(:new_data) { 'Sample new data' } + let(:offset) { 0 } + let(:merged_data) { data + new_data.to_s } - subject + shared_examples_for 'Appending correctly' do + context 'when offset is negative' do + let(:offset) { -1 } + + it { expect { subject }.to raise_error('Offset is out of range') } + end - expect(build_trace_chunk.send(:redis_data)).to eq(value) + context 'when offset is bigger than data size' do + let(:offset) { data.bytesize + 1 } + + it { expect { subject }.to raise_error('Offset is out of range') } end - context 'when fullfilled chunk size' do - let(:value) { 'a' * described_class::CHUNK_SIZE } + context 'when new data overflows chunk size' do + let(:new_data) { 'a' * (described_class::CHUNK_SIZE + 1) } - it 'schedules stashing data' do - expect(Ci::BuildTraceChunkFlushWorker).to receive(:perform_async).once + it { expect { subject }.to raise_error('Chunk size overflow') } + end + + context 'when offset is EOF' do + let(:offset) { data.bytesize } + it 'appends' do subject + + expect(build_trace_chunk.data).to eq(merged_data) end - end - end - context 'when data_store is database' do - let(:data_store) { :db } + context 'when the other process is appending' do + let(:lease_key) { "trace_write:#{build_trace_chunk.build.id}:chunks:#{build_trace_chunk.chunk_index}" } - it 'sets data' do - expect(build_trace_chunk.raw_data).to be_nil + before do + stub_exclusive_lease_taken(lease_key) + end - subject + it 'raise an error' do + expect { subject }.to raise_error('Failed to obtain a lock') + end + end - expect(build_trace_chunk.raw_data).to eq(value) - expect(build_trace_chunk.persisted?).to be_truthy - end + context 'when new_data is nil' do + let(:new_data) { nil } - context 'when raw_data is not changed' do - it 'does not execute UPDATE' do - expect(build_trace_chunk.raw_data).to be_nil - build_trace_chunk.save! + it 'raises an error' do + expect { subject }.to raise_error('New data is missing') + end + end - # First set - expect(ActiveRecord::QueryRecorder.new { subject }.count).to be > 0 - expect(build_trace_chunk.raw_data).to eq(value) - expect(build_trace_chunk.persisted?).to be_truthy + context 'when new_data is empty' do + let(:new_data) { '' } - # Second set - build_trace_chunk.reload - expect(ActiveRecord::QueryRecorder.new { subject }.count).to be(0) + it 'does not append' do + subject + + expect(build_trace_chunk.data).to eq(data) + end + + it 'does not execute UPDATE' do + ActiveRecord::QueryRecorder.new { subject }.log.map do |query| + expect(query).not_to include('UPDATE') + end + end end end - context 'when fullfilled chunk size' do - it 'does not schedule stashing data' do - expect(Ci::BuildTraceChunkFlushWorker).not_to receive(:perform_async) + context 'when offset is middle of datasize' do + let(:offset) { data.bytesize / 2 } + it 'appends' do subject + + expect(build_trace_chunk.data).to eq(data.byteslice(0, offset) + new_data) end end end - end - describe '#truncate' do - subject { build_trace_chunk.truncate(offset) } + shared_examples_for 'Scheduling sidekiq worker to flush data to persist store' do + context 'when new data fullfilled chunk size' do + let(:new_data) { 'a' * described_class::CHUNK_SIZE } - shared_examples_for 'truncates' do - context 'when offset is negative' do - let(:offset) { -1 } + it 'schedules trace chunk flush worker' do + expect(Ci::BuildTraceChunkFlushWorker).to receive(:perform_async).once - it { expect { subject }.to raise_error('Offset is out of range') } - end + subject + end - context 'when offset is bigger than data size' do - let(:offset) { data.bytesize + 1 } + it 'migrates data to object storage' do + Sidekiq::Testing.inline! do + subject - it { expect { subject }.to raise_error('Offset is out of range') } + build_trace_chunk.reload + expect(build_trace_chunk.fog?).to be_truthy + expect(build_trace_chunk.data).to eq(new_data) + end + end end + end - context 'when offset is 10' do - let(:offset) { 10 } + shared_examples_for 'Scheduling no sidekiq worker' do + context 'when new data fullfilled chunk size' do + let(:new_data) { 'a' * described_class::CHUNK_SIZE } + + it 'does not schedule trace chunk flush worker' do + expect(Ci::BuildTraceChunkFlushWorker).not_to receive(:perform_async) - it 'truncates' do subject + end - expect(build_trace_chunk.data).to eq(data.byteslice(0, offset)) + it 'does not migrate data to object storage' do + Sidekiq::Testing.inline! do + data_store = build_trace_chunk.data_store + + subject + + build_trace_chunk.reload + expect(build_trace_chunk.data_store).to eq(data_store) + end end end end context 'when data_store is redis' do let(:data_store) { :redis } - let(:data) { 'Sample data in redis' } - before do - build_trace_chunk.send(:redis_set_data, data) + context 'when there are no data' do + let(:data) { '' } + + it 'has no data' do + expect(build_trace_chunk.data).to be_empty + end + + it_behaves_like 'Appending correctly' + it_behaves_like 'Scheduling sidekiq worker to flush data to persist store' end - it_behaves_like 'truncates' - end + context 'when there are some data' do + let(:data) { 'Sample data in redis' } - context 'when data_store is database' do - let(:data_store) { :db } - let(:raw_data) { 'Sample data in db' } - let(:data) { raw_data } + before do + build_trace_chunk.send(:unsafe_set_data!, data) + end - it_behaves_like 'truncates' + it 'has data' do + expect(build_trace_chunk.data).to eq(data) + end + + it_behaves_like 'Appending correctly' + it_behaves_like 'Scheduling sidekiq worker to flush data to persist store' + end end - end - describe '#append' do - subject { build_trace_chunk.append(new_data, offset) } + context 'when data_store is database' do + let(:data_store) { :database } - let(:new_data) { 'Sample new data' } - let(:offset) { 0 } - let(:total_data) { data + new_data } + context 'when there are no data' do + let(:data) { '' } - shared_examples_for 'appends' do - context 'when offset is negative' do - let(:offset) { -1 } + it 'has no data' do + expect(build_trace_chunk.data).to be_empty + end - it { expect { subject }.to raise_error('Offset is out of range') } + it_behaves_like 'Appending correctly' + it_behaves_like 'Scheduling no sidekiq worker' end - context 'when offset is bigger than data size' do - let(:offset) { data.bytesize + 1 } + context 'when there are some data' do + let(:raw_data) { 'Sample data in database' } + let(:data) { raw_data } - it { expect { subject }.to raise_error('Offset is out of range') } + it 'has data' do + expect(build_trace_chunk.data).to eq(data) + end + + it_behaves_like 'Appending correctly' + it_behaves_like 'Scheduling no sidekiq worker' end + end - context 'when offset is bigger than data size' do - let(:new_data) { 'a' * (described_class::CHUNK_SIZE + 1) } + context 'when data_store is fog' do + let(:data_store) { :fog } - it { expect { subject }.to raise_error('Chunk size overflow') } + context 'when there are no data' do + let(:data) { '' } + + it 'has no data' do + expect(build_trace_chunk.data).to be_empty + end + + it_behaves_like 'Appending correctly' + it_behaves_like 'Scheduling no sidekiq worker' end - context 'when offset is EOF' do - let(:offset) { data.bytesize } + context 'when there are some data' do + let(:data) { 'Sample data in fog' } - it 'appends' do - subject + before do + build_trace_chunk.send(:unsafe_set_data!, data) + end - expect(build_trace_chunk.data).to eq(total_data) + it 'has data' do + expect(build_trace_chunk.data).to eq(data) end + + it_behaves_like 'Appending correctly' + it_behaves_like 'Scheduling no sidekiq worker' + end + end + end + + describe '#truncate' do + subject { build_trace_chunk.truncate(offset) } + + shared_examples_for 'truncates' do + context 'when offset is negative' do + let(:offset) { -1 } + + it { expect { subject }.to raise_error('Offset is out of range') } + end + + context 'when offset is bigger than data size' do + let(:offset) { data.bytesize + 1 } + + it { expect { subject }.to raise_error('Offset is out of range') } end context 'when offset is 10' do let(:offset) { 10 } - it 'appends' do + it 'truncates' do subject - expect(build_trace_chunk.data).to eq(data.byteslice(0, offset) + new_data) + expect(build_trace_chunk.data).to eq(data.byteslice(0, offset)) end end end @@ -228,18 +333,29 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do let(:data) { 'Sample data in redis' } before do - build_trace_chunk.send(:redis_set_data, data) + build_trace_chunk.send(:unsafe_set_data!, data) end - it_behaves_like 'appends' + it_behaves_like 'truncates' end context 'when data_store is database' do - let(:data_store) { :db } - let(:raw_data) { 'Sample data in db' } + let(:data_store) { :database } + let(:raw_data) { 'Sample data in database' } let(:data) { raw_data } - it_behaves_like 'appends' + it_behaves_like 'truncates' + end + + context 'when data_store is fog' do + let(:data_store) { :fog } + let(:data) { 'Sample data in fog' } + + before do + build_trace_chunk.send(:unsafe_set_data!, data) + end + + it_behaves_like 'truncates' end end @@ -253,7 +369,7 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do let(:data) { 'Sample data in redis' } before do - build_trace_chunk.send(:redis_set_data, data) + build_trace_chunk.send(:unsafe_set_data!, data) end it { is_expected.to eq(data.bytesize) } @@ -265,10 +381,10 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do end context 'when data_store is database' do - let(:data_store) { :db } + let(:data_store) { :database } context 'when data exists' do - let(:raw_data) { 'Sample data in db' } + let(:raw_data) { 'Sample data in database' } let(:data) { raw_data } it { is_expected.to eq(data.bytesize) } @@ -278,10 +394,43 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do it { is_expected.to eq(0) } end end + + context 'when data_store is fog' do + let(:data_store) { :fog } + + context 'when data exists' do + let(:data) { 'Sample data in fog' } + let(:key) { "tmp/builds/#{build.id}/chunks/#{chunk_index}.log" } + + before do + build_trace_chunk.send(:unsafe_set_data!, data) + end + + it { is_expected.to eq(data.bytesize) } + end + + context 'when data does not exist' do + it { is_expected.to eq(0) } + end + end end - describe '#use_database!' do - subject { build_trace_chunk.use_database! } + describe '#persist_data!' do + subject { build_trace_chunk.persist_data! } + + shared_examples_for 'Atomic operation' do + context 'when the other process is persisting' do + let(:lease_key) { "trace_write:#{build_trace_chunk.build.id}:chunks:#{build_trace_chunk.chunk_index}" } + + before do + stub_exclusive_lease_taken(lease_key) + end + + it 'raise an error' do + expect { subject }.to raise_error('Failed to obtain a lock') + end + end + end context 'when data_store is redis' do let(:data_store) { :redis } @@ -290,46 +439,93 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do let(:data) { 'Sample data in redis' } before do - build_trace_chunk.send(:redis_set_data, data) + build_trace_chunk.send(:unsafe_set_data!, data) end - it 'stashes the data' do - expect(build_trace_chunk.data_store).to eq('redis') - expect(build_trace_chunk.send(:redis_data)).to eq(data) - expect(build_trace_chunk.raw_data).to be_nil + it 'persists the data' do + expect(build_trace_chunk.redis?).to be_truthy + expect(Ci::BuildTraceChunks::Redis.new.data(build_trace_chunk)).to eq(data) + expect(Ci::BuildTraceChunks::Database.new.data(build_trace_chunk)).to be_nil + expect { Ci::BuildTraceChunks::Fog.new.data(build_trace_chunk) }.to raise_error(Excon::Error::NotFound) subject - expect(build_trace_chunk.data_store).to eq('db') - expect(build_trace_chunk.send(:redis_data)).to be_nil - expect(build_trace_chunk.raw_data).to eq(data) + expect(build_trace_chunk.fog?).to be_truthy + expect(Ci::BuildTraceChunks::Redis.new.data(build_trace_chunk)).to be_nil + expect(Ci::BuildTraceChunks::Database.new.data(build_trace_chunk)).to be_nil + expect(Ci::BuildTraceChunks::Fog.new.data(build_trace_chunk)).to eq(data) end + + it_behaves_like 'Atomic operation' end context 'when data does not exist' do - it 'does not call UPDATE' do - expect(ActiveRecord::QueryRecorder.new { subject }.count).to eq(0) + it 'does not persist' do + expect { subject }.to raise_error('Can not persist empty data') end end end context 'when data_store is database' do - let(:data_store) { :db } + let(:data_store) { :database } - it 'does not call UPDATE' do - expect(ActiveRecord::QueryRecorder.new { subject }.count).to eq(0) + context 'when data exists' do + let(:data) { 'Sample data in database' } + + before do + build_trace_chunk.send(:unsafe_set_data!, data) + end + + it 'persists the data' do + expect(build_trace_chunk.database?).to be_truthy + expect(Ci::BuildTraceChunks::Redis.new.data(build_trace_chunk)).to be_nil + expect(Ci::BuildTraceChunks::Database.new.data(build_trace_chunk)).to eq(data) + expect { Ci::BuildTraceChunks::Fog.new.data(build_trace_chunk) }.to raise_error(Excon::Error::NotFound) + + subject + + expect(build_trace_chunk.fog?).to be_truthy + expect(Ci::BuildTraceChunks::Redis.new.data(build_trace_chunk)).to be_nil + expect(Ci::BuildTraceChunks::Database.new.data(build_trace_chunk)).to be_nil + expect(Ci::BuildTraceChunks::Fog.new.data(build_trace_chunk)).to eq(data) + end + + it_behaves_like 'Atomic operation' end - end - end - describe 'ExclusiveLock' do - before do - stub_exclusive_lease_taken - stub_const('Ci::BuildTraceChunk::WRITE_LOCK_RETRY', 1) + context 'when data does not exist' do + it 'does not persist' do + expect { subject }.to raise_error('Can not persist empty data') + end + end end - it 'raise an error' do - expect { build_trace_chunk.append('ABC', 0) }.to raise_error('Failed to obtain write lock') + context 'when data_store is fog' do + let(:data_store) { :fog } + + context 'when data exists' do + let(:data) { 'Sample data in fog' } + + before do + build_trace_chunk.send(:unsafe_set_data!, data) + end + + it 'does not change data store' do + expect(build_trace_chunk.fog?).to be_truthy + expect(Ci::BuildTraceChunks::Redis.new.data(build_trace_chunk)).to be_nil + expect(Ci::BuildTraceChunks::Database.new.data(build_trace_chunk)).to be_nil + expect(Ci::BuildTraceChunks::Fog.new.data(build_trace_chunk)).to eq(data) + + subject + + expect(build_trace_chunk.fog?).to be_truthy + expect(Ci::BuildTraceChunks::Redis.new.data(build_trace_chunk)).to be_nil + expect(Ci::BuildTraceChunks::Database.new.data(build_trace_chunk)).to be_nil + expect(Ci::BuildTraceChunks::Fog.new.data(build_trace_chunk)).to eq(data) + end + + it_behaves_like 'Atomic operation' + end end end diff --git a/spec/models/ci/build_trace_chunks/database_spec.rb b/spec/models/ci/build_trace_chunks/database_spec.rb new file mode 100644 index 00000000000..d8fc9d57e95 --- /dev/null +++ b/spec/models/ci/build_trace_chunks/database_spec.rb @@ -0,0 +1,105 @@ +require 'spec_helper' + +describe Ci::BuildTraceChunks::Database do + let(:data_store) { described_class.new } + + describe '#available?' do + subject { data_store.available? } + + it { is_expected.to be_truthy } + end + + describe '#data' do + subject { data_store.data(model) } + + context 'when data exists' do + let(:model) { create(:ci_build_trace_chunk, :database_with_data, initial_data: 'sample data in database') } + + it 'returns the data' do + is_expected.to eq('sample data in database') + end + end + + context 'when data does not exist' do + let(:model) { create(:ci_build_trace_chunk, :database_without_data) } + + it 'returns nil' do + is_expected.to be_nil + end + end + end + + describe '#set_data' do + subject { data_store.set_data(model, data) } + + let(:data) { 'abc123' } + + context 'when data exists' do + let(:model) { create(:ci_build_trace_chunk, :database_with_data, initial_data: 'sample data in database') } + + it 'overwrites data' do + expect(data_store.data(model)).to eq('sample data in database') + + subject + + expect(data_store.data(model)).to eq('abc123') + end + end + + context 'when data does not exist' do + let(:model) { create(:ci_build_trace_chunk, :database_without_data) } + + it 'sets new data' do + expect(data_store.data(model)).to be_nil + + subject + + expect(data_store.data(model)).to eq('abc123') + end + end + end + + describe '#delete_data' do + subject { data_store.delete_data(model) } + + context 'when data exists' do + let(:model) { create(:ci_build_trace_chunk, :database_with_data, initial_data: 'sample data in database') } + + it 'deletes data' do + expect(data_store.data(model)).to eq('sample data in database') + + subject + + expect(data_store.data(model)).to be_nil + end + end + + context 'when data does not exist' do + let(:model) { create(:ci_build_trace_chunk, :database_without_data) } + + it 'does nothing' do + expect(data_store.data(model)).to be_nil + + subject + + expect(data_store.data(model)).to be_nil + end + end + end + + describe '#keys' do + subject { data_store.keys(relation) } + + let(:build) { create(:ci_build) } + let(:relation) { build.trace_chunks } + + before do + create(:ci_build_trace_chunk, :database_with_data, chunk_index: 0, build: build) + create(:ci_build_trace_chunk, :database_with_data, chunk_index: 1, build: build) + end + + it 'returns empty array' do + is_expected.to eq([]) + end + end +end diff --git a/spec/models/ci/build_trace_chunks/fog_spec.rb b/spec/models/ci/build_trace_chunks/fog_spec.rb new file mode 100644 index 00000000000..8f49190af13 --- /dev/null +++ b/spec/models/ci/build_trace_chunks/fog_spec.rb @@ -0,0 +1,146 @@ +require 'spec_helper' + +describe Ci::BuildTraceChunks::Fog do + let(:data_store) { described_class.new } + + before do + stub_artifacts_object_storage + end + + describe '#available?' do + subject { data_store.available? } + + context 'when object storage is enabled' do + it { is_expected.to be_truthy } + end + + context 'when object storage is disabled' do + before do + stub_artifacts_object_storage(enabled: false) + end + + it { is_expected.to be_falsy } + end + end + + describe '#data' do + subject { data_store.data(model) } + + context 'when data exists' do + let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: 'sample data in fog') } + + it 'returns the data' do + is_expected.to eq('sample data in fog') + end + end + + context 'when data does not exist' do + let(:model) { create(:ci_build_trace_chunk, :fog_without_data) } + + it 'returns nil' do + expect { data_store.data(model) }.to raise_error(Excon::Error::NotFound) + end + end + end + + describe '#set_data' do + subject { data_store.set_data(model, data) } + + let(:data) { 'abc123' } + + context 'when data exists' do + let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: 'sample data in fog') } + + it 'overwrites data' do + expect(data_store.data(model)).to eq('sample data in fog') + + subject + + expect(data_store.data(model)).to eq('abc123') + end + end + + context 'when data does not exist' do + let(:model) { create(:ci_build_trace_chunk, :fog_without_data) } + + it 'sets new data' do + expect { data_store.data(model) }.to raise_error(Excon::Error::NotFound) + + subject + + expect(data_store.data(model)).to eq('abc123') + end + end + end + + describe '#delete_data' do + subject { data_store.delete_data(model) } + + context 'when data exists' do + let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: 'sample data in fog') } + + it 'deletes data' do + expect(data_store.data(model)).to eq('sample data in fog') + + subject + + expect { data_store.data(model) }.to raise_error(Excon::Error::NotFound) + end + end + + context 'when data does not exist' do + let(:model) { create(:ci_build_trace_chunk, :fog_without_data) } + + it 'does nothing' do + expect { data_store.data(model) }.to raise_error(Excon::Error::NotFound) + + subject + + expect { data_store.data(model) }.to raise_error(Excon::Error::NotFound) + end + end + end + + describe '#keys' do + subject { data_store.keys(relation) } + + let(:build) { create(:ci_build) } + let(:relation) { build.trace_chunks } + + before do + create(:ci_build_trace_chunk, :fog_with_data, chunk_index: 0, build: build) + create(:ci_build_trace_chunk, :fog_with_data, chunk_index: 1, build: build) + end + + it 'returns keys' do + is_expected.to eq([[build.id, 0], [build.id, 1]]) + end + end + + describe '#delete_keys' do + subject { data_store.delete_keys(keys) } + + let(:build) { create(:ci_build) } + let(:relation) { build.trace_chunks } + let(:keys) { data_store.keys(relation) } + + before do + create(:ci_build_trace_chunk, :fog_with_data, chunk_index: 0, build: build) + create(:ci_build_trace_chunk, :fog_with_data, chunk_index: 1, build: build) + end + + it 'deletes multiple data' do + ::Fog::Storage.new(JobArtifactUploader.object_store_credentials).tap do |connection| + expect(connection.get_object('artifacts', "tmp/builds/#{build.id}/chunks/0.log")[:body]).to be_present + expect(connection.get_object('artifacts', "tmp/builds/#{build.id}/chunks/1.log")[:body]).to be_present + end + + subject + + ::Fog::Storage.new(JobArtifactUploader.object_store_credentials).tap do |connection| + expect { connection.get_object('artifacts', "tmp/builds/#{build.id}/chunks/0.log")[:body] }.to raise_error(Excon::Error::NotFound) + expect { connection.get_object('artifacts', "tmp/builds/#{build.id}/chunks/1.log")[:body] }.to raise_error(Excon::Error::NotFound) + end + end + end +end diff --git a/spec/models/ci/build_trace_chunks/redis_spec.rb b/spec/models/ci/build_trace_chunks/redis_spec.rb new file mode 100644 index 00000000000..9da1e6a95ee --- /dev/null +++ b/spec/models/ci/build_trace_chunks/redis_spec.rb @@ -0,0 +1,132 @@ +require 'spec_helper' + +describe Ci::BuildTraceChunks::Redis, :clean_gitlab_redis_shared_state do + let(:data_store) { described_class.new } + + describe '#available?' do + subject { data_store.available? } + + it { is_expected.to be_truthy } + end + + describe '#data' do + subject { data_store.data(model) } + + context 'when data exists' do + let(:model) { create(:ci_build_trace_chunk, :redis_with_data, initial_data: 'sample data in redis') } + + it 'returns the data' do + is_expected.to eq('sample data in redis') + end + end + + context 'when data does not exist' do + let(:model) { create(:ci_build_trace_chunk, :redis_without_data) } + + it 'returns nil' do + is_expected.to be_nil + end + end + end + + describe '#set_data' do + subject { data_store.set_data(model, data) } + + let(:data) { 'abc123' } + + context 'when data exists' do + let(:model) { create(:ci_build_trace_chunk, :redis_with_data, initial_data: 'sample data in redis') } + + it 'overwrites data' do + expect(data_store.data(model)).to eq('sample data in redis') + + subject + + expect(data_store.data(model)).to eq('abc123') + end + end + + context 'when data does not exist' do + let(:model) { create(:ci_build_trace_chunk, :redis_without_data) } + + it 'sets new data' do + expect(data_store.data(model)).to be_nil + + subject + + expect(data_store.data(model)).to eq('abc123') + end + end + end + + describe '#delete_data' do + subject { data_store.delete_data(model) } + + context 'when data exists' do + let(:model) { create(:ci_build_trace_chunk, :redis_with_data, initial_data: 'sample data in redis') } + + it 'deletes data' do + expect(data_store.data(model)).to eq('sample data in redis') + + subject + + expect(data_store.data(model)).to be_nil + end + end + + context 'when data does not exist' do + let(:model) { create(:ci_build_trace_chunk, :redis_without_data) } + + it 'does nothing' do + expect(data_store.data(model)).to be_nil + + subject + + expect(data_store.data(model)).to be_nil + end + end + end + + describe '#keys' do + subject { data_store.keys(relation) } + + let(:build) { create(:ci_build) } + let(:relation) { build.trace_chunks } + + before do + create(:ci_build_trace_chunk, :redis_with_data, chunk_index: 0, build: build) + create(:ci_build_trace_chunk, :redis_with_data, chunk_index: 1, build: build) + end + + it 'returns keys' do + is_expected.to eq([[build.id, 0], [build.id, 1]]) + end + end + + describe '#delete_keys' do + subject { data_store.delete_keys(keys) } + + let(:build) { create(:ci_build) } + let(:relation) { build.trace_chunks } + let(:keys) { data_store.keys(relation) } + + before do + create(:ci_build_trace_chunk, :redis_with_data, chunk_index: 0, build: build) + create(:ci_build_trace_chunk, :redis_with_data, chunk_index: 1, build: build) + end + + it 'deletes multiple data' do + Gitlab::Redis::SharedState.with do |redis| + expect(redis.exists("gitlab:ci:trace:#{build.id}:chunks:0")).to be_truthy + expect(redis.exists("gitlab:ci:trace:#{build.id}:chunks:1")).to be_truthy + end + + subject + + Gitlab::Redis::SharedState.with do |redis| + expect(redis.exists("gitlab:ci:trace:#{build.id}:chunks:0")).to be_falsy + expect(redis.exists("gitlab:ci:trace:#{build.id}:chunks:1")).to be_falsy + end + end + end +end diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb index efddd4e7662..0fd7612c011 100644 --- a/spec/models/ci/job_artifact_spec.rb +++ b/spec/models/ci/job_artifact_spec.rb @@ -25,7 +25,7 @@ describe Ci::JobArtifact do end it 'does not schedule the migration' do - expect(ObjectStorageUploadWorker).not_to receive(:perform_async) + expect(ObjectStorage::BackgroundMoveWorker).not_to receive(:perform_async) subject end @@ -163,7 +163,7 @@ describe Ci::JobArtifact do expect(ProjectStatistics) .not_to receive(:increment_statistic) - project.update_attributes(pending_delete: true) + project.update(pending_delete: true) project.destroy! end end diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index f6433234573..953af2c4710 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -105,7 +105,7 @@ describe Ci::Runner do end end - describe '.shared' do + describe '.instance_type' do let(:group) { create(:group) } let(:project) { create(:project) } let!(:group_runner) { create(:ci_runner, :group, groups: [group]) } @@ -113,7 +113,7 @@ describe Ci::Runner do let!(:shared_runner) { create(:ci_runner, :instance) } it 'returns only shared runners' do - expect(described_class.shared).to contain_exactly(shared_runner) + expect(described_class.instance_type).to contain_exactly(shared_runner) end end @@ -155,7 +155,7 @@ describe Ci::Runner do end end - describe '.owned_or_shared' do + describe '.owned_or_instance_wide' do it 'returns a globally shared, a project specific and a group specific runner' do # group specific group = create(:group) @@ -168,7 +168,7 @@ describe Ci::Runner do # globally shared shared_runner = create(:ci_runner, :instance) - expect(described_class.owned_or_shared(project.id)).to contain_exactly( + expect(described_class.owned_or_instance_wide(project.id)).to contain_exactly( group_runner, project_runner, shared_runner ) end @@ -202,7 +202,6 @@ describe Ci::Runner do it 'transitions shared runner to project runner and assigns project' do expect(subject).to be_truthy - expect(runner).to be_specific expect(runner).to be_project_type expect(runner.projects).to eq([project]) expect(runner.only_for?(project)).to be_truthy diff --git a/spec/models/concerns/batch_destroy_dependent_associations_spec.rb b/spec/models/concerns/batch_destroy_dependent_associations_spec.rb index c16b245bea8..e5392fe0462 100644 --- a/spec/models/concerns/batch_destroy_dependent_associations_spec.rb +++ b/spec/models/concerns/batch_destroy_dependent_associations_spec.rb @@ -4,8 +4,8 @@ describe BatchDestroyDependentAssociations do class TestProject < ActiveRecord::Base self.table_name = 'projects' - has_many :builds, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent - has_many :notification_settings, as: :source, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent + has_many :builds, dependent: :destroy + has_many :notification_settings, as: :source, dependent: :delete_all has_many :pages_domains has_many :todos diff --git a/spec/models/concerns/cache_markdown_field_spec.rb b/spec/models/concerns/cache_markdown_field_spec.rb index 2d75422ee68..da26d802688 100644 --- a/spec/models/concerns/cache_markdown_field_spec.rb +++ b/spec/models/concerns/cache_markdown_field_spec.rb @@ -370,4 +370,20 @@ describe CacheMarkdownField do end end end + + describe CacheMarkdownField::MarkdownEngine do + subject { lambda { |version| CacheMarkdownField::MarkdownEngine.from_version(version) } } + + it 'returns :common_mark as a default' do + expect(subject.call(nil)).to eq :common_mark + end + + it 'returns :common_mark' do + expect(subject.call(CacheMarkdownField::CACHE_COMMONMARK_VERSION)).to eq :common_mark + end + + it 'returns :redcarpet' do + expect(subject.call(CacheMarkdownField::CACHE_REDCARPET_VERSION)).to eq :redcarpet + end + end end diff --git a/spec/models/concerns/cacheable_attributes_spec.rb b/spec/models/concerns/cacheable_attributes_spec.rb index c6331c5ec15..f8c2e29fadd 100644 --- a/spec/models/concerns/cacheable_attributes_spec.rb +++ b/spec/models/concerns/cacheable_attributes_spec.rb @@ -52,7 +52,7 @@ describe CacheableAttributes do describe '.cache_key' do it 'excludes cache attributes' do - expect(minimal_test_class.cache_key).to eq("TestClass:#{Gitlab::VERSION}:#{Gitlab.migrations_hash}:#{Rails.version}") + expect(minimal_test_class.cache_key).to eq("TestClass:#{Gitlab::VERSION}:#{Rails.version}") end end diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index 1cfd526834c..ec6374f3963 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -549,7 +549,7 @@ describe Issuable do let(:project) { create(:project, namespace: group) } let(:other_project) { create(:project) } let(:owner) { create(:owner) } - let(:master) { create(:user) } + let(:maintainer) { create(:user) } let(:reporter) { create(:user) } let(:guest) { create(:user) } @@ -558,7 +558,7 @@ describe Issuable do before do group.add_owner(owner) - project.add_master(master) + project.add_maintainer(maintainer) project.add_reporter(reporter) project.add_guest(guest) project.add_guest(contributor) @@ -570,8 +570,8 @@ describe Issuable do let(:merged_mr_other_project) { create(:merge_request, :merged, author: first_time_contributor, target_project: other_project, source_project: other_project) } context "for merge requests" do - it "is false for MASTER" do - mr = create(:merge_request, author: master, target_project: project, source_project: project) + it "is false for MAINTAINER" do + mr = create(:merge_request, author: maintainer, target_project: project, source_project: project) expect(mr).not_to be_first_contribution end diff --git a/spec/models/concerns/mentionable_spec.rb b/spec/models/concerns/mentionable_spec.rb index c73ea6aa94c..a9b237fa9ea 100644 --- a/spec/models/concerns/mentionable_spec.rb +++ b/spec/models/concerns/mentionable_spec.rb @@ -136,7 +136,7 @@ describe Issue, "Mentionable" do expect(SystemNoteService).not_to receive(:cross_reference) - issue.update_attributes(description: 'New description') + issue.update(description: 'New description') issue.create_new_cross_references! end @@ -145,7 +145,7 @@ describe Issue, "Mentionable" do expect(SystemNoteService).to receive(:cross_reference).with(issues[1], any_args) - issue.update_attributes(description: issues[1].to_reference) + issue.update(description: issues[1].to_reference) issue.create_new_cross_references! end @@ -155,7 +155,7 @@ describe Issue, "Mentionable" do expect(SystemNoteService).to receive(:cross_reference).with(issues[1], any_args) - note.update_attributes(note: issues[1].to_reference) + note.update(note: issues[1].to_reference) note.create_new_cross_references! end end diff --git a/spec/models/concerns/protected_ref_access_spec.rb b/spec/models/concerns/protected_ref_access_spec.rb index a62ca391e25..ce602337647 100644 --- a/spec/models/concerns/protected_ref_access_spec.rb +++ b/spec/models/concerns/protected_ref_access_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe ProtectedRefAccess do subject(:protected_ref_access) do - create(:protected_branch, :masters_can_push).push_access_levels.first + create(:protected_branch, :maintainers_can_push).push_access_levels.first end let(:project) { protected_ref_access.project } @@ -14,11 +14,11 @@ describe ProtectedRefAccess do expect(protected_ref_access.check_access(admin)).to be_truthy end - it 'is true for masters' do - master = create(:user) - project.add_master(master) + it 'is true for maintainers' do + maintainer = create(:user) + project.add_maintainer(maintainer) - expect(protected_ref_access.check_access(master)).to be_truthy + expect(protected_ref_access.check_access(maintainer)).to be_truthy end it 'is for developers of the project' do diff --git a/spec/models/concerns/resolvable_discussion_spec.rb b/spec/models/concerns/resolvable_discussion_spec.rb index 2f9f63ce7e0..97b046b0f21 100644 --- a/spec/models/concerns/resolvable_discussion_spec.rb +++ b/spec/models/concerns/resolvable_discussion_spec.rb @@ -190,7 +190,7 @@ describe Discussion, ResolvableDiscussion do context "when the signed in user can push to the project" do before do - subject.project.add_master(current_user) + subject.project.add_maintainer(current_user) end it "returns true" do diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb index 8cb50d7465c..ed3e28fbeca 100644 --- a/spec/models/concerns/routable_spec.rb +++ b/spec/models/concerns/routable_spec.rb @@ -29,7 +29,7 @@ describe Group, 'Routable' do end it 'updates route record on path change' do - group.update_attributes(path: 'wow', name: 'much') + group.update(path: 'wow', name: 'much') expect(group.route.path).to eq('wow') expect(group.route.name).to eq('much') diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 25d6597084c..4bded9efe91 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -562,7 +562,7 @@ describe Environment do it "is not regenerated if name changes" do original_slug = environment.slug - environment.update_attributes!(name: environment.name.reverse) + environment.update!(name: environment.name.reverse) expect(environment.slug).to eq(original_slug) end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 9fe1186a8c9..0729eb99e78 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -177,7 +177,7 @@ describe Group do describe 'when the user has access to a group' do before do - group.add_user(user, Gitlab::Access::MASTER) + group.add_user(user, Gitlab::Access::MAINTAINER) end it { is_expected.to eq([group]) } @@ -229,10 +229,10 @@ describe Group do let(:user) { create(:user) } before do - group.add_user(user, GroupMember::MASTER) + group.add_user(user, GroupMember::MAINTAINER) end - it { expect(group.group_members.masters.map(&:user)).to include(user) } + it { expect(group.group_members.maintainers.map(&:user)).to include(user) } end describe '#add_users' do @@ -254,7 +254,7 @@ describe Group do let(:user) { create(:user) } before do - group.add_user(user, GroupMember::MASTER) + group.add_user(user, GroupMember::MAINTAINER) end it "is true if avatar is image" do @@ -274,7 +274,7 @@ describe Group do context 'when avatar file is uploaded' do before do - group.add_master(user) + group.add_maintainer(user) end it 'shows correct avatar url' do @@ -317,7 +317,7 @@ describe Group do end it { expect(group.has_owner?(@members[:owner])).to be_truthy } - it { expect(group.has_owner?(@members[:master])).to be_falsey } + it { expect(group.has_owner?(@members[:maintainer])).to be_falsey } it { expect(group.has_owner?(@members[:developer])).to be_falsey } it { expect(group.has_owner?(@members[:reporter])).to be_falsey } it { expect(group.has_owner?(@members[:guest])).to be_falsey } @@ -325,19 +325,19 @@ describe Group do it { expect(group.has_owner?(nil)).to be_falsey } end - describe '#has_master?' do + describe '#has_maintainer?' do before do @members = setup_group_members(group) - create(:group_member, :invited, :master, group: group) + create(:group_member, :invited, :maintainer, group: group) end - it { expect(group.has_master?(@members[:owner])).to be_falsey } - it { expect(group.has_master?(@members[:master])).to be_truthy } - it { expect(group.has_master?(@members[:developer])).to be_falsey } - it { expect(group.has_master?(@members[:reporter])).to be_falsey } - it { expect(group.has_master?(@members[:guest])).to be_falsey } - it { expect(group.has_master?(@members[:requester])).to be_falsey } - it { expect(group.has_master?(nil)).to be_falsey } + it { expect(group.has_maintainer?(@members[:owner])).to be_falsey } + it { expect(group.has_maintainer?(@members[:maintainer])).to be_truthy } + it { expect(group.has_maintainer?(@members[:developer])).to be_falsey } + it { expect(group.has_maintainer?(@members[:reporter])).to be_falsey } + it { expect(group.has_maintainer?(@members[:guest])).to be_falsey } + it { expect(group.has_maintainer?(@members[:requester])).to be_falsey } + it { expect(group.has_maintainer?(nil)).to be_falsey } end describe '#lfs_enabled?' do @@ -401,7 +401,7 @@ describe Group do def setup_group_members(group) members = { owner: create(:user), - master: create(:user), + maintainer: create(:user), developer: create(:user), reporter: create(:user), guest: create(:user), @@ -409,7 +409,7 @@ describe Group do } group.add_user(members[:owner], GroupMember::OWNER) - group.add_user(members[:master], GroupMember::MASTER) + group.add_user(members[:maintainer], GroupMember::MAINTAINER) group.add_user(members[:developer], GroupMember::DEVELOPER) group.add_user(members[:reporter], GroupMember::REPORTER) group.add_user(members[:guest], GroupMember::GUEST) @@ -439,25 +439,25 @@ describe Group do describe '#members_with_parents', :nested_groups do let!(:group) { create(:group, :nested) } - let!(:master) { group.parent.add_user(create(:user), GroupMember::MASTER) } + let!(:maintainer) { group.parent.add_user(create(:user), GroupMember::MAINTAINER) } let!(:developer) { group.add_user(create(:user), GroupMember::DEVELOPER) } it 'returns parents members' do expect(group.members_with_parents).to include(developer) - expect(group.members_with_parents).to include(master) + expect(group.members_with_parents).to include(maintainer) end end describe '#direct_and_indirect_members', :nested_groups do let!(:group) { create(:group, :nested) } let!(:sub_group) { create(:group, parent: group) } - let!(:master) { group.parent.add_user(create(:user), GroupMember::MASTER) } + let!(:maintainer) { group.parent.add_user(create(:user), GroupMember::MAINTAINER) } let!(:developer) { group.add_user(create(:user), GroupMember::DEVELOPER) } let!(:other_developer) { group.add_user(create(:user), GroupMember::DEVELOPER) } it 'returns parents members' do expect(group.direct_and_indirect_members).to include(developer) - expect(group.direct_and_indirect_members).to include(master) + expect(group.direct_and_indirect_members).to include(maintainer) end it 'returns descendant members' do @@ -539,14 +539,14 @@ describe Group do describe '#user_ids_for_project_authorizations' do it 'returns the user IDs for which to refresh authorizations' do - master = create(:user) + maintainer = create(:user) developer = create(:user) - group.add_user(master, GroupMember::MASTER) + group.add_user(maintainer, GroupMember::MAINTAINER) group.add_user(developer, GroupMember::DEVELOPER) expect(group.user_ids_for_project_authorizations) - .to include(master.id, developer.id) + .to include(maintainer.id, developer.id) end end @@ -617,7 +617,7 @@ describe Group do expect(group).to receive(:system_hook_service).and_return(system_hook_service) expect(system_hook_service).to receive(:execute_hooks_for).with(group, :rename) - group.update_attributes!(path: new_path) + group.update!(path: new_path) end end @@ -625,7 +625,7 @@ describe Group do it 'does not trigger system hook' do expect(group).not_to receive(:system_hook_service) - group.update_attributes!(name: 'new name') + group.update!(name: 'new name') end end end diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb index 8bc45715dcd..01129df1107 100644 --- a/spec/models/hooks/system_hook_spec.rb +++ b/spec/models/hooks/system_hook_spec.rb @@ -63,7 +63,7 @@ describe SystemHook do end it "project_create hook" do - project.add_master(user) + project.add_maintainer(user) expect(WebMock).to have_requested(:post, system_hook.url).with( body: /user_add_to_team/, @@ -72,7 +72,7 @@ describe SystemHook do end it "project_destroy hook" do - project.add_master(user) + project.add_maintainer(user) project.project_members.destroy_all expect(WebMock).to have_requested(:post, system_hook.url).with( @@ -100,7 +100,7 @@ describe SystemHook do end it 'group member create hook' do - group.add_master(user) + group.add_maintainer(user) expect(WebMock).to have_requested(:post, system_hook.url).with( body: /user_add_to_group/, @@ -109,7 +109,7 @@ describe SystemHook do end it 'group member destroy hook' do - group.add_master(user) + group.add_maintainer(user) group.group_members.destroy_all expect(WebMock).to have_requested(:post, system_hook.url).with( diff --git a/spec/models/hooks/web_hook_log_spec.rb b/spec/models/hooks/web_hook_log_spec.rb index 19bc88b1333..744a6ccae8b 100644 --- a/spec/models/hooks/web_hook_log_spec.rb +++ b/spec/models/hooks/web_hook_log_spec.rb @@ -9,6 +9,24 @@ describe WebHookLog do it { is_expected.to validate_presence_of(:web_hook) } + describe '.recent' do + let(:hook) { create(:project_hook) } + + it 'does not return web hook logs that are too old' do + create(:web_hook_log, web_hook: hook, created_at: 91.days.ago) + + expect(described_class.recent.size).to be_zero + end + + it 'returns the web hook logs in descending order' do + hook1 = create(:web_hook_log, web_hook: hook, created_at: 2.hours.ago) + hook2 = create(:web_hook_log, web_hook: hook, created_at: 1.hour.ago) + hooks = described_class.recent.to_a + + expect(hooks).to eq([hook2, hook1]) + end + end + describe '#success?' do let(:web_hook_log) { build(:web_hook_log, response_status: status) } diff --git a/spec/models/import_export_upload_spec.rb b/spec/models/import_export_upload_spec.rb new file mode 100644 index 00000000000..58af84b8a08 --- /dev/null +++ b/spec/models/import_export_upload_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe ImportExportUpload do + subject { described_class.new(project: create(:project)) } + + shared_examples 'stores the Import/Export file' do |method| + it 'stores the import file' do + subject.public_send("#{method}=", fixture_file_upload('spec/fixtures/project_export.tar.gz')) + + subject.save! + + url = "/uploads/-/system/import_export_upload/#{method}/#{subject.id}/project_export.tar.gz" + + expect(subject.public_send(method).url).to eq(url) + end + end + + context 'import' do + it_behaves_like 'stores the Import/Export file', :import_file + end + + context 'export' do + it_behaves_like 'stores the Import/Export file', :export_file + end +end diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index e818fbeb9cf..84edfc3ff00 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -669,7 +669,7 @@ describe Issue do context 'when the user is the project owner' do before do - project.add_master(user) + project.add_maintainer(user) end it 'returns true for a regular issue' do diff --git a/spec/models/lfs_file_lock_spec.rb b/spec/models/lfs_file_lock_spec.rb index ce87b01b49c..e74f342d3eb 100644 --- a/spec/models/lfs_file_lock_spec.rb +++ b/spec/models/lfs_file_lock_spec.rb @@ -13,13 +13,13 @@ describe LfsFileLock do describe '#can_be_unlocked_by?' do let(:developer) { create(:user) } - let(:master) { create(:user) } + let(:maintainer) { create(:user) } before do project = lfs_file_lock.project project.add_developer(developer) - project.add_master(master) + project.add_maintainer(maintainer) end context "when it's forced" do @@ -29,8 +29,8 @@ describe LfsFileLock do expect(lfs_file_lock.can_be_unlocked_by?(user, true)).to eq(true) end - it 'can be unlocked by a master' do - expect(lfs_file_lock.can_be_unlocked_by?(master, true)).to eq(true) + it 'can be unlocked by a maintainer' do + expect(lfs_file_lock.can_be_unlocked_by?(maintainer, true)).to eq(true) end it "can't be unlocked by other user" do @@ -45,8 +45,8 @@ describe LfsFileLock do expect(lfs_file_lock.can_be_unlocked_by?(user)).to eq(true) end - it "can't be unlocked by a master" do - expect(lfs_file_lock.can_be_unlocked_by?(master)).to eq(false) + it "can't be unlocked by a maintainer" do + expect(lfs_file_lock.can_be_unlocked_by?(maintainer)).to eq(false) end it "can't be unlocked by other user" do diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index c64cdf8f812..fca1b1f90d9 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -62,16 +62,16 @@ describe Member do @owner_user = create(:user).tap { |u| group.add_owner(u) } @owner = group.members.find_by(user_id: @owner_user.id) - @master_user = create(:user).tap { |u| project.add_master(u) } - @master = project.members.find_by(user_id: @master_user.id) + @maintainer_user = create(:user).tap { |u| project.add_maintainer(u) } + @maintainer = project.members.find_by(user_id: @maintainer_user.id) @blocked_user = create(:user).tap do |u| - project.add_master(u) + project.add_maintainer(u) project.add_developer(u) u.block! end - @blocked_master = project.members.find_by(user_id: @blocked_user.id, access_level: Gitlab::Access::MASTER) + @blocked_maintainer = project.members.find_by(user_id: @blocked_user.id, access_level: Gitlab::Access::MAINTAINER) @blocked_developer = project.members.find_by(user_id: @blocked_user.id, access_level: Gitlab::Access::DEVELOPER) @invited_member = create(:project_member, :developer, @@ -95,10 +95,10 @@ describe Member do describe '.access_for_user_ids' do it 'returns the right access levels' do - users = [@owner_user.id, @master_user.id, @blocked_user.id] + users = [@owner_user.id, @maintainer_user.id, @blocked_user.id] expected = { @owner_user.id => Gitlab::Access::OWNER, - @master_user.id => Gitlab::Access::MASTER + @maintainer_user.id => Gitlab::Access::MAINTAINER } expect(described_class.access_for_user_ids(users)).to eq(expected) @@ -106,7 +106,7 @@ describe Member do end describe '.invite' do - it { expect(described_class.invite).not_to include @master } + it { expect(described_class.invite).not_to include @maintainer } it { expect(described_class.invite).to include @invited_member } it { expect(described_class.invite).not_to include @accepted_invite_member } it { expect(described_class.invite).not_to include @requested_member } @@ -114,7 +114,7 @@ describe Member do end describe '.non_invite' do - it { expect(described_class.non_invite).to include @master } + it { expect(described_class.non_invite).to include @maintainer } it { expect(described_class.non_invite).not_to include @invited_member } it { expect(described_class.non_invite).to include @accepted_invite_member } it { expect(described_class.non_invite).to include @requested_member } @@ -122,7 +122,7 @@ describe Member do end describe '.request' do - it { expect(described_class.request).not_to include @master } + it { expect(described_class.request).not_to include @maintainer } it { expect(described_class.request).not_to include @invited_member } it { expect(described_class.request).not_to include @accepted_invite_member } it { expect(described_class.request).to include @requested_member } @@ -130,7 +130,7 @@ describe Member do end describe '.non_request' do - it { expect(described_class.non_request).to include @master } + it { expect(described_class.non_request).to include @maintainer } it { expect(described_class.non_request).to include @invited_member } it { expect(described_class.non_request).to include @accepted_invite_member } it { expect(described_class.non_request).not_to include @requested_member } @@ -141,35 +141,35 @@ describe Member do subject { described_class.developers.to_a } it { is_expected.not_to include @owner } - it { is_expected.not_to include @master } + it { is_expected.not_to include @maintainer } it { is_expected.to include @invited_member } it { is_expected.to include @accepted_invite_member } it { is_expected.not_to include @requested_member } it { is_expected.to include @accepted_request_member } - it { is_expected.not_to include @blocked_master } + it { is_expected.not_to include @blocked_maintainer } it { is_expected.not_to include @blocked_developer } end - describe '.owners_and_masters' do - it { expect(described_class.owners_and_masters).to include @owner } - it { expect(described_class.owners_and_masters).to include @master } - it { expect(described_class.owners_and_masters).not_to include @invited_member } - it { expect(described_class.owners_and_masters).not_to include @accepted_invite_member } - it { expect(described_class.owners_and_masters).not_to include @requested_member } - it { expect(described_class.owners_and_masters).not_to include @accepted_request_member } - it { expect(described_class.owners_and_masters).not_to include @blocked_master } + describe '.owners_and_maintainers' do + it { expect(described_class.owners_and_maintainers).to include @owner } + it { expect(described_class.owners_and_maintainers).to include @maintainer } + it { expect(described_class.owners_and_maintainers).not_to include @invited_member } + it { expect(described_class.owners_and_maintainers).not_to include @accepted_invite_member } + it { expect(described_class.owners_and_maintainers).not_to include @requested_member } + it { expect(described_class.owners_and_maintainers).not_to include @accepted_request_member } + it { expect(described_class.owners_and_maintainers).not_to include @blocked_maintainer } end describe '.has_access' do subject { described_class.has_access.to_a } it { is_expected.to include @owner } - it { is_expected.to include @master } + it { is_expected.to include @maintainer } it { is_expected.to include @invited_member } it { is_expected.to include @accepted_invite_member } it { is_expected.not_to include @requested_member } it { is_expected.to include @accepted_request_member } - it { is_expected.not_to include @blocked_master } + it { is_expected.not_to include @blocked_maintainer } it { is_expected.not_to include @blocked_developer } end end @@ -187,20 +187,20 @@ describe Member do let!(:admin) { create(:admin) } it 'returns a <Source>Member object' do - member = described_class.add_user(source, user, :master) + member = described_class.add_user(source, user, :maintainer) expect(member).to be_a "#{source_type.classify}Member".constantize expect(member).to be_persisted end it 'sets members.created_by to the given current_user' do - member = described_class.add_user(source, user, :master, current_user: admin) + member = described_class.add_user(source, user, :maintainer, current_user: admin) expect(member.created_by).to eq(admin) end it 'sets members.expires_at to the given expires_at' do - member = described_class.add_user(source, user, :master, expires_at: Date.new(2016, 9, 22)) + member = described_class.add_user(source, user, :maintainer, expires_at: Date.new(2016, 9, 22)) expect(member.expires_at).to eq(Date.new(2016, 9, 22)) end @@ -230,7 +230,7 @@ describe Member do it 'adds the user as a member' do expect(source.users).not_to include(user) - described_class.add_user(source, user.id, :master) + described_class.add_user(source, user.id, :maintainer) expect(source.users.reload).to include(user) end @@ -240,7 +240,7 @@ describe Member do it 'adds the user as a member' do expect(source.users).not_to include(user) - described_class.add_user(source, 42, :master) + described_class.add_user(source, 42, :maintainer) expect(source.users.reload).not_to include(user) end @@ -250,7 +250,7 @@ describe Member do it 'adds the user as a member' do expect(source.users).not_to include(user) - described_class.add_user(source, user, :master) + described_class.add_user(source, user, :maintainer) expect(source.users.reload).to include(user) end @@ -265,7 +265,7 @@ describe Member do expect(source.users).not_to include(user) expect(source.requesters.exists?(user_id: user)).to be_truthy - expect { described_class.add_user(source, user, :master) } + expect { described_class.add_user(source, user, :maintainer) } .to raise_error(Gitlab::Access::AccessDeniedError) expect(source.users.reload).not_to include(user) @@ -277,7 +277,7 @@ describe Member do it 'adds the user as a member' do expect(source.users).not_to include(user) - described_class.add_user(source, user.email, :master) + described_class.add_user(source, user.email, :maintainer) expect(source.users.reload).to include(user) end @@ -287,7 +287,7 @@ describe Member do it 'creates an invited member' do expect(source.users).not_to include(user) - described_class.add_user(source, 'user@example.com', :master) + described_class.add_user(source, 'user@example.com', :maintainer) expect(source.members.invite.pluck(:invite_email)).to include('user@example.com') end @@ -298,7 +298,7 @@ describe Member do it 'creates the member' do expect(source.users).not_to include(user) - described_class.add_user(source, user, :master, current_user: admin) + described_class.add_user(source, user, :maintainer, current_user: admin) expect(source.users.reload).to include(user) end @@ -312,7 +312,7 @@ describe Member do expect(source.users).not_to include(user) expect(source.requesters.exists?(user_id: user)).to be_truthy - described_class.add_user(source, user, :master, current_user: admin) + described_class.add_user(source, user, :maintainer, current_user: admin) expect(source.users.reload).to include(user) expect(source.requesters.reload.exists?(user_id: user)).to be_falsy @@ -324,7 +324,7 @@ describe Member do it 'does not create the member' do expect(source.users).not_to include(user) - member = described_class.add_user(source, user, :master, current_user: user) + member = described_class.add_user(source, user, :maintainer, current_user: user) expect(source.users.reload).not_to include(user) expect(member).not_to be_persisted @@ -339,7 +339,7 @@ describe Member do expect(source.users).not_to include(user) expect(source.requesters.exists?(user_id: user)).to be_truthy - described_class.add_user(source, user, :master, current_user: user) + described_class.add_user(source, user, :maintainer, current_user: user) expect(source.users.reload).not_to include(user) expect(source.requesters.exists?(user_id: user)).to be_truthy @@ -356,9 +356,9 @@ describe Member do it 'updates the member' do expect(source.users).to include(user) - described_class.add_user(source, user, :master) + described_class.add_user(source, user, :maintainer) - expect(source.members.find_by(user_id: user).access_level).to eq(Gitlab::Access::MASTER) + expect(source.members.find_by(user_id: user).access_level).to eq(Gitlab::Access::MAINTAINER) end end @@ -366,9 +366,9 @@ describe Member do it 'updates the member' do expect(source.users).to include(user) - described_class.add_user(source, user, :master, current_user: admin) + described_class.add_user(source, user, :maintainer, current_user: admin) - expect(source.members.find_by(user_id: user).access_level).to eq(Gitlab::Access::MASTER) + expect(source.members.find_by(user_id: user).access_level).to eq(Gitlab::Access::MAINTAINER) end end @@ -376,7 +376,7 @@ describe Member do it 'does not update the member' do expect(source.users).to include(user) - described_class.add_user(source, user, :master, current_user: user) + described_class.add_user(source, user, :maintainer, current_user: user) expect(source.members.find_by(user_id: user).access_level).to eq(Gitlab::Access::DEVELOPER) end @@ -395,7 +395,7 @@ describe Member do let(:user2) { create(:user) } it 'returns a <Source>Member objects' do - members = described_class.add_users(source, [user1, user2], :master) + members = described_class.add_users(source, [user1, user2], :maintainer) expect(members).to be_a Array expect(members.size).to eq(2) @@ -404,7 +404,7 @@ describe Member do end it 'returns an empty array' do - members = described_class.add_users(source, [], :master) + members = described_class.add_users(source, [], :maintainer) expect(members).to be_a Array expect(members).to be_empty @@ -413,7 +413,7 @@ describe Member do it 'supports differents formats' do list = ['joe@local.test', admin, user1.id, user2.id.to_s] - members = described_class.add_users(source, list, :master) + members = described_class.add_users(source, list, :maintainer) expect(members.size).to eq(4) expect(members.first).to be_invite diff --git a/spec/models/members/group_member_spec.rb b/spec/models/members/group_member_spec.rb index ffc78015f94..97959ed4304 100644 --- a/spec/models/members/group_member_spec.rb +++ b/spec/models/members/group_member_spec.rb @@ -21,7 +21,7 @@ describe GroupMember do described_class.add_users( group, [users.first.id, users.second], - described_class::MASTER + described_class::MAINTAINER ) expect(group.users).to include(users.first, users.second) diff --git a/spec/models/members/project_member_spec.rb b/spec/models/members/project_member_spec.rb index 574eb468e4c..334d4f95f53 100644 --- a/spec/models/members/project_member_spec.rb +++ b/spec/models/members/project_member_spec.rb @@ -28,7 +28,7 @@ describe ProjectMember do expect(project.users).not_to include(user) - described_class.add_user(project, user, :master, current_user: project.owner) + described_class.add_user(project, user, :maintainer, current_user: project.owner) expect(project.users.reload).to include(user) end @@ -41,9 +41,9 @@ describe ProjectMember do end describe "#destroy" do - let(:owner) { create(:project_member, access_level: ProjectMember::MASTER) } + let(:owner) { create(:project_member, access_level: ProjectMember::MAINTAINER) } let(:project) { owner.project } - let(:master) { create(:project_member, project: project) } + let(:maintainer) { create(:project_member, project: project) } it "creates an expired event when left due to expiry" do expired = create(:project_member, project: project, expires_at: Time.now - 6.days) @@ -52,7 +52,7 @@ describe ProjectMember do end it "creates a left event when left due to leave" do - master.destroy + maintainer.destroy expect(Event.recent.first.action).to eq(Event::LEFT) end end @@ -95,7 +95,7 @@ describe ProjectMember do described_class.add_users_to_projects( [projects.first.id, projects.second.id], [users.first.id, users.second], - described_class::MASTER) + described_class::MAINTAINER) expect(projects.first.users).to include(users.first) expect(projects.first.users).to include(users.second) diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb index 48c01fc4d4e..ccc3ff861c5 100644 --- a/spec/models/merge_request_diff_spec.rb +++ b/spec/models/merge_request_diff_spec.rb @@ -153,6 +153,13 @@ describe MergeRequestDiff do expect(mr_diff.empty?).to be_truthy end + it 'expands collapsed diffs before saving' do + mr_diff = create(:merge_request, source_branch: 'expand-collapse-lines', target_branch: 'master').merge_request_diff + diff_file = mr_diff.merge_request_diff_files.find_by(new_path: 'expand-collapse/file-5.txt') + + expect(diff_file.diff).not_to be_empty + end + it 'saves binary diffs correctly' do path = 'files/images/icn-time-tracking.pdf' mr_diff = create(:merge_request, source_branch: 'add-pdf-text-binary', target_branch: 'master').merge_request_diff diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 8c6b411ec9a..b0d9d03bf6c 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -724,7 +724,7 @@ describe MergeRequest do subject { merge_request } before do - subject.source_project.add_master(user) + subject.source_project.add_maintainer(user) end it "can't be removed when its a protected branch" do @@ -1199,7 +1199,7 @@ describe MergeRequest do end before do - project.add_master(current_user) + project.add_maintainer(current_user) ProcessCommitWorker.new.perform(project.id, current_user.id, @@ -1569,8 +1569,8 @@ describe MergeRequest do let(:merge_request) { create(:merge_request, source_project: project) } before do - merge_request.source_project.add_master(user) - merge_request.target_project.add_master(user) + merge_request.source_project.add_maintainer(user) + merge_request.target_project.add_maintainer(user) end context 'with multiple environments' do @@ -1891,7 +1891,7 @@ describe MergeRequest do end it 'returns false if the merge request is merged' do - merge_request.update_attributes(state: 'merged') + merge_request.update(state: 'merged') expect(merge_request.reload.reopenable?).to be_falsey end diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 70f1a1c8b38..c1b385aaf76 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -200,7 +200,7 @@ describe Namespace do end it "moves dir if path changed" do - namespace.update_attributes(path: namespace.full_path + '_new') + namespace.update(path: namespace.full_path + '_new') expect(gitlab_shell.exists?(project.repository_storage, "#{namespace.path}/#{project.path}.git")).to be_truthy end @@ -279,7 +279,7 @@ describe Namespace do it "repository directory remains unchanged if path changed" do before_disk_path = project.disk_path - namespace.update_attributes(path: namespace.full_path + '_new') + namespace.update(path: namespace.full_path + '_new') expect(before_disk_path).to eq(project.disk_path) expect(gitlab_shell.exists?(project.repository_storage, "#{project.disk_path}.git")).to be_truthy diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index a2cb716cb93..947be44c903 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -144,8 +144,8 @@ describe Note do describe 'admin' do before do @p1.project_members.create(user: @u1, access_level: ProjectMember::REPORTER) - @p1.project_members.create(user: @u2, access_level: ProjectMember::MASTER) - @p2.project_members.create(user: @u3, access_level: ProjectMember::MASTER) + @p1.project_members.create(user: @u2, access_level: ProjectMember::MAINTAINER) + @p2.project_members.create(user: @u3, access_level: ProjectMember::MAINTAINER) end it { expect(Ability.allowed?(@u1, :admin_note, @p1)).to be_falsey } @@ -225,7 +225,7 @@ describe Note do describe "cross_reference_not_visible_for?" do let(:private_user) { create(:user) } - let(:private_project) { create(:project, namespace: private_user.namespace) { |p| p.add_master(private_user) } } + let(:private_project) { create(:project, namespace: private_user.namespace) { |p| p.add_maintainer(private_user) } } let(:private_issue) { create(:issue, project: private_project) } let(:ext_proj) { create(:project, :public) } diff --git a/spec/models/notification_setting_spec.rb b/spec/models/notification_setting_spec.rb index 12681a147b4..77c475b9f52 100644 --- a/spec/models/notification_setting_spec.rb +++ b/spec/models/notification_setting_spec.rb @@ -58,7 +58,7 @@ RSpec.describe NotificationSetting do 1.upto(4) do |i| setting = create(:notification_setting, user: user) - setting.project.update_attributes(pending_delete: true) if i.even? + setting.project.update(pending_delete: true) if i.even? end end @@ -93,4 +93,10 @@ RSpec.describe NotificationSetting do end end end + + context 'email events' do + it 'includes EXCLUDED_WATCHER_EVENTS in EMAIL_EVENTS' do + expect(described_class::EMAIL_EVENTS).to include(*described_class::EXCLUDED_WATCHER_EVENTS) + end + end end diff --git a/spec/models/project_authorization_spec.rb b/spec/models/project_authorization_spec.rb index 9e7e525b2c0..c289ee0859a 100644 --- a/spec/models/project_authorization_spec.rb +++ b/spec/models/project_authorization_spec.rb @@ -8,15 +8,15 @@ describe ProjectAuthorization do describe '.insert_authorizations' do it 'inserts the authorizations' do described_class - .insert_authorizations([[user.id, project1.id, Gitlab::Access::MASTER]]) + .insert_authorizations([[user.id, project1.id, Gitlab::Access::MAINTAINER]]) expect(user.project_authorizations.count).to eq(1) end it 'inserts rows in batches' do described_class.insert_authorizations([ - [user.id, project1.id, Gitlab::Access::MASTER], - [user.id, project2.id, Gitlab::Access::MASTER] + [user.id, project1.id, Gitlab::Access::MAINTAINER], + [user.id, project2.id, Gitlab::Access::MAINTAINER] ], 1) expect(user.project_authorizations.count).to eq(2) diff --git a/spec/models/project_feature_spec.rb b/spec/models/project_feature_spec.rb index 63c6fbda3f2..cd7f77024da 100644 --- a/spec/models/project_feature_spec.rb +++ b/spec/models/project_feature_spec.rb @@ -77,7 +77,7 @@ describe ProjectFeature do context 'repository related features' do before do - project.project_feature.update_attributes( + project.project_feature.update( merge_requests_access_level: ProjectFeature::DISABLED, builds_access_level: ProjectFeature::DISABLED, repository_access_level: ProjectFeature::PRIVATE diff --git a/spec/models/project_services/bamboo_service_spec.rb b/spec/models/project_services/bamboo_service_spec.rb index 85baaccf035..f4f7afb1b92 100644 --- a/spec/models/project_services/bamboo_service_spec.rb +++ b/spec/models/project_services/bamboo_service_spec.rb @@ -120,6 +120,14 @@ describe BambooService, :use_clean_rails_memory_store_caching do end end + describe '#execute' do + it 'runs update and build action' do + stub_update_and_build_request + + subject.execute(Gitlab::DataBuilder::Push::SAMPLE_DATA) + end + end + describe '#build_page' do it 'returns the contents of the reactive cache' do stub_reactive_cache(service, { build_page: 'foo' }, 'sha', 'ref') @@ -216,10 +224,20 @@ describe BambooService, :use_clean_rails_memory_store_caching do end end + def stub_update_and_build_request(status: 200, body: nil) + bamboo_full_url = 'http://gitlab.com/bamboo/updateAndBuild.action?buildKey=foo&os_authType=basic' + + stub_bamboo_request(bamboo_full_url, status, body) + end + def stub_request(status: 200, body: nil) - bamboo_full_url = 'http://gitlab.com/bamboo/rest/api/latest/result?label=123&os_authType=basic' + bamboo_full_url = 'http://gitlab.com/bamboo/rest/api/latest/result/byChangeset/123?os_authType=basic' + + stub_bamboo_request(bamboo_full_url, status, body) + end - WebMock.stub_request(:get, bamboo_full_url).to_return( + def stub_bamboo_request(url, status, body) + WebMock.stub_request(:get, url).to_return( status: status, headers: { 'Content-Type' => 'application/json' }, body: body diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index abdc65336ca..c01c7bc47b5 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -336,7 +336,7 @@ describe Project do end describe 'delegation' do - [:add_guest, :add_reporter, :add_developer, :add_master, :add_user, :add_users].each do |method| + [:add_guest, :add_reporter, :add_developer, :add_maintainer, :add_user, :add_users].each do |method| it { is_expected.to delegate_method(method).to(:team) } end @@ -567,15 +567,15 @@ describe Project do end it 'returns the most recent timestamp' do - project.update_attributes(updated_at: nil, - last_activity_at: timestamp, - last_repository_updated_at: timestamp - 1.hour) + project.update(updated_at: nil, + last_activity_at: timestamp, + last_repository_updated_at: timestamp - 1.hour) expect(project.last_activity_date).to be_like_time(timestamp) - project.update_attributes(updated_at: timestamp, - last_activity_at: timestamp - 1.hour, - last_repository_updated_at: nil) + project.update(updated_at: timestamp, + last_activity_at: timestamp - 1.hour, + last_repository_updated_at: nil) expect(project.last_activity_date).to be_like_time(timestamp) end @@ -1130,7 +1130,7 @@ describe Project do describe 'when a user has access to a project' do before do - project.add_user(user, Gitlab::Access::MASTER) + project.add_user(user, Gitlab::Access::MAINTAINER) end it { is_expected.to eq([project]) } @@ -1768,7 +1768,7 @@ describe Project do it 'resets project import_error' do error_message = 'Some error' mirror = create(:project_empty_repo, :import_started) - mirror.import_state.update_attributes(last_error: error_message) + mirror.import_state.update(last_error: error_message) expect { mirror.import_finish }.to change { mirror.import_error }.from(error_message).to(nil) end @@ -1929,7 +1929,7 @@ describe Project do end it 'returns false when remote mirror is disabled' do - project.remote_mirrors.first.update_attributes(enabled: false) + project.remote_mirrors.first.update(enabled: false) is_expected.to be_falsy end @@ -1959,7 +1959,7 @@ describe Project do end it 'does not sync disabled remote mirrors' do - project.remote_mirrors.first.update_attributes(enabled: false) + project.remote_mirrors.first.update(enabled: false) expect_any_instance_of(RemoteMirror).not_to receive(:sync) @@ -2292,6 +2292,28 @@ describe Project do end end + describe '#default_environment' do + let(:project) { create(:project) } + + it 'returns production environment when it exists' do + production = create(:environment, name: "production", project: project) + create(:environment, name: 'staging', project: project) + + expect(project.default_environment).to eq(production) + end + + it 'returns first environment when no production environment exists' do + create(:environment, name: 'staging', project: project) + create(:environment, name: 'foo', project: project) + + expect(project.default_environment).to eq(project.environments.first) + end + + it 'returns nil when no available environment exists' do + expect(project.default_environment).to be_nil + end + end + describe '#secret_variables_for' do let(:project) { create(:project) } @@ -2760,6 +2782,10 @@ describe Project do let(:legacy_project) { create(:project, :legacy_storage, :with_export) } let(:project) { create(:project, :with_export) } + before do + stub_feature_flags(import_export_object_storage: false) + end + it 'removes the exports directory for the project' do expect(File.exist?(project.export_path)).to be_truthy @@ -2808,12 +2834,14 @@ describe Project do let(:project) { create(:project, :with_export) } it 'removes the exported project file' do + stub_feature_flags(import_export_object_storage: false) + exported_file = project.export_project_path expect(File.exist?(exported_file)).to be_truthy - allow(FileUtils).to receive(:rm_f).and_call_original - expect(FileUtils).to receive(:rm_f).with(exported_file).and_call_original + allow(FileUtils).to receive(:rm_rf).and_call_original + expect(FileUtils).to receive(:rm_rf).with(exported_file).and_call_original project.remove_exported_project_file @@ -3468,8 +3496,8 @@ describe Project do expect(project.protected_branches).not_to be_empty expect(project.default_branch).to eq(project.protected_branches.first.name) - expect(project.protected_branches.first.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::MASTER]) - expect(project.protected_branches.first.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::MASTER]) + expect(project.protected_branches.first.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER]) + expect(project.protected_branches.first.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER]) end end end @@ -3705,7 +3733,7 @@ describe Project do end it 'does not allow access if the user cannot merge the merge request' do - create(:protected_branch, :masters_can_push, project: target_project, name: 'target-branch') + create(:protected_branch, :maintainers_can_push, project: target_project, name: 'target-branch') expect(project.branch_allows_collaboration?(user, 'awesome-feature-1')) .to be_falsy diff --git a/spec/models/project_team_spec.rb b/spec/models/project_team_spec.rb index 9978f3e9566..c4af17f4726 100644 --- a/spec/models/project_team_spec.rb +++ b/spec/models/project_team_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" describe ProjectTeam do - let(:master) { create(:user) } + let(:maintainer) { create(:user) } let(:reporter) { create(:user) } let(:guest) { create(:user) } let(:nonmember) { create(:user) } @@ -10,23 +10,23 @@ describe ProjectTeam do let(:project) { create(:project) } before do - project.add_master(master) + project.add_maintainer(maintainer) project.add_reporter(reporter) project.add_guest(guest) end describe 'members collection' do - it { expect(project.team.masters).to include(master) } - it { expect(project.team.masters).not_to include(guest) } - it { expect(project.team.masters).not_to include(reporter) } - it { expect(project.team.masters).not_to include(nonmember) } + it { expect(project.team.maintainers).to include(maintainer) } + it { expect(project.team.maintainers).not_to include(guest) } + it { expect(project.team.maintainers).not_to include(reporter) } + it { expect(project.team.maintainers).not_to include(nonmember) } end describe 'access methods' do - it { expect(project.team.master?(master)).to be_truthy } - it { expect(project.team.master?(guest)).to be_falsey } - it { expect(project.team.master?(reporter)).to be_falsey } - it { expect(project.team.master?(nonmember)).to be_falsey } + it { expect(project.team.maintainer?(maintainer)).to be_truthy } + it { expect(project.team.maintainer?(guest)).to be_falsey } + it { expect(project.team.maintainer?(reporter)).to be_falsey } + it { expect(project.team.maintainer?(nonmember)).to be_falsey } it { expect(project.team.member?(nonmember)).to be_falsey } it { expect(project.team.member?(guest)).to be_truthy } it { expect(project.team.member?(reporter, Gitlab::Access::REPORTER)).to be_truthy } @@ -40,35 +40,35 @@ describe ProjectTeam do let!(:project) { create(:project, group: group) } before do - group.add_master(master) + group.add_maintainer(maintainer) group.add_reporter(reporter) group.add_guest(guest) # If user is a group and a project member - GitLab uses highest permission - # So we add group guest as master and add group master as guest + # So we add group guest as maintainer and add group maintainer as guest # to this project to test highest access - project.add_master(guest) - project.add_guest(master) + project.add_maintainer(guest) + project.add_guest(maintainer) end describe 'members collection' do it { expect(project.team.reporters).to include(reporter) } - it { expect(project.team.masters).to include(master) } - it { expect(project.team.masters).to include(guest) } - it { expect(project.team.masters).not_to include(reporter) } - it { expect(project.team.masters).not_to include(nonmember) } + it { expect(project.team.maintainers).to include(maintainer) } + it { expect(project.team.maintainers).to include(guest) } + it { expect(project.team.maintainers).not_to include(reporter) } + it { expect(project.team.maintainers).not_to include(nonmember) } end describe 'access methods' do it { expect(project.team.reporter?(reporter)).to be_truthy } - it { expect(project.team.master?(master)).to be_truthy } - it { expect(project.team.master?(guest)).to be_truthy } - it { expect(project.team.master?(reporter)).to be_falsey } - it { expect(project.team.master?(nonmember)).to be_falsey } + it { expect(project.team.maintainer?(maintainer)).to be_truthy } + it { expect(project.team.maintainer?(guest)).to be_truthy } + it { expect(project.team.maintainer?(reporter)).to be_falsey } + it { expect(project.team.maintainer?(nonmember)).to be_falsey } it { expect(project.team.member?(nonmember)).to be_falsey } it { expect(project.team.member?(guest)).to be_truthy } - it { expect(project.team.member?(guest, Gitlab::Access::MASTER)).to be_truthy } - it { expect(project.team.member?(reporter, Gitlab::Access::MASTER)).to be_falsey } + it { expect(project.team.member?(guest, Gitlab::Access::MAINTAINER)).to be_truthy } + it { expect(project.team.member?(reporter, Gitlab::Access::MAINTAINER)).to be_falsey } it { expect(project.team.member?(nonmember, Gitlab::Access::GUEST)).to be_falsey } end end @@ -145,13 +145,13 @@ describe ProjectTeam do let(:requester) { create(:user) } before do - project.add_master(master) + project.add_maintainer(maintainer) project.add_reporter(reporter) project.add_guest(guest) project.request_access(requester) end - it { expect(project.team.find_member(master.id)).to be_a(ProjectMember) } + it { expect(project.team.find_member(maintainer.id)).to be_a(ProjectMember) } it { expect(project.team.find_member(reporter.id)).to be_a(ProjectMember) } it { expect(project.team.find_member(guest.id)).to be_a(ProjectMember) } it { expect(project.team.find_member(nonmember.id)).to be_nil } @@ -164,13 +164,13 @@ describe ProjectTeam do let(:requester) { create(:user) } before do - group.add_master(master) + group.add_maintainer(maintainer) group.add_reporter(reporter) group.add_guest(guest) group.request_access(requester) end - it { expect(project.team.find_member(master.id)).to be_a(GroupMember) } + it { expect(project.team.find_member(maintainer.id)).to be_a(GroupMember) } it { expect(project.team.find_member(reporter.id)).to be_a(GroupMember) } it { expect(project.team.find_member(guest.id)).to be_a(GroupMember) } it { expect(project.team.find_member(nonmember.id)).to be_nil } @@ -184,7 +184,7 @@ describe ProjectTeam do group = create(:group) project = create(:project, namespace: group) - group.add_master(user) + group.add_maintainer(user) expect(project.team.human_max_access(user.id)).to eq 'Maintainer' end @@ -210,13 +210,13 @@ describe ProjectTeam do context 'when project is not shared with group' do before do - project.add_master(master) + project.add_maintainer(maintainer) project.add_reporter(reporter) project.add_guest(guest) project.request_access(requester) end - it { expect(project.team.max_member_access(master.id)).to eq(Gitlab::Access::MASTER) } + it { expect(project.team.max_member_access(maintainer.id)).to eq(Gitlab::Access::MAINTAINER) } it { expect(project.team.max_member_access(reporter.id)).to eq(Gitlab::Access::REPORTER) } it { expect(project.team.max_member_access(guest.id)).to eq(Gitlab::Access::GUEST) } it { expect(project.team.max_member_access(nonmember.id)).to eq(Gitlab::Access::NO_ACCESS) } @@ -230,11 +230,11 @@ describe ProjectTeam do group: group, group_access: Gitlab::Access::DEVELOPER) - group.add_master(master) + group.add_maintainer(maintainer) group.add_reporter(reporter) end - it { expect(project.team.max_member_access(master.id)).to eq(Gitlab::Access::DEVELOPER) } + it { expect(project.team.max_member_access(maintainer.id)).to eq(Gitlab::Access::DEVELOPER) } it { expect(project.team.max_member_access(reporter.id)).to eq(Gitlab::Access::REPORTER) } it { expect(project.team.max_member_access(nonmember.id)).to eq(Gitlab::Access::NO_ACCESS) } it { expect(project.team.max_member_access(requester.id)).to eq(Gitlab::Access::NO_ACCESS) } @@ -244,7 +244,7 @@ describe ProjectTeam do project.namespace.update(share_with_group_lock: true) end - it { expect(project.team.max_member_access(master.id)).to eq(Gitlab::Access::NO_ACCESS) } + it { expect(project.team.max_member_access(maintainer.id)).to eq(Gitlab::Access::NO_ACCESS) } it { expect(project.team.max_member_access(reporter.id)).to eq(Gitlab::Access::NO_ACCESS) } end end @@ -257,13 +257,13 @@ describe ProjectTeam do end before do - group.add_master(master) + group.add_maintainer(maintainer) group.add_reporter(reporter) group.add_guest(guest) group.request_access(requester) end - it { expect(project.team.max_member_access(master.id)).to eq(Gitlab::Access::MASTER) } + it { expect(project.team.max_member_access(maintainer.id)).to eq(Gitlab::Access::MAINTAINER) } it { expect(project.team.max_member_access(reporter.id)).to eq(Gitlab::Access::REPORTER) } it { expect(project.team.max_member_access(guest.id)).to eq(Gitlab::Access::GUEST) } it { expect(project.team.max_member_access(nonmember.id)).to eq(Gitlab::Access::NO_ACCESS) } @@ -274,7 +274,7 @@ describe ProjectTeam do describe '#member?' do let(:group) { create(:group) } let(:developer) { create(:user) } - let(:master) { create(:user) } + let(:maintainer) { create(:user) } let(:personal_project) do create(:project, namespace: developer.namespace) @@ -288,11 +288,11 @@ describe ProjectTeam do let(:shared_project) { create(:project) } before do - group.add_master(master) + group.add_maintainer(maintainer) group.add_developer(developer) members_project.add_developer(developer) - members_project.add_master(master) + members_project.add_maintainer(maintainer) create(:project_group_link, project: shared_project, group: group) end @@ -318,14 +318,14 @@ describe ProjectTeam do end it 'checks for the correct minimum level access' do - expect(group_project.team.member?(developer, Gitlab::Access::MASTER)).to be(false) - expect(group_project.team.member?(master, Gitlab::Access::MASTER)).to be(true) - expect(members_project.team.member?(developer, Gitlab::Access::MASTER)).to be(false) - expect(members_project.team.member?(master, Gitlab::Access::MASTER)).to be(true) - expect(shared_project.team.member?(developer, Gitlab::Access::MASTER)).to be(false) - expect(shared_project.team.member?(master, Gitlab::Access::MASTER)).to be(false) + expect(group_project.team.member?(developer, Gitlab::Access::MAINTAINER)).to be(false) + expect(group_project.team.member?(maintainer, Gitlab::Access::MAINTAINER)).to be(true) + expect(members_project.team.member?(developer, Gitlab::Access::MAINTAINER)).to be(false) + expect(members_project.team.member?(maintainer, Gitlab::Access::MAINTAINER)).to be(true) + expect(shared_project.team.member?(developer, Gitlab::Access::MAINTAINER)).to be(false) + expect(shared_project.team.member?(maintainer, Gitlab::Access::MAINTAINER)).to be(false) expect(shared_project.team.member?(developer, Gitlab::Access::DEVELOPER)).to be(true) - expect(shared_project.team.member?(master, Gitlab::Access::DEVELOPER)).to be(true) + expect(shared_project.team.member?(maintainer, Gitlab::Access::DEVELOPER)).to be(true) end end @@ -334,7 +334,7 @@ describe ProjectTeam do let(:group) { create(:group) } let(:second_group) { create(:group) } - let(:master) { create(:user) } + let(:maintainer) { create(:user) } let(:reporter) { create(:user) } let(:guest) { create(:user) } @@ -347,23 +347,23 @@ describe ProjectTeam do let(:second_user_without_access) { create(:user) } let(:users) do - [master, reporter, promoted_guest, guest, group_developer, second_developer, user_without_access].map(&:id) + [maintainer, reporter, promoted_guest, guest, group_developer, second_developer, user_without_access].map(&:id) end let(:expected) do { - master.id => Gitlab::Access::MASTER, + maintainer.id => Gitlab::Access::MAINTAINER, reporter.id => Gitlab::Access::REPORTER, promoted_guest.id => Gitlab::Access::DEVELOPER, guest.id => Gitlab::Access::GUEST, group_developer.id => Gitlab::Access::DEVELOPER, - second_developer.id => Gitlab::Access::MASTER, + second_developer.id => Gitlab::Access::MAINTAINER, user_without_access.id => Gitlab::Access::NO_ACCESS } end before do - project.add_master(master) + project.add_maintainer(maintainer) project.add_reporter(reporter) project.add_guest(promoted_guest) project.add_guest(guest) @@ -373,16 +373,16 @@ describe ProjectTeam do group_access: Gitlab::Access::DEVELOPER ) - group.add_master(promoted_guest) + group.add_maintainer(promoted_guest) group.add_developer(group_developer) group.add_developer(second_developer) project.project_group_links.create( group: second_group, - group_access: Gitlab::Access::MASTER + group_access: Gitlab::Access::MAINTAINER ) - second_group.add_master(second_developer) + second_group.add_maintainer(second_developer) end it 'returns correct roles for different users' do diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index 942cd47325d..528f5b610d7 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -1,3 +1,4 @@ +# coding: utf-8 require "spec_helper" describe ProjectWiki do @@ -10,7 +11,6 @@ describe ProjectWiki do subject { project_wiki } - it { is_expected.to delegate_method(:empty?).to :pages } it { is_expected.to delegate_method(:repository_storage).to :project } it { is_expected.to delegate_method(:hashed_storage?).to :project } @@ -92,11 +92,19 @@ describe ProjectWiki do context "when the wiki has pages" do before do project_wiki.create_page("index", "This is an awesome new Gollum Wiki") + project_wiki.create_page("another-page", "This is another page") end describe '#empty?' do subject { super().empty? } it { is_expected.to be_falsey } + + # Re-enable this when https://gitlab.com/gitlab-org/gitaly/issues/1204 is fixed + xit 'only instantiates a Wiki page once' do + expect(WikiPage).to receive(:new).once.and_call_original + + subject + end end end end diff --git a/spec/models/protected_branch/merge_access_level_spec.rb b/spec/models/protected_branch/merge_access_level_spec.rb index f70503eadbc..612e4a0e332 100644 --- a/spec/models/protected_branch/merge_access_level_spec.rb +++ b/spec/models/protected_branch/merge_access_level_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' describe ProtectedBranch::MergeAccessLevel do - it { is_expected.to validate_inclusion_of(:access_level).in_array([Gitlab::Access::MASTER, Gitlab::Access::DEVELOPER, Gitlab::Access::NO_ACCESS]) } + it { is_expected.to validate_inclusion_of(:access_level).in_array([Gitlab::Access::MAINTAINER, Gitlab::Access::DEVELOPER, Gitlab::Access::NO_ACCESS]) } end diff --git a/spec/models/protected_branch/push_access_level_spec.rb b/spec/models/protected_branch/push_access_level_spec.rb index f161f345761..9ccdc22fd41 100644 --- a/spec/models/protected_branch/push_access_level_spec.rb +++ b/spec/models/protected_branch/push_access_level_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' describe ProtectedBranch::PushAccessLevel do - it { is_expected.to validate_inclusion_of(:access_level).in_array([Gitlab::Access::MASTER, Gitlab::Access::DEVELOPER, Gitlab::Access::NO_ACCESS]) } + it { is_expected.to validate_inclusion_of(:access_level).in_array([Gitlab::Access::MAINTAINER, Gitlab::Access::DEVELOPER, Gitlab::Access::NO_ACCESS]) } end diff --git a/spec/models/remote_mirror_spec.rb b/spec/models/remote_mirror_spec.rb index 3597b080021..c2ef0435c8e 100644 --- a/spec/models/remote_mirror_spec.rb +++ b/spec/models/remote_mirror_spec.rb @@ -85,7 +85,7 @@ describe RemoteMirror do expect(RepositoryRemoveRemoteWorker).to receive(:perform_async).with(mirror.project.id, mirror.remote_name).and_call_original - mirror.update_attributes(url: 'http://test.com') + mirror.update(url: 'http://test.com') end end end @@ -167,7 +167,7 @@ describe RemoteMirror do context 'with remote mirroring disabled' do it 'returns nil' do - remote_mirror.update_attributes(enabled: false) + remote_mirror.update(enabled: false) expect(remote_mirror.sync).to be_nil end @@ -229,7 +229,7 @@ describe RemoteMirror do end before do - remote_mirror.update_attributes(last_update_started_at: Time.now) + remote_mirror.update(last_update_started_at: Time.now) end context 'when remote mirror does not have status failed' do @@ -244,7 +244,7 @@ describe RemoteMirror do context 'when remote mirror has status failed' do it 'returns false when last update started after the timestamp' do - remote_mirror.update_attributes(update_status: 'failed') + remote_mirror.update(update_status: 'failed') expect(remote_mirror.updated_since?(timestamp)).to be false end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index cfa78c4472c..02d31098cfd 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -151,7 +151,9 @@ describe Repository do it { is_expected.to eq(['v1.1.0', 'v1.0.0', annotated_tag_name]) } after do - repository.rugged.tags.delete(annotated_tag_name) + Gitlab::GitalyClient::StorageSettings.allow_disk_access do + repository.rugged.tags.delete(annotated_tag_name) + end end end end @@ -431,6 +433,18 @@ describe Repository do it { is_expected.to be_falsey } end + + context 'non merged branch' do + subject { repository.merged_to_root_ref?('fix') } + + it { is_expected.to be_falsey } + end + + context 'non existent branch' do + subject { repository.merged_to_root_ref?('non_existent_branch') } + + it { is_expected.to be_nil } + end end describe '#can_be_merged?' do @@ -452,17 +466,11 @@ describe Repository do it { is_expected.to be_falsey } end - context 'non merged branch' do - subject { repository.merged_to_root_ref?('fix') } + context 'submodule changes that confuse rugged' do + subject { repository.can_be_merged?('update-gitlab-shell-v-6-0-1', 'update-gitlab-shell-v-6-0-3') } it { is_expected.to be_falsey } end - - context 'non existent branch' do - subject { repository.merged_to_root_ref?('non_existent_branch') } - - it { is_expected.to be_nil } - end end describe '#commit' do @@ -1014,24 +1022,6 @@ describe Repository do end end - describe '#find_branch' do - context 'fresh_repo is true' do - it 'delegates the call to raw_repository' do - expect(repository.raw_repository).to receive(:find_branch).with('master', true) - - repository.find_branch('master', fresh_repo: true) - end - end - - context 'fresh_repo is false' do - it 'delegates the call to raw_repository' do - expect(repository.raw_repository).to receive(:find_branch).with('master', false) - - repository.find_branch('master', fresh_repo: false) - end - end - end - describe '#update_branch_with_hooks' do let(:old_rev) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } # git rev-parse feature let(:new_rev) { 'a74ae73c1ccde9b974a70e82b901588071dc142a' } # commit whose parent is old_rev @@ -1861,155 +1851,61 @@ describe Repository do describe '#add_tag' do let(:user) { build_stubbed(:user) } - shared_examples 'adding tag' do - context 'with a valid target' do - it 'creates the tag' do - repository.add_tag(user, '8.5', 'master', 'foo') + context 'with a valid target' do + it 'creates the tag' do + repository.add_tag(user, '8.5', 'master', 'foo') - tag = repository.find_tag('8.5') - expect(tag).to be_present - expect(tag.message).to eq('foo') - expect(tag.dereferenced_target.id).to eq(repository.commit('master').id) - end - - it 'returns a Gitlab::Git::Tag object' do - tag = repository.add_tag(user, '8.5', 'master', 'foo') - - expect(tag).to be_a(Gitlab::Git::Tag) - end - end - - context 'with an invalid target' do - it 'returns false' do - expect(repository.add_tag(user, '8.5', 'bar', 'foo')).to be false - end + tag = repository.find_tag('8.5') + expect(tag).to be_present + expect(tag.message).to eq('foo') + expect(tag.dereferenced_target.id).to eq(repository.commit('master').id) end - end - - context 'when Gitaly operation_user_add_tag feature is enabled' do - it_behaves_like 'adding tag' - end - - context 'when Gitaly operation_user_add_tag feature is disabled', :disable_gitaly do - it_behaves_like 'adding tag' - - it 'passes commit SHA to pre-receive and update hooks and tag SHA to post-receive hook' do - pre_receive_hook = Gitlab::Git::Hook.new('pre-receive', project) - update_hook = Gitlab::Git::Hook.new('update', project) - post_receive_hook = Gitlab::Git::Hook.new('post-receive', project) - - allow(Gitlab::Git::Hook).to receive(:new) - .and_return(pre_receive_hook, update_hook, post_receive_hook) - - allow(pre_receive_hook).to receive(:trigger).and_call_original - allow(update_hook).to receive(:trigger).and_call_original - allow(post_receive_hook).to receive(:trigger).and_call_original + it 'returns a Gitlab::Git::Tag object' do tag = repository.add_tag(user, '8.5', 'master', 'foo') - commit_sha = repository.commit('master').id - tag_sha = tag.target - - expect(pre_receive_hook).to have_received(:trigger) - .with(anything, anything, anything, commit_sha, anything) - expect(update_hook).to have_received(:trigger) - .with(anything, anything, anything, commit_sha, anything) - expect(post_receive_hook).to have_received(:trigger) - .with(anything, anything, anything, tag_sha, anything) + expect(tag).to be_a(Gitlab::Git::Tag) end end - end - - describe '#rm_branch' do - shared_examples "user deleting a branch" do - it 'removes a branch' do - expect(repository).to receive(:before_remove_branch) - expect(repository).to receive(:after_remove_branch) - repository.rm_branch(user, 'feature') + context 'with an invalid target' do + it 'returns false' do + expect(repository.add_tag(user, '8.5', 'bar', 'foo')).to be false end end + end - context 'with gitaly enabled' do - it_behaves_like "user deleting a branch" - - context 'when pre hooks failed' do - before do - allow_any_instance_of(Gitlab::GitalyClient::OperationService) - .to receive(:user_delete_branch).and_raise(Gitlab::Git::PreReceiveError) - end - - it 'gets an error and does not delete the branch' do - expect do - repository.rm_branch(user, 'feature') - end.to raise_error(Gitlab::Git::PreReceiveError) + describe '#rm_branch' do + it 'removes a branch' do + expect(repository).to receive(:before_remove_branch) + expect(repository).to receive(:after_remove_branch) - expect(repository.find_branch('feature')).not_to be_nil - end - end + repository.rm_branch(user, 'feature') end - context 'with gitaly disabled', :disable_gitaly do - it_behaves_like "user deleting a branch" - - let(:old_rev) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } # git rev-parse feature - let(:blank_sha) { '0000000000000000000000000000000000000000' } - - context 'when pre hooks were successful' do - it 'runs without errors' do - expect_any_instance_of(Gitlab::Git::HooksService).to receive(:execute) - .with(git_user, repository.raw_repository, old_rev, blank_sha, 'refs/heads/feature') - - expect { repository.rm_branch(user, 'feature') }.not_to raise_error - end - - it 'deletes the branch' do - allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, nil]) - - expect { repository.rm_branch(user, 'feature') }.not_to raise_error - - expect(repository.find_branch('feature')).to be_nil - end + context 'when pre hooks failed' do + before do + allow_any_instance_of(Gitlab::GitalyClient::OperationService) + .to receive(:user_delete_branch).and_raise(Gitlab::Git::PreReceiveError) end - context 'when pre hooks failed' do - it 'gets an error' do - allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, '']) - - expect do - repository.rm_branch(user, 'feature') - end.to raise_error(Gitlab::Git::PreReceiveError) - end - - it 'does not delete the branch' do - allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, '']) + it 'gets an error and does not delete the branch' do + expect do + repository.rm_branch(user, 'feature') + end.to raise_error(Gitlab::Git::PreReceiveError) - expect do - repository.rm_branch(user, 'feature') - end.to raise_error(Gitlab::Git::PreReceiveError) - expect(repository.find_branch('feature')).not_to be_nil - end + expect(repository.find_branch('feature')).not_to be_nil end end end describe '#rm_tag' do - shared_examples 'removing tag' do - it 'removes a tag' do - expect(repository).to receive(:before_remove_tag) - - repository.rm_tag(build_stubbed(:user), 'v1.1.0') - - expect(repository.find_tag('v1.1.0')).to be_nil - end - end + it 'removes a tag' do + expect(repository).to receive(:before_remove_tag) - context 'when Gitaly operation_user_delete_tag feature is enabled' do - it_behaves_like 'removing tag' - end + repository.rm_tag(build_stubbed(:user), 'v1.1.0') - context 'when Gitaly operation_user_delete_tag feature is disabled', :skip_gitaly_mock do - it_behaves_like 'removing tag' + expect(repository.find_tag('v1.1.0')).to be_nil end end @@ -2319,8 +2215,11 @@ describe Repository do create_remote_branch('joe', 'remote_branch', masterrev) repository.add_branch(user, 'local_branch', masterrev.id) - expect(repository.remote_branches('joe').any? { |branch| branch.name == 'local_branch' }).to eq(false) - expect(repository.remote_branches('joe').any? { |branch| branch.name == 'remote_branch' }).to eq(true) + # TODO: move this test to gitaly https://gitlab.com/gitlab-org/gitaly/issues/1243 + Gitlab::GitalyClient::StorageSettings.allow_disk_access do + expect(repository.remote_branches('joe').any? { |branch| branch.name == 'local_branch' }).to eq(false) + expect(repository.remote_branches('joe').any? { |branch| branch.name == 'remote_branch' }).to eq(true) + end end end diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb index 01238a89a81..48799781b87 100644 --- a/spec/models/route_spec.rb +++ b/spec/models/route_spec.rb @@ -29,12 +29,12 @@ describe Route do context 'after update' do it 'calls #create_redirect_for_old_path' do expect(route).to receive(:create_redirect_for_old_path) - route.update_attributes(path: 'foo') + route.update(path: 'foo') end it 'calls #delete_conflicting_redirects' do expect(route).to receive(:delete_conflicting_redirects) - route.update_attributes(path: 'foo') + route.update(path: 'foo') end end @@ -70,7 +70,7 @@ describe Route do context 'path update' do context 'when route name is set' do before do - route.update_attributes(path: 'bar') + route.update(path: 'bar') end it 'updates children routes with new path' do @@ -89,7 +89,7 @@ describe Route do end it "does not fail" do - expect(route.update_attributes(path: 'bar')).to be_truthy + expect(route.update(path: 'bar')).to be_truthy end end @@ -100,7 +100,7 @@ describe Route do let!(:conflicting_redirect3) { route.create_redirect('gitlab-org') } it 'deletes the conflicting redirects' do - route.update_attributes(path: 'bar') + route.update(path: 'bar') expect(RedirectRoute.exists?(path: 'bar/test')).to be_falsey expect(RedirectRoute.exists?(path: 'bar/test/foo')).to be_falsey @@ -111,7 +111,7 @@ describe Route do context 'name update' do it 'updates children routes with new path' do - route.update_attributes(name: 'bar') + route.update(name: 'bar') expect(described_class.exists?(name: 'bar')).to be_truthy expect(described_class.exists?(name: 'bar / test')).to be_truthy @@ -123,7 +123,7 @@ describe Route do # Note: using `update_columns` to skip all validation and callbacks route.update_columns(name: nil) - expect { route.update_attributes(name: 'bar') } + expect { route.update(name: 'bar') } .to change { route.name }.from(nil).to('bar') end end diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 28c908ea425..029ad7f3e9f 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -78,7 +78,7 @@ describe Service do context 'when template is invalid' do it 'sets service template to inactive when template is invalid' do project = create(:project) - template = JiraService.new(template: true, active: true) + template = KubernetesService.new(template: true, active: true) template.save(validate: false) service = described_class.build_from_template(project.id, template) @@ -280,7 +280,7 @@ describe Service do service.save! expect do - service.update_attributes(active: false) + service.update(active: false) end.to change { service.project.has_external_issue_tracker }.from(true).to(false) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 097144d04ce..fc46551c3be 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -383,7 +383,7 @@ describe User do let(:secondary) { create(:email, :confirmed, email: 'secondary@example.com', user: user) } it 'allows a verfied secondary email to be used as the primary without needing reconfirmation' do - user.update_attributes!(email: secondary.email) + user.update!(email: secondary.email) user.reload expect(user.email).to eq secondary.email expect(user.unconfirmed_email).to eq nil @@ -405,11 +405,11 @@ describe User do it 'gets called when email updated' do expect(@user).to receive(:update_emails_with_primary_email) - @user.update_attributes!(email: 'new_primary@example.com') + @user.update!(email: 'new_primary@example.com') end it 'adds old primary to secondary emails when secondary is a new email ' do - @user.update_attributes!(email: 'new_primary@example.com') + @user.update!(email: 'new_primary@example.com') @user.reload expect(@user.emails.count).to eq 2 @@ -417,7 +417,7 @@ describe User do end it 'adds old primary to secondary emails if secondary is becoming a primary' do - @user.update_attributes!(email: @secondary.email) + @user.update!(email: @secondary.email) @user.reload expect(@user.emails.count).to eq 1 @@ -425,7 +425,7 @@ describe User do end it 'transfers old confirmation values into new secondary' do - @user.update_attributes!(email: @secondary.email) + @user.update!(email: @secondary.email) @user.reload expect(@user.emails.count).to eq 1 @@ -494,12 +494,12 @@ describe User do it 'does nothing when the name is updated' do expect(user).not_to receive(:update_invalid_gpg_signatures) - user.update_attributes!(name: 'Bette') + user.update!(name: 'Bette') end it 'synchronizes the gpg keys when the email is updated' do expect(user).to receive(:update_invalid_gpg_signatures).at_most(:twice) - user.update_attributes!(email: 'shawnee.ritchie@denesik.com') + user.update!(email: 'shawnee.ritchie@denesik.com') end end end @@ -617,13 +617,13 @@ describe User do it 'receives callback when external changes' do expect(user).to receive(:ensure_user_rights_and_limits) - user.update_attributes(external: false) + user.update(external: false) end it 'ensures correct rights and limits for user' do stub_config_setting(default_can_create_group: true) - expect { user.update_attributes(external: false) }.to change { user.can_create_group }.to(true) + expect { user.update(external: false) }.to change { user.can_create_group }.to(true) .and change { user.projects_limit }.to(Gitlab::CurrentSettings.default_projects_limit) end end @@ -634,11 +634,11 @@ describe User do it 'receives callback when external changes' do expect(user).to receive(:ensure_user_rights_and_limits) - user.update_attributes(external: true) + user.update(external: true) end it 'ensures correct rights and limits for user' do - expect { user.update_attributes(external: true) }.to change { user.can_create_group }.to(false) + expect { user.update(external: true) }.to change { user.can_create_group }.to(false) .and change { user.projects_limit }.to(0) end end @@ -700,7 +700,7 @@ describe User do @project = create(:project, namespace: @user.namespace) @project_2 = create(:project, group: create(:group)) do |project| - project.add_master(@user) + project.add_maintainer(@user) end @project_3 = create(:project, group: create(:group)) do |project| project.add_developer(@user) @@ -836,7 +836,7 @@ describe User do before do # add user to project - project.add_master(user) + project.add_maintainer(user) # create invite to projet create(:project_member, :developer, project: project, invite_token: '1234', invite_email: 'inviteduser1@example.com') @@ -1581,8 +1581,8 @@ describe User do let!(:merge_event) { create(:event, :created, project: project3, target: merge_request, author: subject) } before do - project1.add_master(subject) - project2.add_master(subject) + project1.add_maintainer(subject) + project2.add_maintainer(subject) end it "includes IDs for projects the user has pushed to" do @@ -1663,8 +1663,8 @@ describe User do let!(:project) { create(:project, group: project_group) } before do - private_group.add_user(user, Gitlab::Access::MASTER) - project.add_master(user) + private_group.add_user(user, Gitlab::Access::MAINTAINER) + project.add_maintainer(user) end subject { user.authorized_groups } @@ -1678,7 +1678,7 @@ describe User do let!(:child_group) { create(:group, parent: parent_group) } before do - parent_group.add_user(user, Gitlab::Access::MASTER) + parent_group.add_user(user, Gitlab::Access::MAINTAINER) end subject { user.membership_groups } @@ -1696,7 +1696,7 @@ describe User do it 'includes projects that belong to a user, but no other projects' do owned = create(:project, :private, namespace: user.namespace) - member = create(:project, :private).tap { |p| p.add_master(user) } + member = create(:project, :private).tap { |p| p.add_maintainer(user) } other = create(:project) expect(subject).to include(owned) @@ -1726,11 +1726,11 @@ describe User do .to contain_exactly(project) end - it 'includes projects for which the user is a master' do + it 'includes projects for which the user is a maintainer' do user = create(:user) project = create(:project, :private) - project.add_master(user) + project.add_maintainer(user) expect(user.authorized_projects(Gitlab::Access::REPORTER)) .to contain_exactly(project) @@ -1824,10 +1824,10 @@ describe User do it 'includes projects for which the user access level is above or equal to reporter' do reporter_project = create(:project) { |p| p.add_reporter(user) } developer_project = create(:project) { |p| p.add_developer(user) } - master_project = create(:project) { |p| p.add_master(user) } + maintainer_project = create(:project) { |p| p.add_maintainer(user) } - expect(user.projects_where_can_admin_issues.to_a).to match_array([master_project, developer_project, reporter_project]) - expect(user.can?(:admin_issue, master_project)).to eq(true) + expect(user.projects_where_can_admin_issues.to_a).to match_array([maintainer_project, developer_project, reporter_project]) + expect(user.can?(:admin_issue, maintainer_project)).to eq(true) expect(user.can?(:admin_issue, developer_project)).to eq(true) expect(user.can?(:admin_issue, reporter_project)).to eq(true) end @@ -1907,9 +1907,9 @@ describe User do end shared_examples :member do - context 'when the user is a master' do + context 'when the user is a maintainer' do before do - add_user(:master) + add_user(:maintainer) end it 'loads' do @@ -2461,18 +2461,20 @@ describe User do it 'changes the namespace (just to compare to when username is not changed)' do expect do - user.update_attributes!(username: new_username) + Timecop.freeze(1.second.from_now) do + user.update!(username: new_username) + end end.to change { user.namespace.updated_at } end it 'updates the namespace name' do - user.update_attributes!(username: new_username) + user.update!(username: new_username) expect(user.namespace.name).to eq(new_username) end it 'updates the namespace path' do - user.update_attributes!(username: new_username) + user.update!(username: new_username) expect(user.namespace.path).to eq(new_username) end @@ -2481,12 +2483,12 @@ describe User do let!(:conflicting_namespace) { create(:group, path: new_username) } it 'causes the user save to fail' do - expect(user.update_attributes(username: new_username)).to be_falsey + expect(user.update(username: new_username)).to be_falsey expect(user.namespace.errors.messages[:path].first).to eq('has already been taken') end it 'adds the namespace errors to the user' do - user.update_attributes(username: new_username) + user.update(username: new_username) expect(user.errors.full_messages.first).to eq('Username has already been taken') end @@ -2496,7 +2498,7 @@ describe User do context 'when the username is not changed' do it 'does not change the namespace' do expect do - user.update_attributes!(email: 'asdf@asdf.com') + user.update!(email: 'asdf@asdf.com') end.not_to change { user.namespace.updated_at } end end @@ -2526,7 +2528,7 @@ describe User do expect(system_hook_service).to receive(:execute_hooks_for).with(user, :rename) expect(user).to receive(:system_hook_service).and_return(system_hook_service) - user.update_attributes!(username: new_username) + user.update!(username: new_username) end end @@ -2534,7 +2536,7 @@ describe User do it 'does not trigger system hook' do expect(user).not_to receive(:system_hook_service) - user.update_attributes!(email: 'asdf@asdf.com') + user.update!(email: 'asdf@asdf.com') end end end @@ -2666,20 +2668,20 @@ describe User do let(:user) { create(:user) } let(:group) { create(:group) } let(:owner_project) { create(:project, group: group) } - let(:master_project) { create(:project) } + let(:maintainer_project) { create(:project) } let(:reporter_project) { create(:project) } let(:developer_project) { create(:project) } let(:guest_project) { create(:project) } let(:no_access_project) { create(:project) } let(:projects) do - [owner_project, master_project, reporter_project, developer_project, guest_project, no_access_project].map(&:id) + [owner_project, maintainer_project, reporter_project, developer_project, guest_project, no_access_project].map(&:id) end let(:expected) do { owner_project.id => Gitlab::Access::OWNER, - master_project.id => Gitlab::Access::MASTER, + maintainer_project.id => Gitlab::Access::MAINTAINER, reporter_project.id => Gitlab::Access::REPORTER, developer_project.id => Gitlab::Access::DEVELOPER, guest_project.id => Gitlab::Access::GUEST, @@ -2689,7 +2691,7 @@ describe User do before do create(:group_member, user: user, group: group) - master_project.add_master(user) + maintainer_project.add_maintainer(user) reporter_project.add_reporter(user) developer_project.add_developer(user) guest_project.add_guest(user) @@ -2716,14 +2718,14 @@ describe User do end it 'only requests the extra projects when uncached projects are passed' do - second_master_project = create(:project) + second_maintainer_project = create(:project) second_developer_project = create(:project) - second_master_project.add_master(user) + second_maintainer_project.add_maintainer(user) second_developer_project.add_developer(user) - all_projects = projects + [second_master_project.id, second_developer_project.id] + all_projects = projects + [second_maintainer_project.id, second_developer_project.id] - expected_all = expected.merge(second_master_project.id => Gitlab::Access::MASTER, + expected_all = expected.merge(second_maintainer_project.id => Gitlab::Access::MAINTAINER, second_developer_project.id => Gitlab::Access::DEVELOPER) access_levels(projects) @@ -2731,7 +2733,7 @@ describe User do queries = ActiveRecord::QueryRecorder.new { access_levels(all_projects) } expect(queries.count).to eq(1) - expect(queries.log_message).to match(/\W(#{second_master_project.id}, #{second_developer_project.id})\W/) + expect(queries.log_message).to match(/\W(#{second_maintainer_project.id}, #{second_developer_project.id})\W/) expect(access_levels(all_projects)).to eq(expected_all) end end @@ -2745,20 +2747,20 @@ describe User do shared_examples 'max member access for groups' do let(:user) { create(:user) } let(:owner_group) { create(:group) } - let(:master_group) { create(:group) } + let(:maintainer_group) { create(:group) } let(:reporter_group) { create(:group) } let(:developer_group) { create(:group) } let(:guest_group) { create(:group) } let(:no_access_group) { create(:group) } let(:groups) do - [owner_group, master_group, reporter_group, developer_group, guest_group, no_access_group].map(&:id) + [owner_group, maintainer_group, reporter_group, developer_group, guest_group, no_access_group].map(&:id) end let(:expected) do { owner_group.id => Gitlab::Access::OWNER, - master_group.id => Gitlab::Access::MASTER, + maintainer_group.id => Gitlab::Access::MAINTAINER, reporter_group.id => Gitlab::Access::REPORTER, developer_group.id => Gitlab::Access::DEVELOPER, guest_group.id => Gitlab::Access::GUEST, @@ -2768,7 +2770,7 @@ describe User do before do owner_group.add_owner(user) - master_group.add_master(user) + maintainer_group.add_maintainer(user) reporter_group.add_reporter(user) developer_group.add_developer(user) guest_group.add_guest(user) @@ -2795,14 +2797,14 @@ describe User do end it 'only requests the extra groups when uncached groups are passed' do - second_master_group = create(:group) + second_maintainer_group = create(:group) second_developer_group = create(:group) - second_master_group.add_master(user) + second_maintainer_group.add_maintainer(user) second_developer_group.add_developer(user) - all_groups = groups + [second_master_group.id, second_developer_group.id] + all_groups = groups + [second_maintainer_group.id, second_developer_group.id] - expected_all = expected.merge(second_master_group.id => Gitlab::Access::MASTER, + expected_all = expected.merge(second_maintainer_group.id => Gitlab::Access::MAINTAINER, second_developer_group.id => Gitlab::Access::DEVELOPER) access_levels(groups) @@ -2810,7 +2812,7 @@ describe User do queries = ActiveRecord::QueryRecorder.new { access_levels(all_groups) } expect(queries.count).to eq(1) - expect(queries.log_message).to match(/\W(#{second_master_group.id}, #{second_developer_group.id})\W/) + expect(queries.log_message).to match(/\W(#{second_maintainer_group.id}, #{second_developer_group.id})\W/) expect(access_levels(all_groups)).to eq(expected_all) end end diff --git a/spec/policies/ci/build_policy_spec.rb b/spec/policies/ci/build_policy_spec.rb index eead55d33ca..79a616899fa 100644 --- a/spec/policies/ci/build_policy_spec.rb +++ b/spec/policies/ci/build_policy_spec.rb @@ -204,18 +204,18 @@ describe Ci::BuildPolicy do end end - context 'when a master erases a build' do + context 'when a maintainer erases a build' do before do - project.add_master(user) + project.add_maintainer(user) end - context 'when masters can push to the branch' do + context 'when maintainers can push to the branch' do before do - create(:protected_branch, :masters_can_push, + create(:protected_branch, :maintainers_can_push, name: build.ref, project: project) end - context 'when the build was created by the master' do + context 'when the build was created by the maintainer' do let(:owner) { user } it { expect(policy).to be_allowed :erase_build } diff --git a/spec/policies/ci/pipeline_schedule_policy_spec.rb b/spec/policies/ci/pipeline_schedule_policy_spec.rb index c0c3eda4911..f1d3cd04e32 100644 --- a/spec/policies/ci/pipeline_schedule_policy_spec.rb +++ b/spec/policies/ci/pipeline_schedule_policy_spec.rb @@ -77,9 +77,9 @@ describe Ci::PipelineSchedulePolicy, :models do end end - describe 'rules for a master' do + describe 'rules for a maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it 'includes abilities to do do all operations on pipeline schedule' do @@ -93,8 +93,8 @@ describe Ci::PipelineSchedulePolicy, :models do let(:owner) { create(:user) } before do - project.add_master(owner) - project.add_master(user) + project.add_maintainer(owner) + project.add_maintainer(user) pipeline_schedule.update(owner: owner) end diff --git a/spec/policies/ci/trigger_policy_spec.rb b/spec/policies/ci/trigger_policy_spec.rb index 14630748c90..d8a63066265 100644 --- a/spec/policies/ci/trigger_policy_spec.rb +++ b/spec/policies/ci/trigger_policy_spec.rb @@ -43,9 +43,9 @@ describe Ci::TriggerPolicy do context 'when owner is undefined' do let(:owner) { nil } - context 'when user is master of the project' do + context 'when user is maintainer of the project' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'allows to admin and manage trigger' @@ -67,9 +67,9 @@ describe Ci::TriggerPolicy do context 'when owner is an user' do let(:owner) { user } - context 'when user is master of the project' do + context 'when user is maintainer of the project' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'allows to admin and manage trigger' @@ -79,9 +79,9 @@ describe Ci::TriggerPolicy do context 'when owner is another user' do let(:owner) { create(:user) } - context 'when user is master of the project' do + context 'when user is maintainer of the project' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'allows to manage trigger' diff --git a/spec/policies/clusters/cluster_policy_spec.rb b/spec/policies/clusters/cluster_policy_spec.rb index 4207f42b07f..ced969830d8 100644 --- a/spec/policies/clusters/cluster_policy_spec.rb +++ b/spec/policies/clusters/cluster_policy_spec.rb @@ -16,9 +16,9 @@ describe Clusters::ClusterPolicy, :models do it { expect(policy).to be_disallowed :admin_cluster } end - context 'when master' do + context 'when maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it { expect(policy).to be_allowed :update_cluster } diff --git a/spec/policies/deploy_key_policy_spec.rb b/spec/policies/deploy_key_policy_spec.rb index ca7b7fe7ef7..e7263d49613 100644 --- a/spec/policies/deploy_key_policy_spec.rb +++ b/spec/policies/deploy_key_policy_spec.rb @@ -12,7 +12,7 @@ describe DeployKeyPolicy do let(:project) { create(:project_empty_repo) } before do - project.add_master(current_user) + project.add_maintainer(current_user) project.deploy_keys << deploy_key end diff --git a/spec/policies/deploy_token_policy_spec.rb b/spec/policies/deploy_token_policy_spec.rb index eea287d895e..cef5a4a22bc 100644 --- a/spec/policies/deploy_token_policy_spec.rb +++ b/spec/policies/deploy_token_policy_spec.rb @@ -8,15 +8,15 @@ describe DeployTokenPolicy do subject { described_class.new(current_user, deploy_token) } describe 'creating a deploy key' do - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(current_user) + project.add_maintainer(current_user) end it { is_expected.to be_allowed(:create_deploy_token) } end - context 'when user is not master' do + context 'when user is not maintainer' do before do project.add_developer(current_user) end @@ -26,15 +26,15 @@ describe DeployTokenPolicy do end describe 'updating a deploy key' do - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(current_user) + project.add_maintainer(current_user) end it { is_expected.to be_allowed(:update_deploy_token) } end - context 'when user is not master' do + context 'when user is not maintainer' do before do project.add_developer(current_user) end diff --git a/spec/policies/environment_policy_spec.rb b/spec/policies/environment_policy_spec.rb index de4cb5b30c5..0442b032e89 100644 --- a/spec/policies/environment_policy_spec.rb +++ b/spec/policies/environment_policy_spec.rb @@ -1,57 +1,101 @@ require 'spec_helper' describe EnvironmentPolicy do - let(:user) { create(:user) } - let(:project) { create(:project, :repository) } + using RSpec::Parameterized::TableSyntax - let(:environment) do - create(:environment, :with_review_app, project: project) - end + let(:user) { create(:user) } let(:policy) do described_class.new(user, environment) end describe '#rules' do - context 'when user does not have access to the project' do - let(:project) { create(:project, :private, :repository) } + shared_examples 'project permissions' do + context 'with stop action' do + let(:environment) do + create(:environment, :with_review_app, project: project) + end - it 'does not include ability to stop environment' do - expect(policy).to be_disallowed :stop_environment - end - end + where(:access_level, :allowed?) do + nil | false + :guest | false + :reporter | false + :developer | true + :maintainer | true + end - context 'when anonymous user has access to the project' do - let(:project) { create(:project, :public, :repository) } + with_them do + before do + project.add_user(user, access_level) unless access_level.nil? + end - it 'does not include ability to stop environment' do - expect(policy).to be_disallowed :stop_environment - end - end + it { expect(policy.allowed?(:stop_environment)).to be allowed? } + end - context 'when team member has access to the project' do - let(:project) { create(:project, :public, :repository) } + context 'when an admin user' do + let(:user) { create(:user, :admin) } - before do - project.add_developer(user) - end + it { expect(policy).to be_allowed :stop_environment } + end + + context 'with protected branch' do + with_them do + before do + project.add_user(user, access_level) unless access_level.nil? + create(:protected_branch, :no_one_can_push, + name: 'master', project: project) + end - context 'when team member has ability to stop environment' do - it 'does includes ability to stop environment' do - expect(policy).to be_allowed :stop_environment + it { expect(policy).to be_disallowed :stop_environment } + end + + context 'when an admin user' do + let(:user) { create(:user, :admin) } + + it { expect(policy).to be_allowed :stop_environment } + end end end - context 'when team member has no ability to stop environment' do - before do - create(:protected_branch, :no_one_can_push, - name: 'master', project: project) + context 'without stop action' do + let(:environment) do + create(:environment, project: project) + end + + where(:access_level, :allowed?) do + nil | false + :guest | false + :reporter | false + :developer | false + :maintainer | true end - it 'does not include ability to stop environment' do - expect(policy).to be_disallowed :stop_environment + with_them do + before do + project.add_user(user, access_level) unless access_level.nil? + end + + it { expect(policy.allowed?(:stop_environment)).to be allowed? } + end + + context 'when an admin user' do + let(:user) { create(:user, :admin) } + + it { expect(policy).to be_allowed :stop_environment } end end end + + context 'when project is public' do + let(:project) { create(:project, :public, :repository) } + + include_examples 'project permissions' + end + + context 'when project is private' do + let(:project) { create(:project, :private, :repository) } + + include_examples 'project permissions' + end end end diff --git a/spec/policies/global_policy_spec.rb b/spec/policies/global_policy_spec.rb index 873673b50ef..a2047b54deb 100644 --- a/spec/policies/global_policy_spec.rb +++ b/spec/policies/global_policy_spec.rb @@ -65,12 +65,12 @@ describe GlobalPolicy do it { is_expected.not_to be_allowed(:create_fork) } end - context "when user is a master in a group" do + context "when user is a maintainer in a group" do let(:group) { create(:group) } let(:current_user) { create(:user, projects_limit: 0) } before do - group.add_master(current_user) + group.add_maintainer(current_user) end it { is_expected.to be_allowed(:create_fork) } diff --git a/spec/policies/group_policy_spec.rb b/spec/policies/group_policy_spec.rb index 9b5c290b9f9..35951251bc5 100644 --- a/spec/policies/group_policy_spec.rb +++ b/spec/policies/group_policy_spec.rb @@ -4,18 +4,22 @@ describe GroupPolicy do let(:guest) { create(:user) } let(:reporter) { create(:user) } let(:developer) { create(:user) } - let(:master) { create(:user) } + let(:maintainer) { create(:user) } let(:owner) { create(:user) } let(:admin) { create(:admin) } let(:group) { create(:group, :private) } - let(:guest_permissions) { [:read_label, :read_group, :upload_file, :read_namespace] } + let(:guest_permissions) do + [:read_label, :read_group, :upload_file, :read_namespace, :read_group_activity, + :read_group_issues, :read_group_boards, :read_group_labels, :read_group_milestones, + :read_group_merge_requests] + end let(:reporter_permissions) { [:admin_label] } let(:developer_permissions) { [:admin_milestones] } - let(:master_permissions) do + let(:maintainer_permissions) do [ :create_projects ] @@ -35,7 +39,7 @@ describe GroupPolicy do group.add_guest(guest) group.add_reporter(reporter) group.add_developer(developer) - group.add_master(master) + group.add_maintainer(maintainer) group.add_owner(owner) end @@ -58,7 +62,7 @@ describe GroupPolicy do expect_disallowed(:upload_file) expect_disallowed(*reporter_permissions) expect_disallowed(*developer_permissions) - expect_disallowed(*master_permissions) + expect_disallowed(*maintainer_permissions) expect_disallowed(*owner_permissions) expect_disallowed(:read_namespace) end @@ -93,7 +97,7 @@ describe GroupPolicy do expect_allowed(*guest_permissions) expect_disallowed(*reporter_permissions) expect_disallowed(*developer_permissions) - expect_disallowed(*master_permissions) + expect_disallowed(*maintainer_permissions) expect_disallowed(*owner_permissions) end end @@ -105,7 +109,7 @@ describe GroupPolicy do expect_allowed(*guest_permissions) expect_allowed(*reporter_permissions) expect_disallowed(*developer_permissions) - expect_disallowed(*master_permissions) + expect_disallowed(*maintainer_permissions) expect_disallowed(*owner_permissions) end end @@ -117,19 +121,19 @@ describe GroupPolicy do expect_allowed(*guest_permissions) expect_allowed(*reporter_permissions) expect_allowed(*developer_permissions) - expect_disallowed(*master_permissions) + expect_disallowed(*maintainer_permissions) expect_disallowed(*owner_permissions) end end - context 'master' do - let(:current_user) { master } + context 'maintainer' do + let(:current_user) { maintainer } it do expect_allowed(*guest_permissions) expect_allowed(*reporter_permissions) expect_allowed(*developer_permissions) - expect_allowed(*master_permissions) + expect_allowed(*maintainer_permissions) expect_disallowed(*owner_permissions) end end @@ -143,7 +147,7 @@ describe GroupPolicy do expect_allowed(*guest_permissions) expect_allowed(*reporter_permissions) expect_allowed(*developer_permissions) - expect_allowed(*master_permissions) + expect_allowed(*maintainer_permissions) expect_allowed(*owner_permissions) end end @@ -157,7 +161,7 @@ describe GroupPolicy do expect_allowed(*guest_permissions) expect_allowed(*reporter_permissions) expect_allowed(*developer_permissions) - expect_allowed(*master_permissions) + expect_allowed(*maintainer_permissions) expect_allowed(*owner_permissions) end end @@ -199,7 +203,7 @@ describe GroupPolicy do nested_group.add_guest(guest) nested_group.add_guest(reporter) nested_group.add_guest(developer) - nested_group.add_guest(master) + nested_group.add_guest(maintainer) group.owners.destroy_all @@ -216,7 +220,7 @@ describe GroupPolicy do expect_disallowed(*guest_permissions) expect_disallowed(*reporter_permissions) expect_disallowed(*developer_permissions) - expect_disallowed(*master_permissions) + expect_disallowed(*maintainer_permissions) expect_disallowed(*owner_permissions) end end @@ -228,7 +232,7 @@ describe GroupPolicy do expect_allowed(*guest_permissions) expect_disallowed(*reporter_permissions) expect_disallowed(*developer_permissions) - expect_disallowed(*master_permissions) + expect_disallowed(*maintainer_permissions) expect_disallowed(*owner_permissions) end end @@ -240,7 +244,7 @@ describe GroupPolicy do expect_allowed(*guest_permissions) expect_allowed(*reporter_permissions) expect_disallowed(*developer_permissions) - expect_disallowed(*master_permissions) + expect_disallowed(*maintainer_permissions) expect_disallowed(*owner_permissions) end end @@ -252,19 +256,19 @@ describe GroupPolicy do expect_allowed(*guest_permissions) expect_allowed(*reporter_permissions) expect_allowed(*developer_permissions) - expect_disallowed(*master_permissions) + expect_disallowed(*maintainer_permissions) expect_disallowed(*owner_permissions) end end - context 'master' do - let(:current_user) { master } + context 'maintainer' do + let(:current_user) { maintainer } it do expect_allowed(*guest_permissions) expect_allowed(*reporter_permissions) expect_allowed(*developer_permissions) - expect_allowed(*master_permissions) + expect_allowed(*maintainer_permissions) expect_disallowed(*owner_permissions) end end @@ -278,7 +282,7 @@ describe GroupPolicy do expect_allowed(*guest_permissions) expect_allowed(*reporter_permissions) expect_allowed(*developer_permissions) - expect_allowed(*master_permissions) + expect_allowed(*maintainer_permissions) expect_allowed(*owner_permissions) end end diff --git a/spec/policies/project_policy_spec.rb b/spec/policies/project_policy_spec.rb index 6d4676c25a5..dd3fa4e6a51 100644 --- a/spec/policies/project_policy_spec.rb +++ b/spec/policies/project_policy_spec.rb @@ -4,7 +4,7 @@ describe ProjectPolicy do set(:guest) { create(:user) } set(:reporter) { create(:user) } set(:developer) { create(:user) } - set(:master) { create(:user) } + set(:maintainer) { create(:user) } set(:owner) { create(:user) } set(:admin) { create(:admin) } let(:project) { create(:project, :public, namespace: owner.namespace) } @@ -42,7 +42,7 @@ describe ProjectPolicy do ] end - let(:base_master_permissions) do + let(:base_maintainer_permissions) do %i[ push_to_delete_protected_branch update_project_snippet update_environment update_deployment admin_project_snippet @@ -70,15 +70,15 @@ describe ProjectPolicy do # Used in EE specs let(:additional_guest_permissions) { [] } let(:additional_reporter_permissions) { [] } - let(:additional_master_permissions) { [] } + let(:additional_maintainer_permissions) { [] } let(:guest_permissions) { base_guest_permissions + additional_guest_permissions } let(:reporter_permissions) { base_reporter_permissions + additional_reporter_permissions } - let(:master_permissions) { base_master_permissions + additional_master_permissions } + let(:maintainer_permissions) { base_maintainer_permissions + additional_maintainer_permissions } before do project.add_guest(guest) - project.add_master(master) + project.add_maintainer(maintainer) project.add_developer(developer) project.add_reporter(reporter) end @@ -276,7 +276,7 @@ describe ProjectPolicy do expect_disallowed(*reporter_public_build_permissions) expect_disallowed(*team_member_reporter_permissions) expect_disallowed(*developer_permissions) - expect_disallowed(*master_permissions) + expect_disallowed(*maintainer_permissions) expect_disallowed(*owner_permissions) end @@ -326,7 +326,7 @@ describe ProjectPolicy do expect_allowed(*reporter_permissions) expect_allowed(*team_member_reporter_permissions) expect_disallowed(*developer_permissions) - expect_disallowed(*master_permissions) + expect_disallowed(*maintainer_permissions) expect_disallowed(*owner_permissions) end @@ -347,7 +347,7 @@ describe ProjectPolicy do expect_allowed(*reporter_permissions) expect_allowed(*team_member_reporter_permissions) expect_allowed(*developer_permissions) - expect_disallowed(*master_permissions) + expect_disallowed(*maintainer_permissions) expect_disallowed(*owner_permissions) end @@ -357,23 +357,23 @@ describe ProjectPolicy do end end - shared_examples 'project policies as master' do + shared_examples 'project policies as maintainer' do context 'abilities for non-public projects' do let(:project) { create(:project, namespace: owner.namespace) } - subject { described_class.new(master, project) } + subject { described_class.new(maintainer, project) } it do expect_allowed(*guest_permissions) expect_allowed(*reporter_permissions) expect_allowed(*team_member_reporter_permissions) expect_allowed(*developer_permissions) - expect_allowed(*master_permissions) + expect_allowed(*maintainer_permissions) expect_disallowed(*owner_permissions) end it_behaves_like 'archived project policies' do - let(:regular_abilities) { master_permissions } + let(:regular_abilities) { maintainer_permissions } end end end @@ -389,7 +389,7 @@ describe ProjectPolicy do expect_allowed(*reporter_permissions) expect_allowed(*team_member_reporter_permissions) expect_allowed(*developer_permissions) - expect_allowed(*master_permissions) + expect_allowed(*maintainer_permissions) expect_allowed(*owner_permissions) end @@ -410,7 +410,7 @@ describe ProjectPolicy do expect_allowed(*reporter_permissions) expect_disallowed(*team_member_reporter_permissions) expect_allowed(*developer_permissions) - expect_allowed(*master_permissions) + expect_allowed(*maintainer_permissions) expect_allowed(*owner_permissions) end @@ -424,7 +424,7 @@ describe ProjectPolicy do it_behaves_like 'project policies as guest' it_behaves_like 'project policies as reporter' it_behaves_like 'project policies as developer' - it_behaves_like 'project policies as master' + it_behaves_like 'project policies as maintainer' it_behaves_like 'project policies as owner' it_behaves_like 'project policies as admin' diff --git a/spec/policies/protected_branch_policy_spec.rb b/spec/policies/protected_branch_policy_spec.rb index b39de42d721..1587196754d 100644 --- a/spec/policies/protected_branch_policy_spec.rb +++ b/spec/policies/protected_branch_policy_spec.rb @@ -8,8 +8,8 @@ describe ProtectedBranchPolicy do subject { described_class.new(user, protected_branch) } - it 'branches can be updated via project masters' do - project.add_master(user) + it 'branches can be updated via project maintainers' do + project.add_maintainer(user) is_expected.to be_allowed(:update_protected_branch) end diff --git a/spec/presenters/merge_request_presenter_spec.rb b/spec/presenters/merge_request_presenter_spec.rb index e3b37739e8e..46ba6f442f5 100644 --- a/spec/presenters/merge_request_presenter_spec.rb +++ b/spec/presenters/merge_request_presenter_spec.rb @@ -270,7 +270,7 @@ describe MergeRequestPresenter do context 'when can create issue and issues enabled' do it 'returns path' do allow(project).to receive(:issues_enabled?) { true } - project.add_master(user) + project.add_maintainer(user) is_expected .to eq("/#{resource.project.full_path}/issues/new?merge_request_to_resolve_discussions_of=#{resource.iid}") @@ -288,7 +288,7 @@ describe MergeRequestPresenter do context 'when issues disabled' do it 'returns nil' do allow(project).to receive(:issues_enabled?) { false } - project.add_master(user) + project.add_maintainer(user) is_expected.to be_nil end @@ -307,7 +307,7 @@ describe MergeRequestPresenter do context 'when merge request enabled and has permission' do it 'has remove_wip_path' do allow(project).to receive(:merge_requests_enabled?) { true } - project.add_master(user) + project.add_maintainer(user) is_expected .to eq("/#{resource.project.full_path}/merge_requests/#{resource.iid}/remove_wip") diff --git a/spec/presenters/project_presenter_spec.rb b/spec/presenters/project_presenter_spec.rb index 830d2ee3b20..01085dbcb49 100644 --- a/spec/presenters/project_presenter_spec.rb +++ b/spec/presenters/project_presenter_spec.rb @@ -326,7 +326,7 @@ describe ProjectPresenter do context 'when user can admin pipeline and CI yml does not exists' do it 'returns anchor data' do - project.add_master(user) + project.add_maintainer(user) allow(project).to receive(:auto_devops_enabled?).and_return(false) allow(project.repository).to receive(:gitlab_ci_yml).and_return(nil) @@ -340,7 +340,7 @@ describe ProjectPresenter do describe '#kubernetes_cluster_anchor_data' do context 'when user can create Kubernetes cluster' do it 'returns link to cluster if only one exists' do - project.add_master(user) + project.add_maintainer(user) cluster = create(:cluster, projects: [project]) expect(presenter.kubernetes_cluster_anchor_data).to eq(OpenStruct.new(enabled: true, @@ -349,7 +349,7 @@ describe ProjectPresenter do end it 'returns link to clusters page if more than one exists' do - project.add_master(user) + project.add_maintainer(user) create(:cluster, :production_environment, projects: [project]) create(:cluster, projects: [project]) @@ -359,7 +359,7 @@ describe ProjectPresenter do end it 'returns link to create a cluster if no cluster exists' do - project.add_master(user) + project.add_maintainer(user) expect(presenter.kubernetes_cluster_anchor_data).to eq(OpenStruct.new(enabled: false, label: 'Add Kubernetes cluster', diff --git a/spec/requests/api/access_requests_spec.rb b/spec/requests/api/access_requests_spec.rb index 24389f28b21..e13129967b2 100644 --- a/spec/requests/api/access_requests_spec.rb +++ b/spec/requests/api/access_requests_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' describe API::AccessRequests do - set(:master) { create(:user) } + set(:maintainer) { create(:user) } set(:developer) { create(:user) } set(:access_requester) { create(:user) } set(:stranger) { create(:user) } set(:project) do - create(:project, :public, :access_requestable, creator_id: master.id, namespace: master.namespace) do |project| + create(:project, :public, :access_requestable, creator_id: maintainer.id, namespace: maintainer.namespace) do |project| project.add_developer(developer) - project.add_master(master) + project.add_maintainer(maintainer) project.request_access(access_requester) end end @@ -17,7 +17,7 @@ describe API::AccessRequests do set(:group) do create(:group, :public, :access_requestable) do |group| group.add_developer(developer) - group.add_owner(master) + group.add_owner(maintainer) group.request_access(access_requester) end end @@ -28,7 +28,7 @@ describe API::AccessRequests do let(:route) { get api("/#{source_type.pluralize}/#{source.id}/access_requests", stranger) } end - context 'when authenticated as a non-master/owner' do + context 'when authenticated as a non-maintainer/owner' do %i[developer access_requester stranger].each do |type| context "as a #{type}" do it 'returns 403' do @@ -41,9 +41,9 @@ describe API::AccessRequests do end end - context 'when authenticated as a master/owner' do + context 'when authenticated as a maintainer/owner' do it 'returns access requesters' do - get api("/#{source_type.pluralize}/#{source.id}/access_requests", master) + get api("/#{source_type.pluralize}/#{source.id}/access_requests", maintainer) expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers @@ -61,7 +61,7 @@ describe API::AccessRequests do end context 'when authenticated as a member' do - %i[developer master].each do |type| + %i[developer maintainer].each do |type| context "as a #{type}" do it 'returns 403' do expect do @@ -88,7 +88,7 @@ describe API::AccessRequests do context 'when authenticated as a stranger' do context "when access request is disabled for the #{source_type}" do before do - source.update_attributes(request_access_enabled: false) + source.update(request_access_enabled: false) end it 'returns 403' do @@ -128,7 +128,7 @@ describe API::AccessRequests do let(:route) { put api("/#{source_type.pluralize}/#{source.id}/access_requests/#{access_requester.id}/approve", stranger) } end - context 'when authenticated as a non-master/owner' do + context 'when authenticated as a non-maintainer/owner' do %i[developer access_requester stranger].each do |type| context "as a #{type}" do it 'returns 403' do @@ -141,11 +141,11 @@ describe API::AccessRequests do end end - context 'when authenticated as a master/owner' do + context 'when authenticated as a maintainer/owner' do it 'returns 201' do expect do - put api("/#{source_type.pluralize}/#{source.id}/access_requests/#{access_requester.id}/approve", master), - access_level: Member::MASTER + put api("/#{source_type.pluralize}/#{source.id}/access_requests/#{access_requester.id}/approve", maintainer), + access_level: Member::MAINTAINER expect(response).to have_gitlab_http_status(201) end.to change { source.members.count }.by(1) @@ -158,13 +158,13 @@ describe API::AccessRequests do expect(json_response['web_url']).to eq(Gitlab::Routing.url_helpers.user_url(access_requester)) # Member attributes - expect(json_response['access_level']).to eq(Member::MASTER) + expect(json_response['access_level']).to eq(Member::MAINTAINER) end context 'user_id does not match an existing access requester' do it 'returns 404' do expect do - put api("/#{source_type.pluralize}/#{source.id}/access_requests/#{stranger.id}/approve", master) + put api("/#{source_type.pluralize}/#{source.id}/access_requests/#{stranger.id}/approve", maintainer) expect(response).to have_gitlab_http_status(404) end.not_to change { source.members.count } @@ -180,7 +180,7 @@ describe API::AccessRequests do let(:route) { delete api("/#{source_type.pluralize}/#{source.id}/access_requests/#{access_requester.id}", stranger) } end - context 'when authenticated as a non-master/owner' do + context 'when authenticated as a non-maintainer/owner' do %i[developer stranger].each do |type| context "as a #{type}" do it 'returns 403' do @@ -203,10 +203,10 @@ describe API::AccessRequests do end end - context 'when authenticated as a master/owner' do + context 'when authenticated as a maintainer/owner' do it 'deletes the access requester' do expect do - delete api("/#{source_type.pluralize}/#{source.id}/access_requests/#{access_requester.id}", master) + delete api("/#{source_type.pluralize}/#{source.id}/access_requests/#{access_requester.id}", maintainer) expect(response).to have_gitlab_http_status(204) end.to change { source.requesters.count }.by(-1) @@ -215,7 +215,7 @@ describe API::AccessRequests do context 'user_id matches a member, not an access requester' do it 'returns 404' do expect do - delete api("/#{source_type.pluralize}/#{source.id}/access_requests/#{developer.id}", master) + delete api("/#{source_type.pluralize}/#{source.id}/access_requests/#{developer.id}", maintainer) expect(response).to have_gitlab_http_status(404) end.not_to change { source.requesters.count } @@ -225,7 +225,7 @@ describe API::AccessRequests do context 'user_id does not match an existing access requester' do it 'returns 404' do expect do - delete api("/#{source_type.pluralize}/#{source.id}/access_requests/#{stranger.id}", master) + delete api("/#{source_type.pluralize}/#{source.id}/access_requests/#{stranger.id}", maintainer) expect(response).to have_gitlab_http_status(404) end.not_to change { source.requesters.count } diff --git a/spec/requests/api/award_emoji_spec.rb b/spec/requests/api/award_emoji_spec.rb index 5adfb33677f..0921fecb933 100644 --- a/spec/requests/api/award_emoji_spec.rb +++ b/spec/requests/api/award_emoji_spec.rb @@ -10,7 +10,7 @@ describe API::AwardEmoji do set(:note) { create(:note, project: project, noteable: issue) } before do - project.add_master(user) + project.add_maintainer(user) end describe "GET /projects/:id/awardable/:awardable_id/award_emoji" do diff --git a/spec/requests/api/badges_spec.rb b/spec/requests/api/badges_spec.rb index ae64a9ca162..e232e2e04ee 100644 --- a/spec/requests/api/badges_spec.rb +++ b/spec/requests/api/badges_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe API::Badges do - let(:master) { create(:user, username: 'master_user') } + let(:maintainer) { create(:user, username: 'maintainer_user') } let(:developer) { create(:user) } let(:access_requester) { create(:user) } let(:stranger) { create(:user) } @@ -25,7 +25,7 @@ describe API::Badges do let(:route) { get api("/#{source_type.pluralize}/#{source.id}/badges", stranger) } end - %i[master developer access_requester stranger].each do |type| + %i[maintainer developer access_requester stranger].each do |type| context "when authenticated as a #{type}" do it 'returns 200' do user = public_send(type) @@ -43,16 +43,16 @@ describe API::Badges do it 'avoids N+1 queries' do # Establish baseline - get api("/#{source_type.pluralize}/#{source.id}/badges", master) + get api("/#{source_type.pluralize}/#{source.id}/badges", maintainer) control = ActiveRecord::QueryRecorder.new do - get api("/#{source_type.pluralize}/#{source.id}/badges", master) + get api("/#{source_type.pluralize}/#{source.id}/badges", maintainer) end project.add_developer(create(:user)) expect do - get api("/#{source_type.pluralize}/#{source.id}/badges", master) + get api("/#{source_type.pluralize}/#{source.id}/badges", maintainer) end.not_to exceed_query_limit(control) end end @@ -69,7 +69,7 @@ describe API::Badges do end context 'when authenticated as a non-member' do - %i[master developer access_requester stranger].each do |type| + %i[maintainer developer access_requester stranger].each do |type| let(:badge) { source.badges.first } context "as a #{type}" do @@ -122,10 +122,10 @@ describe API::Badges do end end - context 'when authenticated as a master/owner' do + context 'when authenticated as a maintainer/owner' do it 'creates a new badge' do expect do - post api("/#{source_type.pluralize}/#{source.id}/badges", master), + post api("/#{source_type.pluralize}/#{source.id}/badges", maintainer), link_url: example_url, image_url: example_url2 expect(response).to have_gitlab_http_status(201) @@ -138,21 +138,21 @@ describe API::Badges do end it 'returns 400 when link_url is not given' do - post api("/#{source_type.pluralize}/#{source.id}/badges", master), + post api("/#{source_type.pluralize}/#{source.id}/badges", maintainer), link_url: example_url expect(response).to have_gitlab_http_status(400) end it 'returns 400 when image_url is not given' do - post api("/#{source_type.pluralize}/#{source.id}/badges", master), + post api("/#{source_type.pluralize}/#{source.id}/badges", maintainer), image_url: example_url2 expect(response).to have_gitlab_http_status(400) end it 'returns 400 when link_url or image_url is not valid' do - post api("/#{source_type.pluralize}/#{source.id}/badges", master), + post api("/#{source_type.pluralize}/#{source.id}/badges", maintainer), link_url: 'whatever', image_url: 'whatever' expect(response).to have_gitlab_http_status(400) @@ -192,9 +192,9 @@ describe API::Badges do end end - context 'when authenticated as a master/owner' do + context 'when authenticated as a maintainer/owner' do it 'updates the member' do - put api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", master), + put api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", maintainer), link_url: example_url, image_url: example_url2 expect(response).to have_gitlab_http_status(200) @@ -205,7 +205,7 @@ describe API::Badges do end it 'returns 400 when link_url or image_url is not valid' do - put api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", master), + put api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", maintainer), link_url: 'whatever', image_url: 'whatever' expect(response).to have_gitlab_http_status(400) @@ -239,22 +239,22 @@ describe API::Badges do end end - context 'when authenticated as a master/owner' do + context 'when authenticated as a maintainer/owner' do it 'deletes the badge' do expect do - delete api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", master) + delete api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", maintainer) expect(response).to have_gitlab_http_status(204) end.to change { source.badges.count }.by(-1) end it_behaves_like '412 response' do - let(:request) { api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", master) } + let(:request) { api("/#{source_type.pluralize}/#{source.id}/badges/#{badge.id}", maintainer) } end end it 'returns 404 if badge does not exist' do - delete api("/#{source_type.pluralize}/#{source.id}/badges/123", master) + delete api("/#{source_type.pluralize}/#{source.id}/badges/123", maintainer) expect(response).to have_gitlab_http_status(404) end @@ -289,9 +289,9 @@ describe API::Badges do end end - context 'when authenticated as a master/owner' do + context 'when authenticated as a maintainer/owner' do it 'gets the rendered badge values' do - get api("/#{source_type.pluralize}/#{source.id}/badges/render?link_url=#{example_url}&image_url=#{example_url2}", master) + get api("/#{source_type.pluralize}/#{source.id}/badges/render?link_url=#{example_url}&image_url=#{example_url2}", maintainer) expect(response).to have_gitlab_http_status(200) @@ -304,19 +304,19 @@ describe API::Badges do end it 'returns 400 when link_url is not given' do - get api("/#{source_type.pluralize}/#{source.id}/badges/render?link_url=#{example_url}", master) + get api("/#{source_type.pluralize}/#{source.id}/badges/render?link_url=#{example_url}", maintainer) expect(response).to have_gitlab_http_status(400) end it 'returns 400 when image_url is not given' do - get api("/#{source_type.pluralize}/#{source.id}/badges/render?image_url=#{example_url}", master) + get api("/#{source_type.pluralize}/#{source.id}/badges/render?image_url=#{example_url}", maintainer) expect(response).to have_gitlab_http_status(400) end it 'returns 400 when link_url or image_url is not valid' do - get api("/#{source_type.pluralize}/#{source.id}/badges/render?link_url=whatever&image_url=whatever", master) + get api("/#{source_type.pluralize}/#{source.id}/badges/render?link_url=whatever&image_url=whatever", maintainer) expect(response).to have_gitlab_http_status(400) end @@ -326,7 +326,7 @@ describe API::Badges do context 'when deleting a badge' do context 'and the source is a project' do it 'cannot delete badges owned by the project group' do - delete api("/projects/#{project.id}/badges/#{project_group.badges.first.id}", master) + delete api("/projects/#{project.id}/badges/#{project_group.badges.first.id}", maintainer) expect(response).to have_gitlab_http_status(403) end @@ -345,9 +345,9 @@ describe API::Badges do end def setup_project - create(:project, :public, :access_requestable, creator_id: master.id, namespace: project_group) do |project| + create(:project, :public, :access_requestable, creator_id: maintainer.id, namespace: project_group) do |project| project.add_developer(developer) - project.add_master(master) + project.add_maintainer(maintainer) project.request_access(access_requester) project.project_badges << build(:project_badge, project: project) project.project_badges << build(:project_badge, project: project) @@ -358,7 +358,7 @@ describe API::Badges do def setup_group create(:group, :public, :access_requestable) do |group| group.add_developer(developer) - group.add_owner(master) + group.add_owner(maintainer) group.request_access(access_requester) group.badges << build(:group_badge, group: group) group.badges << build(:group_badge, group: group) diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index 9bb6ed62393..7fff0a6cce6 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -13,7 +13,7 @@ describe API::Branches do let(:current_user) { nil } before do - project.add_master(user) + project.add_maintainer(user) end describe "GET /projects/:id/repository/branches" do @@ -75,7 +75,7 @@ describe API::Branches do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } it_behaves_like 'repository branches' @@ -170,7 +170,7 @@ describe API::Branches do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } it_behaves_like 'repository branch' @@ -324,7 +324,7 @@ describe API::Branches do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } context "when a protected branch doesn't already exist" do @@ -381,8 +381,8 @@ describe API::Branches do expect(json_response['protected']).to eq(true) expect(json_response['developers_can_push']).to eq(false) expect(json_response['developers_can_merge']).to eq(false) - expect(protected_branch.reload.push_access_levels.first.access_level).to eq(Gitlab::Access::MASTER) - expect(protected_branch.reload.merge_access_levels.first.access_level).to eq(Gitlab::Access::MASTER) + expect(protected_branch.reload.push_access_levels.first.access_level).to eq(Gitlab::Access::MAINTAINER) + expect(protected_branch.reload.merge_access_levels.first.access_level).to eq(Gitlab::Access::MAINTAINER) end end @@ -458,7 +458,7 @@ describe API::Branches do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } context "when a protected branch doesn't already exist" do @@ -534,7 +534,7 @@ describe API::Branches do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } context "when a protected branch doesn't already exist" do diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb index e73d1a252f5..113703fac38 100644 --- a/spec/requests/api/commits_spec.rb +++ b/spec/requests/api/commits_spec.rb @@ -12,7 +12,7 @@ describe API::Commits do let(:current_user) { nil } before do - project.add_master(user) + project.add_maintainer(user) end describe 'GET /projects/:id/repository/commits' do @@ -55,7 +55,7 @@ describe API::Commits do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } it_behaves_like 'project commits' @@ -667,7 +667,7 @@ describe API::Commits do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } it_behaves_like 'ref commit' @@ -785,7 +785,7 @@ describe API::Commits do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } it_behaves_like 'ref diff' @@ -884,7 +884,7 @@ describe API::Commits do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } it_behaves_like 'ref comments' diff --git a/spec/requests/api/deployments_spec.rb b/spec/requests/api/deployments_spec.rb index 51b70fda148..61ae053cea7 100644 --- a/spec/requests/api/deployments_spec.rb +++ b/spec/requests/api/deployments_spec.rb @@ -5,7 +5,7 @@ describe API::Deployments do let(:non_member) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) end describe 'GET /projects/:id/deployments' do diff --git a/spec/requests/api/environments_spec.rb b/spec/requests/api/environments_spec.rb index fdddca5d0ef..bf93555b0f0 100644 --- a/spec/requests/api/environments_spec.rb +++ b/spec/requests/api/environments_spec.rb @@ -7,7 +7,7 @@ describe API::Environments do let!(:environment) { create(:environment, project: project) } before do - project.add_master(user) + project.add_maintainer(user) end describe 'GET /projects/:id/environments' do @@ -126,7 +126,7 @@ describe API::Environments do end describe 'DELETE /projects/:id/environments/:environment_id' do - context 'as a master' do + context 'as a maintainer' do it 'returns a 200 for an existing environment' do delete api("/projects/#{project.id}/environments/#{environment.id}", user) @@ -155,7 +155,7 @@ describe API::Environments do end describe 'POST /projects/:id/environments/:environment_id/stop' do - context 'as a master' do + context 'as a maintainer' do context 'with a stoppable environment' do before do environment.update(state: :available) diff --git a/spec/requests/api/graphql/project/merge_request_spec.rb b/spec/requests/api/graphql/project/merge_request_spec.rb index ad57c43bc87..deb6abbc026 100644 --- a/spec/requests/api/graphql/project/merge_request_spec.rb +++ b/spec/requests/api/graphql/project/merge_request_spec.rb @@ -67,4 +67,28 @@ describe 'getting merge request information nested in a project' do expect(merge_request_graphql_data).to be_nil end end + + context 'when there are pipelines' do + before do + pipeline = create( + :ci_pipeline, + project: merge_request.source_project, + ref: merge_request.source_branch, + sha: merge_request.diff_head_sha + ) + merge_request.update!(head_pipeline: pipeline) + end + + it 'has a head pipeline' do + post_graphql(query, current_user: current_user) + + expect(merge_request_graphql_data['headPipeline']).to be_present + end + + it 'has pipeline connections' do + post_graphql(query, current_user: current_user) + + expect(merge_request_graphql_data['pipelines']['edges'].size).to eq(1) + end + end end diff --git a/spec/requests/api/graphql/project_query_spec.rb b/spec/requests/api/graphql/project_query_spec.rb index a2b3dc5d121..0727ada4691 100644 --- a/spec/requests/api/graphql/project_query_spec.rb +++ b/spec/requests/api/graphql/project_query_spec.rb @@ -26,6 +26,18 @@ describe 'getting project information' do post_graphql(query, current_user: current_user) end end + + context 'when there are pipelines present' do + before do + create(:ci_pipeline, project: project) + end + + it 'is included in the pipelines connection' do + post_graphql(query, current_user: current_user) + + expect(graphql_data['project']['pipelines']['edges'].size).to eq(1) + end + end end context 'when the user does not have access to the project' do diff --git a/spec/requests/api/group_variables_spec.rb b/spec/requests/api/group_variables_spec.rb index 64fa7dc824c..f87e035c89d 100644 --- a/spec/requests/api/group_variables_spec.rb +++ b/spec/requests/api/group_variables_spec.rb @@ -9,7 +9,7 @@ describe API::GroupVariables do context 'authorized user with proper permissions' do before do - group.add_master(user) + group.add_maintainer(user) end it 'returns group variables' do @@ -42,7 +42,7 @@ describe API::GroupVariables do context 'authorized user with proper permissions' do before do - group.add_master(user) + group.add_maintainer(user) end it 'returns group variable details' do @@ -82,7 +82,7 @@ describe API::GroupVariables do let!(:variable) { create(:ci_group_variable, group: group) } before do - group.add_master(user) + group.add_maintainer(user) end it 'creates variable' do @@ -138,7 +138,7 @@ describe API::GroupVariables do context 'authorized user with proper permissions' do before do - group.add_master(user) + group.add_maintainer(user) end it 'updates variable data' do @@ -184,7 +184,7 @@ describe API::GroupVariables do context 'authorized user with proper permissions' do before do - group.add_master(user) + group.add_maintainer(user) end it 'deletes variable' do diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb index da23fdd7dca..65b387a2170 100644 --- a/spec/requests/api/groups_spec.rb +++ b/spec/requests/api/groups_spec.rb @@ -215,7 +215,7 @@ describe API::Groups do context 'when using owned in the request' do it 'returns an array of groups the user owns' do - group1.add_master(user2) + group1.add_maintainer(user2) get api('/groups', user2), owned: true @@ -251,14 +251,22 @@ describe API::Groups do projects end + def response_project_ids(json_response, key) + json_response[key].map do |project| + project['id'].to_i + end + end + context 'when unauthenticated' do it 'returns 404 for a private group' do get api("/groups/#{group2.id}") + expect(response).to have_gitlab_http_status(404) end it 'returns 200 for a public group' do get api("/groups/#{group1.id}") + expect(response).to have_gitlab_http_status(200) end @@ -268,7 +276,7 @@ describe API::Groups do get api("/groups/#{public_group.id}") - expect(json_response['projects'].map { |p| p['id'].to_i }) + expect(response_project_ids(json_response, 'projects')) .to contain_exactly(projects[:public].id) end @@ -278,7 +286,7 @@ describe API::Groups do get api("/groups/#{group1.id}") - expect(json_response['shared_projects'].map { |p| p['id'].to_i }) + expect(response_project_ids(json_response, 'shared_projects')) .to contain_exactly(projects[:public].id) end end @@ -309,6 +317,17 @@ describe API::Groups do expect(json_response['shared_projects'][0]['id']).to eq(project.id) end + it "returns one of user1's groups without projects when with_projects option is set to false" do + project = create(:project, namespace: group2, path: 'Foo') + create(:project_group_link, project: project, group: group1) + + get api("/groups/#{group1.id}", user1), with_projects: false + + expect(response).to have_gitlab_http_status(200) + expect(json_response['projects']).to be_nil + expect(json_response['shared_projects']).to be_nil + end + it "does not return a non existing group" do get api("/groups/1328", user1) @@ -327,7 +346,7 @@ describe API::Groups do get api("/groups/#{public_group.id}", user2) - expect(json_response['projects'].map { |p| p['id'].to_i }) + expect(response_project_ids(json_response, 'projects')) .to contain_exactly(projects[:public].id, projects[:internal].id) end @@ -337,7 +356,7 @@ describe API::Groups do get api("/groups/#{group1.id}", user2) - expect(json_response['shared_projects'].map { |p| p['id'].to_i }) + expect(response_project_ids(json_response, 'shared_projects')) .to contain_exactly(projects[:public].id, projects[:internal].id) end end @@ -715,9 +734,9 @@ describe API::Groups do end end - context 'as master', :nested_groups do + context 'as maintainer', :nested_groups do before do - group2.add_master(user1) + group2.add_maintainer(user1) end it 'cannot create subgroups' do @@ -793,7 +812,7 @@ describe API::Groups do it "does not remove a group if not an owner" do user4 = create(:user) - group1.add_master(user4) + group1.add_maintainer(user4) delete api("/groups/#{group1.id}", user3) diff --git a/spec/requests/api/helpers_spec.rb b/spec/requests/api/helpers_spec.rb index d8a51f36dba..0a789d58fd8 100644 --- a/spec/requests/api/helpers_spec.rb +++ b/spec/requests/api/helpers_spec.rb @@ -201,7 +201,7 @@ describe API::Helpers do end it 'does not allow expired tokens' do - personal_access_token.update_attributes!(expires_at: 1.day.ago) + personal_access_token.update!(expires_at: 1.day.ago) env[Gitlab::Auth::UserAuthFinders::PRIVATE_TOKEN_HEADER] = personal_access_token.token expect { current_user }.to raise_error Gitlab::Auth::ExpiredError diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index 95eff029f98..66eb18229fa 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -1083,7 +1083,7 @@ describe API::Issues do let(:project) { merge_request.source_project } before do - project.add_master(user) + project.add_maintainer(user) end context 'resolving all discussions in a merge request' do diff --git a/spec/requests/api/jobs_spec.rb b/spec/requests/api/jobs_spec.rb index 50d6f4b4d99..7d1a5c12805 100644 --- a/spec/requests/api/jobs_spec.rb +++ b/spec/requests/api/jobs_spec.rb @@ -535,12 +535,14 @@ describe API::Jobs do context 'authorized user' do context 'when trace is in ObjectStorage' do let!(:job) { create(:ci_build, :trace_artifact, pipeline: pipeline) } + let(:url) { 'http://object-storage/trace' } + let(:file_path) { expand_fixture_path('trace/sample_trace') } before do - stub_remote_trace_206 + stub_remote_url_206(url, file_path) allow_any_instance_of(JobArtifactUploader).to receive(:file_storage?) { false } - allow_any_instance_of(JobArtifactUploader).to receive(:url) { remote_trace_url } - allow_any_instance_of(JobArtifactUploader).to receive(:size) { remote_trace_size } + allow_any_instance_of(JobArtifactUploader).to receive(:url) { url } + allow_any_instance_of(JobArtifactUploader).to receive(:size) { File.size(file_path) } end it 'returns specific job trace' do @@ -643,7 +645,7 @@ describe API::Jobs do end describe 'POST /projects/:id/jobs/:job_id/erase' do - let(:role) { :master } + let(:role) { :maintainer } before do project.add_role(user, role) diff --git a/spec/requests/api/labels_spec.rb b/spec/requests/api/labels_spec.rb index 34cbf75f4c1..a4220f5b2be 100644 --- a/spec/requests/api/labels_spec.rb +++ b/spec/requests/api/labels_spec.rb @@ -7,7 +7,7 @@ describe API::Labels do let!(:priority_label) { create(:label, title: 'bug', project: project, priority: 3) } before do - project.add_master(user) + project.add_maintainer(user) end describe 'GET /projects/:id/labels' do diff --git a/spec/requests/api/members_spec.rb b/spec/requests/api/members_spec.rb index ec500838eb2..01bbe7f5ec6 100644 --- a/spec/requests/api/members_spec.rb +++ b/spec/requests/api/members_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' describe API::Members do - let(:master) { create(:user, username: 'master_user') } + let(:maintainer) { create(:user, username: 'maintainer_user') } let(:developer) { create(:user) } let(:access_requester) { create(:user) } let(:stranger) { create(:user) } let(:project) do - create(:project, :public, :access_requestable, creator_id: master.id, namespace: master.namespace) do |project| + create(:project, :public, :access_requestable, creator_id: maintainer.id, namespace: maintainer.namespace) do |project| project.add_developer(developer) - project.add_master(master) + project.add_maintainer(maintainer) project.request_access(access_requester) end end @@ -17,7 +17,7 @@ describe API::Members do let!(:group) do create(:group, :public, :access_requestable) do |group| group.add_developer(developer) - group.add_owner(master) + group.add_owner(maintainer) group.request_access(access_requester) end end @@ -28,7 +28,7 @@ describe API::Members do let(:route) { get api("/#{source_type.pluralize}/#{source.id}/members", stranger) } end - %i[master developer access_requester stranger].each do |type| + %i[maintainer developer access_requester stranger].each do |type| context "when authenticated as a #{type}" do it 'returns 200' do user = public_send(type) @@ -39,23 +39,23 @@ describe API::Members do expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(2) - expect(json_response.map { |u| u['id'] }).to match_array [master.id, developer.id] + expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id] end end end it 'avoids N+1 queries' do # Establish baseline - get api("/#{source_type.pluralize}/#{source.id}/members", master) + get api("/#{source_type.pluralize}/#{source.id}/members", maintainer) control = ActiveRecord::QueryRecorder.new do - get api("/#{source_type.pluralize}/#{source.id}/members", master) + get api("/#{source_type.pluralize}/#{source.id}/members", maintainer) end project.add_developer(create(:user)) expect do - get api("/#{source_type.pluralize}/#{source.id}/members", master) + get api("/#{source_type.pluralize}/#{source.id}/members", maintainer) end.not_to exceed_query_limit(control) end @@ -68,17 +68,17 @@ describe API::Members do expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.size).to eq(2) - expect(json_response.map { |u| u['id'] }).to match_array [master.id, developer.id] + expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id] end it 'finds members with query string' do - get api("/#{source_type.pluralize}/#{source.id}/members", developer), query: master.username + get api("/#{source_type.pluralize}/#{source.id}/members", developer), query: maintainer.username expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.count).to eq(1) - expect(json_response.first['username']).to eq(master.username) + expect(json_response.first['username']).to eq(maintainer.username) end it 'finds all members with no query specified' do @@ -88,7 +88,7 @@ describe API::Members do expect(response).to include_pagination_headers expect(json_response).to be_an Array expect(json_response.count).to eq(2) - expect(json_response.map { |u| u['id'] }).to match_array [master.id, developer.id] + expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id] end end end @@ -129,7 +129,7 @@ describe API::Members do it_behaves_like 'a 404 response when source is private' do let(:route) do post api("/#{source_type.pluralize}/#{source.id}/members", stranger), - user_id: access_requester.id, access_level: Member::MASTER + user_id: access_requester.id, access_level: Member::MAINTAINER end end @@ -139,7 +139,7 @@ describe API::Members do it 'returns 403' do user = public_send(type) post api("/#{source_type.pluralize}/#{source.id}/members", user), - user_id: access_requester.id, access_level: Member::MASTER + user_id: access_requester.id, access_level: Member::MAINTAINER expect(response).to have_gitlab_http_status(403) end @@ -147,24 +147,24 @@ describe API::Members do end end - context 'when authenticated as a master/owner' do + context 'when authenticated as a maintainer/owner' do context 'and new member is already a requester' do it 'transforms the requester into a proper member' do expect do - post api("/#{source_type.pluralize}/#{source.id}/members", master), - user_id: access_requester.id, access_level: Member::MASTER + post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), + user_id: access_requester.id, access_level: Member::MAINTAINER expect(response).to have_gitlab_http_status(201) end.to change { source.members.count }.by(1) expect(source.requesters.count).to eq(0) expect(json_response['id']).to eq(access_requester.id) - expect(json_response['access_level']).to eq(Member::MASTER) + expect(json_response['access_level']).to eq(Member::MAINTAINER) end end it 'creates a new member' do expect do - post api("/#{source_type.pluralize}/#{source.id}/members", master), + post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), user_id: stranger.id, access_level: Member::DEVELOPER, expires_at: '2016-08-05' expect(response).to have_gitlab_http_status(201) @@ -176,28 +176,28 @@ describe API::Members do end it "returns 409 if member already exists" do - post api("/#{source_type.pluralize}/#{source.id}/members", master), - user_id: master.id, access_level: Member::MASTER + post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), + user_id: maintainer.id, access_level: Member::MAINTAINER expect(response).to have_gitlab_http_status(409) end it 'returns 400 when user_id is not given' do - post api("/#{source_type.pluralize}/#{source.id}/members", master), - access_level: Member::MASTER + post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), + access_level: Member::MAINTAINER expect(response).to have_gitlab_http_status(400) end it 'returns 400 when access_level is not given' do - post api("/#{source_type.pluralize}/#{source.id}/members", master), + post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), user_id: stranger.id expect(response).to have_gitlab_http_status(400) end it 'returns 400 when access_level is not valid' do - post api("/#{source_type.pluralize}/#{source.id}/members", master), + post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), user_id: stranger.id, access_level: 1234 expect(response).to have_gitlab_http_status(400) @@ -210,7 +210,7 @@ describe API::Members do it_behaves_like 'a 404 response when source is private' do let(:route) do put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", stranger), - access_level: Member::MASTER + access_level: Member::MAINTAINER end end @@ -220,7 +220,7 @@ describe API::Members do it 'returns 403' do user = public_send(type) put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", user), - access_level: Member::MASTER + access_level: Member::MAINTAINER expect(response).to have_gitlab_http_status(403) end @@ -228,33 +228,33 @@ describe API::Members do end end - context 'when authenticated as a master/owner' do + context 'when authenticated as a maintainer/owner' do it 'updates the member' do - put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", master), - access_level: Member::MASTER, expires_at: '2016-08-05' + put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer), + access_level: Member::MAINTAINER, expires_at: '2016-08-05' expect(response).to have_gitlab_http_status(200) expect(json_response['id']).to eq(developer.id) - expect(json_response['access_level']).to eq(Member::MASTER) + expect(json_response['access_level']).to eq(Member::MAINTAINER) expect(json_response['expires_at']).to eq('2016-08-05') end end it 'returns 409 if member does not exist' do - put api("/#{source_type.pluralize}/#{source.id}/members/123", master), - access_level: Member::MASTER + put api("/#{source_type.pluralize}/#{source.id}/members/123", maintainer), + access_level: Member::MAINTAINER expect(response).to have_gitlab_http_status(404) end it 'returns 400 when access_level is not given' do - put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", master) + put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer) expect(response).to have_gitlab_http_status(400) end it 'returns 400 when access level is not valid' do - put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", master), + put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer), access_level: 1234 expect(response).to have_gitlab_http_status(400) @@ -291,11 +291,11 @@ describe API::Members do end end - context 'when authenticated as a master/owner' do + context 'when authenticated as a maintainer/owner' do context 'and member is a requester' do it 'returns 404' do expect do - delete api("/#{source_type.pluralize}/#{source.id}/members/#{access_requester.id}", master) + delete api("/#{source_type.pluralize}/#{source.id}/members/#{access_requester.id}", maintainer) expect(response).to have_gitlab_http_status(404) end.not_to change { source.requesters.count } @@ -304,19 +304,19 @@ describe API::Members do it 'deletes the member' do expect do - delete api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", master) + delete api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer) expect(response).to have_gitlab_http_status(204) end.to change { source.members.count }.by(-1) end it_behaves_like '412 response' do - let(:request) { api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", master) } + let(:request) { api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer) } end end it 'returns 404 if member does not exist' do - delete api("/#{source_type.pluralize}/#{source.id}/members/123", master) + delete api("/#{source_type.pluralize}/#{source.id}/members/123", maintainer) expect(response).to have_gitlab_http_status(404) end @@ -366,7 +366,7 @@ describe API::Members do context 'Adding owner to project' do it 'returns 403' do expect do - post api("/projects/#{project.id}/members", master), + post api("/projects/#{project.id}/members", maintainer), user_id: stranger.id, access_level: Member::OWNER expect(response).to have_gitlab_http_status(400) diff --git a/spec/requests/api/merge_request_diffs_spec.rb b/spec/requests/api/merge_request_diffs_spec.rb index cb647aee70f..6530dc956cb 100644 --- a/spec/requests/api/merge_request_diffs_spec.rb +++ b/spec/requests/api/merge_request_diffs_spec.rb @@ -8,7 +8,7 @@ describe API::MergeRequestDiffs, 'MergeRequestDiffs' do before do merge_request.merge_request_diffs.create(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') merge_request.merge_request_diffs.create(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') - project.add_master(user) + project.add_maintainer(user) end describe 'GET /projects/:id/merge_requests/:merge_request_iid/versions' do diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index eba39bb6ccc..1716d182782 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -306,6 +306,14 @@ describe API::MergeRequests do expect(json_response['changes_count']).to eq(merge_request.merge_request_diff.real_size) end + it 'exposes description and title html when render_html is true' do + get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), render_html: true + + expect(response).to have_gitlab_http_status(200) + + expect(json_response).to include('title_html', 'description_html') + end + context 'merge_request_metrics' do before do merge_request.metrics.update!(merged_by: user, diff --git a/spec/requests/api/namespaces_spec.rb b/spec/requests/api/namespaces_spec.rb index 98102fcd6a7..e2000ab42e8 100644 --- a/spec/requests/api/namespaces_spec.rb +++ b/spec/requests/api/namespaces_spec.rb @@ -23,10 +23,10 @@ describe API::Namespaces do expect(response).to have_gitlab_http_status(200) expect(response).to include_pagination_headers - expect(group_kind_json_response.keys).to contain_exactly('id', 'kind', 'name', 'path', 'full_path', - 'parent_id', 'members_count_with_descendants') + expect(group_kind_json_response.keys).to include('id', 'kind', 'name', 'path', 'full_path', + 'parent_id', 'members_count_with_descendants') - expect(user_kind_json_response.keys).to contain_exactly('id', 'kind', 'name', 'path', 'full_path', 'parent_id') + expect(user_kind_json_response.keys).to include('id', 'kind', 'name', 'path', 'full_path', 'parent_id') end it "admin: returns an array of all namespaces" do @@ -58,8 +58,8 @@ describe API::Namespaces do owned_group_response = json_response.find { |resource| resource['id'] == group1.id } - expect(owned_group_response.keys).to contain_exactly('id', 'kind', 'name', 'path', 'full_path', - 'parent_id', 'members_count_with_descendants') + expect(owned_group_response.keys).to include('id', 'kind', 'name', 'path', 'full_path', + 'parent_id', 'members_count_with_descendants') end it "returns correct attributes when user cannot admin group" do @@ -69,7 +69,7 @@ describe API::Namespaces do guest_group_response = json_response.find { |resource| resource['id'] == group1.id } - expect(guest_group_response.keys).to contain_exactly('id', 'kind', 'name', 'path', 'full_path', 'parent_id') + expect(guest_group_response.keys).to include('id', 'kind', 'name', 'path', 'full_path', 'parent_id') end it "user: returns an array of namespaces" do diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb index dd568c24c72..3fb45449c74 100644 --- a/spec/requests/api/notes_spec.rb +++ b/spec/requests/api/notes_spec.rb @@ -44,7 +44,7 @@ describe API::Notes do # For testing the cross-reference of a private issue in a public project let(:private_project) do create(:project, namespace: private_user.namespace) - .tap { |p| p.add_master(private_user) } + .tap { |p| p.add_maintainer(private_user) } end let(:private_issue) { create(:issue, project: private_project) } @@ -71,7 +71,7 @@ describe API::Notes do context "issue is confidential" do before do - ext_issue.update_attributes(confidential: true) + ext_issue.update(confidential: true) end it "returns 404" do @@ -104,7 +104,7 @@ describe API::Notes do context "when issue is confidential" do before do - issue.update_attributes(confidential: true) + issue.update(confidential: true) end it "returns 404" do diff --git a/spec/requests/api/pages_domains_spec.rb b/spec/requests/api/pages_domains_spec.rb index a9ccbb32666..35b6ed8d5c0 100644 --- a/spec/requests/api/pages_domains_spec.rb +++ b/spec/requests/api/pages_domains_spec.rb @@ -80,7 +80,7 @@ describe API::PagesDomains do context 'when pages is disabled' do before do allow(Gitlab.config.pages).to receive(:enabled).and_return(false) - project.add_master(user) + project.add_maintainer(user) end it_behaves_like '404 response' do @@ -88,9 +88,9 @@ describe API::PagesDomains do end end - context 'when user is a master' do + context 'when user is a maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'get pages domains' @@ -177,7 +177,7 @@ describe API::PagesDomains do context 'when domain is vacant' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like '404 response' do @@ -185,9 +185,9 @@ describe API::PagesDomains do end end - context 'when user is a master' do + context 'when user is a maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'get pages domain' @@ -270,9 +270,9 @@ describe API::PagesDomains do end end - context 'when user is a master' do + context 'when user is a maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'post pages domains' @@ -380,7 +380,7 @@ describe API::PagesDomains do context 'when domain is vacant' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like '404 response' do @@ -388,9 +388,9 @@ describe API::PagesDomains do end end - context 'when user is a master' do + context 'when user is a maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'put pages domain' @@ -444,7 +444,7 @@ describe API::PagesDomains do context 'when domain is vacant' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like '404 response' do @@ -452,9 +452,9 @@ describe API::PagesDomains do end end - context 'when user is a master' do + context 'when user is a maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'delete pages domain' diff --git a/spec/requests/api/pipeline_schedules_spec.rb b/spec/requests/api/pipeline_schedules_spec.rb index 91d4d5d3de9..997d413eb4f 100644 --- a/spec/requests/api/pipeline_schedules_spec.rb +++ b/spec/requests/api/pipeline_schedules_spec.rb @@ -22,7 +22,7 @@ describe API::PipelineSchedules do .each do |pipeline_schedule| create(:user).tap do |user| project.add_developer(user) - pipeline_schedule.update_attributes(owner: user) + pipeline_schedule.update(owner: user) end pipeline_schedule.pipelines << build(:ci_pipeline, project: project) end @@ -270,38 +270,38 @@ describe API::PipelineSchedules do end describe 'DELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id' do - let(:master) { create(:user) } + let(:maintainer) { create(:user) } let!(:pipeline_schedule) do create(:ci_pipeline_schedule, project: project, owner: developer) end before do - project.add_master(master) + project.add_maintainer(maintainer) end context 'authenticated user with valid permissions' do it 'deletes pipeline_schedule' do expect do - delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", master) + delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", maintainer) end.to change { project.pipeline_schedules.count }.by(-1) expect(response).to have_gitlab_http_status(204) end it 'responds with 404 Not Found if requesting non-existing pipeline_schedule' do - delete api("/projects/#{project.id}/pipeline_schedules/-5", master) + delete api("/projects/#{project.id}/pipeline_schedules/-5", maintainer) expect(response).to have_gitlab_http_status(:not_found) end it_behaves_like '412 response' do - let(:request) { api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", master) } + let(:request) { api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", maintainer) } end end context 'authenticated user with invalid permissions' do - let!(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: master) } + let!(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: maintainer) } it 'does not delete pipeline_schedule' do delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", developer) @@ -415,7 +415,7 @@ describe API::PipelineSchedules do end describe 'DELETE /projects/:id/pipeline_schedules/:pipeline_schedule_id/variables/:key' do - let(:master) { create(:user) } + let(:maintainer) { create(:user) } set(:pipeline_schedule) do create(:ci_pipeline_schedule, project: project, owner: developer) @@ -426,13 +426,13 @@ describe API::PipelineSchedules do end before do - project.add_master(master) + project.add_maintainer(maintainer) end context 'authenticated user with valid permissions' do it 'deletes pipeline_schedule_variable' do expect do - delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables/#{pipeline_schedule_variable.key}", master) + delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables/#{pipeline_schedule_variable.key}", maintainer) end.to change { Ci::PipelineScheduleVariable.count }.by(-1) expect(response).to have_gitlab_http_status(:accepted) @@ -440,14 +440,14 @@ describe API::PipelineSchedules do end it 'responds with 404 Not Found if requesting non-existing pipeline_schedule_variable' do - delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables/____", master) + delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables/____", maintainer) expect(response).to have_gitlab_http_status(:not_found) end end context 'authenticated user with invalid permissions' do - let!(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: master) } + let!(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: maintainer) } it 'does not delete pipeline_schedule_variable' do delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/variables/#{pipeline_schedule_variable.key}", developer) diff --git a/spec/requests/api/pipelines_spec.rb b/spec/requests/api/pipelines_spec.rb index 78ea77cb3bb..e2ca27f5d41 100644 --- a/spec/requests/api/pipelines_spec.rb +++ b/spec/requests/api/pipelines_spec.rb @@ -11,7 +11,7 @@ describe API::Pipelines do end before do - project.add_master(user) + project.add_maintainer(user) end describe 'GET /projects/:id/pipelines ' do diff --git a/spec/requests/api/project_export_spec.rb b/spec/requests/api/project_export_spec.rb index 3834d27d0a9..45e4e35d773 100644 --- a/spec/requests/api/project_export_spec.rb +++ b/spec/requests/api/project_export_spec.rb @@ -109,13 +109,13 @@ describe API::ProjectExport do it_behaves_like 'get project export status ok' end - context 'when user is a master' do + context 'when user is a maintainer' do before do - project.add_master(user) - project_none.add_master(user) - project_started.add_master(user) - project_finished.add_master(user) - project_after_export.add_master(user) + project.add_maintainer(user) + project_none.add_maintainer(user) + project_started.add_maintainer(user) + project_finished.add_maintainer(user) + project_after_export.add_maintainer(user) end it_behaves_like 'get project export status ok' @@ -192,6 +192,13 @@ describe API::ProjectExport do context 'when upload complete' do before do FileUtils.rm_rf(project_after_export.export_path) + + if project_after_export.export_project_object_exists? + upload = project_after_export.import_export_upload + + upload.remove_export_file! + upload.save + end end it_behaves_like '404 response' do @@ -221,13 +228,13 @@ describe API::ProjectExport do it_behaves_like 'get project download by strategy' end - context 'when user is a master' do + context 'when user is a maintainer' do before do - project.add_master(user) - project_none.add_master(user) - project_started.add_master(user) - project_finished.add_master(user) - project_after_export.add_master(user) + project.add_maintainer(user) + project_none.add_maintainer(user) + project_started.add_maintainer(user) + project_finished.add_maintainer(user) + project_after_export.add_maintainer(user) end it_behaves_like 'get project download by strategy' @@ -261,6 +268,22 @@ describe API::ProjectExport do it_behaves_like 'get project export download not found' end end + + context 'when an uploader is used' do + before do + stub_uploads_object_storage(ImportExportUploader) + + [project, project_finished, project_after_export].each do |p| + p.add_maintainer(user) + + upload = ImportExportUpload.new(project: p) + upload.export_file = fixture_file_upload('spec/fixtures/project_export.tar.gz', "`/tar.gz") + upload.save! + end + end + + it_behaves_like 'get project download by strategy' + end end describe 'POST /projects/:project_id/export' do @@ -315,13 +338,13 @@ describe API::ProjectExport do it_behaves_like 'post project export start' end - context 'when user is a master' do + context 'when user is a maintainer' do before do - project.add_master(user) - project_none.add_master(user) - project_started.add_master(user) - project_finished.add_master(user) - project_after_export.add_master(user) + project.add_maintainer(user) + project_none.add_maintainer(user) + project_started.add_maintainer(user) + project_finished.add_maintainer(user) + project_after_export.add_maintainer(user) end it_behaves_like 'post project export start' diff --git a/spec/requests/api/project_hooks_spec.rb b/spec/requests/api/project_hooks_spec.rb index 12a183fed1e..bc45a63d9f1 100644 --- a/spec/requests/api/project_hooks_spec.rb +++ b/spec/requests/api/project_hooks_spec.rb @@ -13,7 +13,7 @@ describe API::ProjectHooks, 'ProjectHooks' do end before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(user3) end @@ -214,7 +214,7 @@ describe API::ProjectHooks, 'ProjectHooks' do it "returns a 404 if a user attempts to delete project hooks he/she does not own" do test_user = create(:user) other_project = create(:project) - other_project.add_master(test_user) + other_project.add_maintainer(test_user) delete api("/projects/#{other_project.id}/hooks/#{hook.id}", test_user) expect(response).to have_gitlab_http_status(404) diff --git a/spec/requests/api/project_import_spec.rb b/spec/requests/api/project_import_spec.rb index 97dffdc9233..41243854ebc 100644 --- a/spec/requests/api/project_import_spec.rb +++ b/spec/requests/api/project_import_spec.rb @@ -146,7 +146,7 @@ describe API::ProjectImport do describe 'GET /projects/:id/import' do it 'returns the import status' do project = create(:project, :import_started) - project.add_master(user) + project.add_maintainer(user) get api("/projects/#{project.id}/import", user) @@ -156,8 +156,8 @@ describe API::ProjectImport do it 'returns the import status and the error if failed' do project = create(:project, :import_failed) - project.add_master(user) - project.import_state.update_attributes(last_error: 'error') + project.add_maintainer(user) + project.import_state.update(last_error: 'error') get api("/projects/#{project.id}/import", user) diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index abf9ad738bd..8389cb7cf9c 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -40,7 +40,7 @@ describe API::Projects do create(:project_member, user: user4, project: project3, - access_level: ProjectMember::MASTER) + access_level: ProjectMember::MAINTAINER) end let(:project4) do create(:project, @@ -312,7 +312,7 @@ describe API::Projects do before do project_member - user3.update_attributes(starred_projects: [project, project2, project3, public_project]) + user3.update(starred_projects: [project, project2, project3, public_project]) end it 'returns the starred projects viewable by the user' do @@ -333,7 +333,7 @@ describe API::Projects do let!(:project9) { create(:project, :public, path: 'gitlab9') } before do - user.update_attributes(starred_projects: [project5, project7, project8, project9]) + user.update(starred_projects: [project5, project7, project8, project9]) end context 'including owned filter' do @@ -353,7 +353,7 @@ describe API::Projects do create(:project_member, user: user, project: project5, - access_level: ProjectMember::MASTER) + access_level: ProjectMember::MAINTAINER) end it 'returns only projects that satisfy all query parameters' do @@ -961,7 +961,7 @@ describe API::Projects do describe 'permissions' do context 'all projects' do before do - project.add_master(user) + project.add_maintainer(user) end it 'contains permission information' do @@ -969,19 +969,19 @@ describe API::Projects do expect(response).to have_gitlab_http_status(200) expect(json_response.first['permissions']['project_access']['access_level']) - .to eq(Gitlab::Access::MASTER) + .to eq(Gitlab::Access::MAINTAINER) expect(json_response.first['permissions']['group_access']).to be_nil end end context 'personal project' do it 'sets project access and returns 200' do - project.add_master(user) + project.add_maintainer(user) get api("/projects/#{project.id}", user) expect(response).to have_gitlab_http_status(200) expect(json_response['permissions']['project_access']['access_level']) - .to eq(Gitlab::Access::MASTER) + .to eq(Gitlab::Access::MAINTAINER) expect(json_response['permissions']['group_access']).to be_nil end end @@ -1451,7 +1451,7 @@ describe API::Projects do end it 'updates visibility_level from public to private' do - project3.update_attributes({ visibility_level: Gitlab::VisibilityLevel::PUBLIC }) + project3.update({ visibility_level: Gitlab::VisibilityLevel::PUBLIC }) project_param = { visibility: 'private' } put api("/projects/#{project3.id}", user), project_param @@ -1526,9 +1526,23 @@ describe API::Projects do expect(response).to have_gitlab_http_status(400) end + + it 'updates avatar' do + project_param = { + avatar: fixture_file_upload('spec/fixtures/banana_sample.gif', + 'image/gif') + } + + put api("/projects/#{project3.id}", user), project_param + + expect(response).to have_gitlab_http_status(200) + expect(json_response['avatar_url']).to eq('http://localhost/uploads/'\ + '-/system/project/avatar/'\ + "#{project3.id}/banana_sample.gif") + end end - context 'when authenticated as project master' do + context 'when authenticated as project maintainer' do it 'updates path' do project_param = { path: 'bar' } put api("/projects/#{project3.id}", user4), project_param diff --git a/spec/requests/api/protected_branches_spec.rb b/spec/requests/api/protected_branches_spec.rb index 576fde46615..69a601d7b40 100644 --- a/spec/requests/api/protected_branches_spec.rb +++ b/spec/requests/api/protected_branches_spec.rb @@ -26,9 +26,9 @@ describe API::ProtectedBranches do end end - context 'when authenticated as a master' do + context 'when authenticated as a maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'protected branches' @@ -54,8 +54,8 @@ describe API::ProtectedBranches do expect(response).to have_gitlab_http_status(200) expect(json_response['name']).to eq(branch_name) - expect(json_response['push_access_levels'][0]['access_level']).to eq(::Gitlab::Access::MASTER) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(::Gitlab::Access::MASTER) + expect(json_response['push_access_levels'][0]['access_level']).to eq(::Gitlab::Access::MAINTAINER) + expect(json_response['merge_access_levels'][0]['access_level']).to eq(::Gitlab::Access::MAINTAINER) end context 'when protected branch does not exist' do @@ -68,9 +68,9 @@ describe API::ProtectedBranches do end end - context 'when authenticated as a master' do + context 'when authenticated as a maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it_behaves_like 'protected branch' @@ -108,9 +108,9 @@ describe API::ProtectedBranches do expect(json_response['name']).to eq(branch_name) end - context 'when authenticated as a master' do + context 'when authenticated as a maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end it 'protects a single branch' do @@ -118,8 +118,8 @@ describe API::ProtectedBranches do expect(response).to have_gitlab_http_status(201) expect(json_response['name']).to eq(branch_name) - expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::MASTER) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::MASTER) + expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) + expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) end it 'protects a single branch and developers can push' do @@ -128,7 +128,7 @@ describe API::ProtectedBranches do expect(response).to have_gitlab_http_status(201) expect(json_response['name']).to eq(branch_name) expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::DEVELOPER) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::MASTER) + expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) end it 'protects a single branch and developers can merge' do @@ -136,7 +136,7 @@ describe API::ProtectedBranches do expect(response).to have_gitlab_http_status(201) expect(json_response['name']).to eq(branch_name) - expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::MASTER) + expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::DEVELOPER) end @@ -155,7 +155,7 @@ describe API::ProtectedBranches do expect(response).to have_gitlab_http_status(201) expect(json_response['name']).to eq(branch_name) expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::NO_ACCESS) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::MASTER) + expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) end it 'protects a single branch and no one can merge' do @@ -163,7 +163,7 @@ describe API::ProtectedBranches do expect(response).to have_gitlab_http_status(201) expect(json_response['name']).to eq(branch_name) - expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::MASTER) + expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::NO_ACCESS) end @@ -189,8 +189,8 @@ describe API::ProtectedBranches do post post_endpoint, name: branch_name expect_protection_to_be_successful - expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::MASTER) - expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::MASTER) + expect(json_response['push_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) + expect(json_response['merge_access_levels'][0]['access_level']).to eq(Gitlab::Access::MAINTAINER) end end @@ -225,7 +225,7 @@ describe API::ProtectedBranches do let(:delete_endpoint) { api("/projects/#{project.id}/protected_branches/#{branch_name}", user) } before do - project.add_master(user) + project.add_maintainer(user) end it "unprotects a single branch" do diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb index 28f8564ae92..6063afc213d 100644 --- a/spec/requests/api/repositories_spec.rb +++ b/spec/requests/api/repositories_spec.rb @@ -8,7 +8,7 @@ describe API::Repositories do let(:user) { create(:user) } let(:guest) { create(:user).tap { |u| create(:project_member, :guest, user: u, project: project) } } let!(:project) { create(:project, :repository, creator: user) } - let!(:master) { create(:project_member, :master, user: user, project: project) } + let!(:maintainer) { create(:project_member, :maintainer, user: user, project: project) } describe "GET /projects/:id/repository/tree" do let(:route) { "/projects/#{project.id}/repository/tree" } diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index e7639599874..d57993ab454 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -851,6 +851,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do it 'does not update job status and job trace' do update_job(state: 'success', trace: 'BUILD TRACE UPDATED') + job.reload expect(response).to have_gitlab_http_status(403) expect(response.header['Job-Status']).to eq 'failed' expect(job.trace.raw).to eq 'Job failed' diff --git a/spec/requests/api/runners_spec.rb b/spec/requests/api/runners_spec.rb index 0c7937feed6..3ebdb54f71f 100644 --- a/spec/requests/api/runners_spec.rb +++ b/spec/requests/api/runners_spec.rb @@ -18,8 +18,8 @@ describe API::Runners do before do # Set project access for users - create(:project_member, :master, user: user, project: project) - create(:project_member, :master, user: user, project: project2) + create(:project_member, :maintainer, user: user, project: project) + create(:project_member, :maintainer, user: user, project: project2) create(:project_member, :reporter, user: user2, project: project) end @@ -90,6 +90,17 @@ describe API::Runners do end it 'filters runners by scope' do + get api('/runners/all?scope=shared', admin) + + shared = json_response.all? { |r| r['is_shared'] } + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response[0]).to have_key('ip_address') + expect(shared).to be_truthy + end + + it 'filters runners by scope' do get api('/runners/all?scope=specific', admin) shared = json_response.any? { |r| r['is_shared'] } @@ -136,7 +147,7 @@ describe API::Runners do delete api("/runners/#{unused_project_runner.id}", admin) expect(response).to have_gitlab_http_status(204) - end.to change { Ci::Runner.specific.count }.by(-1) + end.to change { Ci::Runner.project_type.count }.by(-1) end end @@ -200,6 +211,69 @@ describe API::Runners do describe 'PUT /runners/:id' do context 'admin user' do + # see https://gitlab.com/gitlab-org/gitlab-ce/issues/48625 + context 'single parameter update' do + it 'runner description' do + description = shared_runner.description + update_runner(shared_runner.id, admin, description: "#{description}_updated") + + expect(response).to have_gitlab_http_status(200) + expect(shared_runner.reload.description).to eq("#{description}_updated") + end + + it 'runner active state' do + active = shared_runner.active + update_runner(shared_runner.id, admin, active: !active) + + expect(response).to have_gitlab_http_status(200) + expect(shared_runner.reload.active).to eq(!active) + end + + it 'runner tag list' do + update_runner(shared_runner.id, admin, tag_list: ['ruby2.1', 'pgsql', 'mysql']) + + expect(response).to have_gitlab_http_status(200) + expect(shared_runner.reload.tag_list).to include('ruby2.1', 'pgsql', 'mysql') + end + + it 'runner untagged flag' do + # Ensure tag list is non-empty before setting untagged to false. + update_runner(shared_runner.id, admin, tag_list: ['ruby2.1', 'pgsql', 'mysql']) + update_runner(shared_runner.id, admin, run_untagged: 'false') + + expect(response).to have_gitlab_http_status(200) + expect(shared_runner.reload.run_untagged?).to be(false) + end + + it 'runner unlocked flag' do + update_runner(shared_runner.id, admin, locked: 'true') + + expect(response).to have_gitlab_http_status(200) + expect(shared_runner.reload.locked?).to be(true) + end + + it 'runner access level' do + update_runner(shared_runner.id, admin, access_level: 'ref_protected') + + expect(response).to have_gitlab_http_status(200) + expect(shared_runner.reload.ref_protected?).to be_truthy + end + + it 'runner maximum timeout' do + update_runner(shared_runner.id, admin, maximum_timeout: 1234) + + expect(response).to have_gitlab_http_status(200) + expect(shared_runner.reload.maximum_timeout).to eq(1234) + end + + it 'fails with no parameters' do + put api("/runners/#{shared_runner.id}", admin) + + shared_runner.reload + expect(response).to have_gitlab_http_status(400) + end + end + context 'when runner is shared' do it 'updates runner' do description = shared_runner.description @@ -300,7 +374,7 @@ describe API::Runners do delete api("/runners/#{shared_runner.id}", admin) expect(response).to have_gitlab_http_status(204) - end.to change { Ci::Runner.shared.count }.by(-1) + end.to change { Ci::Runner.instance_type.count }.by(-1) end it_behaves_like '412 response' do @@ -314,7 +388,7 @@ describe API::Runners do delete api("/runners/#{project_runner.id}", admin) expect(response).to have_http_status(204) - end.to change { Ci::Runner.specific.count }.by(-1) + end.to change { Ci::Runner.project_type.count }.by(-1) end end @@ -349,7 +423,7 @@ describe API::Runners do delete api("/runners/#{project_runner.id}", user) expect(response).to have_http_status(204) - end.to change { Ci::Runner.specific.count }.by(-1) + end.to change { Ci::Runner.project_type.count }.by(-1) end it_behaves_like '412 response' do @@ -502,7 +576,7 @@ describe API::Runners do end describe 'GET /projects/:id/runners' do - context 'authorized user with master privileges' do + context 'authorized user with maintainer privileges' do it "returns project's runners" do get api("/projects/#{project.id}/runners", user) @@ -515,7 +589,7 @@ describe API::Runners do end end - context 'authorized user without master privileges' do + context 'authorized user without maintainer privileges' do it "does not return project's runners" do get api("/projects/#{project.id}/runners", user2) @@ -584,12 +658,12 @@ describe API::Runners do end end - it 'enables a shared runner' do + it 'enables a instance type runner' do expect do post api("/projects/#{project.id}/runners", admin), runner_id: shared_runner.id end.to change { project.runners.count }.by(1) - expect(shared_runner.reload).not_to be_shared + expect(shared_runner.reload).not_to be_instance_type expect(response).to have_gitlab_http_status(201) end end diff --git a/spec/requests/api/tags_spec.rb b/spec/requests/api/tags_spec.rb index 969710d6613..98f995df06f 100644 --- a/spec/requests/api/tags_spec.rb +++ b/spec/requests/api/tags_spec.rb @@ -10,7 +10,7 @@ describe API::Tags do let(:current_user) { nil } before do - project.add_master(user) + project.add_maintainer(user) end describe 'GET /projects/:id/repository/tags' do @@ -86,7 +86,7 @@ describe API::Tags do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } it_behaves_like 'repository tags' @@ -109,7 +109,7 @@ describe API::Tags do before do release = project.releases.find_or_initialize_by(tag: tag_name) - release.update_attributes(description: description) + release.update(description: description) end it 'returns an array of project tags with release info' do @@ -168,7 +168,7 @@ describe API::Tags do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } it_behaves_like 'repository tag' @@ -222,7 +222,7 @@ describe API::Tags do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } context "when a protected branch doesn't already exist" do @@ -341,7 +341,7 @@ describe API::Tags do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } it_behaves_like 'repository delete tag' @@ -386,7 +386,7 @@ describe API::Tags do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } it_behaves_like 'repository new release' @@ -400,7 +400,7 @@ describe API::Tags do context 'on tag with existing release' do before do release = project.releases.find_or_initialize_by(tag: tag_name) - release.update_attributes(description: description) + release.update(description: description) end it 'returns 409 if there is already a release' do @@ -422,7 +422,7 @@ describe API::Tags do context 'on tag with existing release' do before do release = project.releases.find_or_initialize_by(tag: tag_name) - release.update_attributes(description: description) + release.update(description: description) end it 'updates the release description' do @@ -452,7 +452,7 @@ describe API::Tags do end end - context 'when authenticated', 'as a master' do + context 'when authenticated', 'as a maintainer' do let(:current_user) { user } it_behaves_like 'repository update release' diff --git a/spec/requests/api/triggers_spec.rb b/spec/requests/api/triggers_spec.rb index b2c56f7af2c..0ae6796d1e4 100644 --- a/spec/requests/api/triggers_spec.rb +++ b/spec/requests/api/triggers_spec.rb @@ -6,7 +6,7 @@ describe API::Triggers do let!(:trigger_token) { 'secure_token' } let!(:trigger_token_2) { 'secure_token_2' } let!(:project) { create(:project, :repository, creator: user) } - let!(:master) { create(:project_member, :master, user: user, project: project) } + let!(:maintainer) { create(:project_member, :maintainer, user: user, project: project) } let!(:developer) { create(:project_member, :developer, user: user2, project: project) } let!(:trigger) { create(:ci_trigger, project: project, token: trigger_token, owner: user) } let!(:trigger2) { create(:ci_trigger, project: project, token: trigger_token_2, owner: user2) } diff --git a/spec/requests/api/variables_spec.rb b/spec/requests/api/variables_spec.rb index 62215ea3d7d..be333df1d78 100644 --- a/spec/requests/api/variables_spec.rb +++ b/spec/requests/api/variables_spec.rb @@ -4,7 +4,7 @@ describe API::Variables do let(:user) { create(:user) } let(:user2) { create(:user) } let!(:project) { create(:project, creator_id: user.id) } - let!(:master) { create(:project_member, :master, user: user, project: project) } + let!(:maintainer) { create(:project_member, :maintainer, user: user, project: project) } let!(:developer) { create(:project_member, :developer, user: user2, project: project) } let!(:variable) { create(:ci_variable, project: project) } diff --git a/spec/requests/api/wikis_spec.rb b/spec/requests/api/wikis_spec.rb index 850ba696098..489cb001b82 100644 --- a/spec/requests/api/wikis_spec.rb +++ b/spec/requests/api/wikis_spec.rb @@ -7,7 +7,7 @@ require 'spec_helper' # Every state is tested for 3 user roles: # - guest # - developer -# - master +# - maintainer # because they are 3 edge cases of using wiki pages. describe API::Wikis do @@ -163,9 +163,9 @@ describe API::Wikis do include_examples '403 Forbidden' end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) get api(url, user) end @@ -193,9 +193,9 @@ describe API::Wikis do include_examples 'returns list of wiki pages' end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end include_examples 'returns list of wiki pages' @@ -221,9 +221,9 @@ describe API::Wikis do include_examples 'returns list of wiki pages' end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end include_examples 'returns list of wiki pages' @@ -256,9 +256,9 @@ describe API::Wikis do include_examples '403 Forbidden' end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) get api(url, user) end @@ -293,9 +293,9 @@ describe API::Wikis do end end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) get api(url, user) end @@ -337,9 +337,9 @@ describe API::Wikis do end end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) get api(url, user) end @@ -379,9 +379,9 @@ describe API::Wikis do include_examples '403 Forbidden' end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) post(api(url, user), payload) end @@ -408,9 +408,9 @@ describe API::Wikis do include_examples 'creates wiki page' end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end include_examples 'creates wiki page' @@ -436,9 +436,9 @@ describe API::Wikis do include_examples 'creates wiki page' end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) end include_examples 'creates wiki page' @@ -472,9 +472,9 @@ describe API::Wikis do include_examples '403 Forbidden' end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) put(api(url, user), payload) end @@ -510,9 +510,9 @@ describe API::Wikis do end end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) put(api(url, user), payload) end @@ -554,9 +554,9 @@ describe API::Wikis do end end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) put(api(url, user), payload) end @@ -607,9 +607,9 @@ describe API::Wikis do include_examples '403 Forbidden' end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) delete(api(url, user)) end @@ -639,9 +639,9 @@ describe API::Wikis do include_examples '403 Forbidden' end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) delete(api(url, user)) end @@ -671,9 +671,9 @@ describe API::Wikis do include_examples '403 Forbidden' end - context 'when user is master' do + context 'when user is maintainer' do before do - project.add_master(user) + project.add_maintainer(user) delete(api(url, user)) end diff --git a/spec/requests/git_http_spec.rb b/spec/requests/git_http_spec.rb index 92fcfb65269..b030d9862c6 100644 --- a/spec/requests/git_http_spec.rb +++ b/spec/requests/git_http_spec.rb @@ -312,7 +312,7 @@ describe 'Git HTTP requests' do let(:project) { fork_project(canonical_project, nil, repository: true) } before do - canonical_project.add_master(user) + canonical_project.add_maintainer(user) create(:merge_request, source_project: project, target_project: canonical_project, @@ -398,13 +398,13 @@ describe 'Git HTTP requests' do context "when the user has access to the project" do before do - project.add_master(user) + project.add_maintainer(user) end context "when the user is blocked" do it "rejects pulls with 401 Unauthorized" do user.block - project.add_master(user) + project.add_maintainer(user) download(path, env) do |response| expect(response).to have_gitlab_http_status(:unauthorized) @@ -467,7 +467,7 @@ describe 'Git HTTP requests' do let(:path) { "#{project.full_path}.git" } before do - project.add_master(user) + project.add_maintainer(user) end context 'when username and password are provided' do @@ -827,7 +827,7 @@ describe 'Git HTTP requests' do context 'and the user is on the team' do before do - project.add_master(user) + project.add_maintainer(user) end it "responds with status 200" do @@ -850,7 +850,7 @@ describe 'Git HTTP requests' do let(:env) { { user: user.username, password: user.password } } before do - project.add_master(user) + project.add_maintainer(user) enforce_terms end diff --git a/spec/requests/lfs_http_spec.rb b/spec/requests/lfs_http_spec.rb index 4d30b99262e..de39abdb746 100644 --- a/spec/requests/lfs_http_spec.rb +++ b/spec/requests/lfs_http_spec.rb @@ -63,7 +63,7 @@ describe 'Git LFS API and storage' do context 'with LFS disabled globally' do before do - project.add_master(user) + project.add_maintainer(user) allow(Gitlab.config.lfs).to receive(:enabled).and_return(false) end @@ -106,7 +106,7 @@ describe 'Git LFS API and storage' do context 'with LFS enabled globally' do before do - project.add_master(user) + project.add_maintainer(user) enable_lfs end @@ -236,7 +236,7 @@ describe 'Git LFS API and storage' do context 'and does have project access' do let(:update_permissions) do - project.add_master(user) + project.add_maintainer(user) project.lfs_objects << lfs_object end @@ -293,7 +293,7 @@ describe 'Git LFS API and storage' do context 'when user allowed' do let(:update_permissions) do - project.add_master(user) + project.add_maintainer(user) project.lfs_objects << lfs_object end @@ -829,7 +829,7 @@ describe 'Git LFS API and storage' do context 'when user is not authenticated' do context 'when user has push access' do let(:update_user_permissions) do - project.add_master(user) + project.add_maintainer(user) end it 'responds with status 401' do @@ -874,7 +874,7 @@ describe 'Git LFS API and storage' do before do allow(Gitlab::Database).to receive(:read_only?) { true } - project.add_master(user) + project.add_maintainer(user) enable_lfs end @@ -1307,7 +1307,7 @@ describe 'Git LFS API and storage' do let(:authorization) { authorize_user } before do - second_project.add_master(user) + second_project.add_maintainer(user) upstream_project.lfs_objects << lfs_object end diff --git a/spec/requests/lfs_locks_api_spec.rb b/spec/requests/lfs_locks_api_spec.rb index e44a11a7232..a44b43a591f 100644 --- a/spec/requests/lfs_locks_api_spec.rb +++ b/spec/requests/lfs_locks_api_spec.rb @@ -4,7 +4,7 @@ describe 'Git LFS File Locking API' do include WorkhorseHelpers let(:project) { create(:project) } - let(:master) { create(:user) } + let(:maintainer) { create(:user) } let(:developer) { create(:user) } let(:guest) { create(:user) } let(:path) { 'README.md' } @@ -29,7 +29,7 @@ describe 'Git LFS File Locking API' do before do allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) - project.add_developer(master) + project.add_developer(maintainer) project.add_developer(developer) project.add_guest(guest) end @@ -99,7 +99,7 @@ describe 'Git LFS File Locking API' do include_examples 'unauthorized request' it 'returns the list of locked files grouped by owner' do - lock_file('README.md', master) + lock_file('README.md', maintainer) lock_file('README', developer) post_lfs_json url, nil, headers diff --git a/spec/serializers/deploy_key_entity_spec.rb b/spec/serializers/deploy_key_entity_spec.rb index 2bd8162d1b7..01264cf7fb5 100644 --- a/spec/serializers/deploy_key_entity_spec.rb +++ b/spec/serializers/deploy_key_entity_spec.rb @@ -44,9 +44,9 @@ describe DeployKeyEntity do it { expect(entity.as_json).to eq(expected_result) } end - describe 'returns can_edit true if user is a master of project' do + describe 'returns can_edit true if user is a maintainer of project' do before do - project.add_master(user) + project.add_maintainer(user) end it { expect(entity.as_json).to include(can_edit: true) } diff --git a/spec/serializers/diff_file_entity_spec.rb b/spec/serializers/diff_file_entity_spec.rb index c4a6c117b76..00b2146dc86 100644 --- a/spec/serializers/diff_file_entity_spec.rb +++ b/spec/serializers/diff_file_entity_spec.rb @@ -25,6 +25,20 @@ describe DiffFileEntity do :context_lines_path ) end + + # Converted diff files from GitHub import does not contain blob file + # and content sha. + context 'when diff file does not have a blob and content sha' do + it 'exposes some attributes as nil' do + allow(diff_file).to receive(:content_sha).and_return(nil) + allow(diff_file).to receive(:blob).and_return(nil) + + expect(subject[:context_lines_path]).to be_nil + expect(subject[:view_path]).to be_nil + expect(subject[:highlighted_diff_lines]).to be_nil + expect(subject[:can_modify_blob]).to be_nil + end + end end context 'when there is no merge request' do diff --git a/spec/serializers/discussion_entity_spec.rb b/spec/serializers/discussion_entity_spec.rb index 44d8cc69d9b..378540a35b6 100644 --- a/spec/serializers/discussion_entity_spec.rb +++ b/spec/serializers/discussion_entity_spec.rb @@ -36,6 +36,25 @@ describe DiscussionEntity do ) end + context 'when is LegacyDiffDiscussion' do + let(:project) { create(:project) } + let(:merge_request) { create(:merge_request, source_project: project) } + let(:discussion) { create(:legacy_diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion } + + it 'exposes correct attributes' do + expect(subject.keys.sort).to include( + :diff_discussion, + :expanded, + :id, + :individual_note, + :notes, + :discussion_path, + :for_commit, + :commit_id + ) + end + end + context 'when diff file is present' do let(:note) { create(:diff_note_on_merge_request) } diff --git a/spec/serializers/environment_entity_spec.rb b/spec/serializers/environment_entity_spec.rb index 8f32c5639a1..b7324a26ed2 100644 --- a/spec/serializers/environment_entity_spec.rb +++ b/spec/serializers/environment_entity_spec.rb @@ -1,8 +1,9 @@ require 'spec_helper' describe EnvironmentEntity do + let(:request) { double('request') } let(:entity) do - described_class.new(environment, request: double) + described_class.new(environment, request: spy('request')) end let(:environment) { create(:environment) } diff --git a/spec/serializers/environment_serializer_spec.rb b/spec/serializers/environment_serializer_spec.rb index ca9b520fb38..0f0ab5ac796 100644 --- a/spec/serializers/environment_serializer_spec.rb +++ b/spec/serializers/environment_serializer_spec.rb @@ -54,7 +54,9 @@ describe EnvironmentSerializer do context 'when representing environments within folders' do let(:serializer) do - described_class.new(project: project).within_folders + described_class + .new(current_user: user, project: project) + .within_folders end let(:resource) { Environment.all } @@ -123,7 +125,8 @@ describe EnvironmentSerializer do let(:pagination) { { page: 1, per_page: 2 } } let(:serializer) do - described_class.new(project: project) + described_class + .new(current_user: user, project: project) .with_pagination(request, response) end @@ -169,7 +172,8 @@ describe EnvironmentSerializer do context 'when grouping environments within folders' do let(:serializer) do - described_class.new(project: project) + described_class + .new(current_user: user, project: project) .with_pagination(request, response) .within_folders end diff --git a/spec/serializers/group_child_entity_spec.rb b/spec/serializers/group_child_entity_spec.rb index 505a9eaac5a..dbc40bddc30 100644 --- a/spec/serializers/group_child_entity_spec.rb +++ b/spec/serializers/group_child_entity_spec.rb @@ -42,7 +42,7 @@ describe GroupChildEntity do end before do - object.add_master(user) + object.add_maintainer(user) end it 'has the correct type' do diff --git a/spec/services/auth/container_registry_authentication_service_spec.rb b/spec/services/auth/container_registry_authentication_service_spec.rb index fce73e0ac1f..037484931b8 100644 --- a/spec/services/auth/container_registry_authentication_service_spec.rb +++ b/spec/services/auth/container_registry_authentication_service_spec.rb @@ -348,7 +348,7 @@ describe Auth::ContainerRegistryAuthenticationService do end end - context 'delete authorized as master' do + context 'delete authorized as maintainer' do let(:current_project) { create(:project) } let(:current_user) { create(:user) } @@ -357,7 +357,7 @@ describe Auth::ContainerRegistryAuthenticationService do end before do - current_project.add_master(current_user) + current_project.add_maintainer(current_user) end it_behaves_like 'a valid token' diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 2b88fcc9a96..054b7b1561c 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -462,11 +462,11 @@ describe Ci::CreatePipelineService do end end - context 'when user is master' do + context 'when user is maintainer' do let(:pipeline) { execute_service } before do - project.add_master(user) + project.add_maintainer(user) end it 'creates a protected pipeline' do @@ -503,13 +503,13 @@ describe Ci::CreatePipelineService do end end - context 'when trigger belongs to a master' do + context 'when trigger belongs to a maintainer' do let(:user) { create(:user) } let(:trigger) { create(:ci_trigger, owner: user) } let(:trigger_request) { create(:ci_trigger_request, trigger: trigger) } before do - project.add_master(user) + project.add_maintainer(user) end it 'creates a pipeline' do diff --git a/spec/services/ci/register_job_service_spec.rb b/spec/services/ci/register_job_service_spec.rb index 3816bd0deb5..dbb5e33bbdc 100644 --- a/spec/services/ci/register_job_service_spec.rb +++ b/spec/services/ci/register_job_service_spec.rb @@ -548,8 +548,21 @@ module Ci end end - def execute(runner) - described_class.new(runner).execute.build + context 'when runner_session params are' do + it 'present sets runner session configuration in the build' do + runner_session_params = { session: { 'url' => 'https://example.com' } } + + expect(execute(specific_runner, runner_session_params).runner_session.attributes) + .to include(runner_session_params[:session]) + end + + it 'not present it does not configure the runner session' do + expect(execute(specific_runner).runner_session).to be_nil + end + end + + def execute(runner, params = {}) + described_class.new(runner).execute(params).build end end end diff --git a/spec/services/ci/retry_build_service_spec.rb b/spec/services/ci/retry_build_service_spec.rb index e1cb7ed8110..ecf5d849d3f 100644 --- a/spec/services/ci/retry_build_service_spec.rb +++ b/spec/services/ci/retry_build_service_spec.rb @@ -32,7 +32,7 @@ describe Ci::RetryBuildService do runner_id tag_taggings taggings tags trigger_request_id user_id auto_canceled_by_id retried failure_reason artifacts_file_store artifacts_metadata_store - metadata trace_chunks].freeze + metadata runner_session trace_chunks].freeze shared_examples 'build duplication' do let(:another_pipeline) { create(:ci_empty_pipeline, project: project) } @@ -49,7 +49,7 @@ describe Ci::RetryBuildService do # Make sure that build has both `stage_id` and `stage` because FactoryBot # can reset one of the fields when assigning another. We plan to deprecate # and remove legacy `stage` column in the future. - build.update_attributes(stage: 'test', stage_id: stage.id) + build.update(stage: 'test', stage_id: stage.id) end describe 'clone accessors' do @@ -100,7 +100,11 @@ describe Ci::RetryBuildService do end describe '#execute' do - let(:new_build) { service.execute(build) } + let(:new_build) do + Timecop.freeze(1.second.from_now) do + service.execute(build) + end + end context 'when user has ability to execute build' do before do @@ -150,7 +154,11 @@ describe Ci::RetryBuildService do end describe '#reprocess' do - let(:new_build) { service.reprocess!(build) } + let(:new_build) do + Timecop.freeze(1.second.from_now) do + service.reprocess!(build) + end + end context 'when user has ability to execute build' do before do diff --git a/spec/services/ci/retry_pipeline_service_spec.rb b/spec/services/ci/retry_pipeline_service_spec.rb index 688d3b8c038..55445e71539 100644 --- a/spec/services/ci/retry_pipeline_service_spec.rb +++ b/spec/services/ci/retry_pipeline_service_spec.rb @@ -237,7 +237,7 @@ describe Ci::RetryPipelineService, '#execute' do context 'when user is not allowed to trigger manual action' do before do project.add_developer(user) - create(:protected_branch, :masters_can_push, + create(:protected_branch, :maintainers_can_push, name: pipeline.ref, project: project) end @@ -275,7 +275,7 @@ describe Ci::RetryPipelineService, '#execute' do let(:pipeline) { create(:ci_pipeline, project: forked_project, ref: 'fixes') } before do - project.add_master(user) + project.add_maintainer(user) create(:merge_request, source_project: forked_project, target_project: project, diff --git a/spec/services/ci/stop_environments_service_spec.rb b/spec/services/ci/stop_environments_service_spec.rb index 3fc4e499b0c..cdd3d851f61 100644 --- a/spec/services/ci/stop_environments_service_spec.rb +++ b/spec/services/ci/stop_environments_service_spec.rb @@ -86,7 +86,7 @@ describe Ci::StopEnvironmentsService do context 'when user has permission to stop environments' do before do - project.add_master(user) + project.add_maintainer(user) end it 'does not stop environment' do diff --git a/spec/services/discussions/resolve_service_spec.rb b/spec/services/discussions/resolve_service_spec.rb index 3895a0b3aea..4e0d4749239 100644 --- a/spec/services/discussions/resolve_service_spec.rb +++ b/spec/services/discussions/resolve_service_spec.rb @@ -9,7 +9,7 @@ describe Discussions::ResolveService do let(:service) { described_class.new(discussion.noteable.project, user, merge_request: merge_request) } before do - project.add_master(user) + project.add_maintainer(user) end it "doesn't resolve discussions the user can't resolve" do diff --git a/spec/services/files/create_service_spec.rb b/spec/services/files/create_service_spec.rb index abe99b9e794..30d94e4318d 100644 --- a/spec/services/files/create_service_spec.rb +++ b/spec/services/files/create_service_spec.rb @@ -23,7 +23,7 @@ describe Files::CreateService do subject { described_class.new(project, user, commit_params) } before do - project.add_master(user) + project.add_maintainer(user) end describe "#execute" do diff --git a/spec/services/files/delete_service_spec.rb b/spec/services/files/delete_service_spec.rb index ace5f293097..73566afe8c8 100644 --- a/spec/services/files/delete_service_spec.rb +++ b/spec/services/files/delete_service_spec.rb @@ -37,7 +37,7 @@ describe Files::DeleteService do end before do - project.add_master(user) + project.add_maintainer(user) end describe "#execute" do diff --git a/spec/services/files/multi_service_spec.rb b/spec/services/files/multi_service_spec.rb index 59984c10990..3bdedaf3770 100644 --- a/spec/services/files/multi_service_spec.rb +++ b/spec/services/files/multi_service_spec.rb @@ -38,7 +38,7 @@ describe Files::MultiService do end before do - project.add_master(user) + project.add_maintainer(user) end describe '#execute' do diff --git a/spec/services/files/update_service_spec.rb b/spec/services/files/update_service_spec.rb index 16bfbdf3089..e01fe487ffa 100644 --- a/spec/services/files/update_service_spec.rb +++ b/spec/services/files/update_service_spec.rb @@ -24,7 +24,7 @@ describe Files::UpdateService do end before do - project.add_master(user) + project.add_maintainer(user) end describe "#execute" do @@ -71,17 +71,5 @@ describe Files::UpdateService do expect(results.data).to eq(new_contents) end end - - context 'with gitaly disabled', :skip_gitaly_mock do - context 'when target branch is different than source branch' do - let(:branch_name) { "#{project.default_branch}-new" } - - it 'fires hooks only once' do - expect(Gitlab::Git::HooksService).to receive(:new).once.and_call_original - - subject.execute - end - end - end end end diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb index 35826de5814..3f62e7e61e1 100644 --- a/spec/services/git_push_service_spec.rb +++ b/spec/services/git_push_service_spec.rb @@ -11,7 +11,7 @@ describe GitPushService, services: true do let(:ref) { 'refs/heads/master' } before do - project.add_master(user) + project.add_maintainer(user) end describe 'with remote mirrors' do @@ -267,8 +267,8 @@ describe GitPushService, services: true do expect(project.default_branch).to eq("master") execute_service(project, user, blankrev, 'newrev', ref) expect(project.protected_branches).not_to be_empty - expect(project.protected_branches.first.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::MASTER]) - expect(project.protected_branches.first.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::MASTER]) + expect(project.protected_branches.first.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER]) + expect(project.protected_branches.first.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER]) end it "when pushing a branch for the first time with default branch protection disabled" do @@ -290,7 +290,7 @@ describe GitPushService, services: true do expect(project.protected_branches).not_to be_empty expect(project.protected_branches.last.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::DEVELOPER]) - expect(project.protected_branches.last.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::MASTER]) + expect(project.protected_branches.last.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER]) end it "when pushing a branch for the first time with an existing branch permission configured" do @@ -315,7 +315,7 @@ describe GitPushService, services: true do expect(project.default_branch).to eq("master") execute_service(project, user, blankrev, 'newrev', ref) expect(project.protected_branches).not_to be_empty - expect(project.protected_branches.first.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::MASTER]) + expect(project.protected_branches.first.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER]) expect(project.protected_branches.first.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::DEVELOPER]) end @@ -442,7 +442,7 @@ describe GitPushService, services: true do allow_any_instance_of(ProcessCommitWorker).to receive(:build_commit) .and_return(closing_commit) - project.add_master(commit_author) + project.add_maintainer(commit_author) end context "to default branches" do diff --git a/spec/services/groups/update_service_spec.rb b/spec/services/groups/update_service_spec.rb index 1737fd0a9fc..48d689e11d4 100644 --- a/spec/services/groups/update_service_spec.rb +++ b/spec/services/groups/update_service_spec.rb @@ -12,7 +12,7 @@ describe Groups::UpdateService do let!(:service) { described_class.new(public_group, user, visibility_level: Gitlab::VisibilityLevel::INTERNAL) } before do - public_group.add_user(user, Gitlab::Access::MASTER) + public_group.add_user(user, Gitlab::Access::MAINTAINER) create(:project, :public, group: public_group) end @@ -26,7 +26,7 @@ describe Groups::UpdateService do let!(:service) { described_class.new(internal_group, user, visibility_level: Gitlab::VisibilityLevel::PRIVATE) } before do - internal_group.add_user(user, Gitlab::Access::MASTER) + internal_group.add_user(user, Gitlab::Access::MAINTAINER) create(:project, :internal, group: internal_group) end @@ -55,7 +55,7 @@ describe Groups::UpdateService do context "unauthorized visibility_level validation" do let!(:service) { described_class.new(internal_group, user, visibility_level: 99) } before do - internal_group.add_user(user, Gitlab::Access::MASTER) + internal_group.add_user(user, Gitlab::Access::MAINTAINER) end it "does not change permission level" do @@ -68,7 +68,7 @@ describe Groups::UpdateService do let!(:service) { described_class.new(internal_group, user, path: SecureRandom.hex) } before do - internal_group.add_user(user, Gitlab::Access::MASTER) + internal_group.add_user(user, Gitlab::Access::MAINTAINER) create(:project, :internal, group: internal_group) end diff --git a/spec/services/import_export_clean_up_service_spec.rb b/spec/services/import_export_clean_up_service_spec.rb index 1875d0448cd..d5fcef1246f 100644 --- a/spec/services/import_export_clean_up_service_spec.rb +++ b/spec/services/import_export_clean_up_service_spec.rb @@ -11,7 +11,6 @@ describe ImportExportCleanUpService do path = '/invalid/path/' stub_repository_downloads_path(path) - expect(File).to receive(:directory?).with(path + tmp_import_export_folder).and_return(false).at_least(:once) expect(service).not_to receive(:clean_up_export_files) service.execute @@ -38,6 +37,24 @@ describe ImportExportCleanUpService do end end + context 'with uploader exports' do + it 'removes old files' do + upload = create(:import_export_upload, + updated_at: 2.days.ago, + export_file: fixture_file_upload('spec/fixtures/project_export.tar.gz')) + + expect { service.execute }.to change { upload.reload.export_file.file.nil? }.to(true) + end + + it 'does not remove new files' do + upload = create(:import_export_upload, + updated_at: 1.hour.ago, + export_file: fixture_file_upload('spec/fixtures/project_export.tar.gz')) + + expect { service.execute }.not_to change { upload.reload.export_file.file.nil? } + end + end + def in_directory_with_files(mtime:) Dir.mktmpdir do |tmpdir| stub_repository_downloads_path(tmpdir) diff --git a/spec/services/issues/close_service_spec.rb b/spec/services/issues/close_service_spec.rb index 7ae49c06896..5e38d0aeb6a 100644 --- a/spec/services/issues/close_service_spec.rb +++ b/spec/services/issues/close_service_spec.rb @@ -9,7 +9,7 @@ describe Issues::CloseService do let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) } before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(user2) project.add_guest(guest) end diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb index 79bcdc41fb0..c61c1ddcb3d 100644 --- a/spec/services/issues/create_service_spec.rb +++ b/spec/services/issues/create_service_spec.rb @@ -13,8 +13,8 @@ describe Issues::CreateService do let(:labels) { create_pair(:label, project: project) } before do - project.add_master(user) - project.add_master(assignee) + project.add_maintainer(user) + project.add_maintainer(assignee) end let(:opts) do @@ -130,7 +130,7 @@ describe Issues::CreateService do end it 'invalidates open issues counter for assignees when issue is assigned' do - project.add_master(assignee) + project.add_maintainer(assignee) described_class.new(project, user, opts).execute @@ -160,7 +160,7 @@ describe Issues::CreateService do context 'issue create service' do context 'assignees' do before do - project.add_master(user) + project.add_maintainer(user) end it 'removes assignee when user id is invalid' do @@ -180,7 +180,7 @@ describe Issues::CreateService do end it 'saves assignee when user id is valid' do - project.add_master(assignee) + project.add_maintainer(assignee) opts = { title: 'Title', description: 'Description', assignee_ids: [assignee.id] } issue = described_class.new(project, user, opts).execute @@ -224,8 +224,8 @@ describe Issues::CreateService do end before do - project.add_master(user) - project.add_master(assignee) + project.add_maintainer(user) + project.add_maintainer(assignee) end it 'assigns and sets milestone to issuable from command' do @@ -242,7 +242,7 @@ describe Issues::CreateService do let(:project) { merge_request.source_project } before do - project.add_master(user) + project.add_maintainer(user) end describe 'for a single discussion' do diff --git a/spec/services/issues/reopen_service_spec.rb b/spec/services/issues/reopen_service_spec.rb index 42e5d544f4c..3b617d4ca54 100644 --- a/spec/services/issues/reopen_service_spec.rb +++ b/spec/services/issues/reopen_service_spec.rb @@ -24,7 +24,7 @@ describe Issues::ReopenService do let(:user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) end it 'invalidates counter cache for assignees' do diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index 158541d36e3..fa98d05c61b 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -18,7 +18,7 @@ describe Issues::UpdateService, :mailer do end before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(user2) project.add_developer(user3) end @@ -501,7 +501,7 @@ describe Issues::UpdateService, :mailer do let(:params) { { label_ids: [], remove_label_ids: [label.id] } } before do - issue.update_attributes(labels: [label, label3]) + issue.update(labels: [label, label3]) end it 'ignores the label_ids parameter' do @@ -517,7 +517,7 @@ describe Issues::UpdateService, :mailer do let(:params) { { add_label_ids: [label3.id], remove_label_ids: [label.id] } } before do - issue.update_attributes(labels: [label]) + issue.update(labels: [label]) end it 'adds the passed labels' do @@ -596,7 +596,7 @@ describe Issues::UpdateService, :mailer do context 'valid project' do before do - target_project.add_master(user) + target_project.add_maintainer(user) end it 'calls the move service with the proper issue and project' do diff --git a/spec/services/labels/find_or_create_service_spec.rb b/spec/services/labels/find_or_create_service_spec.rb index 68d5660445a..97ba2742392 100644 --- a/spec/services/labels/find_or_create_service_spec.rb +++ b/spec/services/labels/find_or_create_service_spec.rb @@ -44,6 +44,26 @@ describe Labels::FindOrCreateService do expect(service.execute).to eq project_label end end + + context 'when include_ancestor_groups is true' do + let(:group) { create(:group, :nested) } + let(:params) do + { + title: 'Audit', + include_ancestor_groups: true + } + end + + it 'returns the ancestor group labels' do + group_label = create(:group_label, group: group.parent, title: 'Audit') + + expect(service.execute).to eq group_label + end + + it 'creates new labels if labels are not found' do + expect { service.execute }.to change(project.labels, :count).by(1) + end + end end context 'when finding labels on group level' do diff --git a/spec/services/lfs/unlock_file_service_spec.rb b/spec/services/lfs/unlock_file_service_spec.rb index 948401d7bdc..539417644db 100644 --- a/spec/services/lfs/unlock_file_service_spec.rb +++ b/spec/services/lfs/unlock_file_service_spec.rb @@ -62,11 +62,11 @@ describe Lfs::UnlockFileService do context 'when forced' do let(:developer) { create(:user) } - let(:master) { create(:user) } + let(:maintainer) { create(:user) } before do project.add_developer(developer) - project.add_master(master) + project.add_maintainer(maintainer) end context 'by a regular user' do @@ -86,7 +86,7 @@ describe Lfs::UnlockFileService do end context 'by a maintainer user' do - let(:current_user) { master } + let(:current_user) { maintainer } let(:params) do { id: lock.id, force: true } diff --git a/spec/services/members/approve_access_request_service_spec.rb b/spec/services/members/approve_access_request_service_spec.rb index 7076571b753..5c30f5b6a61 100644 --- a/spec/services/members/approve_access_request_service_spec.rb +++ b/spec/services/members/approve_access_request_service_spec.rb @@ -34,9 +34,9 @@ describe Members::ApproveAccessRequestService do context 'with a custom access level' do it 'returns a ProjectMember with the custom access level' do - member = described_class.new(current_user, access_level: Gitlab::Access::MASTER).execute(access_requester, opts) + member = described_class.new(current_user, access_level: Gitlab::Access::MAINTAINER).execute(access_requester, opts) - expect(member.access_level).to eq(Gitlab::Access::MASTER) + expect(member.access_level).to eq(Gitlab::Access::MAINTAINER) end end end @@ -97,7 +97,7 @@ describe Members::ApproveAccessRequestService do context 'when current user can approve access request to the project' do before do - project.add_master(current_user) + project.add_maintainer(current_user) group.add_owner(current_user) end diff --git a/spec/services/members/create_service_spec.rb b/spec/services/members/create_service_spec.rb index 1831c62d788..5c01463d757 100644 --- a/spec/services/members/create_service_spec.rb +++ b/spec/services/members/create_service_spec.rb @@ -6,7 +6,7 @@ describe Members::CreateService do let(:project_user) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) end it 'adds user to members' do diff --git a/spec/services/members/destroy_service_spec.rb b/spec/services/members/destroy_service_spec.rb index 36b6e5a701e..ef47b0a450b 100644 --- a/spec/services/members/destroy_service_spec.rb +++ b/spec/services/members/destroy_service_spec.rb @@ -114,7 +114,7 @@ describe Members::DestroyService do context 'when current user can destroy the given member' do before do - group_project.add_master(current_user) + group_project.add_maintainer(current_user) group.add_owner(current_user) end @@ -142,8 +142,8 @@ describe Members::DestroyService do context 'with an access requester' do before do - group_project.update_attributes(request_access_enabled: true) - group.update_attributes(request_access_enabled: true) + group_project.update(request_access_enabled: true) + group.update(request_access_enabled: true) group_project.request_access(member_user) group.request_access(member_user) end @@ -170,7 +170,7 @@ describe Members::DestroyService do context 'when current user can destroy the given access requester' do before do - group_project.add_master(current_user) + group_project.add_maintainer(current_user) group.add_owner(current_user) end @@ -210,7 +210,7 @@ describe Members::DestroyService do context 'when current user can destroy the given invited user' do before do - group_project.add_master(current_user) + group_project.add_maintainer(current_user) group.add_owner(current_user) end diff --git a/spec/services/members/update_service_spec.rb b/spec/services/members/update_service_spec.rb index a451272dd1f..6d19a95ffeb 100644 --- a/spec/services/members/update_service_spec.rb +++ b/spec/services/members/update_service_spec.rb @@ -8,7 +8,7 @@ describe Members::UpdateService do let(:permission) { :update } let(:member) { source.members_and_requesters.find_by!(user_id: member_user.id) } let(:params) do - { access_level: Gitlab::Access::MASTER } + { access_level: Gitlab::Access::MAINTAINER } end shared_examples 'a service raising Gitlab::Access::AccessDeniedError' do @@ -23,7 +23,7 @@ describe Members::UpdateService do updated_member = described_class.new(current_user, params).execute(member, permission: permission) expect(updated_member).to be_valid - expect(updated_member.access_level).to eq(Gitlab::Access::MASTER) + expect(updated_member.access_level).to eq(Gitlab::Access::MAINTAINER) end end @@ -44,7 +44,7 @@ describe Members::UpdateService do context 'when current user can update the given member' do before do - project.add_master(current_user) + project.add_maintainer(current_user) group.add_owner(current_user) end diff --git a/spec/services/merge_requests/close_service_spec.rb b/spec/services/merge_requests/close_service_spec.rb index 216e0cd4266..433ffbd97f0 100644 --- a/spec/services/merge_requests/close_service_spec.rb +++ b/spec/services/merge_requests/close_service_spec.rb @@ -9,7 +9,7 @@ describe MergeRequests::CloseService do let!(:todo) { create(:todo, :assigned, user: user, project: project, target: merge_request, author: user2) } before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(user2) project.add_guest(guest) end diff --git a/spec/services/merge_requests/conflicts/list_service_spec.rb b/spec/services/merge_requests/conflicts/list_service_spec.rb index d57852615d9..c81fa95e4b7 100644 --- a/spec/services/merge_requests/conflicts/list_service_spec.rb +++ b/spec/services/merge_requests/conflicts/list_service_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' describe MergeRequests::Conflicts::ListService do describe '#can_be_resolved_in_ui?' do - def create_merge_request(source_branch) - create(:merge_request, source_branch: source_branch, target_branch: 'conflict-start', merge_status: :unchecked) do |mr| + def create_merge_request(source_branch, target_branch = 'conflict-start') + create(:merge_request, source_branch: source_branch, target_branch: target_branch, merge_status: :unchecked) do |mr| mr.mark_as_unmergeable end end @@ -34,7 +34,7 @@ describe MergeRequests::Conflicts::ListService do it 'returns a falsey value when the MR does not support new diff notes' do merge_request = create_merge_request('conflict-resolvable') - merge_request.merge_request_diff.update_attributes(start_commit_sha: nil) + merge_request.merge_request_diff.update(start_commit_sha: nil) expect(conflicts_service(merge_request).can_be_resolved_in_ui?).to be_falsey end @@ -85,22 +85,10 @@ describe MergeRequests::Conflicts::ListService do expect(service.can_be_resolved_in_ui?).to be_falsey end - context 'with gitaly disabled', :skip_gitaly_mock do - it 'returns a falsey value when the MR has a missing ref after a force push' do - merge_request = create_merge_request('conflict-resolvable') - service = conflicts_service(merge_request) - allow_any_instance_of(Rugged::Repository).to receive(:merge_commits).and_raise(Rugged::OdbError) + it 'returns a falsey value when the conflict is in a submodule revision' do + merge_request = create_merge_request('update-gitlab-shell-v-6-0-3', 'update-gitlab-shell-v-6-0-1') - expect(service.can_be_resolved_in_ui?).to be_falsey - end - - it 'returns a falsey value when the MR has a missing revision after a force push' do - merge_request = create_merge_request('conflict-resolvable') - service = conflicts_service(merge_request) - allow(merge_request).to receive_message_chain(:target_branch_head, :raw, :id).and_return(Gitlab::Git::BLANK_SHA) - - expect(service.can_be_resolved_in_ui?).to be_falsey - end + expect(conflicts_service(merge_request).can_be_resolved_in_ui?).to be_falsey end end end diff --git a/spec/services/merge_requests/conflicts/resolve_service_spec.rb b/spec/services/merge_requests/conflicts/resolve_service_spec.rb index cff09237005..7edf8a96c94 100644 --- a/spec/services/merge_requests/conflicts/resolve_service_spec.rb +++ b/spec/services/merge_requests/conflicts/resolve_service_spec.rb @@ -123,17 +123,6 @@ describe MergeRequests::Conflicts::ResolveService do expect(merge_request_from_fork.source_branch_head.parents.map(&:id)) .to eq(['404fa3fc7c2c9b5dacff102f353bdf55b1be2813', target_head]) end - - context 'when gitaly is disabled', :skip_gitaly_mock do - it 'gets conflicts from the source project' do - # REFACTOR NOTE: We used to test that `project.repository.rugged` wasn't - # used in this case, but since the refactor, for simplification, - # we always use that repository for read only operations. - expect(forked_project.repository.rugged).to receive(:merge_commits).and_call_original - - subject - end - end end end diff --git a/spec/services/merge_requests/create_service_spec.rb b/spec/services/merge_requests/create_service_spec.rb index 736a50b2c15..06fb61baf33 100644 --- a/spec/services/merge_requests/create_service_spec.rb +++ b/spec/services/merge_requests/create_service_spec.rb @@ -23,7 +23,7 @@ describe MergeRequests::CreateService do let(:merge_request) { service.execute } before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(assignee) allow(service).to receive(:execute_hooks) end @@ -185,8 +185,8 @@ describe MergeRequests::CreateService do end before do - project.add_master(user) - project.add_master(assignee) + project.add_maintainer(user) + project.add_maintainer(assignee) end it 'assigns and sets milestone to issuable from command' do @@ -202,7 +202,7 @@ describe MergeRequests::CreateService do let(:assignee) { create(:user) } before do - project.add_master(user) + project.add_maintainer(user) end it 'removes assignee_id when user id is invalid' do @@ -222,7 +222,7 @@ describe MergeRequests::CreateService do end it 'saves assignee when user id is valid' do - project.add_master(assignee) + project.add_maintainer(assignee) opts = { title: 'Title', description: 'Description', assignee_id: assignee.id } merge_request = described_class.new(project, user, opts).execute @@ -242,7 +242,7 @@ describe MergeRequests::CreateService do end it 'invalidates open merge request counter for assignees when merge request is assigned' do - project.add_master(assignee) + project.add_maintainer(assignee) described_class.new(project, user, opts).execute @@ -286,7 +286,7 @@ describe MergeRequests::CreateService do end before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(assignee) end @@ -316,7 +316,7 @@ describe MergeRequests::CreateService do context 'when user can not access source project' do before do target_project.add_developer(assignee) - target_project.add_master(user) + target_project.add_maintainer(user) end it 'raises an error' do @@ -328,7 +328,7 @@ describe MergeRequests::CreateService do context 'when user can not access target project' do before do target_project.add_developer(assignee) - target_project.add_master(user) + target_project.add_maintainer(user) end it 'raises an error' do @@ -372,7 +372,7 @@ describe MergeRequests::CreateService do before do project.add_developer(assignee) - project.add_master(user) + project.add_maintainer(user) end it 'ignores source_project_id' do diff --git a/spec/services/merge_requests/ff_merge_service_spec.rb b/spec/services/merge_requests/ff_merge_service_spec.rb index 28f56d19657..fe673de46aa 100644 --- a/spec/services/merge_requests/ff_merge_service_spec.rb +++ b/spec/services/merge_requests/ff_merge_service_spec.rb @@ -13,7 +13,7 @@ describe MergeRequests::FfMergeService do let(:project) { merge_request.project } before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(user2) end diff --git a/spec/services/merge_requests/merge_service_spec.rb b/spec/services/merge_requests/merge_service_spec.rb index ef2738ef504..9dd235f6660 100644 --- a/spec/services/merge_requests/merge_service_spec.rb +++ b/spec/services/merge_requests/merge_service_spec.rb @@ -7,7 +7,7 @@ describe MergeRequests::MergeService do let(:project) { merge_request.project } before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(user2) end @@ -63,7 +63,7 @@ describe MergeRequests::MergeService do let(:commit) { double('commit', safe_message: "Fixes #{jira_issue.to_reference}") } before do - project.update_attributes!(has_external_issue_tracker: true) + project.update!(has_external_issue_tracker: true) jira_service_settings stub_jira_urls(jira_issue.id) allow(merge_request).to receive(:commits).and_return([commit]) diff --git a/spec/services/merge_requests/post_merge_service_spec.rb b/spec/services/merge_requests/post_merge_service_spec.rb index 46e4e3559dc..ba2b062875b 100644 --- a/spec/services/merge_requests/post_merge_service_spec.rb +++ b/spec/services/merge_requests/post_merge_service_spec.rb @@ -6,7 +6,7 @@ describe MergeRequests::PostMergeService do let(:project) { merge_request.project } before do - project.add_master(user) + project.add_maintainer(user) end describe '#execute' do diff --git a/spec/services/merge_requests/rebase_service_spec.rb b/spec/services/merge_requests/rebase_service_spec.rb index 757c31ab692..2703da7ae44 100644 --- a/spec/services/merge_requests/rebase_service_spec.rb +++ b/spec/services/merge_requests/rebase_service_spec.rb @@ -15,7 +15,7 @@ describe MergeRequests::RebaseService do subject(:service) { described_class.new(project, user, {}) } before do - project.add_master(user) + project.add_maintainer(user) end describe '#execute' do @@ -36,9 +36,9 @@ describe MergeRequests::RebaseService do end end - context 'when unexpected error occurs', :disable_gitaly do + context 'when unexpected error occurs' do before do - allow(repository).to receive(:run_git!).and_raise('Something went wrong') + allow(repository).to receive(:gitaly_operation_client).and_raise('Something went wrong') end it 'saves a generic error message' do @@ -53,9 +53,9 @@ describe MergeRequests::RebaseService do end end - context 'with git command failure', :disable_gitaly do + context 'with git command failure' do before do - allow(repository).to receive(:run_git!).and_raise(Gitlab::Git::Repository::GitError, 'Something went wrong') + allow(repository).to receive(:gitaly_operation_client).and_raise(Gitlab::Git::Repository::GitError, 'Something went wrong') end it 'saves a generic error message' do @@ -71,7 +71,7 @@ describe MergeRequests::RebaseService do end context 'valid params' do - shared_examples 'successful rebase' do + describe 'successful rebase' do before do service.execute(merge_request) end @@ -97,26 +97,8 @@ describe MergeRequests::RebaseService do end end - context 'when Gitaly rebase feature is enabled' do - it_behaves_like 'successful rebase' - end - - context 'when Gitaly rebase feature is disabled', :disable_gitaly do - it_behaves_like 'successful rebase' - end - - context 'git commands', :disable_gitaly do - it 'sets GL_REPOSITORY env variable when calling git commands' do - expect(repository).to receive(:popen).exactly(3) - .with(anything, anything, hash_including('GL_REPOSITORY'), anything) - .and_return(['', 0]) - - service.execute(merge_request) - end - end - context 'fork' do - shared_examples 'successful fork rebase' do + describe 'successful fork rebase' do let(:forked_project) do fork_project(project, user, repository: true) end @@ -140,14 +122,6 @@ describe MergeRequests::RebaseService do expect(parent_sha).to eq(target_branch_sha) end end - - context 'when Gitaly rebase feature is enabled' do - it_behaves_like 'successful fork rebase' - end - - context 'when Gitaly rebase feature is disabled', :disable_gitaly do - it_behaves_like 'successful fork rebase' - end end end end diff --git a/spec/services/merge_requests/reopen_service_spec.rb b/spec/services/merge_requests/reopen_service_spec.rb index 9ee37c51d95..e10eaa95da4 100644 --- a/spec/services/merge_requests/reopen_service_spec.rb +++ b/spec/services/merge_requests/reopen_service_spec.rb @@ -8,7 +8,7 @@ describe MergeRequests::ReopenService do let(:project) { merge_request.project } before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(user2) project.add_guest(guest) end diff --git a/spec/services/merge_requests/squash_service_spec.rb b/spec/services/merge_requests/squash_service_spec.rb index ded17fa92a4..8ab09412f55 100644 --- a/spec/services/merge_requests/squash_service_spec.rb +++ b/spec/services/merge_requests/squash_service_spec.rb @@ -124,51 +124,6 @@ describe MergeRequests::SquashService do message: a_string_including('squash')) end end - - context 'with Gitaly disabled', :skip_gitaly_mock do - stages = { - 'add worktree for squash' => 'worktree', - 'configure sparse checkout' => 'config', - 'get files in diff' => 'diff --name-only', - 'check out target branch' => 'checkout', - 'apply patch' => 'diff --binary', - 'commit squashed changes' => 'commit', - 'get SHA of squashed commit' => 'rev-parse' - } - - stages.each do |stage, command| - context "when the #{stage} stage fails" do - before do - git_command = a_collection_containing_exactly( - a_string_starting_with("#{Gitlab.config.git.bin_path} #{command}") - ).or( - a_collection_starting_with([Gitlab.config.git.bin_path] + command.split) - ) - - allow(repository).to receive(:popen).and_return(['', 0]) - allow(repository).to receive(:popen).with(git_command, anything, anything, anything).and_return([error, 1]) - end - - it 'logs the stage and output' do - expect(service).to receive(:log_error).with(log_error) - expect(service).to receive(:log_error).with(error) - - service.execute(merge_request) - end - - it 'returns an error' do - expect(service.execute(merge_request)).to match(status: :error, - message: a_string_including('squash')) - end - - it 'cleans up the temporary directory' do - expect(File.exist?(squash_dir_path)).to be(false) - - service.execute(merge_request) - end - end - end - end end context 'when any other exception is thrown' do diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb index 443dcd92a8b..f0029af83cc 100644 --- a/spec/services/merge_requests/update_service_spec.rb +++ b/spec/services/merge_requests/update_service_spec.rb @@ -19,7 +19,7 @@ describe MergeRequests::UpdateService, :mailer do end before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(user2) project.add_developer(user3) end diff --git a/spec/services/milestones/close_service_spec.rb b/spec/services/milestones/close_service_spec.rb index adad73f7e11..3f7a544ea0a 100644 --- a/spec/services/milestones/close_service_spec.rb +++ b/spec/services/milestones/close_service_spec.rb @@ -6,7 +6,7 @@ describe Milestones::CloseService do let(:milestone) { create(:milestone, title: "Milestone v1.2", project: project) } before do - project.add_master(user) + project.add_maintainer(user) end describe '#execute' do diff --git a/spec/services/milestones/create_service_spec.rb b/spec/services/milestones/create_service_spec.rb index f2a18c7295a..0c91112026f 100644 --- a/spec/services/milestones/create_service_spec.rb +++ b/spec/services/milestones/create_service_spec.rb @@ -7,7 +7,7 @@ describe Milestones::CreateService do describe '#execute' do context "valid params" do before do - project.add_master(user) + project.add_maintainer(user) opts = { title: 'v2.1.9', diff --git a/spec/services/milestones/destroy_service_spec.rb b/spec/services/milestones/destroy_service_spec.rb index 9703780b0e9..6f3612501f4 100644 --- a/spec/services/milestones/destroy_service_spec.rb +++ b/spec/services/milestones/destroy_service_spec.rb @@ -8,7 +8,7 @@ describe Milestones::DestroyService do let!(:merge_request) { create(:merge_request, source_project: project, milestone: milestone) } before do - project.add_master(user) + project.add_maintainer(user) end def service diff --git a/spec/services/milestones/promote_service_spec.rb b/spec/services/milestones/promote_service_spec.rb index a0a2843b676..df212d912e9 100644 --- a/spec/services/milestones/promote_service_spec.rb +++ b/spec/services/milestones/promote_service_spec.rb @@ -10,7 +10,7 @@ describe Milestones::PromoteService do describe '#execute' do before do - group.add_master(user) + group.add_maintainer(user) end context 'validations' do diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index 2b2b983494f..0fd37c95e42 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -10,7 +10,7 @@ describe Notes::CreateService do describe '#execute' do before do - project.add_master(user) + project.add_maintainer(user) end context "valid params" do diff --git a/spec/services/notes/post_process_service_spec.rb b/spec/services/notes/post_process_service_spec.rb index 4e2ab919f0f..5aae0d711c3 100644 --- a/spec/services/notes/post_process_service_spec.rb +++ b/spec/services/notes/post_process_service_spec.rb @@ -7,7 +7,7 @@ describe Notes::PostProcessService do describe '#execute' do before do - project.add_master(user) + project.add_maintainer(user) note_opts = { note: 'Awesome comment', noteable_type: 'Issue', diff --git a/spec/services/notes/quick_actions_service_spec.rb b/spec/services/notes/quick_actions_service_spec.rb index b1e218821d2..784dac55454 100644 --- a/spec/services/notes/quick_actions_service_spec.rb +++ b/spec/services/notes/quick_actions_service_spec.rb @@ -3,11 +3,11 @@ require 'spec_helper' describe Notes::QuickActionsService do shared_context 'note on noteable' do let(:project) { create(:project) } - let(:master) { create(:user).tap { |u| project.add_master(u) } } + let(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } } let(:assignee) { create(:user) } before do - project.add_master(assignee) + project.add_maintainer(assignee) end end @@ -184,7 +184,7 @@ describe Notes::QuickActionsService do include_context 'note on noteable' it 'delegates to the class method' do - service = described_class.new(project, master) + service = described_class.new(project, maintainer) note = create(:note_on_issue, project: project) expect(described_class).to receive(:supported?).with(note) @@ -194,7 +194,7 @@ describe Notes::QuickActionsService do end describe '#execute' do - let(:service) { described_class.new(project, master) } + let(:service) { described_class.new(project, maintainer) } it_behaves_like 'note on noteable that supports quick actions' do let(:note) { build(:note_on_issue, project: project) } @@ -212,19 +212,19 @@ describe Notes::QuickActionsService do context 'CE restriction for issue assignees' do describe '/assign' do let(:project) { create(:project) } - let(:master) { create(:user).tap { |u| project.add_master(u) } } + let(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } } let(:assignee) { create(:user) } - let(:master) { create(:user) } - let(:service) { described_class.new(project, master) } + let(:maintainer) { create(:user) } + let(:service) { described_class.new(project, maintainer) } let(:note) { create(:note_on_issue, note: note_text, project: project) } let(:note_text) do - %(/assign @#{assignee.username} @#{master.username}\n") + %(/assign @#{assignee.username} @#{maintainer.username}\n") end before do - project.add_master(master) - project.add_master(assignee) + project.add_maintainer(maintainer) + project.add_maintainer(assignee) end it 'adds only one assignee from the list' do diff --git a/spec/services/notes/update_service_spec.rb b/spec/services/notes/update_service_spec.rb index 65b1d613998..533dcdcd6cd 100644 --- a/spec/services/notes/update_service_spec.rb +++ b/spec/services/notes/update_service_spec.rb @@ -9,7 +9,7 @@ describe Notes::UpdateService do let(:note) { create(:note, project: project, noteable: issue, author: user, note: "Old note #{user2.to_reference}") } before do - project.add_master(user) + project.add_maintainer(user) project.add_developer(user2) project.add_developer(user3) end diff --git a/spec/services/notification_recipient_service_spec.rb b/spec/services/notification_recipient_service_spec.rb index 7f536ce4e68..14ba6b7bed2 100644 --- a/spec/services/notification_recipient_service_spec.rb +++ b/spec/services/notification_recipient_service_spec.rb @@ -12,15 +12,15 @@ describe NotificationRecipientService do def create_watcher watcher = create(:user) - create(:notification_setting, project: project, user: watcher, level: :watch) + create(:notification_setting, source: project, user: watcher, level: :watch) other_projects.each do |other_project| - create(:notification_setting, project: other_project, user: watcher, level: :watch) + create(:notification_setting, source: other_project, user: watcher, level: :watch) end end it 'avoids N+1 queries', :request_store do - Gitlab::GitalyClient.allow_n_plus_1_calls { create_watcher } + create_watcher service.build_new_note_recipients(note) @@ -28,7 +28,7 @@ describe NotificationRecipientService do service.build_new_note_recipients(note) end - Gitlab::GitalyClient.allow_n_plus_1_calls { create_watcher } + create_watcher expect { service.build_new_note_recipients(note) }.not_to exceed_query_limit(control_count) end diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 0eadc83bfe3..c442f6fe32f 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -172,9 +172,9 @@ describe NotificationService, :mailer do before do build_team(note.project) - project.add_master(issue.author) - project.add_master(assignee) - project.add_master(note.author) + project.add_maintainer(issue.author) + project.add_maintainer(assignee) + project.add_maintainer(note.author) @u_custom_off = create_user_with_notification(:custom, 'custom_off') project.add_guest(@u_custom_off) @@ -255,8 +255,8 @@ describe NotificationService, :mailer do describe 'new note on issue in project that belongs to a group' do before do note.project.namespace_id = group.id - group.add_user(@u_watcher, GroupMember::MASTER) - group.add_user(@u_custom_global, GroupMember::MASTER) + group.add_user(@u_watcher, GroupMember::MAINTAINER) + group.add_user(@u_custom_global, GroupMember::MAINTAINER) note.project.save @u_watcher.notification_settings_for(note.project).participating! @@ -373,7 +373,7 @@ describe NotificationService, :mailer do before do build_team(note.project) build_group(note.project) - note.project.add_master(note.author) + note.project.add_maintainer(note.author) add_users_with_subscription(note.project, issue) reset_delivered_emails! end @@ -436,7 +436,7 @@ describe NotificationService, :mailer do project.add_guest(@u_guest_watcher) project.add_guest(@u_guest_custom) add_member_for_parent_group(@pg_watcher, project) - note.project.add_master(note.author) + note.project.add_maintainer(note.author) reset_delivered_emails! end @@ -577,8 +577,8 @@ describe NotificationService, :mailer do before do build_team(note.project) - project.add_master(merge_request.author) - project.add_master(merge_request.assignee) + project.add_maintainer(merge_request.author) + project.add_maintainer(merge_request.assignee) end describe '#new_note' do @@ -1088,8 +1088,8 @@ describe NotificationService, :mailer do let(:merge_request) { create :merge_request, source_project: project, assignee: create(:user), description: 'cc @participant' } before do - project.add_master(merge_request.author) - project.add_master(merge_request.assignee) + project.add_maintainer(merge_request.author) + project.add_maintainer(merge_request.assignee) build_team(merge_request.target_project) add_users_with_subscription(merge_request.target_project, merge_request) update_custom_notification(:new_merge_request, @u_guest_custom, resource: project) @@ -1314,7 +1314,7 @@ describe NotificationService, :mailer do describe 'when merge_when_pipeline_succeeds is true' do before do - merge_request.update_attributes( + merge_request.update( merge_when_pipeline_succeeds: true, merge_user: create(:user) ) @@ -1529,13 +1529,13 @@ describe NotificationService, :mailer do let(:added_user) { create(:user) } describe '#new_access_request' do - let(:master) { create(:user) } + let(:maintainer) { create(:user) } let(:owner) { create(:user) } let(:developer) { create(:user) } let!(:group) do create(:group, :public, :access_requestable) do |group| group.add_owner(owner) - group.add_master(master) + group.add_maintainer(maintainer) group.add_developer(developer) end end @@ -1544,11 +1544,11 @@ describe NotificationService, :mailer do reset_delivered_emails! end - it 'sends notification to group owners_and_masters' do + it 'sends notification to group owners_and_maintainers' do group.request_access(added_user) should_email(owner) - should_email(master) + should_email(maintainer) should_not_email(developer) end end @@ -1601,11 +1601,11 @@ describe NotificationService, :mailer do context 'for a project in a user namespace' do let(:project) do create(:project, :public, :access_requestable) do |project| - project.add_master(project.owner) + project.add_maintainer(project.owner) end end - it 'sends notification to project owners_and_masters' do + it 'sends notification to project owners_and_maintainers' do project.request_access(added_user) should_only_email(project.owner) @@ -1621,7 +1621,7 @@ describe NotificationService, :mailer do reset_delivered_emails! end - it 'sends notification to group owners_and_masters' do + it 'sends notification to group owners_and_maintainers' do project.request_access(added_user) should_only_email(group_owner) @@ -1759,11 +1759,11 @@ describe NotificationService, :mailer do end before do - project.add_master(u_member) - project.add_master(u_watcher) - project.add_master(u_custom_notification_unset) - project.add_master(u_custom_notification_enabled) - project.add_master(u_custom_notification_disabled) + project.add_maintainer(u_member) + project.add_maintainer(u_watcher) + project.add_maintainer(u_custom_notification_unset) + project.add_maintainer(u_custom_notification_enabled) + project.add_maintainer(u_custom_notification_disabled) reset_delivered_emails! end @@ -1903,15 +1903,15 @@ describe NotificationService, :mailer do set(:u_blocked) { create(:user, :blocked) } set(:u_silence) { create_user_with_notification(:disabled, 'silent', project) } set(:u_owner) { project.owner } - set(:u_master1) { create(:user) } - set(:u_master2) { create(:user) } + set(:u_maintainer1) { create(:user) } + set(:u_maintainer2) { create(:user) } set(:u_developer) { create(:user) } before do - project.add_master(u_blocked) - project.add_master(u_silence) - project.add_master(u_master1) - project.add_master(u_master2) + project.add_maintainer(u_blocked) + project.add_maintainer(u_silence) + project.add_maintainer(u_maintainer1) + project.add_maintainer(u_maintainer2) project.add_developer(u_developer) reset_delivered_emails! @@ -1926,12 +1926,12 @@ describe NotificationService, :mailer do describe "##{sym}" do subject(:notify!) { notification.send(sym, domain) } - it 'emails current watching masters' do + it 'emails current watching maintainers' do expect(Notify).to receive(:"#{sym}_email").at_least(:once).and_call_original notify! - should_only_email(u_master1, u_master2, u_owner) + should_only_email(u_maintainer1, u_maintainer2, u_owner) end it 'emails nobody if the project is missing' do @@ -1945,26 +1945,26 @@ describe NotificationService, :mailer do end describe '#pages_domain_verification_failed' do - it 'emails current watching masters' do + it 'emails current watching maintainers' do notification.pages_domain_verification_failed(domain) - should_only_email(u_master1, u_master2, u_owner) + should_only_email(u_maintainer1, u_maintainer2, u_owner) end end describe '#pages_domain_enabled' do - it 'emails current watching masters' do + it 'emails current watching maintainers' do notification.pages_domain_enabled(domain) - should_only_email(u_master1, u_master2, u_owner) + should_only_email(u_maintainer1, u_maintainer2, u_owner) end end describe '#pages_domain_disabled' do - it 'emails current watching masters' do + it 'emails current watching maintainers' do notification.pages_domain_disabled(domain) - should_only_email(u_master1, u_master2, u_owner) + should_only_email(u_maintainer1, u_maintainer2, u_owner) end end end @@ -1988,15 +1988,15 @@ describe NotificationService, :mailer do @u_guest_watcher = create_user_with_notification(:watch, 'guest_watching') @u_guest_custom = create_user_with_notification(:custom, 'guest_custom') - project.add_master(@u_watcher) - project.add_master(@u_participating) - project.add_master(@u_participant_mentioned) - project.add_master(@u_disabled) - project.add_master(@u_mentioned) - project.add_master(@u_committer) - project.add_master(@u_not_mentioned) - project.add_master(@u_lazy_participant) - project.add_master(@u_custom_global) + project.add_maintainer(@u_watcher) + project.add_maintainer(@u_participating) + project.add_maintainer(@u_participant_mentioned) + project.add_maintainer(@u_disabled) + project.add_maintainer(@u_mentioned) + project.add_maintainer(@u_committer) + project.add_maintainer(@u_not_mentioned) + project.add_maintainer(@u_lazy_participant) + project.add_maintainer(@u_custom_global) end # Users in the project's group but not part of project's team @@ -2011,7 +2011,7 @@ describe NotificationService, :mailer do # Group member: global=watch, group=global @g_global_watcher ||= create_global_setting_for(create(:user), :watch) - group.add_users([@g_watcher, @g_global_watcher], :master) + group.add_users([@g_watcher, @g_global_watcher], :maintainer) group end @@ -2050,7 +2050,7 @@ describe NotificationService, :mailer do project.reload - project.group.parent.add_master(user) + project.group.parent.add_maintainer(user) end def should_email_nested_group_user(user, times: 1, recipients: email_recipients) @@ -2072,11 +2072,11 @@ describe NotificationService, :mailer do @subscribed_participant = create_global_setting_for(create(:user, username: 'subscribed_participant'), :participating) @watcher_and_subscriber = create_global_setting_for(create(:user), :watch) - project.add_master(@subscribed_participant) - project.add_master(@subscriber) - project.add_master(@unsubscriber) - project.add_master(@watcher_and_subscriber) - project.add_master(@unsubscribed_mentioned) + project.add_maintainer(@subscribed_participant) + project.add_maintainer(@subscriber) + project.add_maintainer(@unsubscriber) + project.add_maintainer(@watcher_and_subscriber) + project.add_maintainer(@unsubscribed_mentioned) issuable.subscriptions.create(user: @unsubscribed_mentioned, project: project, subscribed: false) issuable.subscriptions.create(user: @subscriber, project: project, subscribed: true) diff --git a/spec/services/preview_markdown_service_spec.rb b/spec/services/preview_markdown_service_spec.rb index 64a9559791f..81dc7c57f4a 100644 --- a/spec/services/preview_markdown_service_spec.rb +++ b/spec/services/preview_markdown_service_spec.rb @@ -64,4 +64,16 @@ describe PreviewMarkdownService do expect(result[:commands]).to eq 'Sets time estimate to 2y.' end end + + it 'sets correct markdown engine' do + service = described_class.new(project, user, { markdown_version: CacheMarkdownField::CACHE_REDCARPET_VERSION }) + result = service.execute + + expect(result[:markdown_engine]).to eq :redcarpet + + service = described_class.new(project, user, { markdown_version: CacheMarkdownField::CACHE_COMMONMARK_VERSION }) + result = service.execute + + expect(result[:markdown_engine]).to eq :common_mark + end end diff --git a/spec/services/projects/autocomplete_service_spec.rb b/spec/services/projects/autocomplete_service_spec.rb index 6fd73a50511..e98df375d48 100644 --- a/spec/services/projects/autocomplete_service_spec.rb +++ b/spec/services/projects/autocomplete_service_spec.rb @@ -131,4 +131,58 @@ describe Projects::AutocompleteService do end end end + + describe '#labels_as_hash' do + def expect_labels_to_equal(labels, expected_labels) + expect(labels.size).to eq(expected_labels.size) + extract_title = lambda { |label| label['title'] } + expect(labels.map(&extract_title)).to eq(expected_labels.map(&extract_title)) + end + + let(:user) { create(:user) } + let(:group) { create(:group, :nested) } + let!(:sub_group) { create(:group, parent: group) } + let(:project) { create(:project, :public, group: group) } + let(:issue) { create(:issue, project: project) } + + let!(:label1) { create(:label, project: project) } + let!(:label2) { create(:label, project: project) } + let!(:sub_group_label) { create(:group_label, group: sub_group) } + let!(:parent_group_label) { create(:group_label, group: group.parent) } + + before do + create(:group_member, group: group, user: user) + end + + it 'returns labels from project and ancestor groups' do + service = described_class.new(project, user) + results = service.labels_as_hash + expected_labels = [label1, label2, parent_group_label] + + expect_labels_to_equal(results, expected_labels) + end + + context 'some labels are already assigned' do + before do + issue.labels << label1 + end + + it 'marks already assigned as set' do + service = described_class.new(project, user) + results = service.labels_as_hash(issue) + expected_labels = [label1, label2, parent_group_label] + + expect_labels_to_equal(results, expected_labels) + + assigned_label_titles = issue.labels.map(&:title) + results.each do |hash| + if assigned_label_titles.include?(hash['title']) + expect(hash[:set]).to eq(true) + else + expect(hash.key?(:set)).to eq(false) + end + end + end + end + end end diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb index e8cbf84e3be..fd69fe04053 100644 --- a/spec/services/projects/create_service_spec.rb +++ b/spec/services/projects/create_service_spec.rb @@ -23,7 +23,7 @@ describe Projects::CreateService, '#execute' do expect(project).to be_valid expect(project.owner).to eq(user) - expect(project.team.masters).to include(user) + expect(project.team.maintainers).to include(user) expect(project.namespace).to eq(user.namespace) end end @@ -47,7 +47,7 @@ describe Projects::CreateService, '#execute' do expect(project).to be_persisted expect(project.owner).to eq(user) - expect(project.team.masters).to contain_exactly(user) + expect(project.team.maintainers).to contain_exactly(user) expect(project.namespace).to eq(user.namespace) end end @@ -236,6 +236,18 @@ describe Projects::CreateService, '#execute' do end end + context 'when readme initialization is requested' do + it 'creates README.md' do + opts[:initialize_with_readme] = '1' + + project = create_project(user, opts) + + expect(project.repository.commit_count).to be(1) + expect(project.repository.readme.name).to eql('README.md') + expect(project.repository.readme.data).to include('# GitLab') + end + end + context 'when there is an active service template' do before do create(:service, project: nil, template: true, active: true) diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb index c15f5120b8a..f89f9b54f53 100644 --- a/spec/services/projects/fork_service_spec.rb +++ b/spec/services/projects/fork_service_spec.rb @@ -135,7 +135,7 @@ describe Projects::ForkService do context "when project has restricted visibility level" do context "and only one visibility level is restricted" do before do - @from_project.update_attributes(visibility_level: Gitlab::VisibilityLevel::INTERNAL) + @from_project.update(visibility_level: Gitlab::VisibilityLevel::INTERNAL) stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL]) end diff --git a/spec/services/projects/move_access_service_spec.rb b/spec/services/projects/move_access_service_spec.rb index a820ebd91f4..88d9d93c33b 100644 --- a/spec/services/projects/move_access_service_spec.rb +++ b/spec/services/projects/move_access_service_spec.rb @@ -4,18 +4,18 @@ describe Projects::MoveAccessService do let(:user) { create(:user) } let(:group) { create(:group) } let(:project_with_access) { create(:project, namespace: user.namespace) } - let(:master_user) { create(:user) } + let(:maintainer_user) { create(:user) } let(:reporter_user) { create(:user) } let(:developer_user) { create(:user) } - let(:master_group) { create(:group) } + let(:maintainer_group) { create(:group) } let(:reporter_group) { create(:group) } let(:developer_group) { create(:group) } before do - project_with_access.add_master(master_user) + project_with_access.add_maintainer(maintainer_user) project_with_access.add_developer(developer_user) project_with_access.add_reporter(reporter_user) - project_with_access.project_group_links.create(group: master_group, group_access: Gitlab::Access::MASTER) + project_with_access.project_group_links.create(group: maintainer_group, group_access: Gitlab::Access::MAINTAINER) project_with_access.project_group_links.create(group: developer_group, group_access: Gitlab::Access::DEVELOPER) project_with_access.project_group_links.create(group: reporter_group, group_access: Gitlab::Access::REPORTER) end @@ -87,7 +87,7 @@ describe Projects::MoveAccessService do let(:options) { { remove_remaining_elements: false } } it 'does not remove remaining memberships' do - target_project.add_master(master_user) + target_project.add_maintainer(maintainer_user) subject.execute(project_with_access, options) @@ -95,7 +95,7 @@ describe Projects::MoveAccessService do end it 'does not remove remaining group links' do - target_project.project_group_links.create(group: master_group, group_access: Gitlab::Access::MASTER) + target_project.project_group_links.create(group: maintainer_group, group_access: Gitlab::Access::MAINTAINER) subject.execute(project_with_access, options) diff --git a/spec/services/projects/move_project_authorizations_service_spec.rb b/spec/services/projects/move_project_authorizations_service_spec.rb index f7262b9b887..b4408393624 100644 --- a/spec/services/projects/move_project_authorizations_service_spec.rb +++ b/spec/services/projects/move_project_authorizations_service_spec.rb @@ -4,7 +4,7 @@ describe Projects::MoveProjectAuthorizationsService do let!(:user) { create(:user) } let(:project_with_users) { create(:project, namespace: user.namespace) } let(:target_project) { create(:project, namespace: user.namespace) } - let(:master_user) { create(:user) } + let(:maintainer_user) { create(:user) } let(:reporter_user) { create(:user) } let(:developer_user) { create(:user) } @@ -12,7 +12,7 @@ describe Projects::MoveProjectAuthorizationsService do describe '#execute' do before do - project_with_users.add_master(master_user) + project_with_users.add_maintainer(maintainer_user) project_with_users.add_developer(developer_user) project_with_users.add_reporter(reporter_user) end @@ -28,7 +28,7 @@ describe Projects::MoveProjectAuthorizationsService do end it 'does not move existent authorizations to the current project' do - target_project.add_master(developer_user) + target_project.add_maintainer(developer_user) target_project.add_developer(reporter_user) expect(project_with_users.authorized_users.count).to eq 4 @@ -44,7 +44,7 @@ describe Projects::MoveProjectAuthorizationsService do let(:options) { { remove_remaining_elements: false } } it 'does not remove remaining project authorizations' do - target_project.add_master(developer_user) + target_project.add_maintainer(developer_user) target_project.add_developer(reporter_user) subject.execute(project_with_users, options) diff --git a/spec/services/projects/move_project_group_links_service_spec.rb b/spec/services/projects/move_project_group_links_service_spec.rb index e3d06e6d3d7..7ca8cf304fe 100644 --- a/spec/services/projects/move_project_group_links_service_spec.rb +++ b/spec/services/projects/move_project_group_links_service_spec.rb @@ -4,7 +4,7 @@ describe Projects::MoveProjectGroupLinksService do let!(:user) { create(:user) } let(:project_with_groups) { create(:project, namespace: user.namespace) } let(:target_project) { create(:project, namespace: user.namespace) } - let(:master_group) { create(:group) } + let(:maintainer_group) { create(:group) } let(:reporter_group) { create(:group) } let(:developer_group) { create(:group) } @@ -12,7 +12,7 @@ describe Projects::MoveProjectGroupLinksService do describe '#execute' do before do - project_with_groups.project_group_links.create(group: master_group, group_access: Gitlab::Access::MASTER) + project_with_groups.project_group_links.create(group: maintainer_group, group_access: Gitlab::Access::MAINTAINER) project_with_groups.project_group_links.create(group: developer_group, group_access: Gitlab::Access::DEVELOPER) project_with_groups.project_group_links.create(group: reporter_group, group_access: Gitlab::Access::REPORTER) end @@ -28,7 +28,7 @@ describe Projects::MoveProjectGroupLinksService do end it 'does not move existent group links in the current project' do - target_project.project_group_links.create(group: master_group, group_access: Gitlab::Access::MASTER) + target_project.project_group_links.create(group: maintainer_group, group_access: Gitlab::Access::MAINTAINER) target_project.project_group_links.create(group: developer_group, group_access: Gitlab::Access::DEVELOPER) expect(project_with_groups.project_group_links.count).to eq 3 @@ -53,7 +53,7 @@ describe Projects::MoveProjectGroupLinksService do let(:options) { { remove_remaining_elements: false } } it 'does not remove remaining project group links' do - target_project.project_group_links.create(group: master_group, group_access: Gitlab::Access::MASTER) + target_project.project_group_links.create(group: maintainer_group, group_access: Gitlab::Access::MAINTAINER) target_project.project_group_links.create(group: developer_group, group_access: Gitlab::Access::DEVELOPER) subject.execute(project_with_groups, options) diff --git a/spec/services/projects/move_project_members_service_spec.rb b/spec/services/projects/move_project_members_service_spec.rb index 9c9a2d2fde1..c8c0eac1f13 100644 --- a/spec/services/projects/move_project_members_service_spec.rb +++ b/spec/services/projects/move_project_members_service_spec.rb @@ -4,7 +4,7 @@ describe Projects::MoveProjectMembersService do let!(:user) { create(:user) } let(:project_with_users) { create(:project, namespace: user.namespace) } let(:target_project) { create(:project, namespace: user.namespace) } - let(:master_user) { create(:user) } + let(:maintainer_user) { create(:user) } let(:reporter_user) { create(:user) } let(:developer_user) { create(:user) } @@ -12,7 +12,7 @@ describe Projects::MoveProjectMembersService do describe '#execute' do before do - project_with_users.add_master(master_user) + project_with_users.add_maintainer(maintainer_user) project_with_users.add_developer(developer_user) project_with_users.add_reporter(reporter_user) end @@ -28,7 +28,7 @@ describe Projects::MoveProjectMembersService do end it 'does not move existent members to the current project' do - target_project.add_master(developer_user) + target_project.add_maintainer(developer_user) target_project.add_developer(reporter_user) expect(project_with_users.project_members.count).to eq 4 @@ -53,7 +53,7 @@ describe Projects::MoveProjectMembersService do let(:options) { { remove_remaining_elements: false } } it 'does not remove remaining project members' do - target_project.add_master(developer_user) + target_project.add_maintainer(developer_user) target_project.add_developer(reporter_user) subject.execute(project_with_users, options) diff --git a/spec/services/projects/overwrite_project_service_spec.rb b/spec/services/projects/overwrite_project_service_spec.rb index 252c61f4224..c7900629f5f 100644 --- a/spec/services/projects/overwrite_project_service_spec.rb +++ b/spec/services/projects/overwrite_project_service_spec.rb @@ -96,10 +96,10 @@ describe Projects::OverwriteProjectService do context 'when project with elements' do it_behaves_like 'overwrite actions' do - let(:master_user) { create(:user) } + let(:maintainer_user) { create(:user) } let(:reporter_user) { create(:user) } let(:developer_user) { create(:user) } - let(:master_group) { create(:group) } + let(:maintainer_group) { create(:group) } let(:reporter_group) { create(:group) } let(:developer_group) { create(:group) } @@ -107,10 +107,10 @@ describe Projects::OverwriteProjectService do create_list(:deploy_keys_project, 2, project: project_from) create_list(:notification_setting, 2, source: project_from) create_list(:users_star_project, 2, project: project_from) - project_from.project_group_links.create(group: master_group, group_access: Gitlab::Access::MASTER) + project_from.project_group_links.create(group: maintainer_group, group_access: Gitlab::Access::MAINTAINER) project_from.project_group_links.create(group: developer_group, group_access: Gitlab::Access::DEVELOPER) project_from.project_group_links.create(group: reporter_group, group_access: Gitlab::Access::REPORTER) - project_from.add_master(master_user) + project_from.add_maintainer(maintainer_user) project_from.add_developer(developer_user) project_from.add_reporter(reporter_user) end diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb index 5100987c2fe..7e85f599afb 100644 --- a/spec/services/projects/transfer_service_spec.rb +++ b/spec/services/projects/transfer_service_spec.rb @@ -247,7 +247,7 @@ describe Projects::TransferService do let(:group_member) { create(:user) } before do - group.add_user(owner, GroupMember::MASTER) + group.add_user(owner, GroupMember::MAINTAINER) group.add_user(group_member, GroupMember::DEVELOPER) end diff --git a/spec/services/projects/update_pages_service_spec.rb b/spec/services/projects/update_pages_service_spec.rb index 1bffeee6790..a4c103e6f30 100644 --- a/spec/services/projects/update_pages_service_spec.rb +++ b/spec/services/projects/update_pages_service_spec.rb @@ -24,8 +24,8 @@ describe Projects::UpdatePagesService do let(:extension) { 'zip' } before do - build.update_attributes(legacy_artifacts_file: file) - build.update_attributes(legacy_artifacts_metadata: metadata) + build.update(legacy_artifacts_file: file) + build.update(legacy_artifacts_metadata: metadata) end describe 'pages artifacts' do @@ -62,13 +62,13 @@ describe Projects::UpdatePagesService do end it 'fails if sha on branch is not latest' do - build.update_attributes(ref: 'feature') + build.update(ref: 'feature') expect(execute).not_to eq(:success) end it 'fails for empty file fails' do - build.update_attributes(legacy_artifacts_file: empty_file) + build.update(legacy_artifacts_file: empty_file) expect { execute } .to raise_error(Projects::UpdatePagesService::FailedToExtractError) @@ -118,7 +118,7 @@ describe Projects::UpdatePagesService do end it 'fails if sha on branch is not latest' do - build.update_attributes(ref: 'feature') + build.update(ref: 'feature') expect(execute).not_to eq(:success) end @@ -188,7 +188,7 @@ describe Projects::UpdatePagesService do end it 'fails for invalid archive' do - build.update_attributes(legacy_artifacts_file: invalid_file) + build.update(legacy_artifacts_file: invalid_file) expect(execute).not_to eq(:success) end @@ -199,8 +199,8 @@ describe Projects::UpdatePagesService do file = fixture_file_upload('spec/fixtures/pages.zip') metafile = fixture_file_upload('spec/fixtures/pages.zip.meta') - build.update_attributes(legacy_artifacts_file: file) - build.update_attributes(legacy_artifacts_metadata: metafile) + build.update(legacy_artifacts_file: file) + build.update(legacy_artifacts_metadata: metafile) allow(build).to receive(:artifacts_metadata_entry) .and_return(metadata) diff --git a/spec/services/protected_branches/create_service_spec.rb b/spec/services/protected_branches/create_service_spec.rb index 786493c3577..79b744142c6 100644 --- a/spec/services/protected_branches/create_service_spec.rb +++ b/spec/services/protected_branches/create_service_spec.rb @@ -6,8 +6,8 @@ describe ProtectedBranches::CreateService do let(:params) do { name: 'master', - merge_access_levels_attributes: [{ access_level: Gitlab::Access::MASTER }], - push_access_levels_attributes: [{ access_level: Gitlab::Access::MASTER }] + merge_access_levels_attributes: [{ access_level: Gitlab::Access::MAINTAINER }], + push_access_levels_attributes: [{ access_level: Gitlab::Access::MAINTAINER }] } end @@ -16,8 +16,8 @@ describe ProtectedBranches::CreateService do it 'creates a new protected branch' do expect { service.execute }.to change(ProtectedBranch, :count).by(1) - expect(project.protected_branches.last.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::MASTER]) - expect(project.protected_branches.last.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::MASTER]) + expect(project.protected_branches.last.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER]) + expect(project.protected_branches.last.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER]) end context 'when user does not have permission' do diff --git a/spec/services/protected_tags/create_service_spec.rb b/spec/services/protected_tags/create_service_spec.rb index c3ed95aaebf..b16acf1d36c 100644 --- a/spec/services/protected_tags/create_service_spec.rb +++ b/spec/services/protected_tags/create_service_spec.rb @@ -6,7 +6,7 @@ describe ProtectedTags::CreateService do let(:params) do { name: 'master', - create_access_levels_attributes: [{ access_level: Gitlab::Access::MASTER }] + create_access_levels_attributes: [{ access_level: Gitlab::Access::MAINTAINER }] } end @@ -15,7 +15,7 @@ describe ProtectedTags::CreateService do it 'creates a new protected tag' do expect { service.execute }.to change(ProtectedTag, :count).by(1) - expect(project.protected_tags.last.create_access_levels.map(&:access_level)).to eq([Gitlab::Access::MASTER]) + expect(project.protected_tags.last.create_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER]) end end end diff --git a/spec/services/reset_project_cache_service_spec.rb b/spec/services/reset_project_cache_service_spec.rb index de475d16586..1490ad5fe3b 100644 --- a/spec/services/reset_project_cache_service_spec.rb +++ b/spec/services/reset_project_cache_service_spec.rb @@ -18,7 +18,7 @@ describe ResetProjectCacheService do context 'when project cache_index is a numeric value' do before do - project.update_attributes(jobs_cache_index: 1) + project.update(jobs_cache_index: 1) end it 'increments project cache index' do diff --git a/spec/services/search/global_service_spec.rb b/spec/services/search/global_service_spec.rb index d8dba26e194..980545b8083 100644 --- a/spec/services/search/global_service_spec.rb +++ b/spec/services/search/global_service_spec.rb @@ -10,7 +10,7 @@ describe Search::GlobalService do let!(:public_project) { create(:project, :public, name: 'searchable_public_project') } before do - found_project.add_master(user) + found_project.add_maintainer(user) end describe '#execute' do diff --git a/spec/services/search_service_spec.rb b/spec/services/search_service_spec.rb index 02de83a2df8..e5e036c7d44 100644 --- a/spec/services/search_service_spec.rb +++ b/spec/services/search_service_spec.rb @@ -16,7 +16,7 @@ describe SearchService do let(:public_project) { create(:project, :public, name: 'public_project') } before do - accessible_project.add_master(user) + accessible_project.add_maintainer(user) end describe '#project' do diff --git a/spec/services/system_hooks_service_spec.rb b/spec/services/system_hooks_service_spec.rb index 51396d34f8f..e0335880e8e 100644 --- a/spec/services/system_hooks_service_spec.rb +++ b/spec/services/system_hooks_service_spec.rb @@ -75,7 +75,7 @@ describe SystemHooksService do end it 'handles nil datetime columns' do - user.update_attributes(created_at: nil, updated_at: nil) + user.update(created_at: nil, updated_at: nil) data = event_data(user, :destroy) expect(data[:created_at]).to be(nil) diff --git a/spec/services/users/refresh_authorized_projects_service_spec.rb b/spec/services/users/refresh_authorized_projects_service_spec.rb index e5fde07a6eb..122b96ef216 100644 --- a/spec/services/users/refresh_authorized_projects_service_spec.rb +++ b/spec/services/users/refresh_authorized_projects_service_spec.rb @@ -30,10 +30,10 @@ describe Users::RefreshAuthorizedProjectsService do it 'updates the authorized projects of the user' do project2 = create(:project) to_remove = user.project_authorizations - .create!(project: project2, access_level: Gitlab::Access::MASTER) + .create!(project: project2, access_level: Gitlab::Access::MAINTAINER) expect(service).to receive(:update_authorizations) - .with([to_remove.project_id], [[user.id, project.id, Gitlab::Access::MASTER]]) + .with([to_remove.project_id], [[user.id, project.id, Gitlab::Access::MAINTAINER]]) service.execute_without_lease end @@ -45,7 +45,7 @@ describe Users::RefreshAuthorizedProjectsService do .create!(project: project, access_level: Gitlab::Access::DEVELOPER) expect(service).to receive(:update_authorizations) - .with([to_remove.project_id], [[user.id, project.id, Gitlab::Access::MASTER]]) + .with([to_remove.project_id], [[user.id, project.id, Gitlab::Access::MAINTAINER]]) service.execute_without_lease end @@ -76,14 +76,14 @@ describe Users::RefreshAuthorizedProjectsService do it 'inserts authorizations that should be added' do user.project_authorizations.delete_all - service.update_authorizations([], [[user.id, project.id, Gitlab::Access::MASTER]]) + service.update_authorizations([], [[user.id, project.id, Gitlab::Access::MAINTAINER]]) authorizations = user.project_authorizations expect(authorizations.length).to eq(1) expect(authorizations[0].user_id).to eq(user.id) expect(authorizations[0].project_id).to eq(project.id) - expect(authorizations[0].access_level).to eq(Gitlab::Access::MASTER) + expect(authorizations[0].access_level).to eq(Gitlab::Access::MAINTAINER) end end @@ -99,12 +99,12 @@ describe Users::RefreshAuthorizedProjectsService do end it 'sets the values to the access levels' do - expect(hash.values).to eq([Gitlab::Access::MASTER]) + expect(hash.values).to eq([Gitlab::Access::MAINTAINER]) end context 'personal projects' do it 'includes the project with the right access level' do - expect(hash[project.id]).to eq(Gitlab::Access::MASTER) + expect(hash[project.id]).to eq(Gitlab::Access::MAINTAINER) end end @@ -139,11 +139,11 @@ describe Users::RefreshAuthorizedProjectsService do let!(:other_project) { create(:project, group: nested_group) } before do - group.add_master(user) + group.add_maintainer(user) end it 'includes the project with the right access level' do - expect(hash[other_project.id]).to eq(Gitlab::Access::MASTER) + expect(hash[other_project.id]).to eq(Gitlab::Access::MAINTAINER) end end @@ -153,7 +153,7 @@ describe Users::RefreshAuthorizedProjectsService do let!(:project_group_link) { create(:project_group_link, project: other_project, group: group, group_access: Gitlab::Access::GUEST) } before do - group.add_master(user) + group.add_maintainer(user) end it 'includes the project with the right access level' do @@ -168,7 +168,7 @@ describe Users::RefreshAuthorizedProjectsService do let!(:project_group_link) { create(:project_group_link, project: other_project, group: nested_group, group_access: Gitlab::Access::DEVELOPER) } before do - group.add_master(user) + group.add_maintainer(user) end it 'includes the project with the right access level' do @@ -194,7 +194,7 @@ describe Users::RefreshAuthorizedProjectsService do value = hash.values[0] expect(value.project_id).to eq(project.id) - expect(value.access_level).to eq(Gitlab::Access::MASTER) + expect(value.access_level).to eq(Gitlab::Access::MAINTAINER) end end @@ -219,7 +219,7 @@ describe Users::RefreshAuthorizedProjectsService do end it 'includes the access level for every row' do - expect(row.access_level).to eq(Gitlab::Access::MASTER) + expect(row.access_level).to eq(Gitlab::Access::MAINTAINER) end end end @@ -235,7 +235,7 @@ describe Users::RefreshAuthorizedProjectsService do rows = service.fresh_authorizations.to_a expect(rows.length).to eq(1) - expect(rows.first.access_level).to eq(Gitlab::Access::MASTER) + expect(rows.first.access_level).to eq(Gitlab::Access::MAINTAINER) end context 'every returned row' do @@ -246,7 +246,7 @@ describe Users::RefreshAuthorizedProjectsService do end it 'includes the access level' do - expect(row.access_level).to eq(Gitlab::Access::MASTER) + expect(row.access_level).to eq(Gitlab::Access::MAINTAINER) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fdce8e84620..bd564cc60a6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,7 @@ SimpleCovEnv.start! ENV["RAILS_ENV"] = 'test' ENV["IN_MEMORY_APPLICATION_SETTINGS"] = 'true' -require File.expand_path("../../config/environment", __FILE__) +require File.expand_path('../config/environment', __dir__) require 'rspec/rails' require 'shoulda/matchers' require 'rspec/retry' @@ -170,6 +170,17 @@ RSpec.configure do |config| redis_queues_cleanup! end + config.around(:each, :use_clean_rails_memory_store_fragment_caching) do |example| + caching_store = ActionController::Base.cache_store + ActionController::Base.cache_store = ActiveSupport::Cache::MemoryStore.new + ActionController::Base.perform_caching = true + + example.run + + ActionController::Base.perform_caching = false + ActionController::Base.cache_store = caching_store + end + # The :each scope runs "inside" the example, so this hook ensures the DB is in the # correct state before any examples' before hooks are called. This prevents a # problem where `ScheduleIssuesClosedAtTypeChange` (or any migration that depends diff --git a/spec/support/api/repositories_shared_context.rb b/spec/support/api/repositories_shared_context.rb index ea38fe4f5b8..f1341804e56 100644 --- a/spec/support/api/repositories_shared_context.rb +++ b/spec/support/api/repositories_shared_context.rb @@ -1,6 +1,6 @@ shared_context 'disabled repository' do before do - project.project_feature.update_attributes!( + project.project_feature.update!( repository_access_level: ProjectFeature::DISABLED, merge_requests_access_level: ProjectFeature::DISABLED, builds_access_level: ProjectFeature::DISABLED diff --git a/spec/support/api/time_tracking_shared_examples.rb b/spec/support/api/time_tracking_shared_examples.rb index 52e1bc55191..fee464c15a3 100644 --- a/spec/support/api/time_tracking_shared_examples.rb +++ b/spec/support/api/time_tracking_shared_examples.rb @@ -85,7 +85,7 @@ shared_examples 'time tracking endpoints' do |issuable_name| it 'subtracts time of the total spent time' do Timecop.travel(1.minute.from_now) do expect do - issuable.update_attributes!(spend_time: { duration: 7200, user_id: user.id }) + issuable.update!(spend_time: { duration: 7200, user_id: user.id }) end.to change { issuable.reload.updated_at } end @@ -99,7 +99,7 @@ shared_examples 'time tracking endpoints' do |issuable_name| context 'when time to subtract is greater than the total spent time' do it 'does not modify the total time spent' do - issuable.update_attributes!(spend_time: { duration: 7200, user_id: user.id }) + issuable.update!(spend_time: { duration: 7200, user_id: user.id }) Timecop.travel(1.minute.from_now) do expect do @@ -135,8 +135,8 @@ shared_examples 'time tracking endpoints' do |issuable_name| describe "GET /projects/:id/#{issuable_collection_name}/:#{issuable_name}_id/time_stats" do it "returns the time stats for #{issuable_name}" do - issuable.update_attributes!(spend_time: { duration: 1800, user_id: user.id }, - time_estimate: 3600) + issuable.update!(spend_time: { duration: 1800, user_id: user.id }, + time_estimate: 3600) get api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/time_stats", user) diff --git a/spec/support/features/issuable_slash_commands_shared_examples.rb b/spec/support/features/issuable_slash_commands_shared_examples.rb index 1bd6c25100e..9b44c532ff6 100644 --- a/spec/support/features/issuable_slash_commands_shared_examples.rb +++ b/spec/support/features/issuable_slash_commands_shared_examples.rb @@ -4,7 +4,7 @@ shared_examples 'issuable record that supports quick actions in its description and notes' do |issuable_type| include Spec::Support::Helpers::Features::NotesHelpers - let(:master) { create(:user) } + let(:maintainer) { create(:user) } let(:project) do case issuable_type when :merge_request @@ -19,9 +19,9 @@ shared_examples 'issuable record that supports quick actions in its description let(:new_url_opts) { {} } before do - project.add_master(master) + project.add_maintainer(maintainer) - gitlab_sign_in(master) + gitlab_sign_in(maintainer) end after do @@ -210,31 +210,31 @@ shared_examples 'issuable record that supports quick actions in its description expect(page).not_to have_content '/todo' expect(page).to have_content 'Commands applied' - todos = TodosFinder.new(master).execute + todos = TodosFinder.new(maintainer).execute todo = todos.first expect(todos.size).to eq 1 expect(todo).to be_pending expect(todo.target).to eq issuable - expect(todo.author).to eq master - expect(todo.user).to eq master + expect(todo.author).to eq maintainer + expect(todo.user).to eq maintainer end end context "with a note marking the #{issuable_type} as done" do before do - TodoService.new.mark_todo(issuable, master) + TodoService.new.mark_todo(issuable, maintainer) end it "creates a new todo for the #{issuable_type}" do - todos = TodosFinder.new(master).execute + todos = TodosFinder.new(maintainer).execute todo = todos.first expect(todos.size).to eq 1 expect(todos.first).to be_pending expect(todo.target).to eq issuable - expect(todo.author).to eq master - expect(todo.user).to eq master + expect(todo.author).to eq maintainer + expect(todo.user).to eq maintainer add_note("/done") @@ -247,31 +247,31 @@ shared_examples 'issuable record that supports quick actions in its description context "with a note subscribing to the #{issuable_type}" do it "creates a new todo for the #{issuable_type}" do - expect(issuable.subscribed?(master, project)).to be_falsy + expect(issuable.subscribed?(maintainer, project)).to be_falsy add_note("/subscribe") expect(page).not_to have_content '/subscribe' expect(page).to have_content 'Commands applied' - expect(issuable.subscribed?(master, project)).to be_truthy + expect(issuable.subscribed?(maintainer, project)).to be_truthy end end context "with a note unsubscribing to the #{issuable_type} as done" do before do - issuable.subscribe(master, project) + issuable.subscribe(maintainer, project) end it "creates a new todo for the #{issuable_type}" do - expect(issuable.subscribed?(master, project)).to be_truthy + expect(issuable.subscribed?(maintainer, project)).to be_truthy add_note("/unsubscribe") expect(page).not_to have_content '/unsubscribe' expect(page).to have_content 'Commands applied' - expect(issuable.subscribed?(master, project)).to be_falsy + expect(issuable.subscribed?(maintainer, project)).to be_falsy end end @@ -282,7 +282,7 @@ shared_examples 'issuable record that supports quick actions in its description expect(page).not_to have_content '/assign me' expect(page).to have_content 'Commands applied' - expect(issuable.reload.assignees).to eq [master] + expect(issuable.reload.assignees).to eq [maintainer] end end end diff --git a/spec/support/generate-seed-repo-rb b/spec/support/generate-seed-repo-rb index 44b3de23b99..bee9d419376 100755 --- a/spec/support/generate-seed-repo-rb +++ b/spec/support/generate-seed-repo-rb @@ -15,7 +15,7 @@ require 'erb' require 'tempfile' -SOURCE = File.expand_path('../gitlab-git-test.git', __FILE__).freeze +SOURCE = File.expand_path('gitlab-git-test.git', __dir__).freeze SCRIPT_NAME = 'generate-seed-repo-rb'.freeze REPO_NAME = 'gitlab-git-test.git'.freeze diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index 0930b9da368..b9322975b5a 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -57,12 +57,12 @@ module GraphqlHelpers type.fields.map do |name, field| # We can't guess arguments, so skip fields that require them - next if field.arguments.any? + next if required_arguments?(field) - if scalar?(field) - name - else + if nested_fields?(field) "#{name} { #{all_graphql_fields_for(field_type(field))} }" + else + name end end.compact.join("\n") end @@ -85,10 +85,22 @@ module GraphqlHelpers json_response['data'] end + def nested_fields?(field) + !scalar?(field) && !enum?(field) + end + def scalar?(field) field_type(field).kind.scalar? end + def enum?(field) + field_type(field).kind.enum? + end + + def required_arguments?(field) + field.arguments.values.any? { |argument| argument.type.non_null? } + end + def field_type(field) if field.type.respond_to?(:of_type) field.type.of_type diff --git a/spec/support/helpers/jira_service_helper.rb b/spec/support/helpers/jira_service_helper.rb index 88a7aeba461..f4d5343c4ed 100644 --- a/spec/support/helpers/jira_service_helper.rb +++ b/spec/support/helpers/jira_service_helper.rb @@ -12,7 +12,7 @@ module JiraServiceHelper jira_issue_transition_id: '1' } - jira_tracker.update_attributes(properties: properties, active: true) + jira_tracker.update(properties: properties, active: true) end def jira_issue_comments diff --git a/spec/support/helpers/key_generator_helper.rb b/spec/support/helpers/key_generator_helper.rb index b1c289ffef7..d55d8312c65 100644 --- a/spec/support/helpers/key_generator_helper.rb +++ b/spec/support/helpers/key_generator_helper.rb @@ -24,7 +24,7 @@ module Spec private # Encodes an openssh-mpi-encoded integer. - def encode_mpi(n) + def encode_mpi(n) # rubocop:disable Naming/UncommunicativeMethodParamName chars, n = [], n.to_i chars << (n & 0xff) && n >>= 8 while n != 0 chars << 0 if chars.empty? || chars.last >= 0x80 diff --git a/spec/support/helpers/markdown_feature.rb b/spec/support/helpers/markdown_feature.rb index 39e94ad53de..346f5b1cc4d 100644 --- a/spec/support/helpers/markdown_feature.rb +++ b/spec/support/helpers/markdown_feature.rb @@ -24,7 +24,7 @@ class MarkdownFeature def project @project ||= create(:project, :repository, group: group).tap do |project| - project.add_master(user) + project.add_maintainer(user) end end diff --git a/spec/support/helpers/stub_object_storage.rb b/spec/support/helpers/stub_object_storage.rb index 471b0a74a19..58b5c6a6435 100644 --- a/spec/support/helpers/stub_object_storage.rb +++ b/spec/support/helpers/stub_object_storage.rb @@ -25,6 +25,11 @@ module StubObjectStorage ::Fog::Storage.new(connection_params).tap do |connection| begin connection.directories.create(key: remote_directory) + + # Cleanup remaining files + connection.directories.each do |directory| + directory.files.map(&:destroy) + end rescue Excon::Error::Conflict end end diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb index 05a8e6206ae..e531495d917 100644 --- a/spec/support/helpers/test_env.rb +++ b/spec/support/helpers/test_env.rb @@ -49,7 +49,9 @@ module TestEnv 'add-pdf-file' => 'e774ebd', 'squash-large-files' => '54cec52', 'add-pdf-text-binary' => '79faa7b', - 'add_images_and_changes' => '010d106' + 'add_images_and_changes' => '010d106', + 'update-gitlab-shell-v-6-0-1' => '2f61d70', + 'update-gitlab-shell-v-6-0-3' => 'de78448' }.freeze # gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily diff --git a/spec/support/helpers/wait_for_requests.rb b/spec/support/helpers/wait_for_requests.rb index fda0e29f983..c7f878b7371 100644 --- a/spec/support/helpers/wait_for_requests.rb +++ b/spec/support/helpers/wait_for_requests.rb @@ -24,7 +24,9 @@ module WaitForRequests # Wait for client-side AJAX requests def wait_for_requests - wait_for('JS requests complete') { finished_all_js_requests? } + wait_for('JS requests complete', max_wait_time: 2 * Capybara.default_max_wait_time) do + finished_all_js_requests? + end end # Wait for active Rack requests and client-side AJAX requests diff --git a/spec/support/http_io/http_io_helpers.rb b/spec/support/http_io/http_io_helpers.rb index 2c68c2cd9a6..42144870eb5 100644 --- a/spec/support/http_io/http_io_helpers.rb +++ b/spec/support/http_io/http_io_helpers.rb @@ -1,65 +1,49 @@ module HttpIOHelpers - def stub_remote_trace_206 - WebMock.stub_request(:get, remote_trace_url) - .to_return { |request| remote_trace_response(request, 206) } + def stub_remote_url_206(url, file_path) + WebMock.stub_request(:get, url) + .to_return { |request| remote_url_response(file_path, request, 206) } end - def stub_remote_trace_200 - WebMock.stub_request(:get, remote_trace_url) - .to_return { |request| remote_trace_response(request, 200) } + def stub_remote_url_200(url, file_path) + WebMock.stub_request(:get, url) + .to_return { |request| remote_url_response(file_path, request, 200) } end - def stub_remote_trace_500 - WebMock.stub_request(:get, remote_trace_url) + def stub_remote_url_500(url) + WebMock.stub_request(:get, url) .to_return(status: [500, "Internal Server Error"]) end - def remote_trace_url - "http://trace.com/trace" - end - - def remote_trace_response(request, responce_status) + def remote_url_response(file_path, request, response_status) range = request.headers['Range'].match(/bytes=(\d+)-(\d+)/) + body = File.read(file_path).force_encoding(Encoding::BINARY) + size = body.bytesize + { - status: responce_status, - headers: remote_trace_response_headers(responce_status, range[1].to_i, range[2].to_i), - body: range_trace_body(range[1].to_i, range[2].to_i) + status: response_status, + headers: remote_url_response_headers(response_status, range[1].to_i, range[2].to_i, size), + body: body[range[1].to_i..range[2].to_i] } end - def remote_trace_response_headers(responce_status, from, to) - headers = { 'Content-Type' => 'text/plain' } - - if responce_status == 206 - headers.merge('Content-Range' => "bytes #{from}-#{to}/#{remote_trace_size}") + def remote_url_response_headers(response_status, from, to, size) + { 'Content-Type' => 'text/plain' }.tap do |headers| + if response_status == 206 + headers.merge('Content-Range' => "bytes #{from}-#{to}/#{size}") + end end - - headers - end - - def range_trace_body(from, to) - remote_trace_body[from..to] - end - - def remote_trace_body - @remote_trace_body ||= File.read(expand_fixture_path('trace/sample_trace')) - .force_encoding(Encoding::BINARY) - end - - def remote_trace_size - remote_trace_body.bytesize end def set_smaller_buffer_size_than(file_size) blocks = (file_size / 128) new_size = (blocks / 2) * 128 - stub_const("Gitlab::Ci::Trace::HttpIO::BUFFER_SIZE", new_size) + stub_const("Gitlab::HttpIO::BUFFER_SIZE", new_size) end def set_larger_buffer_size_than(file_size) blocks = (file_size / 128) new_size = (blocks * 2) * 128 - stub_const("Gitlab::Ci::Trace::HttpIO::BUFFER_SIZE", new_size) + stub_const("Gitlab::HttpIO::BUFFER_SIZE", new_size) end end diff --git a/spec/support/import_export/export_file_helper.rb b/spec/support/import_export/export_file_helper.rb index 562423afc2a..4d925ac77f4 100644 --- a/spec/support/import_export/export_file_helper.rb +++ b/spec/support/import_export/export_file_helper.rb @@ -37,7 +37,7 @@ module ExportFileHelper event = create(:event, :created, target: milestone, project: project, author: user, action: 5) create(:push_event_payload, event: event) - create(:project_member, :master, user: user, project: project) + create(:project_member, :maintainer, user: user, project: project) create(:ci_variable, project: project) create(:ci_trigger, project: project) key = create(:deploy_key) diff --git a/spec/support/matchers/access_matchers_for_controller.rb b/spec/support/matchers/access_matchers_for_controller.rb index 42a9ed9ff34..429401a5da8 100644 --- a/spec/support/matchers/access_matchers_for_controller.rb +++ b/spec/support/matchers/access_matchers_for_controller.rb @@ -24,7 +24,7 @@ module AccessMatchersForController when User user = role sign_in(user) - when *Gitlab::Access.sym_options_with_owner.keys # owner, master, developer, reporter, guest + when *Gitlab::Access.sym_options_with_owner.keys # owner, maintainer, developer, reporter, guest raise ArgumentError, "cannot emulate #{role} without membership parent" unless membership user = create_user_by_membership(role, membership) diff --git a/spec/support/matchers/disallow_request_matchers.rb b/spec/support/matchers/disallow_request_matchers.rb new file mode 100644 index 00000000000..db4d90e4fd0 --- /dev/null +++ b/spec/support/matchers/disallow_request_matchers.rb @@ -0,0 +1,15 @@ +RSpec::Matchers.define :disallow_request do + match do |middleware| + alert = middleware.env['rack.session'].to_hash + .dig('flash', 'flashes', 'alert') + + alert&.include?('You cannot perform write operations') + end +end + +RSpec::Matchers.define :disallow_request_in_json do + match do |response| + json_response = JSON.parse(response.body) + response.body.include?('You cannot perform write operations') && json_response.key?('message') + end +end diff --git a/spec/support/services/issuable_create_service_slash_commands_shared_examples.rb b/spec/support/services/issuable_create_service_slash_commands_shared_examples.rb index 7b064162726..8b4cffaac19 100644 --- a/spec/support/services/issuable_create_service_slash_commands_shared_examples.rb +++ b/spec/support/services/issuable_create_service_slash_commands_shared_examples.rb @@ -3,7 +3,7 @@ shared_examples 'new issuable record that supports quick actions' do let!(:project) { create(:project, :repository) } - let(:user) { create(:user).tap { |u| project.add_master(u) } } + let(:user) { create(:user).tap { |u| project.add_maintainer(u) } } let(:assignee) { create(:user) } let!(:milestone) { create(:milestone, project: project) } let!(:labels) { create_list(:label, 3, project: project) } @@ -12,7 +12,7 @@ shared_examples 'new issuable record that supports quick actions' do let(:issuable) { described_class.new(project, user, params).execute } before do - project.add_master(assignee) + project.add_maintainer(assignee) end context 'with labels in command only' do diff --git a/spec/support/shared_examples/ci_trace_shared_examples.rb b/spec/support/shared_examples/ci_trace_shared_examples.rb index db723a323f8..94e82b8ce90 100644 --- a/spec/support/shared_examples/ci_trace_shared_examples.rb +++ b/spec/support/shared_examples/ci_trace_shared_examples.rb @@ -138,6 +138,28 @@ shared_examples_for 'common trace features' do end end + describe '#write' do + subject { trace.send(:write, mode) { } } + + let(:mode) { 'wb' } + + context 'when arhicved trace does not exist yet' do + it 'does not raise an error' do + expect { subject }.not_to raise_error + end + end + + context 'when arhicved trace already exists' do + before do + create(:ci_job_artifact, :trace, job: build) + end + + it 'raises an error' do + expect { subject }.to raise_error(Gitlab::Ci::Trace::AlreadyArchivedError) + end + end + end + describe '#set' do before do trace.set("12") @@ -574,7 +596,7 @@ shared_examples_for 'trace with disabled live trace feature' do it 'does not archive' do expect_any_instance_of(described_class).not_to receive(:archive_stream!) - expect { subject }.to raise_error('Already archived') + expect { subject }.to raise_error(Gitlab::Ci::Trace::AlreadyArchivedError) expect(build.job_artifacts_trace.file.exists?).to be_truthy end end @@ -589,6 +611,55 @@ shared_examples_for 'trace with disabled live trace feature' do end end end + + describe '#erase!' do + subject { trace.erase! } + + context 'when it is a live trace' do + context 'when trace is stored in database' do + let(:build) { create(:ci_build) } + + before do + build.update_column(:trace, 'sample trace') + end + + it { expect(trace.raw).not_to be_nil } + + it "removes trace" do + subject + + expect(trace.raw).to be_nil + end + end + + context 'when trace is stored in file storage' do + let(:build) { create(:ci_build, :trace_live) } + + it { expect(trace.raw).not_to be_nil } + + it "removes trace" do + subject + + expect(trace.raw).to be_nil + end + end + end + + context 'when it is an archived trace' do + let(:build) { create(:ci_build, :trace_artifact) } + + it "has trace at first" do + expect(trace.raw).not_to be_nil + end + + it "removes trace" do + subject + + build.reload + expect(trace.raw).to be_nil + end + end + end end shared_examples_for 'trace with enabled live trace feature' do @@ -761,7 +832,7 @@ shared_examples_for 'trace with enabled live trace feature' do it 'does not archive' do expect_any_instance_of(described_class).not_to receive(:archive_stream!) - expect { subject }.to raise_error('Already archived') + expect { subject }.to raise_error(Gitlab::Ci::Trace::AlreadyArchivedError) expect(build.job_artifacts_trace.file.exists?).to be_truthy end end @@ -776,4 +847,35 @@ shared_examples_for 'trace with enabled live trace feature' do end end end + + describe '#erase!' do + subject { trace.erase! } + + context 'when it is a live trace' do + let(:build) { create(:ci_build, :trace_live) } + + it { expect(trace.raw).not_to be_nil } + + it "removes trace" do + subject + + expect(trace.raw).to be_nil + end + end + + context 'when it is an archived trace' do + let(:build) { create(:ci_build, :trace_artifact) } + + it "has trace at first" do + expect(trace.raw).not_to be_nil + end + + it "removes trace" do + subject + + build.reload + expect(trace.raw).to be_nil + end + end + end end diff --git a/spec/support/shared_examples/controllers/uploads_actions_shared_examples.rb b/spec/support/shared_examples/controllers/uploads_actions_shared_examples.rb index bbbad86dcd5..7088fb1e5fb 100644 --- a/spec/support/shared_examples/controllers/uploads_actions_shared_examples.rb +++ b/spec/support/shared_examples/controllers/uploads_actions_shared_examples.rb @@ -260,4 +260,83 @@ shared_examples 'handle uploads' do end end end + + describe "POST #authorize" do + context 'when a user is not authorized to upload a file' do + it 'returns 404 status' do + post_authorize + + expect(response.status).to eq(404) + end + end + + context 'when a user can upload a file' do + before do + sign_in(user) + model.add_developer(user) + end + + context 'and the request bypassed workhorse' do + it 'raises an exception' do + expect { post_authorize(verified: false) }.to raise_error JWT::DecodeError + end + end + + context 'and request is sent by gitlab-workhorse to authorize the request' do + shared_examples 'a valid response' do + before do + post_authorize + end + + it 'responds with status 200' do + expect(response).to have_gitlab_http_status(200) + end + + it 'uses the gitlab-workhorse content type' do + expect(response.headers["Content-Type"]).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) + end + end + + shared_examples 'a local file' do + it_behaves_like 'a valid response' do + it 'responds with status 200, location of uploads store and object details' do + expect(json_response['TempPath']).to eq(uploader_class.workhorse_local_upload_path) + expect(json_response['RemoteObject']).to be_nil + end + end + end + + context 'when using local storage' do + it_behaves_like 'a local file' + end + + context 'when using remote storage' do + context 'when direct upload is enabled' do + before do + stub_uploads_object_storage(uploader_class, direct_upload: true) + end + + it_behaves_like 'a valid response' do + it 'responds with status 200, location of uploads remote store and object details' do + expect(json_response['TempPath']).to eq(uploader_class.workhorse_local_upload_path) + expect(json_response['RemoteObject']).to have_key('ID') + expect(json_response['RemoteObject']).to have_key('GetURL') + expect(json_response['RemoteObject']).to have_key('StoreURL') + expect(json_response['RemoteObject']).to have_key('DeleteURL') + expect(json_response['RemoteObject']).to have_key('MultipartUpload') + end + end + end + + context 'when direct upload is disabled' do + before do + stub_uploads_object_storage(uploader_class, direct_upload: false) + end + + it_behaves_like 'a local file' + end + end + end + end + end end diff --git a/spec/support/shared_examples/features/creatable_merge_request_shared_examples.rb b/spec/support/shared_examples/features/creatable_merge_request_shared_examples.rb index 5a569d233bc..7038a366144 100644 --- a/spec/support/shared_examples/features/creatable_merge_request_shared_examples.rb +++ b/spec/support/shared_examples/features/creatable_merge_request_shared_examples.rb @@ -10,9 +10,9 @@ RSpec.shared_examples 'a creatable merge request' do let!(:label2) { create(:label, project: target_project) } before do - source_project.add_master(user) - target_project.add_master(user) - target_project.add_master(user2) + source_project.add_maintainer(user) + target_project.add_maintainer(user) + target_project.add_maintainer(user2) sign_in(user) visit project_new_merge_request_path( diff --git a/spec/support/shared_examples/features/editable_merge_request_shared_examples.rb b/spec/support/shared_examples/features/editable_merge_request_shared_examples.rb index 645db41cddc..3057845061b 100644 --- a/spec/support/shared_examples/features/editable_merge_request_shared_examples.rb +++ b/spec/support/shared_examples/features/editable_merge_request_shared_examples.rb @@ -15,9 +15,9 @@ RSpec.shared_examples 'an editable merge request' do end before do - source_project.add_master(user) - target_project.add_master(user) - target_project.add_master(user2) + source_project.add_maintainer(user) + target_project.add_maintainer(user) + target_project.add_maintainer(user2) sign_in(user) visit edit_project_merge_request_path(target_project, merge_request) diff --git a/spec/support/shared_examples/features/master_manages_access_requests_shared_example.rb b/spec/support/shared_examples/features/master_manages_access_requests_shared_example.rb index b29bb3c2fc0..75ad948e42c 100644 --- a/spec/support/shared_examples/features/master_manages_access_requests_shared_example.rb +++ b/spec/support/shared_examples/features/master_manages_access_requests_shared_example.rb @@ -1,20 +1,20 @@ -RSpec.shared_examples 'Master manages access requests' do +RSpec.shared_examples 'Maintainer manages access requests' do let(:user) { create(:user) } - let(:master) { create(:user) } + let(:maintainer) { create(:user) } before do entity.request_access(user) - entity.respond_to?(:add_owner) ? entity.add_owner(master) : entity.add_master(master) - sign_in(master) + entity.respond_to?(:add_owner) ? entity.add_owner(maintainer) : entity.add_maintainer(maintainer) + sign_in(maintainer) end - it 'master can see access requests' do + it 'maintainer can see access requests' do visit members_page_path expect_visible_access_request(entity, user) end - it 'master can grant access', :js do + it 'maintainer can grant access', :js do visit members_page_path expect_visible_access_request(entity, user) @@ -28,7 +28,7 @@ RSpec.shared_examples 'Master manages access requests' do end end - it 'master can deny access', :js do + it 'maintainer can deny access', :js do visit members_page_path expect_visible_access_request(entity, user) diff --git a/spec/support/shared_examples/helm_generated_script.rb b/spec/support/shared_examples/helm_generated_script.rb index 56e86a87ab9..05d53a13fd3 100644 --- a/spec/support/shared_examples/helm_generated_script.rb +++ b/spec/support/shared_examples/helm_generated_script.rb @@ -6,7 +6,7 @@ shared_examples 'helm commands' do ALPINE_VERSION=$(cat /etc/alpine-release | cut -d '.' -f 1,2) echo http://mirror.clarkson.edu/alpine/v$ALPINE_VERSION/main >> /etc/apk/repositories echo http://mirror1.hs-esslingen.de/pub/Mirrors/alpine/v$ALPINE_VERSION/main >> /etc/apk/repositories - apk add -U ca-certificates openssl >/dev/null + apk add -U wget ca-certificates openssl >/dev/null wget -q -O - https://kubernetes-helm.storage.googleapis.com/helm-v2.7.0-linux-amd64.tar.gz | tar zxC /tmp >/dev/null mv /tmp/linux-amd64/helm /usr/bin/ EOS diff --git a/spec/support/shared_examples/models/members_notifications_shared_example.rb b/spec/support/shared_examples/models/members_notifications_shared_example.rb index 76611e54306..ef5cea3f2a5 100644 --- a/spec/support/shared_examples/models/members_notifications_shared_example.rb +++ b/spec/support/shared_examples/models/members_notifications_shared_example.rb @@ -21,7 +21,7 @@ RSpec.shared_examples 'members notifications' do |entity_type| it "calls NotificationService.update_#{entity_type}_member" do expect(notification_service).to receive(:"update_#{entity_type}_member").with(member) - member.update_attribute(:access_level, Member::MASTER) + member.update_attribute(:access_level, Member::MAINTAINER) end it "does not send an email when the access level has not changed" do diff --git a/spec/support/shared_examples/requests/api/merge_requests_list.rb b/spec/support/shared_examples/requests/api/merge_requests_list.rb index a401f7541f0..1aed8ab0113 100644 --- a/spec/support/shared_examples/requests/api/merge_requests_list.rb +++ b/spec/support/shared_examples/requests/api/merge_requests_list.rb @@ -136,8 +136,9 @@ shared_examples 'merge requests list' do it 'returns an array of merge requests in given milestone' do get api(endpoint_path, user), milestone: '0.9' - expect(json_response.first['title']).to eq merge_request_closed.title - expect(json_response.first['id']).to eq merge_request_closed.id + closed_issues = json_response.select { |mr| mr['id'] == merge_request_closed.id } + expect(closed_issues.length).to eq(1) + expect(closed_issues.first['title']).to eq merge_request_closed.title end it 'returns an array of merge requests matching state in milestone' do diff --git a/spec/support/shared_examples/requests/api/notes.rb b/spec/support/shared_examples/requests/api/notes.rb index 79b2196660c..1b563021244 100644 --- a/spec/support/shared_examples/requests/api/notes.rb +++ b/spec/support/shared_examples/requests/api/notes.rb @@ -121,6 +121,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| expect(json_response['body']).to eq('hi!') expect(json_response['author']['username']).to eq(user.username) expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time) + expect(Time.parse(json_response['updated_at'])).to be_like_time(creation_time) end end diff --git a/spec/support/shared_examples/slack_mattermost_notifications_shared_examples.rb b/spec/support/shared_examples/slack_mattermost_notifications_shared_examples.rb index 7c34c7b4977..940c24c8d67 100644 --- a/spec/support/shared_examples/slack_mattermost_notifications_shared_examples.rb +++ b/spec/support/shared_examples/slack_mattermost_notifications_shared_examples.rb @@ -130,7 +130,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do context "event channels" do it "uses the right channel for push event" do - chat_service.update_attributes(push_channel: "random") + chat_service.update(push_channel: "random") expect(Slack::Notifier).to receive(:new) .with(webhook_url, channel: "random") @@ -142,7 +142,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do end it "uses the right channel for merge request event" do - chat_service.update_attributes(merge_request_channel: "random") + chat_service.update(merge_request_channel: "random") expect(Slack::Notifier).to receive(:new) .with(webhook_url, channel: "random") @@ -154,7 +154,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do end it "uses the right channel for issue event" do - chat_service.update_attributes(issue_channel: "random") + chat_service.update(issue_channel: "random") expect(Slack::Notifier).to receive(:new) .with(webhook_url, channel: "random") @@ -169,7 +169,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do let(:issue_service_options) { { title: 'Secret', confidential: true } } it "uses confidential issue channel" do - chat_service.update_attributes(confidential_issue_channel: 'confidential') + chat_service.update(confidential_issue_channel: 'confidential') expect(Slack::Notifier).to execute_with_options(channel: 'confidential') @@ -177,7 +177,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do end it 'falls back to issue channel' do - chat_service.update_attributes(issue_channel: 'fallback_channel') + chat_service.update(issue_channel: 'fallback_channel') expect(Slack::Notifier).to execute_with_options(channel: 'fallback_channel') @@ -186,7 +186,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do end it "uses the right channel for wiki event" do - chat_service.update_attributes(wiki_page_channel: "random") + chat_service.update(wiki_page_channel: "random") expect(Slack::Notifier).to receive(:new) .with(webhook_url, channel: "random") @@ -203,7 +203,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do end it "uses the right channel" do - chat_service.update_attributes(note_channel: "random") + chat_service.update(note_channel: "random") note_data = Gitlab::DataBuilder::Note.build(issue_note, user) @@ -222,7 +222,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do end it "uses confidential channel" do - chat_service.update_attributes(confidential_note_channel: "confidential") + chat_service.update(confidential_note_channel: "confidential") note_data = Gitlab::DataBuilder::Note.build(issue_note, user) @@ -232,7 +232,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do end it 'falls back to note channel' do - chat_service.update_attributes(note_channel: "fallback_channel") + chat_service.update(note_channel: "fallback_channel") note_data = Gitlab::DataBuilder::Note.build(issue_note, user) diff --git a/spec/tasks/gitlab/git_rake_spec.rb b/spec/tasks/gitlab/git_rake_spec.rb index 1efaecc63a5..d0263ad9a37 100644 --- a/spec/tasks/gitlab/git_rake_spec.rb +++ b/spec/tasks/gitlab/git_rake_spec.rb @@ -1,15 +1,20 @@ require 'rake_helper' describe 'gitlab:git rake tasks' do + let(:base_path) { 'tmp/tests/default_storage' } + before(:all) do @default_storage_hash = Gitlab.config.repositories.storages.default.to_h end before do Rake.application.rake_require 'tasks/gitlab/git' - storages = { 'default' => Gitlab::GitalyClient::StorageSettings.new(@default_storage_hash.merge('path' => 'tmp/tests/default_storage')) } + storages = { 'default' => Gitlab::GitalyClient::StorageSettings.new(@default_storage_hash.merge('path' => base_path)) } + + path = Settings.absolute("#{base_path}/@hashed/1/2/test.git") + FileUtils.mkdir_p(path) + Gitlab::Popen.popen(%W[git -C #{path} init --bare]) - FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/@hashed/1/2/test.git')) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow_any_instance_of(String).to receive(:color) { |string, _color| string } @@ -17,7 +22,7 @@ describe 'gitlab:git rake tasks' do end after do - FileUtils.rm_rf(Settings.absolute('tmp/tests/default_storage')) + FileUtils.rm_rf(Settings.absolute(base_path)) end describe 'fsck' do @@ -26,14 +31,14 @@ describe 'gitlab:git rake tasks' do end it 'errors out about config.lock issues' do - FileUtils.touch(Settings.absolute('tmp/tests/default_storage/@hashed/1/2/test.git/config.lock')) + FileUtils.touch(Settings.absolute("#{base_path}/@hashed/1/2/test.git/config.lock")) expect { run_rake_task('gitlab:git:fsck') }.to output(/file exists\? ... yes/).to_stdout end it 'errors out about ref lock issues' do - FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/@hashed/1/2/test.git/refs/heads')) - FileUtils.touch(Settings.absolute('tmp/tests/default_storage/@hashed/1/2/test.git/refs/heads/blah.lock')) + FileUtils.mkdir_p(Settings.absolute("#{base_path}/@hashed/1/2/test.git/refs/heads")) + FileUtils.touch(Settings.absolute("#{base_path}/@hashed/1/2/test.git/refs/heads/blah.lock")) expect { run_rake_task('gitlab:git:fsck') }.to output(/Ref lock files exist:/).to_stdout end diff --git a/spec/uploaders/file_uploader_spec.rb b/spec/uploaders/file_uploader_spec.rb index 59013a02938..7ba28b4fc1f 100644 --- a/spec/uploaders/file_uploader_spec.rb +++ b/spec/uploaders/file_uploader_spec.rb @@ -80,6 +80,50 @@ describe FileUploader do end end + describe 'copy_to' do + shared_examples 'returns a valid uploader' do + describe 'returned uploader' do + let(:new_project) { create(:project) } + let(:moved) { described_class.copy_to(subject, new_project) } + + it 'generates a new secret' do + expect(subject).to be + expect(described_class).to receive(:generate_secret).once.and_call_original + expect(moved).to be + end + + it 'create new upload' do + expect(moved.upload).not_to eq(subject.upload) + end + + it 'copies the file' do + expect(subject.file).to exist + expect(moved.file).to exist + expect(subject.file).not_to eq(moved.file) + expect(subject.object_store).to eq(moved.object_store) + end + end + end + + context 'files are stored locally' do + before do + subject.store!(fixture_file_upload('spec/fixtures/dk.png')) + end + + include_examples 'returns a valid uploader' + end + + context 'files are stored remotely' do + before do + stub_uploads_object_storage + subject.store!(fixture_file_upload('spec/fixtures/dk.png')) + subject.migrate!(ObjectStorage::Store::REMOTE) + end + + include_examples 'returns a valid uploader' + end + end + describe '#secret' do it 'generates a secret if none is provided' do expect(described_class).to receive(:generate_secret).and_return('secret') diff --git a/spec/uploaders/gitlab_uploader_spec.rb b/spec/uploaders/gitlab_uploader_spec.rb index 362f89424d4..44718ed1212 100644 --- a/spec/uploaders/gitlab_uploader_spec.rb +++ b/spec/uploaders/gitlab_uploader_spec.rb @@ -68,4 +68,66 @@ describe GitlabUploader do expect(subject.file.path).to match(/#{subject.cache_dir}/) end end + + describe '#open' do + context 'when trace is stored in File storage' do + context 'when file exists' do + let(:file) do + fixture_file_upload('spec/fixtures/trace/sample_trace', 'text/plain') + end + + before do + subject.store!(file) + end + + it 'returns io stream' do + expect(subject.open).to be_a(IO) + end + + it 'when passing block it yields' do + expect { |b| subject.open(&b) }.to yield_control + end + end + + context 'when file does not exist' do + it 'returns nil' do + expect(subject.open).to be_nil + end + + it 'when passing block it does not yield' do + expect { |b| subject.open(&b) }.not_to yield_control + end + end + end + + context 'when trace is stored in Object storage' do + before do + allow(subject).to receive(:file_storage?) { false } + end + + context 'when file exists' do + before do + allow(subject).to receive(:url) { 'http://object_storage.com/trace' } + end + + it 'returns http io stream' do + expect(subject.open).to be_a(Gitlab::HttpIO) + end + + it 'when passing block it yields' do + expect { |b| subject.open(&b) }.to yield_control.once + end + end + + context 'when file does not exist' do + it 'returns nil' do + expect(subject.open).to be_nil + end + + it 'when passing block it does not yield' do + expect { |b| subject.open(&b) }.not_to yield_control + end + end + end + end end diff --git a/spec/uploaders/import_export_uploader_spec.rb b/spec/uploaders/import_export_uploader_spec.rb new file mode 100644 index 00000000000..51b173b682d --- /dev/null +++ b/spec/uploaders/import_export_uploader_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe ImportExportUploader do + let(:model) { build_stubbed(:import_export_upload) } + let(:upload) { create(:upload, model: model) } + + subject { described_class.new(model, :import_file) } + + context "object_store is REMOTE" do + before do + stub_uploads_object_storage + end + + include_context 'with storage', described_class::Store::REMOTE + + it_behaves_like 'builds correct paths', + store_dir: %r[import_export_upload/import_file/], + upload_path: %r[import_export_upload/import_file/] + end +end diff --git a/spec/uploaders/job_artifact_uploader_spec.rb b/spec/uploaders/job_artifact_uploader_spec.rb index 026e4356ed6..3ad5fe7e3b3 100644 --- a/spec/uploaders/job_artifact_uploader_spec.rb +++ b/spec/uploaders/job_artifact_uploader_spec.rb @@ -23,43 +23,6 @@ describe JobArtifactUploader do store_dir: %r[\h{2}/\h{2}/\h{64}/\d{4}_\d{1,2}_\d{1,2}/\d+/\d+\z] end - describe '#open' do - subject { uploader.open } - - context 'when trace is stored in File storage' do - context 'when file exists' do - let(:file) do - fixture_file_upload('spec/fixtures/trace/sample_trace', 'text/plain') - end - - before do - uploader.store!(file) - end - - it 'returns io stream' do - is_expected.to be_a(IO) - end - end - - context 'when file does not exist' do - it 'returns nil' do - is_expected.to be_nil - end - end - end - - context 'when trace is stored in Object storage' do - before do - allow(uploader).to receive(:file_storage?) { false } - allow(uploader).to receive(:url) { 'http://object_storage.com/trace' } - end - - it 'returns http io stream' do - is_expected.to be_a(Gitlab::Ci::Trace::HttpIO) - end - end - end - context 'file is stored in valid local_path' do let(:file) do fixture_file_upload('spec/fixtures/ci_build_artifacts.zip', 'application/zip') diff --git a/spec/views/projects/imports/new.html.haml_spec.rb b/spec/views/projects/imports/new.html.haml_spec.rb index 32d73d0c5ab..11fe144d1d2 100644 --- a/spec/views/projects/imports/new.html.haml_spec.rb +++ b/spec/views/projects/imports/new.html.haml_spec.rb @@ -7,9 +7,9 @@ describe "projects/imports/new.html.haml" do let(:project) { create(:project_empty_repo, :import_failed, import_type: :gitlab_project, import_source: '/var/opt/gitlab/gitlab-rails/shared/tmp/project_exports/uploads/t.tar.gz', import_url: nil) } before do - project.import_state.update_attributes(last_error: '<a href="http://googl.com">Foo</a>') + project.import_state.update(last_error: '<a href="http://googl.com">Foo</a>') sign_in(user) - project.add_master(user) + project.add_maintainer(user) end it "escapes HTML in import errors" do diff --git a/spec/views/projects/merge_requests/show.html.haml_spec.rb b/spec/views/projects/merge_requests/show.html.haml_spec.rb index 264e0ce0b40..fe6ad26a6f6 100644 --- a/spec/views/projects/merge_requests/show.html.haml_spec.rb +++ b/spec/views/projects/merge_requests/show.html.haml_spec.rb @@ -52,7 +52,7 @@ describe 'projects/merge_requests/show.html.haml' do context 'when the merge request is open' do it 'closes the merge request if the source project does not exist' do - closed_merge_request.update_attributes(state: 'open') + closed_merge_request.update(state: 'open') forked_project.destroy # Reload merge request so MergeRequest#source_project turns to `nil` closed_merge_request.reload diff --git a/spec/views/projects/pipeline_schedules/_pipeline_schedule.html.haml_spec.rb b/spec/views/projects/pipeline_schedules/_pipeline_schedule.html.haml_spec.rb index 6e7d8db99c4..5d60d6bc5e7 100644 --- a/spec/views/projects/pipeline_schedules/_pipeline_schedule.html.haml_spec.rb +++ b/spec/views/projects/pipeline_schedules/_pipeline_schedule.html.haml_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe 'projects/pipeline_schedules/_pipeline_schedule' do let(:owner) { create(:user) } - let(:master) { create(:user) } + let(:maintainer) { create(:user) } let(:project) { create(:project) } let(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly, project: project) } @@ -17,10 +17,10 @@ describe 'projects/pipeline_schedules/_pipeline_schedule' do context 'taking ownership of schedule' do context 'when non-owner is signed in' do - let(:user) { master } + let(:user) { maintainer } before do - allow(view).to receive(:can?).with(master, :take_ownership_pipeline_schedule, pipeline_schedule).and_return(true) + allow(view).to receive(:can?).with(maintainer, :take_ownership_pipeline_schedule, pipeline_schedule).and_return(true) end it 'non-owner can take ownership of pipeline' do diff --git a/spec/views/shared/notes/_form.html.haml_spec.rb b/spec/views/shared/notes/_form.html.haml_spec.rb index 50980718e66..c57319869f3 100644 --- a/spec/views/shared/notes/_form.html.haml_spec.rb +++ b/spec/views/shared/notes/_form.html.haml_spec.rb @@ -7,7 +7,7 @@ describe 'shared/notes/_form' do let(:project) { create(:project, :repository) } before do - project.add_master(user) + project.add_maintainer(user) assign(:project, project) assign(:note, note) diff --git a/spec/workers/ci/archive_traces_cron_worker_spec.rb b/spec/workers/ci/archive_traces_cron_worker_spec.rb index 9af51b7d4d8..23f5dda298a 100644 --- a/spec/workers/ci/archive_traces_cron_worker_spec.rb +++ b/spec/workers/ci/archive_traces_cron_worker_spec.rb @@ -25,24 +25,36 @@ describe Ci::ArchiveTracesCronWorker do end end - context 'when a job was succeeded' do + context 'when a job succeeded' do let!(:build) { create(:ci_build, :success, :trace_live) } it_behaves_like 'archives trace' - context 'when archive raised an exception' do - let!(:build) { create(:ci_build, :success, :trace_artifact, :trace_live) } + context 'when a trace had already been archived' do + let!(:build) { create(:ci_build, :success, :trace_live, :trace_artifact) } let!(:build2) { create(:ci_build, :success, :trace_live) } - it 'archives valid targets' do - expect(Rails.logger).to receive(:error).with("Failed to archive stale live trace. id: #{build.id} message: Already archived") - + it 'continues to archive live traces' do subject build2.reload expect(build2.job_artifacts_trace).to be_exist end end + + context 'when an unexpected exception happened during archiving' do + let!(:build) { create(:ci_build, :success, :trace_live) } + + before do + allow_any_instance_of(Gitlab::Ci::Trace).to receive(:archive!).and_raise('Unexpected error') + end + + it 'puts a log' do + expect(Rails.logger).to receive(:error).with("Failed to archive stale live trace. id: #{build.id} message: Unexpected error") + + subject + end + end end context 'when a job was cancelled' do diff --git a/spec/workers/concerns/waitable_worker_spec.rb b/spec/workers/concerns/waitable_worker_spec.rb index 199825b5097..ce38cde9208 100644 --- a/spec/workers/concerns/waitable_worker_spec.rb +++ b/spec/workers/concerns/waitable_worker_spec.rb @@ -18,8 +18,8 @@ describe WaitableWorker do def self.bulk_perform_inline(args_list) end - def perform(i = 0) - self.class.counter += i + def perform(count = 0) + self.class.counter += count end end end diff --git a/spec/workers/git_garbage_collect_worker_spec.rb b/spec/workers/git_garbage_collect_worker_spec.rb index e39dec556fc..30e67e67e0e 100644 --- a/spec/workers/git_garbage_collect_worker_spec.rb +++ b/spec/workers/git_garbage_collect_worker_spec.rb @@ -27,6 +27,12 @@ describe GitGarbageCollectWorker do subject.perform(project.id, :gc, lease_key, lease_uuid) end + + it 'handles gRPC errors' do + expect_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive(:garbage_collect).and_raise(GRPC::NotFound) + + expect { subject.perform(project.id, :gc, lease_key, lease_uuid) }.to raise_exception(Gitlab::Git::Repository::NoRepository) + end end context 'with different lease than the active one' do @@ -203,12 +209,7 @@ describe GitGarbageCollectWorker do tree: old_commit.tree, parents: [old_commit] ) - Gitlab::Git::OperationService.new(nil, project.repository.raw_repository).send( - :update_ref, - "refs/heads/#{SecureRandom.hex(6)}", - new_commit_sha, - Gitlab::Git::BLANK_SHA - ) + rugged.references.create("refs/heads/#{SecureRandom.hex(6)}", new_commit_sha) end def packs(project) diff --git a/spec/workers/merge_worker_spec.rb b/spec/workers/merge_worker_spec.rb index c861a56497e..b57c275c770 100644 --- a/spec/workers/merge_worker_spec.rb +++ b/spec/workers/merge_worker_spec.rb @@ -8,7 +8,7 @@ describe MergeWorker do let!(:author) { merge_request.author } before do - source_project.add_master(author) + source_project.add_maintainer(author) source_project.repository.expire_branches_cache end diff --git a/spec/workers/object_storage_upload_worker_spec.rb b/spec/workers/object_storage_upload_worker_spec.rb deleted file mode 100644 index 32ddcbe9757..00000000000 --- a/spec/workers/object_storage_upload_worker_spec.rb +++ /dev/null @@ -1,108 +0,0 @@ -require 'spec_helper' - -describe ObjectStorageUploadWorker do - let(:local) { ObjectStorage::Store::LOCAL } - let(:remote) { ObjectStorage::Store::REMOTE } - - def perform - described_class.perform_async(uploader_class.name, subject_class, file_field, subject_id) - end - - context 'for LFS' do - let!(:lfs_object) { create(:lfs_object, :with_file, file_store: local) } - let(:uploader_class) { LfsObjectUploader } - let(:subject_class) { LfsObject } - let(:file_field) { :file } - let(:subject_id) { lfs_object.id } - - context 'when object storage is enabled' do - before do - stub_lfs_object_storage(background_upload: true) - end - - it 'uploads object to storage' do - expect { perform }.to change { lfs_object.reload.file_store }.from(local).to(remote) - end - - context 'when background upload is disabled' do - before do - allow(Gitlab.config.lfs.object_store).to receive(:background_upload) { false } - end - - it 'is skipped' do - expect { perform }.not_to change { lfs_object.reload.file_store } - end - end - end - - context 'when object storage is disabled' do - before do - stub_lfs_object_storage(enabled: false) - end - - it "doesn't migrate files" do - perform - - expect(lfs_object.reload.file_store).to eq(local) - end - end - end - - context 'for legacy artifacts' do - let(:build) { create(:ci_build, :legacy_artifacts) } - let(:uploader_class) { LegacyArtifactUploader } - let(:subject_class) { Ci::Build } - let(:file_field) { :artifacts_file } - let(:subject_id) { build.id } - - context 'when local storage is used' do - let(:store) { local } - - context 'and remote storage is defined' do - before do - stub_artifacts_object_storage(background_upload: true) - end - - it "migrates file to remote storage" do - perform - - expect(build.reload.artifacts_file_store).to eq(remote) - end - - context 'for artifacts_metadata' do - let(:file_field) { :artifacts_metadata } - - it 'migrates metadata to remote storage' do - perform - - expect(build.reload.artifacts_metadata_store).to eq(remote) - end - end - end - end - end - - context 'for job artifacts' do - let(:artifact) { create(:ci_job_artifact, :archive) } - let(:uploader_class) { JobArtifactUploader } - let(:subject_class) { Ci::JobArtifact } - let(:file_field) { :file } - let(:subject_id) { artifact.id } - - context 'when local storage is used' do - let(:store) { local } - - context 'and remote storage is defined' do - before do - stub_artifacts_object_storage(background_upload: true) - end - - it "migrates file to remote storage" do - perform - - expect(artifact.reload.file_store).to eq(remote) - end - end - end - end -end diff --git a/spec/workers/pipeline_schedule_worker_spec.rb b/spec/workers/pipeline_schedule_worker_spec.rb index e7a4ac0f3d6..a2fe4734d47 100644 --- a/spec/workers/pipeline_schedule_worker_spec.rb +++ b/spec/workers/pipeline_schedule_worker_spec.rb @@ -18,7 +18,7 @@ describe PipelineScheduleWorker do context 'when the schedule is runnable by the user' do before do - project.add_master(user) + project.add_maintainer(user) end context 'when there is a scheduled pipeline within next_run_at' do diff --git a/spec/workers/process_commit_worker_spec.rb b/spec/workers/process_commit_worker_spec.rb index ac79d9c0ac1..2d071c181c2 100644 --- a/spec/workers/process_commit_worker_spec.rb +++ b/spec/workers/process_commit_worker_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe ProcessCommitWorker do + include ProjectForksHelper + let(:worker) { described_class.new } let(:user) { create(:user) } let(:project) { create(:project, :public, :repository) } @@ -32,15 +34,41 @@ describe ProcessCommitWorker do worker.perform(project.id, user.id, commit.to_hash) end - context 'when commit already exists in upstream project' do - let(:forked) { create(:project, :public, :repository) } + context 'when the project is forked' do + context 'when commit already exists in the upstream project' do + it 'does not process the commit message' do + forked = fork_project(project, user, repository: true) + + expect(worker).not_to receive(:process_commit_message) + + worker.perform(forked.id, user.id, forked.commit.to_hash) + end + end + + context 'when the commit does not exist in the upstream project' do + it 'processes the commit message' do + empty_project = create(:project, :public) + forked = fork_project(empty_project, user, repository: true) + + TestEnv.copy_repo(forked, + bare_repo: TestEnv.factory_repo_path_bare, + refs: TestEnv::BRANCH_SHA) + + expect(worker).to receive(:process_commit_message) + + worker.perform(forked.id, user.id, forked.commit.to_hash) + end + end - it 'does not process commit message' do - create(:forked_project_link, forked_to_project: forked, forked_from_project: project) + context 'when the upstream project no longer exists' do + it 'processes the commit message' do + forked = fork_project(project, user, repository: true) + project.destroy! - expect(worker).not_to receive(:process_commit_message) + expect(worker).to receive(:process_commit_message) - worker.perform(forked.id, user.id, forked.commit.to_hash) + worker.perform(forked.id, user.id, forked.commit.to_hash) + end end end end diff --git a/spec/workers/project_cache_worker_spec.rb b/spec/workers/project_cache_worker_spec.rb index 8c4daac5f80..b9b5445562f 100644 --- a/spec/workers/project_cache_worker_spec.rb +++ b/spec/workers/project_cache_worker_spec.rb @@ -9,50 +9,44 @@ describe ProjectCacheWorker do let(:lease_key) { "project_cache_worker:#{project.id}:update_statistics" } let(:lease_timeout) { ProjectCacheWorker::LEASE_TIMEOUT } - before do - stub_exclusive_lease(lease_key, timeout: lease_timeout) - - allow(Project).to receive(:find_by) - .with(id: project.id) - .and_return(project) - end - describe '#perform' do - context 'with a non-existing project' do - it 'does not update statistic' do - allow(Project).to receive(:find_by).with(id: -1).and_return(nil) + before do + stub_exclusive_lease(lease_key, timeout: lease_timeout) + end - expect(subject).not_to receive(:update_statistics) + context 'with a non-existing project' do + it 'does nothing' do + expect(worker).not_to receive(:update_statistics) - subject.perform(-1) + worker.perform(-1) end end context 'with an existing project without a repository' do - it 'does not update statistics' do - allow(project.repository).to receive(:exists?).and_return(false) + it 'does nothing' do + allow_any_instance_of(Repository).to receive(:exists?).and_return(false) - expect(subject).not_to receive(:update_statistics) + expect(worker).not_to receive(:update_statistics) - subject.perform(project.id) + worker.perform(project.id) end end context 'with an existing project' do it 'updates the project statistics' do - expect(subject).to receive(:update_statistics) - .with(%w(repository_size)) - .and_call_original + expect(worker).to receive(:update_statistics) + .with(kind_of(Project), %i(repository_size)) + .and_call_original - subject.perform(project.id, [], %w(repository_size)) + worker.perform(project.id, [], %w(repository_size)) end it 'refreshes the method caches' do - expect(project.repository).to receive(:refresh_method_caches) - .with(%i(readme)) - .and_call_original + expect_any_instance_of(Repository).to receive(:refresh_method_caches) + .with(%i(readme)) + .and_call_original - subject.perform(project.id, %w(readme)) + worker.perform(project.id, %w(readme)) end context 'with plain readme' do @@ -60,22 +54,23 @@ describe ProjectCacheWorker do allow(MarkupHelper).to receive(:gitlab_markdown?).and_return(false) allow(MarkupHelper).to receive(:plain?).and_return(true) - expect(project.repository).to receive(:refresh_method_caches) - .with(%i(readme)) - .and_call_original - - subject.perform(project.id, %w(readme)) + expect_any_instance_of(Repository).to receive(:refresh_method_caches) + .with(%i(readme)) + .and_call_original + worker.perform(project.id, %w(readme)) end end end + end + describe '#update_statistics' do context 'when a lease could not be obtained' do it 'does not update the repository size' do stub_exclusive_lease_taken(lease_key, timeout: lease_timeout) - expect(project.statistics).not_to receive(:refresh!) + expect(statistics).not_to receive(:refresh!) - subject.perform(project.id, [], %w(repository_size)) + worker.update_statistics(project) end end @@ -83,17 +78,11 @@ describe ProjectCacheWorker do it 'updates the project statistics' do stub_exclusive_lease(lease_key, timeout: lease_timeout) - expect(project.statistics).to receive(:refresh!) - .with(only: %i(repository_size)) - .and_call_original - - subject.perform(project.id, [], %i(repository_size)) - end - - it 'cancels the lease after statistics has been updated' do - expect(subject).to receive(:release_lease).with('uuid') + expect(statistics).to receive(:refresh!) + .with(only: %i(repository_size)) + .and_call_original - subject.perform(project.id, [], %i(repository_size)) + worker.update_statistics(project, %i(repository_size)) end end end diff --git a/spec/workers/prune_web_hook_logs_worker_spec.rb b/spec/workers/prune_web_hook_logs_worker_spec.rb new file mode 100644 index 00000000000..d7d64a1f641 --- /dev/null +++ b/spec/workers/prune_web_hook_logs_worker_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe PruneWebHookLogsWorker do + describe '#perform' do + before do + hook = create(:project_hook) + + 5.times do + create(:web_hook_log, web_hook: hook, created_at: 5.months.ago) + end + + create(:web_hook_log, web_hook: hook, response_status: '404') + end + + it 'removes all web hook logs older than one month' do + described_class.new.perform + + expect(WebHookLog.count).to eq(1) + expect(WebHookLog.first.response_status).to eq('404') + end + end +end diff --git a/spec/workers/repository_check/batch_worker_spec.rb b/spec/workers/repository_check/batch_worker_spec.rb index 6bc551be9ad..ede271b2cdd 100644 --- a/spec/workers/repository_check/batch_worker_spec.rb +++ b/spec/workers/repository_check/batch_worker_spec.rb @@ -62,4 +62,12 @@ describe RepositoryCheck::BatchWorker do expect(subject.perform(shard_name)).to eq([]) end + + it 'does not run if the exclusive lease is taken' do + allow(subject).to receive(:try_obtain_lease).and_return(false) + + expect(subject).not_to receive(:perform_repository_checks) + + subject.perform(shard_name) + end end diff --git a/spec/workers/repository_check/dispatch_worker_spec.rb b/spec/workers/repository_check/dispatch_worker_spec.rb index 20a4f1f5344..7877429aa8f 100644 --- a/spec/workers/repository_check/dispatch_worker_spec.rb +++ b/spec/workers/repository_check/dispatch_worker_spec.rb @@ -11,6 +11,14 @@ describe RepositoryCheck::DispatchWorker do subject.perform end + it 'does nothing if the exclusive lease is taken' do + allow(subject).to receive(:try_obtain_lease).and_return(false) + + expect(RepositoryCheck::BatchWorker).not_to receive(:perform_async) + + subject.perform + end + it 'dispatches work to RepositoryCheck::BatchWorker' do expect(RepositoryCheck::BatchWorker).to receive(:perform_async).at_least(:once) diff --git a/spec/workers/repository_import_worker_spec.rb b/spec/workers/repository_import_worker_spec.rb index f0884ad0aff..d07e40377d4 100644 --- a/spec/workers/repository_import_worker_spec.rb +++ b/spec/workers/repository_import_worker_spec.rb @@ -51,7 +51,7 @@ describe RepositoryImportWorker do it 'hide the credentials that were used in the import URL' do error = %q{remote: Not Found fatal: repository 'https://user:pass@test.com/root/repoC.git/' not found } - project.update_attributes(import_jid: '123') + project.update(import_jid: '123') expect_any_instance_of(Projects::ImportService).to receive(:execute).and_return({ status: :error, message: error }) expect do @@ -63,7 +63,7 @@ describe RepositoryImportWorker do it 'updates the error on Import/Export' do error = %q{remote: Not Found fatal: repository 'https://user:pass@test.com/root/repoC.git/' not found } - project.update_attributes(import_jid: '123', import_type: 'gitlab_project') + project.update(import_jid: '123', import_type: 'gitlab_project') expect_any_instance_of(Projects::ImportService).to receive(:execute).and_return({ status: :error, message: error }) expect do diff --git a/spec/workers/repository_update_remote_mirror_worker_spec.rb b/spec/workers/repository_update_remote_mirror_worker_spec.rb index 152ba2509b9..4f1ad2474f5 100644 --- a/spec/workers/repository_update_remote_mirror_worker_spec.rb +++ b/spec/workers/repository_update_remote_mirror_worker_spec.rb @@ -13,7 +13,7 @@ describe RepositoryUpdateRemoteMirrorWorker do describe '#perform' do context 'with status none' do before do - remote_mirror.update_attributes(update_status: 'none') + remote_mirror.update(update_status: 'none') end it 'sets status as finished when update remote mirror service executes successfully' do @@ -34,7 +34,7 @@ describe RepositoryUpdateRemoteMirrorWorker do end it 'does nothing if last_update_started_at is higher than the time the job was scheduled in' do - remote_mirror.update_attributes(last_update_started_at: Time.now) + remote_mirror.update(last_update_started_at: Time.now) expect_any_instance_of(RemoteMirror).to receive(:updated_since?).with(scheduled_time).and_return(true) expect_any_instance_of(Projects::UpdateRemoteMirrorService).not_to receive(:execute).with(remote_mirror) @@ -56,7 +56,7 @@ describe RepositoryUpdateRemoteMirrorWorker do context 'with another worker already running' do before do - remote_mirror.update_attributes(update_status: 'started') + remote_mirror.update(update_status: 'started') end it 'raises RemoteMirrorUpdateAlreadyInProgressError' do @@ -68,11 +68,11 @@ describe RepositoryUpdateRemoteMirrorWorker do context 'with status failed' do before do - remote_mirror.update_attributes(update_status: 'failed') + remote_mirror.update(update_status: 'failed') end it 'sets status as finished if last_update_started_at is higher than the time the job was scheduled in' do - remote_mirror.update_attributes(last_update_started_at: Time.now) + remote_mirror.update(last_update_started_at: Time.now) expect_any_instance_of(RemoteMirror).to receive(:updated_since?).with(scheduled_time).and_return(false) expect_any_instance_of(Projects::UpdateRemoteMirrorService).to receive(:execute).with(remote_mirror).and_return(status: :success) diff --git a/spec/workers/stuck_import_jobs_worker_spec.rb b/spec/workers/stuck_import_jobs_worker_spec.rb index af7675c8cab..2169c14218b 100644 --- a/spec/workers/stuck_import_jobs_worker_spec.rb +++ b/spec/workers/stuck_import_jobs_worker_spec.rb @@ -51,7 +51,7 @@ describe StuckImportJobsWorker do let(:project) { create(:project, :import_scheduled) } before do - project.import_state.update_attributes(jid: '123') + project.import_state.update(jid: '123') end end end @@ -61,7 +61,7 @@ describe StuckImportJobsWorker do let(:project) { create(:project, :import_started) } before do - project.import_state.update_attributes(jid: '123') + project.import_state.update(jid: '123') end end end |