Commit c30eef935f284f8a5e4ab34cf2c5df0543ebf662
1 parent
2fd4e490
Exists in
colab
and in
4 other branches
Removes duplication from RepositoriesController
Showing
1 changed file
with
8 additions
and
14 deletions
Show diff stats
app/controllers/repositories_controller.rb
@@ -5,6 +5,7 @@ class RepositoriesController < ApplicationController | @@ -5,6 +5,7 @@ class RepositoriesController < ApplicationController | ||
5 | before_action :project_owner?, only: [:new, :create] | 5 | before_action :project_owner?, only: [:new, :create] |
6 | before_action :repository_owner?, only: [:edit, :update, :destroy, :process_repository] | 6 | before_action :repository_owner?, only: [:edit, :update, :destroy, :process_repository] |
7 | before_action :set_repository, only: [:show, :edit, :update, :destroy, :state, :state_with_date, :process_repository] | 7 | before_action :set_repository, only: [:show, :edit, :update, :destroy, :state, :state_with_date, :process_repository] |
8 | + before_action :set_project_id_repository_types_and_configurations, only: [:new, :edit] | ||
8 | 9 | ||
9 | # GET /projects/1/repositories/1 | 10 | # GET /projects/1/repositories/1 |
10 | # GET /projects/1/repositories/1.json | 11 | # GET /projects/1/repositories/1.json |
@@ -16,22 +17,11 @@ class RepositoriesController < ApplicationController | @@ -16,22 +17,11 @@ class RepositoriesController < ApplicationController | ||
16 | 17 | ||
17 | # GET projects/1/repositories/new | 18 | # GET projects/1/repositories/new |
18 | def new | 19 | def new |
19 | - @project_id = params[:project_id] | ||
20 | @repository = Repository.new | 20 | @repository = Repository.new |
21 | - @repository_types = Repository.repository_types | ||
22 | - @configurations = KalibroConfiguration.public_or_owned_by_user(current_user).map { |conf| | ||
23 | - [conf.name, conf.id] | ||
24 | - } | ||
25 | end | 21 | end |
26 | 22 | ||
27 | # GET /repositories/1/edit | 23 | # GET /repositories/1/edit |
28 | - def edit | ||
29 | - @project_id = params[:project_id] | ||
30 | - @repository_types = Repository.repository_types | ||
31 | - @configurations = KalibroConfiguration.public_or_owned_by_user(current_user).map { |conf| | ||
32 | - [conf.name, conf.id] | ||
33 | - } | ||
34 | - end | 24 | + def edit; end |
35 | 25 | ||
36 | # POST /projects/1/repositories | 26 | # POST /projects/1/repositories |
37 | # POST /projects/1/repositories.json | 27 | # POST /projects/1/repositories.json |
@@ -95,13 +85,17 @@ class RepositoriesController < ApplicationController | @@ -95,13 +85,17 @@ class RepositoriesController < ApplicationController | ||
95 | end | 85 | end |
96 | 86 | ||
97 | private | 87 | private |
98 | - # Duplicated code on create and update actions extracted here | ||
99 | - def failed_action(format, destiny_action) | 88 | + def set_project_id_repository_types_and_configurations |
100 | @project_id = params[:project_id] | 89 | @project_id = params[:project_id] |
101 | @repository_types = Repository.repository_types | 90 | @repository_types = Repository.repository_types |
102 | @configurations = KalibroConfiguration.public_or_owned_by_user(current_user).map { |conf| | 91 | @configurations = KalibroConfiguration.public_or_owned_by_user(current_user).map { |conf| |
103 | [conf.name, conf.id] | 92 | [conf.name, conf.id] |
104 | } | 93 | } |
94 | + end | ||
95 | + | ||
96 | + # Duplicated code on create and update actions extracted here | ||
97 | + def failed_action(format, destiny_action) | ||
98 | + set_project_id_repository_types_and_configurations | ||
105 | 99 | ||
106 | format.html { render action: destiny_action } | 100 | format.html { render action: destiny_action } |
107 | format.json { render json: @repository.errors, status: :unprocessable_entity } | 101 | format.json { render json: @repository.errors, status: :unprocessable_entity } |