diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2018-07-13 12:34:27 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2018-07-13 12:34:27 +0300 |
commit | d9f26586b4ec00c00fb470e55af3dc5c1f4ce33a (patch) | |
tree | 1a16bb35e6b103042ed405dcb37227c4dc44244f /spec/models | |
parent | 99c80156ae6058f70fde77baabd5f007f0246e6d (diff) | |
parent | a3c8525dc9a69d0e1048c114fd27317dcffc4221 (diff) |
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/models')
45 files changed, 1337 insertions, 560 deletions
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 |