Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Ivan Vargas <jvargas@gitlab.com>2017-02-02 22:35:15 +0300
committerJose Ivan Vargas <jvargas@gitlab.com>2017-02-06 23:51:19 +0300
commitf3aaf906d488ee67ecd84f52febd0ce060fb7683 (patch)
treeea4ab82dcaaa25c2483a88cbe9d2d7b93dba469a
parentd9d417d405c42721b300e3b4a0dc6656529c3411 (diff)
Added tests for the variables controller #update action
-rw-r--r--app/controllers/projects/variables_controller.rb5
-rw-r--r--spec/controllers/projects/variables_controller_spec.rb27
2 files changed, 29 insertions, 3 deletions
diff --git a/app/controllers/projects/variables_controller.rb b/app/controllers/projects/variables_controller.rb
index 06429f56116..d07ef7889ca 100644
--- a/app/controllers/projects/variables_controller.rb
+++ b/app/controllers/projects/variables_controller.rb
@@ -15,10 +15,11 @@ class Projects::VariablesController < Projects::ApplicationController
@variable = @project.variables.find(params[:id])
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
- render action: "show"
+ flash[:alert] = @variable.errors.full_messages.join(',').html_safe
end
+ redirect_to namespace_project_settings_ci_cd_path(project.namespace, project)
end
def create
diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb
index 315d1b66e73..9914e217d70 100644
--- a/spec/controllers/projects/variables_controller_spec.rb
+++ b/spec/controllers/projects/variables_controller_spec.rb
@@ -20,7 +20,7 @@ describe Projects::VariablesController do
end
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,
variable: { key: "..one", value: "two" }
expect(flash[:alert]).to include 'Key can contain only letters, digits and \'_\'.'
@@ -28,4 +28,29 @@ describe Projects::VariablesController do
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