Commit f3aaf906 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Added tests for the variables controller #update action

parent d9d417d4
...@@ -15,10 +15,11 @@ class Projects::VariablesController < Projects::ApplicationController ...@@ -15,10 +15,11 @@ class Projects::VariablesController < Projects::ApplicationController
@variable = @project.variables.find(params[:id]) @variable = @project.variables.find(params[:id])
if @variable.update_attributes(project_params) if @variable.update_attributes(project_params)
redirect_to namespace_project_settings_ci_cd_path(project.namespace, project), notice: 'Variable was successfully updated.' flash[:notice] = 'Variables were successfully updated.'
else else
render action: "show" flash[:alert] = @variable.errors.full_messages.join(',').html_safe
end end
redirect_to namespace_project_settings_ci_cd_path(project.namespace, project)
end end
def create def create
......
...@@ -20,7 +20,7 @@ describe Projects::VariablesController do ...@@ -20,7 +20,7 @@ describe Projects::VariablesController do
end end
context 'variable is invalid' do context 'variable is invalid' do
it 'shows a failure flash message' do it 'shows an alert flash message' do
post :create, namespace_id: project.namespace.to_param, project_id: project.to_param, post :create, namespace_id: project.namespace.to_param, project_id: project.to_param,
variable: { key: "..one", value: "two" } variable: { key: "..one", value: "two" }
expect(flash[:alert]).to include 'Key can contain only letters, digits and \'_\'.' expect(flash[:alert]).to include 'Key can contain only letters, digits and \'_\'.'
...@@ -28,4 +28,29 @@ describe Projects::VariablesController do ...@@ -28,4 +28,29 @@ describe Projects::VariablesController do
end end
end end
end end
describe 'POST #update' do
let(:variable) { create(:ci_variable) }
context 'updating a variable with valid characters' do
before do
variable.gl_project_id = project.id
project.variables << variable
end
it 'shows a success flash message' do
post :update, namespace_id: project.namespace.to_param, project_id: project.to_param,
id: variable.id, variable: { key: variable.key, value: 'two' }
expect(flash[:notice]).to include 'Variables were successfully updated.'
expect(response).to redirect_to(namespace_project_settings_ci_cd_path(project.namespace, project))
end
it 'shows an alert flash message' do
post :update, namespace_id: project.namespace.to_param, project_id: project.to_param,
id: variable.id, variable: { key: '?', value: variable.value }
expect(flash[:alert]).to include 'Key can contain only letters, digits and \'_\'.'
expect(response).to redirect_to(namespace_project_settings_ci_cd_path(project.namespace, project))
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment