2016-06-24 15:43:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::TemplatesController do
|
2017-01-25 16:44:33 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-06-24 15:43:46 -04:00
|
|
|
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
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2016-06-24 15:43:46 -04:00
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_user(user, Gitlab::Access::MAINTAINER)
|
2017-02-15 18:28:29 -05:00
|
|
|
project.repository.create_file(user, file_path_1, 'something valid',
|
|
|
|
message: 'test 3', branch_name: 'master')
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#show' do
|
|
|
|
it 'renders template name and content as json' do
|
2017-02-23 18:55:01 -05:00
|
|
|
get(:show, namespace_id: project.namespace.to_param, template_type: "issue", key: "bug", project_id: project, format: :json)
|
2016-06-24 15:43:46 -04:00
|
|
|
|
|
|
|
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-02-23 18:55:01 -05:00
|
|
|
get(:show, namespace_id: project.namespace.to_param, template_type: "issue", key: "bug", project_id: project, format: :json)
|
2016-06-24 15:43:46 -04:00
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders 404 when template type is not found' do
|
|
|
|
sign_in(user)
|
2017-02-23 18:55:01 -05:00
|
|
|
get(:show, namespace_id: project.namespace.to_param, template_type: "dont_exist", key: "bug", project_id: project, format: :json)
|
2016-06-24 15:43:46 -04:00
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders 404 without errors' do
|
|
|
|
sign_in(user)
|
2017-02-23 18:55:01 -05:00
|
|
|
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-06-24 15:43:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|