Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-12 00:05:59 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-12 00:05:59 +0300
commitac062237da66db75b22f5dab2cc5766ee62a44d1 (patch)
treeae5a7eb248ddbf5c8c32c29a269127a936356364 /spec
parent0dfbcd8f8b1587a7e10eb79940a8dc13bd72c664 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/models/note_spec.rb31
-rw-r--r--spec/spec_helper.rb2
-rw-r--r--spec/support/helpers/expect_next_instance_of.rb15
-rw-r--r--spec/support/helpers/next_instance_of.rb28
4 files changed, 60 insertions, 16 deletions
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 66e3c6d5e9d..989024dee60 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -70,6 +70,37 @@ describe Note do
is_expected.to be_valid
end
end
+
+ describe 'max notes limit' do
+ let_it_be(:noteable) { create(:issue) }
+ let_it_be(:existing_note) { create(:note, project: noteable.project, noteable: noteable) }
+
+ before do
+ stub_const('Noteable::MAX_NOTES_LIMIT', 1)
+ end
+
+ context 'when creating a system note' do
+ subject { build(:system_note, project: noteable.project, noteable: noteable) }
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'when creating a user note' do
+ subject { build(:note, project: noteable.project, noteable: noteable) }
+
+ it { is_expected.not_to be_valid }
+ end
+
+ context 'when updating an existing note on a noteable that already exceeds the limit' do
+ subject { existing_note }
+
+ before do
+ create(:system_note, project: noteable.project, noteable: noteable)
+ end
+
+ it { is_expected.to be_valid }
+ end
+ end
end
describe "Commit notes" do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index bf87c078ac6..948e5e6250b 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -90,7 +90,7 @@ RSpec.configure do |config|
config.include StubFeatureFlags
config.include StubGitlabCalls
config.include StubGitlabData
- config.include ExpectNextInstanceOf
+ config.include NextInstanceOf
config.include TestEnv
config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::IntegrationHelpers, type: :feature
diff --git a/spec/support/helpers/expect_next_instance_of.rb b/spec/support/helpers/expect_next_instance_of.rb
deleted file mode 100644
index 749d2cb2a56..00000000000
--- a/spec/support/helpers/expect_next_instance_of.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-module ExpectNextInstanceOf
- def expect_next_instance_of(klass, *new_args)
- receive_new = receive(:new)
- receive_new.with(*new_args) if new_args.any?
-
- expect(klass).to receive_new
- .and_wrap_original do |method, *original_args|
- method.call(*original_args).tap do |instance|
- yield(instance)
- end
- end
- end
-end
diff --git a/spec/support/helpers/next_instance_of.rb b/spec/support/helpers/next_instance_of.rb
new file mode 100644
index 00000000000..83c788c3d38
--- /dev/null
+++ b/spec/support/helpers/next_instance_of.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module NextInstanceOf
+ def expect_next_instance_of(klass, *new_args)
+ stub_new(expect(klass), *new_args) do |expectation|
+ yield(expectation)
+ end
+ end
+
+ def allow_next_instance_of(klass, *new_args)
+ stub_new(allow(klass), *new_args) do |allowance|
+ yield(allowance)
+ end
+ end
+
+ private
+
+ def stub_new(target, *new_args)
+ receive_new = receive(:new)
+ receive_new.with(*new_args) if new_args.any?
+
+ target.to receive_new.and_wrap_original do |method, *original_args|
+ method.call(*original_args).tap do |instance|
+ yield(instance)
+ end
+ end
+ end
+end