From 983a0bba5d2a042c4a3bbb22432ec192c7501d82 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 20 Apr 2020 18:38:24 +0000 Subject: Add latest changes from gitlab-org/gitlab@12-10-stable-ee --- spec/services/snippets/create_service_spec.rb | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'spec/services/snippets/create_service_spec.rb') 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 -- cgit v1.2.3