Commit 6035730f503f5ade9ece01c42729984314b4cad6

Authored by Heitor
1 parent 48def916

Finished creation of a repository without a project

Fixed acceptance tests and removed project list selector from repository
form

Signed-off-by: Pedro Scocco <pedroscocco@gmail.com>
Signed off by: Diego Araújo <diegoamc90@gmail.com>
app/controllers/repositories_controller.rb
... ... @@ -30,11 +30,7 @@ class RepositoriesController &lt; ApplicationController
30 30 # POST /projects/1/repositories
31 31 # POST /projects/1/repositories.json
32 32 def create
33   - r_params = repository_params
34   - r_params.require(:project_id)
35   - r_params[:project_id] = nil if r_params[:project_id].to_i == 0
36   -
37   - @repository = Repository.new(r_params)
  33 + @repository = Repository.new(repository_params)
38 34 respond_to do |format|
39 35 create_and_redir(format)
40 36 end
... ... @@ -107,9 +103,6 @@ private
107 103 @configurations = KalibroConfiguration.public_or_owned_by_user(current_user).map { |conf|
108 104 [conf.name, conf.id]
109 105 }
110   - @projects = current_user.projects.map do |proj|
111   - [proj.name, proj.id]
112   - end if @project_id.nil?
113 106 end
114 107  
115 108 # Duplicated code on create and update actions extracted here
... ... @@ -135,6 +128,7 @@ private
135 128 def repository_params
136 129 params[:repository][:name].strip!
137 130 params[:repository][:address].strip!
  131 + params[:repository][:project_id] = params[:project_id] if params.key? :project_id
138 132 params[:repository]
139 133 end
140 134  
... ...
app/views/repositories/_form.html.erb
... ... @@ -101,24 +101,6 @@
101 101 </p>
102 102 </div>
103 103 </div>
104   -
105   - <div class="form-row">
106   - <div class="field-container">
107   - <%= f.label :project_id, Project.model_name.human, class: 'control-label' %>
108   - <%= f.select( :project_id, @projects, class: 'tooltip-control' ) %>
109   -
110   - <div class="form-inline">
111   - <%= f.check_box :project_id, {id: "no_project_checkbox", class: "checkbox"}, "0", nil %>
112   - <%= f.label "no_project" %>
113   - </div>
114   - </div>
115   - <div class="help-container">
116   - <p>
117   - <%= t('activemodel.hints.repository.project').html_safe %>
118   - </p>
119   - </div>
120   - </div>
121   -
122 104 </div>
123 105 </div>
124 106 <div class="row margin-left-none" style="margin-top: 20px">
... ...
features/repository/create.feature
... ... @@ -4,10 +4,11 @@ Feature: Repository Creation
4 4 I should be able to create repositories
5 5  
6 6 @kalibro_configuration_restart @kalibro_processor_restart @javascript
7   -Scenario: repository creation
  7 +Scenario: repository creation associated with a project
8 8 Given I am a regular user
9 9 And I am signed in
10 10 And I own a sample project
  11 + And I have sample project_attributes
11 12 And I have a sample configuration with native metrics
12 13 And I am at the New Repository page
13 14 And I fill the Name field with "Kalibro"
... ... @@ -23,6 +24,8 @@ Scenario: repository creation
23 24 And I set the select field "Configuration" as "Java"
24 25 When I press the Save button
25 26 Then I should see the saved repository's content
  27 + When I am at the Sample Project page
  28 + Then I should see the sample repository name
26 29  
27 30 @kalibro_configuration_restart @kalibro_processor_restart @javascript
28 31 Scenario: repository creation blank validations
... ... @@ -88,6 +91,5 @@ Scenario: Create repository without project
88 91 And I set the select field "Type" as "GIT"
89 92 And I set the select field "Process Period" as "1 day"
90 93 And I set the select field "Configuration" as "Java"
91   - And I set the select field "Project" as "No Project"
92 94 When I press the Save button
93 95 Then I should see the saved repository's content
... ...
spec/controllers/repositories_controller_spec.rb
... ... @@ -97,6 +97,9 @@ describe RepositoriesController, :type =&gt; :controller do
97 97  
98 98 it { is_expected.to redirect_to(repository_process_path(id: repository.id)) }
99 99 it { is_expected.to respond_with(:redirect) }
  100 + it "is expected to set the project_id" do
  101 + expect(assigns(:repository).project_id).to be > 0
  102 + end
100 103 end
101 104  
102 105 context 'with an invalid field' do
... ... @@ -134,6 +137,9 @@ describe RepositoriesController, :type =&gt; :controller do
134 137  
135 138 it { is_expected.to redirect_to(repository_process_path(id: repository.id)) }
136 139 it { is_expected.to respond_with(:redirect) }
  140 + it "is expected to not set the project_id" do
  141 + expect(assigns(:repository).project_id).to be_nil
  142 + end
137 143 end
138 144  
139 145 context 'with an invalid field' do
... ...
spec/factories/project_attributes.rb
1 1 FactoryGirl.define do
2 2 factory :project_attributes, :class => 'ProjectAttributes' do
3 3 project_id 1
4   - image_url "MyString"
  4 + image_url ''
5 5 user_id 1
6 6 hidden false
  7 +
  8 + trait :with_image do
  9 + image_url '#'
  10 + end
7 11 end
8 12 end
... ...
spec/helpers/projects_helper_spec.rb
... ... @@ -45,7 +45,7 @@ describe ProjectsHelper, :type =&gt; :helper do
45 45  
46 46 describe 'project_image_html' do
47 47 let(:project) { FactoryGirl.build(:project) }
48   - let(:project_attributes) { FactoryGirl.build(:project_attributes) }
  48 + let(:project_attributes) { FactoryGirl.build(:project_attributes, :with_image) }
49 49  
50 50 context 'when the project has an image' do
51 51 before :each do
... ...