diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/support/shared_examples/models | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/support/shared_examples/models')
7 files changed, 57 insertions, 63 deletions
diff --git a/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb b/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb index 0efa5e56199..f80ca235220 100644 --- a/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb +++ b/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb @@ -88,16 +88,6 @@ RSpec.shared_examples 'cluster application status specs' do |application_name| end end - it 'sets the correct version of the application' do - subject.update!(version: '0.0.0') - - subject.make_installed! - - subject.reload - - expect(subject.version).to eq(subject.class.const_get(:VERSION, false)) - end - context 'application is updating' do subject { create(application_name, :updating) } @@ -146,16 +136,6 @@ RSpec.shared_examples 'cluster application status specs' do |application_name| end end end - - it 'updates the version of the application' do - subject.update!(version: '0.0.0') - - subject.make_installed! - - subject.reload - - expect(subject.version).to eq(subject.class.const_get(:VERSION, false)) - end end end diff --git a/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb b/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb index cf7010c48c2..ed2e4fee2de 100644 --- a/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb +++ b/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb @@ -19,4 +19,32 @@ RSpec.shared_examples 'cluster application version specs' do |application_name| it { is_expected.to be_falsey } end end + + describe '#make_installed' do + subject { create(application_name, :installing) } + + it 'sets the correct version of the application' do + subject.update!(version: '0.0.0') + + subject.make_installed! + + subject.reload + + expect(subject.version).to eq(subject.class.const_get(:VERSION, false)) + end + + context 'application is updating' do + subject { create(application_name, :updating) } + + it 'updates the version of the application' do + subject.update!(version: '0.0.0') + + subject.make_installed! + + subject.reload + + expect(subject.version).to eq(subject.class.const_get(:VERSION, false)) + end + end + end end diff --git a/spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb b/spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb index 7bcd6191f1d..3db5d7a8d7d 100644 --- a/spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb +++ b/spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb @@ -7,17 +7,17 @@ RSpec.shared_examples 'a BulkInsertSafe model' do |klass| let(:target_class) { klass.dup } # We consider all callbacks unsafe for bulk insertions unless we have explicitly - # whitelisted them (esp. anything related to :save, :create, :commit etc.) - let(:callback_method_blacklist) do + # allowed them (especially anything related to :save, :create, :commit, etc.) + let(:unsafe_callbacks) do ActiveRecord::Callbacks::CALLBACKS.reject do |callback| cb_name = callback.to_s.gsub(/(before_|after_|around_)/, '').to_sym - BulkInsertSafe::CALLBACK_NAME_WHITELIST.include?(cb_name) + BulkInsertSafe::ALLOWED_CALLBACKS.include?(cb_name) end.to_set end context 'when calling class methods directly' do it 'raises an error when method is not bulk-insert safe' do - callback_method_blacklist.each do |m| + unsafe_callbacks.each do |m| expect { target_class.send(m, nil) }.to( raise_error(BulkInsertSafe::MethodNotAllowedError), "Expected call to #{m} to raise an error, but it didn't" @@ -26,7 +26,7 @@ RSpec.shared_examples 'a BulkInsertSafe model' do |klass| end it 'does not raise an error when method is bulk-insert safe' do - BulkInsertSafe::CALLBACK_NAME_WHITELIST.each do |name| + BulkInsertSafe::ALLOWED_CALLBACKS.each do |name| expect { target_class.set_callback(name) {} }.not_to raise_error end end diff --git a/spec/support/shared_examples/models/jira_import_state_shared_examples.rb b/spec/support/shared_examples/models/jira_import_state_shared_examples.rb index f4643375c8e..1999f0f3c49 100644 --- a/spec/support/shared_examples/models/jira_import_state_shared_examples.rb +++ b/spec/support/shared_examples/models/jira_import_state_shared_examples.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_examples 'multiple running imports not allowed' do +RSpec.shared_examples 'multiple running imports not allowed' do it 'returns not valid' do new_import = build(:jira_import_state, project: project) @@ -9,21 +9,21 @@ shared_examples 'multiple running imports not allowed' do end end -shared_examples 'in progress' do |status| +RSpec.shared_examples 'in progress' do |status| it 'returns true' do jira_import_state = build(:jira_import_state, status: status) expect(jira_import_state).to be_in_progress end end -shared_examples 'not in progress' do |status| +RSpec.shared_examples 'not in progress' do |status| it 'returns false' do jira_import_state = build(:jira_import_state, status: status) expect(jira_import_state).not_to be_in_progress end end -shared_examples 'can transition' do |states| +RSpec.shared_examples 'can transition' do |states| states.each do |state| it 'returns true' do expect(jira_import.send(state)).to be true @@ -31,7 +31,7 @@ shared_examples 'can transition' do |states| end end -shared_examples 'cannot transition' do |states| +RSpec.shared_examples 'cannot transition' do |states| states.each do |state| it 'returns false' do expect(jira_import.send(state)).to be false diff --git a/spec/support/shared_examples/models/note_access_check_shared_examples.rb b/spec/support/shared_examples/models/note_access_check_shared_examples.rb index 3bafad202f6..44edafe9091 100644 --- a/spec/support/shared_examples/models/note_access_check_shared_examples.rb +++ b/spec/support/shared_examples/models/note_access_check_shared_examples.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_examples 'users with note access' do +RSpec.shared_examples 'users with note access' do it 'returns true' do users.each do |user| expect(note.system_note_with_references_visible_for?(user)).to be_truthy @@ -9,7 +9,7 @@ shared_examples 'users with note access' do end end -shared_examples 'users without note access' do +RSpec.shared_examples 'users without note access' do it 'returns false' do users.each do |user| expect(note.system_note_with_references_visible_for?(user)).to be_falsy diff --git a/spec/support/shared_examples/models/services_fields_shared_examples.rb b/spec/support/shared_examples/models/services_fields_shared_examples.rb deleted file mode 100644 index cb36f74460d..00000000000 --- a/spec/support/shared_examples/models/services_fields_shared_examples.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples 'issue tracker fields' do - let(:title) { 'custom title' } - let(:description) { 'custom description' } - let(:url) { 'http://issue_tracker.example.com' } - - context 'when data are stored in the properties' do - describe '#update' do - before do - service.update(title: 'new_title', description: 'new description') - end - - it 'removes title and description from properties' do - expect(service.reload.properties).not_to include('title', 'description') - end - - it 'stores title & description in services table' do - expect(service.read_attribute(:title)).to eq('new_title') - expect(service.read_attribute(:description)).to eq('new description') - end - end - - describe 'reading fields' do - it 'returns correct values' do - expect(service.title).to eq(title) - expect(service.description).to eq(description) - end - end - end -end diff --git a/spec/support/shared_examples/models/synthetic_note_shared_examples.rb b/spec/support/shared_examples/models/synthetic_note_shared_examples.rb new file mode 100644 index 00000000000..a41ade2950a --- /dev/null +++ b/spec/support/shared_examples/models/synthetic_note_shared_examples.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'a synthetic note' do |action| + it_behaves_like 'a system note', exclude_project: true do + let(:action) { action } + end + + describe '#discussion_id' do + before do + allow(event).to receive(:discussion_id).and_return('foobar42') + end + + it 'returns the expected discussion id' do + expect(subject.discussion_id(nil)).to eq('foobar42') + end + end +end |