summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Ivan Vargas <jvargas@gitlab.com>2017-02-03 16:51:34 -0600
committerJose Ivan Vargas <jvargas@gitlab.com>2017-02-06 14:51:19 -0600
commit44bb70c8c95fbee97661302e1279ed2c83f5d2e0 (patch)
tree6c8defb1cc25b0aa96df4b0f0de7df8b1ff4df86
parentf3aaf906d488ee67ecd84f52febd0ce060fb7683 (diff)
downloadgitlab-ce-44bb70c8c95fbee97661302e1279ed2c83f5d2e0.tar.gz
Improved code styling on the variables_controller_spec
Also updated the #update action inside the variables controller as to render the show and not redirect back to the settings route
-rw-r--r--app/controllers/projects/triggers_controller.rb4
-rw-r--r--app/controllers/projects/variables_controller.rb5
-rw-r--r--spec/controllers/projects/variables_controller_spec.rb18
3 files changed, 15 insertions, 12 deletions
diff --git a/app/controllers/projects/triggers_controller.rb b/app/controllers/projects/triggers_controller.rb
index 224a25eec99..b2c11ea4156 100644
--- a/app/controllers/projects/triggers_controller.rb
+++ b/app/controllers/projects/triggers_controller.rb
@@ -12,11 +12,11 @@ class Projects::TriggersController < Projects::ApplicationController
@trigger.save
if @trigger.valid?
- flash[:notice] = "Trigger has been created successfully"
+ redirect_to namespace_project_variables_path(project.namespace, project), notice: 'Trigger was created successfully.'
else
@triggers = project.triggers.select(&:persisted?)
+ render action: "show"
end
- redirect_to namespace_project_settings_ci_cd_path(@project.namespace, @project)
end
def destroy
diff --git a/app/controllers/projects/variables_controller.rb b/app/controllers/projects/variables_controller.rb
index d07ef7889ca..2ebd8ccee70 100644
--- a/app/controllers/projects/variables_controller.rb
+++ b/app/controllers/projects/variables_controller.rb
@@ -15,11 +15,10 @@ class Projects::VariablesController < Projects::ApplicationController
@variable = @project.variables.find(params[:id])
if @variable.update_attributes(project_params)
- flash[:notice] = 'Variables were successfully updated.'
+ redirect_to namespace_project_variables_path(project.namespace, project), notice: 'Variable was successfully updated.'
else
- flash[:alert] = @variable.errors.full_messages.join(',').html_safe
+ render action: "show"
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 9914e217d70..228cb513554 100644
--- a/spec/controllers/projects/variables_controller_spec.rb
+++ b/spec/controllers/projects/variables_controller_spec.rb
@@ -14,6 +14,7 @@ describe Projects::VariablesController do
it 'shows a success flash message' do
post :create, namespace_id: project.namespace.to_param, project_id: project.to_param,
variable: { key: "one", 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
@@ -23,6 +24,7 @@ describe Projects::VariablesController 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 \'_\'.'
expect(response).to redirect_to(namespace_project_settings_ci_cd_path(project.namespace, project))
end
@@ -40,16 +42,18 @@ describe Projects::VariablesController do
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))
+ 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))
end
- it 'shows an alert flash message' do
+ it 'renders the action #show if the variable key is invalid' 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))
+ id: variable.id, variable: { key: '?', value: variable.value }
+
+ expect(response).to have_http_status(200)
+ expect(response).to render_template :show
end
end
end