2016-09-13 17:45:13 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::TemplatesController do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let(:file_path_1) { '.gitlab/issue_templates/bug.md' }
|
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_developer(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_user(user, Gitlab::Access::MAINTAINER)
|
2017-08-17 22:00:37 +05:30
|
|
|
project.repository.create_file(user, file_path_1, 'something valid',
|
|
|
|
message: 'test 3', branch_name: 'master')
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe '#show' do
|
|
|
|
it 'renders template name and content as json' do
|
2019-02-13 22:33:31 +05:30
|
|
|
get(:show, params: { namespace_id: project.namespace.to_param, template_type: "issue", key: "bug", project_id: project }, format: :json)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(body["name"]).to eq("bug")
|
|
|
|
expect(body["content"]).to eq("something valid")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders 404 when unauthorized' do
|
|
|
|
sign_in(user2)
|
2019-02-13 22:33:31 +05:30
|
|
|
get(:show, params: { namespace_id: project.namespace.to_param, template_type: "issue", key: "bug", project_id: project }, format: :json)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders 404 when template type is not found' do
|
|
|
|
sign_in(user)
|
2019-02-13 22:33:31 +05:30
|
|
|
get(:show, params: { namespace_id: project.namespace.to_param, template_type: "dont_exist", key: "bug", project_id: project }, format: :json)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders 404 without errors' do
|
|
|
|
sign_in(user)
|
2019-02-13 22:33:31 +05:30
|
|
|
expect { get(:show, params: { namespace_id: project.namespace.to_param, template_type: "dont_exist", key: "bug", project_id: project }, format: :json) }.not_to raise_error
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|