diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 00:08:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 00:08:48 +0300 |
commit | 006e89697dd5165f355afc20fc6bb0cdfa7b381a (patch) | |
tree | 9095aeb37b2c80f3b0cc5a8dfd27baf93f05b61b /spec/models | |
parent | 43e3dc2f95a25c600e08f65d4f1c406a1a63ed3d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/concerns/bulk_insert_safe_spec.rb | 38 | ||||
-rw-r--r-- | spec/models/label_link_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/merge_request_diff_commit_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/merge_request_diff_file_spec.rb | 2 |
4 files changed, 44 insertions, 0 deletions
diff --git a/spec/models/concerns/bulk_insert_safe_spec.rb b/spec/models/concerns/bulk_insert_safe_spec.rb new file mode 100644 index 00000000000..91884680738 --- /dev/null +++ b/spec/models/concerns/bulk_insert_safe_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe BulkInsertSafe do + class BulkInsertItem < ApplicationRecord + include BulkInsertSafe + end + + module InheritedUnsafeMethods + extend ActiveSupport::Concern + + included do + after_save -> { "unsafe" } + end + end + + module InheritedSafeMethods + extend ActiveSupport::Concern + + included do + after_initialize -> { "safe" } + end + end + + it_behaves_like 'a BulkInsertSafe model', BulkInsertItem + + context 'when inheriting class methods' do + it 'raises an error when method is not bulk-insert safe' do + expect { BulkInsertItem.include(InheritedUnsafeMethods) }.to( + raise_error(subject::MethodNotAllowedError)) + end + + it 'does not raise an error when method is bulk-insert safe' do + expect { BulkInsertItem.include(InheritedSafeMethods) }.not_to raise_error + end + end +end diff --git a/spec/models/label_link_spec.rb b/spec/models/label_link_spec.rb index b160e72e759..0a5cb5374b0 100644 --- a/spec/models/label_link_spec.rb +++ b/spec/models/label_link_spec.rb @@ -7,4 +7,6 @@ describe LabelLink do it { is_expected.to belong_to(:label) } it { is_expected.to belong_to(:target) } + + it_behaves_like 'a BulkInsertSafe model', LabelLink end diff --git a/spec/models/merge_request_diff_commit_spec.rb b/spec/models/merge_request_diff_commit_spec.rb index a74c0b20642..a296122ae09 100644 --- a/spec/models/merge_request_diff_commit_spec.rb +++ b/spec/models/merge_request_diff_commit_spec.rb @@ -6,6 +6,8 @@ describe MergeRequestDiffCommit do let(:merge_request) { create(:merge_request) } let(:project) { merge_request.project } + it_behaves_like 'a BulkInsertSafe model', MergeRequestDiffCommit + describe '#to_hash' do subject { merge_request.commits.first } diff --git a/spec/models/merge_request_diff_file_spec.rb b/spec/models/merge_request_diff_file_spec.rb index 84f9c9d06ba..6ecbc5bf832 100644 --- a/spec/models/merge_request_diff_file_spec.rb +++ b/spec/models/merge_request_diff_file_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' describe MergeRequestDiffFile do + it_behaves_like 'a BulkInsertSafe model', MergeRequestDiffFile + describe '#diff' do context 'when diff is not stored' do let(:unpacked) { 'unpacked' } |