2017-02-02 17:25:12 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::VariablesController do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2017-02-02 17:25:12 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2017-12-22 08:18:28 +00:00
|
|
|
project.add_master(user)
|
2017-02-02 17:25:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
context 'variable is valid' do
|
|
|
|
it 'shows a success flash message' do
|
2017-02-23 23:55:01 +00:00
|
|
|
post :create, namespace_id: project.namespace.to_param, project_id: project,
|
2017-02-02 17:25:12 +00:00
|
|
|
variable: { key: "one", value: "two" }
|
2017-02-03 22:51:34 +00:00
|
|
|
|
2017-07-06 11:10:07 +00:00
|
|
|
expect(flash[:notice]).to include 'Variable was successfully created.'
|
2017-06-29 17:06:35 +00:00
|
|
|
expect(response).to redirect_to(project_settings_ci_cd_path(project))
|
2017-02-02 17:25:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'variable is invalid' do
|
2017-05-03 18:51:55 +00:00
|
|
|
it 'renders show' do
|
2017-02-23 23:55:01 +00:00
|
|
|
post :create, namespace_id: project.namespace.to_param, project_id: project,
|
2017-02-02 17:25:12 +00:00
|
|
|
variable: { key: "..one", value: "two" }
|
2017-02-03 22:51:34 +00:00
|
|
|
|
2017-02-06 20:46:13 +00:00
|
|
|
expect(response).to render_template("projects/variables/show")
|
2017-02-02 17:25:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-02-02 19:35:15 +00:00
|
|
|
|
|
|
|
describe 'POST #update' do
|
|
|
|
let(:variable) { create(:ci_variable) }
|
|
|
|
|
|
|
|
context 'updating a variable with valid characters' do
|
|
|
|
before do
|
|
|
|
project.variables << variable
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows a success flash message' do
|
2017-02-23 23:55:01 +00:00
|
|
|
post :update, namespace_id: project.namespace.to_param, project_id: project,
|
2017-02-03 22:51:34 +00:00
|
|
|
id: variable.id, variable: { key: variable.key, value: 'two' }
|
|
|
|
|
|
|
|
expect(flash[:notice]).to include 'Variable was successfully updated.'
|
2017-06-29 17:06:35 +00:00
|
|
|
expect(response).to redirect_to(project_variables_path(project))
|
2017-02-02 19:35:15 +00:00
|
|
|
end
|
|
|
|
|
2017-02-03 22:51:34 +00:00
|
|
|
it 'renders the action #show if the variable key is invalid' do
|
2017-02-23 23:55:01 +00:00
|
|
|
post :update, namespace_id: project.namespace.to_param, project_id: project,
|
2017-02-03 22:51:34 +00:00
|
|
|
id: variable.id, variable: { key: '?', value: variable.value }
|
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-02-03 22:51:34 +00:00
|
|
|
expect(response).to render_template :show
|
2017-02-02 19:35:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-02-02 17:25:12 +00:00
|
|
|
end
|