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