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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-21 18:21:10 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-21 18:21:10 +0300
commite33f87ac0fabaab468ce4b457996cc0f1b1bb648 (patch)
tree8bf0de72a9acac014cfdaddab7d463b208294af2 /spec/services/snippets
parent5baf990db20a75078684702782c24399ef9eb0fa (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/snippets')
-rw-r--r--spec/services/snippets/create_service_spec.rb37
-rw-r--r--spec/services/snippets/update_service_spec.rb31
2 files changed, 68 insertions, 0 deletions
diff --git a/spec/services/snippets/create_service_spec.rb b/spec/services/snippets/create_service_spec.rb
index 690aa2c066e..c1a8a026b90 100644
--- a/spec/services/snippets/create_service_spec.rb
+++ b/spec/services/snippets/create_service_spec.rb
@@ -252,6 +252,39 @@ describe Snippets::CreateService do
end
end
+ shared_examples 'after_save callback to store_mentions' do
+ context 'when mentionable attributes change' do
+ let(:extra_opts) { { description: "Description with #{user.to_reference}" } }
+
+ it 'saves mentions' do
+ expect_next_instance_of(Snippet) do |instance|
+ expect(instance).to receive(:store_mentions!).and_call_original
+ end
+ expect(snippet.user_mentions.count).to eq 1
+ end
+ end
+
+ context 'when mentionable attributes do not change' do
+ it 'does not call store_mentions' do
+ expect_next_instance_of(Snippet) do |instance|
+ expect(instance).not_to receive(:store_mentions!)
+ end
+ expect(snippet.user_mentions.count).to eq 0
+ end
+ end
+
+ context 'when save fails' do
+ it 'does not call store_mentions' do
+ base_opts.delete(:title)
+
+ expect_next_instance_of(Snippet) do |instance|
+ expect(instance).not_to receive(:store_mentions!)
+ end
+ expect(snippet.valid?).to be false
+ end
+ end
+ end
+
context 'when ProjectSnippet' do
let_it_be(:project) { create(:project) }
@@ -265,6 +298,7 @@ describe Snippets::CreateService do
it_behaves_like 'snippet create data is tracked'
it_behaves_like 'an error service response when save fails'
it_behaves_like 'creates repository and files'
+ it_behaves_like 'after_save callback to store_mentions'
end
context 'when PersonalSnippet' do
@@ -276,6 +310,9 @@ describe Snippets::CreateService do
it_behaves_like 'snippet create data is tracked'
it_behaves_like 'an error service response when save fails'
it_behaves_like 'creates repository and files'
+ pending('See https://gitlab.com/gitlab-org/gitlab/issues/30742') do
+ it_behaves_like 'after_save callback to store_mentions'
+ end
end
end
end
diff --git a/spec/services/snippets/update_service_spec.rb b/spec/services/snippets/update_service_spec.rb
index 05fb725c065..4274a7d05d9 100644
--- a/spec/services/snippets/update_service_spec.rb
+++ b/spec/services/snippets/update_service_spec.rb
@@ -270,6 +270,35 @@ describe Snippets::UpdateService do
end
end
+ shared_examples 'committable attributes' do
+ context 'when file_name is updated' do
+ let(:options) { { file_name: 'snippet.rb' } }
+
+ it 'commits to repository' do
+ expect(service).to receive(:create_commit)
+ expect(subject).to be_success
+ end
+ end
+
+ context 'when content is updated' do
+ let(:options) { { content: 'puts "hello world"' } }
+
+ it 'commits to repository' do
+ expect(service).to receive(:create_commit)
+ expect(subject).to be_success
+ end
+ end
+
+ context 'when content or file_name is not updated' do
+ let(:options) { { title: 'Test snippet' } }
+
+ it 'does not perform any commit' do
+ expect(service).not_to receive(:create_commit)
+ expect(subject).to be_success
+ end
+ end
+ end
+
context 'when Project Snippet' do
let_it_be(:project) { create(:project) }
let!(:snippet) { create(:project_snippet, :repository, author: user, project: project) }
@@ -283,6 +312,7 @@ describe Snippets::UpdateService do
it_behaves_like 'snippet update data is tracked'
it_behaves_like 'updates repository content'
it_behaves_like 'commit operation fails'
+ it_behaves_like 'committable attributes'
context 'when snippet does not have a repository' do
let!(:snippet) { create(:project_snippet, author: user, project: project) }
@@ -301,6 +331,7 @@ describe Snippets::UpdateService do
it_behaves_like 'snippet update data is tracked'
it_behaves_like 'updates repository content'
it_behaves_like 'commit operation fails'
+ it_behaves_like 'committable attributes'
context 'when snippet does not have a repository' do
let!(:snippet) { create(:personal_snippet, author: user, project: project) }