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
|
2016-11-03 12:29:30 +05:30
|
|
|
project.add_user(user, Gitlab::Access::MASTER)
|
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
|
2017-08-17 22:00:37 +05:30
|
|
|
get(:show, 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)
|
2017-08-17 22:00:37 +05:30
|
|
|
get(:show, 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)
|
2017-08-17 22:00:37 +05:30
|
|
|
get(:show, 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)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect { get(:show, 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
|