2017-02-02 12:25:12 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::VariablesController do
|
|
|
|
let(:project) { create(:empty_project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :master]
|
|
|
|
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-02-02 12:25:12 -05:00
|
|
|
expect(flash[:notice]).to include 'Variables were successfully updated.'
|
|
|
|
expect(response).to redirect_to(namespace_project_settings_ci_cd_path(project.namespace, project))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'variable is invalid' do
|
2017-02-02 14:35:15 -05:00
|
|
|
it 'shows an alert 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-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
|
2017-03-17 19:06:11 -04:00
|
|
|
variable.project_id = project.id
|
2017-02-02 14:35:15 -05:00
|
|
|
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.'
|
|
|
|
expect(response).to redirect_to(namespace_project_variables_path(project.namespace, 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 }
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
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
|