Skip to content
代码片段 群组 项目
未验证 提交 eea14d25 编辑于 作者: hustewart's avatar hustewart
浏览文件

Use reason instead of http_status

上级 a1dec6a1
No related branches found
No related tags found
无相关合并请求
...@@ -30,7 +30,6 @@ Gitlab/ServiceResponse: ...@@ -30,7 +30,6 @@ Gitlab/ServiceResponse:
- 'app/services/snippets/base_service.rb' - 'app/services/snippets/base_service.rb'
- 'app/services/snippets/bulk_destroy_service.rb' - 'app/services/snippets/bulk_destroy_service.rb'
- 'app/services/snippets/destroy_service.rb' - 'app/services/snippets/destroy_service.rb'
- 'app/services/snippets/repository_validation_service.rb'
- 'app/services/timelogs/base_service.rb' - 'app/services/timelogs/base_service.rb'
- 'app/services/work_items/create_and_link_service.rb' - 'app/services/work_items/create_and_link_service.rb'
- 'app/services/work_items/create_from_task_service.rb' - 'app/services/work_items/create_from_task_service.rb'
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
module Snippets module Snippets
class RepositoryValidationService class RepositoryValidationService
INVALID_REPOSITORY = :invalid_snippet_repository
attr_reader :current_user, :snippet, :repository attr_reader :current_user, :snippet, :repository
RepositoryValidationError = Class.new(StandardError) RepositoryValidationError = Class.new(StandardError)
...@@ -25,7 +27,7 @@ def execute ...@@ -25,7 +27,7 @@ def execute
ServiceResponse.success(message: 'Valid snippet repository.') ServiceResponse.success(message: 'Valid snippet repository.')
rescue RepositoryValidationError => e rescue RepositoryValidationError => e
ServiceResponse.error(message: "Error: #{e.message}", http_status: 400) ServiceResponse.error(message: "Error: #{e.message}", reason: INVALID_REPOSITORY)
end end
private private
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
allow(repository).to receive(:branch_count).and_return(2) allow(repository).to receive(:branch_count).and_return(2)
expect(subject).to be_error expect(subject).to be_error
expect(subject.reason).to eq(described_class::INVALID_REPOSITORY)
expect(subject.message).to match(/Repository has more than one branch/) expect(subject.message).to match(/Repository has more than one branch/)
end end
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
allow(repository).to receive(:branch_names).and_return(['foo']) allow(repository).to receive(:branch_names).and_return(['foo'])
expect(subject).to be_error expect(subject).to be_error
expect(subject.reason).to eq(described_class::INVALID_REPOSITORY)
expect(subject.message).to match(/Repository has an invalid default branch name/) expect(subject.message).to match(/Repository has an invalid default branch name/)
end end
...@@ -36,6 +38,7 @@ ...@@ -36,6 +38,7 @@
allow(repository).to receive(:tag_count).and_return(1) allow(repository).to receive(:tag_count).and_return(1)
expect(subject).to be_error expect(subject).to be_error
expect(subject.reason).to eq(described_class::INVALID_REPOSITORY)
expect(subject.message).to match(/Repository has tags/) expect(subject.message).to match(/Repository has tags/)
end end
...@@ -45,6 +48,7 @@ ...@@ -45,6 +48,7 @@
allow(repository).to receive(:ls_files).and_return(files) allow(repository).to receive(:ls_files).and_return(files)
expect(subject).to be_error expect(subject).to be_error
expect(subject.reason).to eq(described_class::INVALID_REPOSITORY)
expect(subject.message).to match(/Repository files count over the limit/) expect(subject.message).to match(/Repository files count over the limit/)
end end
...@@ -52,6 +56,7 @@ ...@@ -52,6 +56,7 @@
allow(repository).to receive(:ls_files).and_return([]) allow(repository).to receive(:ls_files).and_return([])
expect(subject).to be_error expect(subject).to be_error
expect(subject.reason).to eq(described_class::INVALID_REPOSITORY)
expect(subject.message).to match(/Repository must contain at least 1 file/) expect(subject.message).to match(/Repository must contain at least 1 file/)
end end
...@@ -61,6 +66,7 @@ ...@@ -61,6 +66,7 @@
end end
expect(subject).to be_error expect(subject).to be_error
expect(subject.reason).to eq(described_class::INVALID_REPOSITORY)
expect(subject.message).to match(/Repository size is above the limit/) expect(subject.message).to match(/Repository size is above the limit/)
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册