Commit c30eef935f284f8a5e4ab34cf2c5df0543ebf662

Authored by Rafael Manzo
1 parent 2fd4e490

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 5 before_action :project_owner?, only: [:new, :create]
6 6 before_action :repository_owner?, only: [:edit, :update, :destroy, :process_repository]
7 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 10 # GET /projects/1/repositories/1
10 11 # GET /projects/1/repositories/1.json
... ... @@ -16,22 +17,11 @@ class RepositoriesController < ApplicationController
16 17  
17 18 # GET projects/1/repositories/new
18 19 def new
19   - @project_id = params[:project_id]
20 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 21 end
26 22  
27 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 26 # POST /projects/1/repositories
37 27 # POST /projects/1/repositories.json
... ... @@ -95,13 +85,17 @@ class RepositoriesController < ApplicationController
95 85 end
96 86  
97 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 89 @project_id = params[:project_id]
101 90 @repository_types = Repository.repository_types
102 91 @configurations = KalibroConfiguration.public_or_owned_by_user(current_user).map { |conf|
103 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 100 format.html { render action: destiny_action }
107 101 format.json { render json: @repository.errors, status: :unprocessable_entity }
... ...