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-06 21:09:37 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-06 21:09:37 +0300
commit495c22d1245b6212b21b7379a542df73dfa77206 (patch)
tree5f0f82dd6c8c4fe1c4bd411f9e398b1a6eaaa69f /spec/services
parentf3b1e07903a7f509b11ad7cf188fac46d98f77f6 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/notification_service_spec.rb18
-rw-r--r--spec/services/snippets/update_service_spec.rb81
2 files changed, 74 insertions, 25 deletions
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb
index 9fa8f807330..86f37e9204c 100644
--- a/spec/services/notification_service_spec.rb
+++ b/spec/services/notification_service_spec.rb
@@ -1022,24 +1022,6 @@ describe NotificationService, :mailer do
should_not_email(@u_lazy_participant)
end
- it 'emails new assignee' do
- issue.assignees = [@u_mentioned]
- notification.reassigned_issue(issue, @u_disabled, [@u_mentioned])
-
- expect(issue.assignees.first).to be @u_mentioned
- should_email(issue.assignees.first)
- should_email(@u_watcher)
- should_email(@u_guest_watcher)
- should_email(@u_guest_custom)
- should_email(@u_participant_mentioned)
- should_email(@subscriber)
- should_email(@u_custom_global)
- should_not_email(@unsubscriber)
- should_not_email(@u_participating)
- should_not_email(@u_disabled)
- should_not_email(@u_lazy_participant)
- end
-
it 'does not email new assignee if they are the current user' do
issue.assignees = [@u_mentioned]
notification.reassigned_issue(issue, @u_mentioned, [@u_mentioned])
diff --git a/spec/services/snippets/update_service_spec.rb b/spec/services/snippets/update_service_spec.rb
index 9c88e741d51..05fb725c065 100644
--- a/spec/services/snippets/update_service_spec.rb
+++ b/spec/services/snippets/update_service_spec.rb
@@ -139,18 +139,80 @@ describe Snippets::UpdateService do
subject
end
end
+ end
- it 'returns error when the commit action fails' do
- error_message = 'foobar'
+ shared_examples 'commit operation fails' do
+ let_it_be(:gitlab_shell) { Gitlab::Shell.new }
- allow_next_instance_of(SnippetRepository) do |instance|
- allow(instance).to receive(:multi_files_action).and_raise(SnippetRepository::CommitError, error_message)
- end
+ before do
+ allow(service).to receive(:create_commit).and_raise(SnippetRepository::CommitError)
+ end
+ it 'returns error' do
response = subject
expect(response).to be_error
- expect(response.payload[:snippet].errors[:repository].to_sentence).to eq error_message
+ expect(response.payload[:snippet].errors[:repository].to_sentence).to eq 'Error updating the snippet'
+ end
+
+ context 'when repository is empty' do
+ before do
+ allow(service).to receive(:repository_empty?).and_return(true)
+ end
+
+ it 'destroys the created repository in disk' do
+ subject
+
+ expect(gitlab_shell.repository_exists?(snippet.repository.storage, "#{snippet.disk_path}.git")).to be_falsey
+ end
+
+ it 'destroys the SnippetRepository object' do
+ subject
+
+ expect(snippet.reload.snippet_repository).to be_nil
+ end
+
+ it 'expires the repository exists method cache' do
+ response = subject
+
+ expect(response).to be_error
+ expect(response.payload[:snippet].repository_exists?).to be_falsey
+ end
+ end
+
+ context 'when repository is not empty' do
+ before do
+ allow(service).to receive(:repository_empty?).and_return(false)
+ end
+
+ it 'does not destroy the repository' do
+ subject
+
+ expect(gitlab_shell.repository_exists?(snippet.repository.storage, "#{snippet.disk_path}.git")).to be_truthy
+ end
+
+ it 'does not destroy the snippet repository' do
+ subject
+
+ expect(snippet.reload.snippet_repository).not_to be_nil
+ end
+
+ it 'expires the repository exists method cache' do
+ response = subject
+
+ expect(response).to be_error
+ expect(response.payload[:snippet].repository_exists?).to be_truthy
+ end
+ end
+
+ it 'rolls back any snippet modifications' do
+ option_keys = options.stringify_keys.keys
+ orig_attrs = snippet.attributes.select { |k, v| k.in?(option_keys) }
+
+ subject
+
+ current_attrs = snippet.attributes.select { |k, v| k.in?(option_keys) }
+ expect(orig_attrs).to eq current_attrs
end
end
@@ -186,12 +248,13 @@ describe Snippets::UpdateService do
response = subject
expect(response).to be_error
- expect(response.payload[:snippet].errors[:repository].to_sentence).to eq error_message
+ expect(response.payload[:snippet].errors[:repository].to_sentence).to eq 'Error updating the snippet'
end
end
it 'returns error if snippet does not have a snippet_repository' do
allow(snippet).to receive(:snippet_repository).and_return(nil)
+ allow(snippet).to receive(:track_snippet_repository).and_return(nil)
expect(subject).to be_error
end
@@ -219,11 +282,13 @@ describe Snippets::UpdateService do
it_behaves_like 'public visibility level restrictions apply'
it_behaves_like 'snippet update data is tracked'
it_behaves_like 'updates repository content'
+ it_behaves_like 'commit operation fails'
context 'when snippet does not have a repository' do
let!(:snippet) { create(:project_snippet, author: user, project: project) }
it_behaves_like 'creates repository and creates file'
+ it_behaves_like 'commit operation fails'
end
end
@@ -235,11 +300,13 @@ describe Snippets::UpdateService do
it_behaves_like 'public visibility level restrictions apply'
it_behaves_like 'snippet update data is tracked'
it_behaves_like 'updates repository content'
+ it_behaves_like 'commit operation fails'
context 'when snippet does not have a repository' do
let!(:snippet) { create(:personal_snippet, author: user, project: project) }
it_behaves_like 'creates repository and creates file'
+ it_behaves_like 'commit operation fails'
end
end
end