Commit 8f1fe233298bb0be274df13df9c76e73b93540a8

Authored by Rafael Manzo
2 parents 3444faab 16d3a22e

Merge pull request #249 from mezuro/independent_repositories

Independent repositories
@@ -5,7 +5,7 @@ addons: @@ -5,7 +5,7 @@ addons:
5 postgresql: "9.3" 5 postgresql: "9.3"
6 6
7 before_script: 7 before_script:
8 - - git clone https://github.com/mezuro/kalibro_install.git -b v2.5 kalibro_install 8 + - git clone https://github.com/mezuro/kalibro_install.git -b v2.7 kalibro_install
9 - pushd kalibro_install 9 - pushd kalibro_install
10 # Remove bugged libzmq3 package, see https://github.com/travis-ci/travis-ci/issues/982 and https://github.com/travis-ci/travis-ci/issues/1715 for details 10 # Remove bugged libzmq3 package, see https://github.com/travis-ci/travis-ci/issues/982 and https://github.com/travis-ci/travis-ci/issues/1715 for details
11 - sudo apt-get remove libzmq3 11 - sudo apt-get remove libzmq3
@@ -31,7 +31,7 @@ gem 'jbuilder', '~> 2.0' @@ -31,7 +31,7 @@ gem 'jbuilder', '~> 2.0'
31 gem 'devise', '~> 3.5.1' 31 gem 'devise', '~> 3.5.1'
32 32
33 # Kalibro integration 33 # Kalibro integration
34 -gem 'kalibro_client', '~> 0.3.0' 34 +gem 'kalibro_client', '~> 0.4.0'
35 35
36 # PostgreSQL integration 36 # PostgreSQL integration
37 gem "pg", "~> 0.18.1" 37 gem "pg", "~> 0.18.1"
@@ -157,7 +157,7 @@ GEM @@ -157,7 +157,7 @@ GEM
157 jquery-ui-rails (5.0.5) 157 jquery-ui-rails (5.0.5)
158 railties (>= 3.2.16) 158 railties (>= 3.2.16)
159 json (1.8.3) 159 json (1.8.3)
160 - kalibro_client (0.3.0) 160 + kalibro_client (0.4.0)
161 activesupport (>= 2.2.1) 161 activesupport (>= 2.2.1)
162 faraday_middleware (~> 0.9.0) 162 faraday_middleware (~> 0.9.0)
163 konacha (3.5.1) 163 konacha (3.5.1)
@@ -353,7 +353,7 @@ DEPENDENCIES @@ -353,7 +353,7 @@ DEPENDENCIES
353 jbuilder (~> 2.0) 353 jbuilder (~> 2.0)
354 jquery-rails 354 jquery-rails
355 jquery-ui-rails (~> 5.0.0) 355 jquery-ui-rails (~> 5.0.0)
356 - kalibro_client (~> 0.3.0) 356 + kalibro_client (~> 0.4.0)
357 konacha 357 konacha
358 mocha 358 mocha
359 pg (~> 0.18.1) 359 pg (~> 0.18.1)
app/controllers/repositories_controller.rb
1 include OwnershipAuthentication 1 include OwnershipAuthentication
2 2
3 class RepositoriesController < ApplicationController 3 class RepositoriesController < ApplicationController
4 - before_action :authenticate_user!, except: [:show, :state, :state_with_date] 4 + before_action :authenticate_user!, except: [:show, :state, :state_with_date, :index]
5 before_action :project_owner?, only: [:new, :create], unless: Proc.new { params[:project_id].nil? } 5 before_action :project_owner?, only: [:new, :create], unless: Proc.new { params[:project_id].nil? }
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 before_action :set_project_id_repository_types_and_configurations, only: [:new, :edit]
9 9
  10 + def index
  11 + @repositories = Repository.all
  12 + end
  13 +
10 # GET /projects/1/repositories/1 14 # GET /projects/1/repositories/1
11 # GET /projects/1/repositories/1.json 15 # GET /projects/1/repositories/1.json
12 # GET /projects/1/repositories/1/modules/1 16 # GET /projects/1/repositories/1/modules/1
@@ -27,7 +31,6 @@ class RepositoriesController &lt; ApplicationController @@ -27,7 +31,6 @@ class RepositoriesController &lt; ApplicationController
27 # POST /projects/1/repositories.json 31 # POST /projects/1/repositories.json
28 def create 32 def create
29 @repository = Repository.new(repository_params) 33 @repository = Repository.new(repository_params)
30 - @repository.project_id = params[:project_id]  
31 respond_to do |format| 34 respond_to do |format|
32 create_and_redir(format) 35 create_and_redir(format)
33 end 36 end
@@ -125,6 +128,7 @@ private @@ -125,6 +128,7 @@ private
125 def repository_params 128 def repository_params
126 params[:repository][:name].strip! 129 params[:repository][:name].strip!
127 params[:repository][:address].strip! 130 params[:repository][:address].strip!
  131 + params[:repository][:project_id] = params[:project_id] if params.key? :project_id
128 params[:repository] 132 params[:repository]
129 end 133 end
130 134
app/helpers/repository_helper.rb
@@ -23,6 +23,11 @@ module RepositoryHelper @@ -23,6 +23,11 @@ module RepositoryHelper
23 end 23 end
24 24
25 def year_options 25 def year_options
  26 + # FIXME: this will not work some years from now
26 (2013..2020).to_a.map {|year| [year, year]} 27 (2013..2020).to_a.map {|year| [year, year]}
27 end 28 end
  29 +
  30 + def repository_owner? repository_id
  31 + user_signed_in? && !current_user.repository_attributes.find_by_repository_id(repository_id).nil?
  32 + end
28 end 33 end
app/views/layouts/application.html.erb
@@ -60,6 +60,7 @@ @@ -60,6 +60,7 @@
60 <ul class="nav navbar-nav"> 60 <ul class="nav navbar-nav">
61 <li><%= link_to t('home'), root_path %></li> 61 <li><%= link_to t('home'), root_path %></li>
62 <li><%= link_to Project.model_name.human, projects_path %></li> 62 <li><%= link_to Project.model_name.human, projects_path %></li>
  63 + <li><%= link_to Repository.model_name.human, repositories_path %></li>
63 <li><%= link_to KalibroConfiguration.model_name.human, kalibro_configurations_path %></li> 64 <li><%= link_to KalibroConfiguration.model_name.human, kalibro_configurations_path %></li>
64 <li><%= link_to ReadingGroup.model_name.human, reading_groups_path %></li> 65 <li><%= link_to ReadingGroup.model_name.human, reading_groups_path %></li>
65 </ul> 66 </ul>
app/views/repositories/_form.html.erb
@@ -101,7 +101,6 @@ @@ -101,7 +101,6 @@
101 </p> 101 </p>
102 </div> 102 </div>
103 </div> 103 </div>
104 -  
105 </div> 104 </div>
106 </div> 105 </div>
107 <div class="row margin-left-none" style="margin-top: 20px"> 106 <div class="row margin-left-none" style="margin-top: 20px">
@@ -111,8 +110,4 @@ @@ -111,8 +110,4 @@
111 110
112 <script type="text/javascript"> 111 <script type="text/javascript">
113 var _repository_branch = new Repository.Branch; 112 var _repository_branch = new Repository.Branch;
114 -  
115 - $(document).on('page:load ready', function() {  
116 - _repository_branch.toggle();  
117 - });  
118 </script> 113 </script>
app/views/repositories/index.html.erb 0 → 100644
@@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
  1 +<div class="page-header">
  2 + <h1><%= "#{Repository.model_name.human(count: 2)}" %></h1>
  3 +</div>
  4 +
  5 +<% if user_signed_in? %>
  6 + <p>
  7 + <%= link_to t_action(:create, Repository), new_repository_path, class: 'btn btn-primary' %>
  8 + </p>
  9 +<%else%>
  10 + <p class="alert alert-warning alert-dismissable">
  11 + <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
  12 + <%= t('unauthenticated', action: t_action(:create, Repository, count: 2).downcase) %>
  13 + </p>
  14 +<% end %>
  15 +
  16 +<%= render partial: 'shared/repository_list', locals: {repositories: @repositories} %>
app/views/repositories/new.html.erb
@@ -2,7 +2,13 @@ @@ -2,7 +2,13 @@
2 <h1><%= t_action(:new, Repository) %></h1> 2 <h1><%= t_action(:new, Repository) %></h1>
3 </div> 3 </div>
4 4
5 -<%= form_for(@repository, :url => project_repositories_url(@project_id)) do |f| %>  
6 - <%= render partial: 'form', locals: {f: f} %> 5 +<% unless @project_id.nil? %>
  6 + <%= form_for(@repository, :url => project_repositories_url(@project_id)) do |f| %>
  7 + <%= render partial: 'form', locals: {f: f} %>
  8 + <% end %>
  9 +<% else %>
  10 + <%= form_for(@repository, :url => repositories_url) do |f| %>
  11 + <%= render partial: 'form', locals: {f: f} %>
  12 + <% end %>
7 <% end %> 13 <% end %>
8 14
app/views/shared/_project_list.html.erb
1 <table class="table table-hover"> 1 <table class="table table-hover">
2 <thead> 2 <thead>
3 <tr> 3 <tr>
4 - <th>Name</th>  
5 - <th>Description</th> 4 + <th><%= Project.human_attribute_name('name') %></th>
  5 + <th><%= Project.human_attribute_name('description') %></th>
6 <th colspan="2"></th> 6 <th colspan="2"></th>
7 </tr> 7 </tr>
8 </thead> 8 </thead>
app/views/shared/_repository_list.html.erb 0 → 100644
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +<table class="table table-hover">
  2 + <thead>
  3 + <tr>
  4 + <th><%= Repository.human_attribute_name('name') %></th>
  5 + <th><%= Repository.human_attribute_name('description') %></th>
  6 + <th colspan="2"></th>
  7 + </tr>
  8 + </thead>
  9 +
  10 + <tbody>
  11 + <% repositories.each do |repository| %>
  12 + <tr>
  13 + <td><%= repository.name %></td>
  14 + <td><%= repository.description %></td>
  15 + <td><%= link_to t('show'), repository_path(repository.id), class: 'btn btn-info' %></td>
  16 + <td>
  17 + <% if repository_owner? repository.id %>
  18 + <%= link_to t('edit'), edit_repository_path(repository.id), class: 'btn btn-info' %>
  19 + <% end %>
  20 + </td>
  21 + </tr>
  22 + <% end %>
  23 + </tbody>
  24 +</table>
0 \ No newline at end of file 25 \ No newline at end of file
config/routes.rb
@@ -7,7 +7,7 @@ Rails.application.routes.draw do @@ -7,7 +7,7 @@ Rails.application.routes.draw do
7 resources :repositories, only: [:new, :create] 7 resources :repositories, only: [:new, :create]
8 end 8 end
9 9
10 - resources :repositories, except: [:update, :index] 10 + resources :repositories, except: [:update]
11 get '/repositories/:id/modules/:module_result_id' => 'repositories#show', as: :repository_module 11 get '/repositories/:id/modules/:module_result_id' => 'repositories#show', as: :repository_module
12 get '/repositories/:id/state' => 'repositories#state', as: :repository_state 12 get '/repositories/:id/state' => 'repositories#state', as: :repository_state
13 get '/repositories/:id/state_with_date' => 'repositories#state_with_date', as: :repository_state_with_date 13 get '/repositories/:id/state_with_date' => 'repositories#state_with_date', as: :repository_state_with_date
features/project/show.feature
@@ -24,6 +24,16 @@ Scenario: Should show the create repository link the project owner @@ -24,6 +24,16 @@ Scenario: Should show the create repository link the project owner
24 When I am at the Sample Project page 24 When I am at the Sample Project page
25 Then I should see "New Repository" 25 Then I should see "New Repository"
26 26
  27 +@kalibro_processor_restart @kalibro_configuration_restart
  28 +Scenario: Should not show the independent repositories for a project
  29 + Given I am a regular user
  30 + And I am signed in
  31 + And I own a sample project
  32 + And I have sample project_attributes
  33 + And I have a sample configuration
  34 + And I have a sample repository
  35 + When I am at the Sample Project page
  36 + Then I should see "There are no Repositories yet!"
27 37
28 @kalibro_processor_restart 38 @kalibro_processor_restart
29 Scenario: Considering the project has no repositories 39 Scenario: Considering the project has no repositories
features/repository/create.feature
@@ -4,10 +4,11 @@ Feature: Repository Creation @@ -4,10 +4,11 @@ Feature: Repository Creation
4 I should be able to create repositories 4 I should be able to create repositories
5 5
6 @kalibro_configuration_restart @kalibro_processor_restart @javascript 6 @kalibro_configuration_restart @kalibro_processor_restart @javascript
7 -Scenario: repository creation 7 +Scenario: repository creation associated with a project
8 Given I am a regular user 8 Given I am a regular user
9 And I am signed in 9 And I am signed in
10 And I own a sample project 10 And I own a sample project
  11 + And I have sample project_attributes
11 And I have a sample configuration with native metrics 12 And I have a sample configuration with native metrics
12 And I am at the New Repository page 13 And I am at the New Repository page
13 And I fill the Name field with "Kalibro" 14 And I fill the Name field with "Kalibro"
@@ -23,6 +24,8 @@ Scenario: repository creation @@ -23,6 +24,8 @@ Scenario: repository creation
23 And I set the select field "Configuration" as "Java" 24 And I set the select field "Configuration" as "Java"
24 When I press the Save button 25 When I press the Save button
25 Then I should see the saved repository's content 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 @kalibro_configuration_restart @kalibro_processor_restart @javascript 30 @kalibro_configuration_restart @kalibro_processor_restart @javascript
28 Scenario: repository creation blank validations 31 Scenario: repository creation blank validations
@@ -45,9 +48,8 @@ Scenario: repository creation blank validations @@ -45,9 +48,8 @@ Scenario: repository creation blank validations
45 Scenario: repository creation with name already taken 48 Scenario: repository creation with name already taken
46 Given I am a regular user 49 Given I am a regular user
47 And I am signed in 50 And I am signed in
48 - And I own a sample project  
49 And I have a sample configuration with native metrics 51 And I have a sample configuration with native metrics
50 - And I have a sample repository within the sample project named "KalibroEntities" 52 + And I have a sample repository named "KalibroEntities"
51 And I am at the New Repository page 53 And I am at the New Repository page
52 And I fill the Name field with "KalibroEntities" 54 And I fill the Name field with "KalibroEntities"
53 And I fill the Description field with "Description" 55 And I fill the Description field with "Description"
@@ -57,7 +59,7 @@ Scenario: repository creation with name already taken @@ -57,7 +59,7 @@ Scenario: repository creation with name already taken
57 And I set the select field "Process Period" as "1 day" 59 And I set the select field "Process Period" as "1 day"
58 And I set the select field "Configuration" as "Java" 60 And I set the select field "Configuration" as "Java"
59 When I press the Save button 61 When I press the Save button
60 - Then I should see "Name should be unique within project" 62 + Then I should see "Name has already been taken"
61 63
62 @kalibro_configuration_restart @kalibro_processor_restart @javascript 64 @kalibro_configuration_restart @kalibro_processor_restart @javascript
63 Scenario: Repository name with whitespaces 65 Scenario: Repository name with whitespaces
@@ -74,4 +76,19 @@ Scenario: Repository name with whitespaces @@ -74,4 +76,19 @@ Scenario: Repository name with whitespaces
74 And I set the select field "Process Period" as "1 day" 76 And I set the select field "Process Period" as "1 day"
75 And I set the select field "Configuration" as "Java" 77 And I set the select field "Configuration" as "Java"
76 When I press the Save button 78 When I press the Save button
77 - Then I should see "Name should be unique within project" 79 + Then I should see "Name has already been taken"
  80 +
  81 +@kalibro_configuration_restart @kalibro_processor_restart @javascript
  82 +Scenario: Create repository without project
  83 + Given I am a regular user
  84 + And I am signed in
  85 + And I have a sample configuration with native metrics
  86 + And I am at the New Repository page
  87 + And I fill the Name field with "Kalibro Client"
  88 + And I set the select field "License" as "ISC License (ISC)"
  89 + And I fill the Address field with "https://github.com/mezuro/kalibro_client.git"
  90 + And I set the select field "Type" as "GIT"
  91 + And I set the select field "Process Period" as "1 day"
  92 + And I set the select field "Configuration" as "Java"
  93 + When I press the Save button
  94 + Then I should see the saved repository's content
features/repository/edit.feature
@@ -54,4 +54,4 @@ Feature: Repository Edit @@ -54,4 +54,4 @@ Feature: Repository Edit
54 And I am at repository edit page 54 And I am at repository edit page
55 When I fill the Name field with "MedSquare" 55 When I fill the Name field with "MedSquare"
56 And I press the Save button 56 And I press the Save button
57 - Then I should see "Name should be unique within project" 57 + Then I should see "Name has already been taken"
features/repository/index.feature 0 → 100644
@@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
  1 +Feature: Repository listing
  2 + In order to interact with other repositories
  3 + As a regular user
  4 + I should have various listings
  5 +
  6 + Scenario: Listing repositories
  7 + Given I am at the homepage
  8 + When I click the Repository link
  9 + Then I should see "Repositories"
  10 + And I should see "Name"
  11 + And I should see "Description"
  12 + And I should see "You must be logged in to create repositories"
  13 +
  14 + @kalibro_processor_restart @kalibro_configuration_restart
  15 + Scenario: Should list the existing repositories
  16 + Given I am a regular user
  17 + And I am signed in
  18 + And I have a sample configuration
  19 + And I have a sample repository
  20 + And I have a sample project
  21 + And I have a sample repository within the sample project
  22 + And I am at the All Repositories page
  23 + Then the sample repository should be there
  24 + And the project repository should be there
  25 + And I should not see "You must be logged in to create new Repositories."
  26 +
  27 + @kalibro_processor_restart @kalibro_configuration_restart
  28 + Scenario: Should show the existing repository
  29 + Given I am a regular user
  30 + And I am signed in
  31 + And I have a sample configuration
  32 + And I have a sample repository
  33 + And I own that independent repository
  34 + And I am at the All Repositories page
  35 + When I click the Show link
  36 + Then the sample repository should be there
features/step_definitions/repository_steps.rb
@@ -38,6 +38,15 @@ Given(/^I have a sample repository within the sample project named &quot;(.+)&quot;$/) do @@ -38,6 +38,15 @@ Given(/^I have a sample repository within the sample project named &quot;(.+)&quot;$/) do
38 kalibro_configuration_id: @kalibro_configuration.id, id: nil, name: name}) 38 kalibro_configuration_id: @kalibro_configuration.id, id: nil, name: name})
39 end 39 end
40 40
  41 +Given(/^I have a sample repository named "(.+)"$/) do |name|
  42 + @repository = FactoryGirl.create(:repository,
  43 + project_id: nil,
  44 + kalibro_configuration_id: @kalibro_configuration.id,
  45 + id: nil,
  46 + name: name)
  47 +end
  48 +
  49 +
41 Given(/^I have a sample of an invalid repository within the sample project$/) do 50 Given(/^I have a sample of an invalid repository within the sample project$/) do
42 @repository = FactoryGirl.create(:repository, {project_id: @project.id, 51 @repository = FactoryGirl.create(:repository, {project_id: @project.id,
43 kalibro_configuration_id: @kalibro_configuration.id, id: nil, address: "https://invalidrepository.git"}) 52 kalibro_configuration_id: @kalibro_configuration.id, id: nil, address: "https://invalidrepository.git"})
@@ -66,7 +75,11 @@ Given(/^I wait up for a error processing$/) do @@ -66,7 +75,11 @@ Given(/^I wait up for a error processing$/) do
66 end 75 end
67 76
68 Given(/^I am at the New Repository page$/) do 77 Given(/^I am at the New Repository page$/) do
69 - visit new_project_repository_path(project_id: @project.id) 78 + if @project
  79 + visit new_project_repository_path(project_id: @project.id)
  80 + else
  81 + visit new_repository_path
  82 + end
70 end 83 end
71 84
72 Given(/^I am at repository edit page$/) do 85 Given(/^I am at repository edit page$/) do
@@ -93,6 +106,18 @@ Given(/^I own that repository$/) do @@ -93,6 +106,18 @@ Given(/^I own that repository$/) do
93 FactoryGirl.create(:repository_attributes, {repository_id: @repository.id, user_id: @user.id}) 106 FactoryGirl.create(:repository_attributes, {repository_id: @repository.id, user_id: @user.id})
94 end 107 end
95 108
  109 +Given(/^I own that independent repository$/) do
  110 + FactoryGirl.create(:repository_attributes, {repository_id: @independent_repository.id, user_id: @user.id})
  111 +end
  112 +
  113 +Given(/^I have a sample repository$/) do
  114 + @independent_repository = FactoryGirl.create(:ruby_repository, kalibro_configuration_id: @kalibro_configuration.id)
  115 +end
  116 +
  117 +Given(/^I am at the All Repositories page$/) do
  118 + visit repositories_path
  119 +end
  120 +
96 When(/^I click on the sample metric's name$/) do 121 When(/^I click on the sample metric's name$/) do
97 find_link(@metric_results.first.metric_configuration.metric.name).trigger('click') 122 find_link(@metric_results.first.metric_configuration.metric.name).trigger('click')
98 end 123 end
@@ -179,3 +204,14 @@ Then(/^&quot;(.*?)&quot; should be lesser than &quot;(.*?)&quot;$/) do |arg1, arg2| @@ -179,3 +204,14 @@ Then(/^&quot;(.*?)&quot; should be lesser than &quot;(.*?)&quot;$/) do |arg1, arg2|
179 v2 = eval "@#{arg2}" 204 v2 = eval "@#{arg2}"
180 expect(v1 < v2).to be_truthy 205 expect(v1 < v2).to be_truthy
181 end 206 end
  207 +
  208 +Then(/^the sample repository should be there$/) do
  209 + expect(page).to have_content(@independent_repository.name)
  210 + expect(page).to have_content(@independent_repository.description)
  211 +end
  212 +
  213 +Then(/^the project repository should be there$/) do
  214 + expect(page).to have_content(@repository.name)
  215 + expect(page).to have_content(@repository.description)
  216 +end
  217 +
spec/controllers/repositories_controller_spec.rb
1 require 'rails_helper' 1 require 'rails_helper'
2 2
3 describe RepositoriesController, :type => :controller do 3 describe RepositoriesController, :type => :controller do
  4 + describe 'index' do
  5 + let!(:repository) { FactoryGirl.build(:repository) }
  6 +
  7 + before :each do
  8 + Repository.expects(:all).returns([repository])
  9 + get :index
  10 + end
  11 +
  12 + it { is_expected.to render_template(:index) }
  13 + end
  14 +
4 describe 'new' do 15 describe 'new' do
5 context 'with a User logged in' do 16 context 'with a User logged in' do
6 let!(:user) { FactoryGirl.create(:user) } 17 let!(:user) { FactoryGirl.create(:user) }
@@ -86,6 +97,9 @@ describe RepositoriesController, :type =&gt; :controller do @@ -86,6 +97,9 @@ describe RepositoriesController, :type =&gt; :controller do
86 97
87 it { is_expected.to redirect_to(repository_process_path(id: repository.id)) } 98 it { is_expected.to redirect_to(repository_process_path(id: repository.id)) }
88 it { is_expected.to respond_with(:redirect) } 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
89 end 103 end
90 104
91 context 'with an invalid field' do 105 context 'with an invalid field' do
@@ -123,6 +137,9 @@ describe RepositoriesController, :type =&gt; :controller do @@ -123,6 +137,9 @@ describe RepositoriesController, :type =&gt; :controller do
123 137
124 it { is_expected.to redirect_to(repository_process_path(id: repository.id)) } 138 it { is_expected.to redirect_to(repository_process_path(id: repository.id)) }
125 it { is_expected.to respond_with(:redirect) } 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
126 end 143 end
127 144
128 context 'with an invalid field' do 145 context 'with an invalid field' do
spec/factories/project_attributes.rb
1 FactoryGirl.define do 1 FactoryGirl.define do
2 factory :project_attributes, :class => 'ProjectAttributes' do 2 factory :project_attributes, :class => 'ProjectAttributes' do
3 project_id 1 3 project_id 1
4 - image_url "MyString" 4 + image_url ''
5 user_id 1 5 user_id 1
6 hidden false 6 hidden false
  7 +
  8 + trait :with_image do
  9 + image_url '#'
  10 + end
7 end 11 end
8 end 12 end
spec/factories/repositories.rb
@@ -23,7 +23,6 @@ FactoryGirl.define do @@ -23,7 +23,6 @@ FactoryGirl.define do
23 scm_type "GIT" 23 scm_type "GIT"
24 address "https://github.com/rafamanzo/runge-kutta-vtk.git" 24 address "https://github.com/rafamanzo/runge-kutta-vtk.git"
25 kalibro_configuration_id 1 25 kalibro_configuration_id 1
26 - send_email "test@test.com"  
27 end 26 end
28 27
29 factory :ruby_repository, class: Repository do 28 factory :ruby_repository, class: Repository do
@@ -35,7 +34,6 @@ FactoryGirl.define do @@ -35,7 +34,6 @@ FactoryGirl.define do
35 scm_type "GIT" 34 scm_type "GIT"
36 address "https://github.com/mezuro/kalibro_processor.git" 35 address "https://github.com/mezuro/kalibro_processor.git"
37 kalibro_configuration_id 1 36 kalibro_configuration_id 1
38 - send_email "test@test.com"  
39 end 37 end
40 38
41 factory :another_repository, parent: :repository do 39 factory :another_repository, parent: :repository do
spec/helpers/projects_helper_spec.rb
@@ -45,7 +45,7 @@ describe ProjectsHelper, :type =&gt; :helper do @@ -45,7 +45,7 @@ describe ProjectsHelper, :type =&gt; :helper do
45 45
46 describe 'project_image_html' do 46 describe 'project_image_html' do
47 let(:project) { FactoryGirl.build(:project) } 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 context 'when the project has an image' do 50 context 'when the project has an image' do
51 before :each do 51 before :each do
spec/helpers/repository_helper_spec.rb
1 require 'rails_helper' 1 require 'rails_helper'
2 2
3 describe RepositoryHelper, :type => :helper do 3 describe RepositoryHelper, :type => :helper do
  4 + describe 'repository_owner?' do
  5 + subject { FactoryGirl.build(:repository) }
  6 +
  7 + context 'returns false if not logged in' do
  8 + before :each do
  9 + helper.expects(:user_signed_in?).returns(false)
  10 + end
  11 + it { expect(helper.repository_owner?(subject.id)).to be_falsey }
  12 + end
  13 +
  14 + context 'returns false if is not the owner' do
  15 + let!(:attributes) { [] }
  16 +
  17 + before :each do
  18 + helper.expects(:user_signed_in?).returns(true)
  19 + helper.expects(:current_user).returns(FactoryGirl.build(:user))
  20 +
  21 + attributes.expects(:find_by_repository_id).with(subject.id).returns(nil)
  22 +
  23 + User.any_instance.expects(:repository_attributes).returns(attributes)
  24 + end
  25 +
  26 + it { expect(helper.repository_owner?(subject.id)).to be_falsey }
  27 + end
  28 +
  29 + context 'returns true if user is the repository owner' do
  30 + let!(:repository_attributes) { FactoryGirl.build(:repository_attributes) }
  31 + let!(:attributes) { [] }
  32 +
  33 + before :each do
  34 + helper.expects(:user_signed_in?).returns(true)
  35 + helper.expects(:current_user).returns(FactoryGirl.build(:user))
  36 +
  37 + attributes.expects(:find_by_repository_id).with(subject.id).returns(repository_attributes)
  38 + User.any_instance.expects(:repository_attributes).returns(attributes)
  39 + end
  40 +
  41 + it { expect(helper.repository_owner?(subject.id)).to be_truthy }
  42 + end
  43 + end
4 44
5 describe 'periodicity_options' do 45 describe 'periodicity_options' do
6 it 'should return an array with some sample periods' do 46 it 'should return an array with some sample periods' do
spec/routing/repositories_routing_spec.rb
@@ -4,6 +4,8 @@ describe RepositoriesController, :type =&gt; :routing do @@ -4,6 +4,8 @@ describe RepositoriesController, :type =&gt; :routing do
4 describe "routing" do 4 describe "routing" do
5 it { is_expected.to route(:post, '/repositories'). 5 it { is_expected.to route(:post, '/repositories').
6 to(controller: :repositories, action: :create) } 6 to(controller: :repositories, action: :create) }
  7 + it { is_expected.to route(:get, '/repositories').
  8 + to(controller: :repositories, action: :index) }
7 it { is_expected.to route(:get, '/repositories/new'). 9 it { is_expected.to route(:get, '/repositories/new').
8 to(controller: :repositories, action: :new) } 10 to(controller: :repositories, action: :new) }
9 it { is_expected.to route(:get, '/repositories/1/edit'). 11 it { is_expected.to route(:get, '/repositories/1/edit').
@@ -16,8 +18,6 @@ describe RepositoriesController, :type =&gt; :routing do @@ -16,8 +18,6 @@ describe RepositoriesController, :type =&gt; :routing do
16 to(controller: :repositories, action: :destroy, id: 1) } 18 to(controller: :repositories, action: :destroy, id: 1) }
17 it { is_expected.to route(:put, '/repositories/1'). 19 it { is_expected.to route(:put, '/repositories/1').
18 to(controller: :repositories, action: :update, id: 1) } 20 to(controller: :repositories, action: :update, id: 1) }
19 - it { is_expected.not_to route(:get, '/repositories').  
20 - to(controller: :repositories, action: :index) }  
21 it { is_expected.to route(:get, '/repositories/1/state'). 21 it { is_expected.to route(:get, '/repositories/1/state').
22 to(controller: :repositories, action: :state, id: 1) } 22 to(controller: :repositories, action: :state, id: 1) }
23 it { is_expected.to route(:get, '/repositories/1/state_with_date'). 23 it { is_expected.to route(:get, '/repositories/1/state_with_date').