Commit 9176570d13e730329cae5c5f11db8c0bc29ab6d7

Authored by Diego Camarinha
Committed by Rafael Manzo
1 parent b787b495

WIP: Working on Project's acceptance tests.

Also refactored Project's factory

Signed off by: Daniel Alves <danpaulalves@gmail.com>
Gemfile.lock
1 1 GIT
2 2 remote: https://github.com/mezuro/kalibro_client
3   - revision: a4315323d18e70eb7161c4bce93227c614fce295
  3 + revision: 6288c9bb83557f3ced7cc3cb20bc857c1a6166af
4 4 specs:
5 5 kalibro_client (0.0.1)
6 6 activesupport (>= 2.2.1)
... ...
app/controllers/projects_controller.rb
... ... @@ -84,7 +84,7 @@ class ProjectsController &lt; ApplicationController
84 84 format.json { render action: 'show', status: :created, location: @project }
85 85 else
86 86 format.html { render action: 'new' }
87   - format.json { render json: @project.errors, status: :unprocessable_entity }
  87 + format.json { render json: @project.kalibro_errors, status: :unprocessable_entity }
88 88 end
89 89 end
90 90 end
... ...
app/views/projects/show.html.erb
... ... @@ -46,7 +46,7 @@
46 46 <% @project_repositories.each do |repository| %>
47 47 <tr>
48 48 <td><%= repository.name %></td>
49   - <td><%= repository.type %></td>
  49 + <td><%= repository.scm_type %></td>
50 50 <td><%= repository.address %></td>
51 51 <td>
52 52 <% if project_owner? @project.id %>
... ...
app/views/repositories/_form.html.erb
... ... @@ -42,8 +42,8 @@
42 42  
43 43 <div class="form-row">
44 44 <div class="field-container">
45   - <%= f.label :type, class: 'control-label' %>
46   - <%= f.select( :type, @repository_types, class: 'tooltip-control' ) %>
  45 + <%= f.label :scm_type, class: 'control-label' %>
  46 + <%= f.select( :scm_type, @repository_types, class: 'tooltip-control' ) %>
47 47 </div>
48 48 <div class="help-container">
49 49 <p>
... ...
app/views/repositories/show.html.erb
... ... @@ -14,7 +14,7 @@
14 14  
15 15 <p>
16 16 <strong>Type:</strong>
17   - <%= @repository.type %>
  17 + <%= @repository.scm_type %>
18 18 </p>
19 19  
20 20 <p>
... ...
app/views/shared/_form_errors.html.erb
1   -<% if object.errors.any? %>
  1 +<% if object.kalibro_errors.any? %>
2 2 <div id="error_explanation">
3   - <h2><%= pluralize(object.errors.count, "error") %> prohibited this <%= object.class.to_s %> from being saved:</h2>
  3 + <h2><%= pluralize(object.kalibro_errors.count, "error") %> prohibited this <%= object.class.to_s %> from being saved:</h2>
4 4  
5 5 <ul>
6   - <% object.errors.full_messages.each do |msg| %>
  6 + <% object.kalibro_errors.each do |msg| %>
7 7 <li><%= msg %></li>
8 8 <% end %>
9 9 </ul>
... ...
features/project/create.feature
... ... @@ -27,7 +27,7 @@ Feature: Project Creation
27 27 And I fill the Name field with "Kalibro"
28 28 And I fill the Description field with "Web Service to collect metrics"
29 29 When I press the Save button
30   - Then I should see "Name There is already a Project with name Kalibro!"
  30 + Then I should see "Name has already been taken"
31 31  
32 32 Scenario: project creation with blank name
33 33 Given I am a regular user
... ...
features/project/edition.feature
... ... @@ -64,7 +64,7 @@ Feature: Project
64 64 And I have a sample project_image
65 65 And I fill the Name field with "Qt-Calculator"
66 66 When I press the Save button
67   - Then I should see "Name There is already a Project with name Qt-Calculator!"
  67 + Then I should see "Name has already been taken"
68 68  
69 69 @kalibro_processor_restart
70 70 Scenario: Editing just the description
... ...
features/step_definitions/project_steps.rb
... ... @@ -5,7 +5,7 @@ Given(/^I am at the All Projects page$/) do
5 5 end
6 6  
7 7 Given(/^I have a sample project$/) do
8   - @project = FactoryGirl.create(:project, {id: nil})
  8 + @project = FactoryGirl.create(:project)
9 9 end
10 10  
11 11 Given(/^I have a sample project_image$/) do
... ... @@ -13,16 +13,16 @@ Given(/^I have a sample project_image$/) do
13 13 end
14 14  
15 15 Given(/^I have a project named "(.*?)"$/) do |name|
16   - @project = FactoryGirl.create(:project, {id: nil, name: name})
  16 + @project = FactoryGirl.create(:project, {name: name})
17 17 end
18 18  
19 19 Given(/^I own a sample project$/) do
20   - @project = FactoryGirl.create(:project, {id: nil})
  20 + @project = FactoryGirl.create(:project)
21 21 FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @project.id})
22 22 end
23 23  
24 24 Given(/^I own a project named "(.*?)"$/) do |name|
25   - @project = FactoryGirl.create(:project, {id: nil, name: name})
  25 + @project = FactoryGirl.create(:project, {name: name})
26 26 FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @project.id})
27 27 end
28 28  
... ...
features/step_definitions/repository_steps.rb
... ... @@ -5,40 +5,35 @@ Given(/^I have a sample configuration with native metrics but without ranges$/)
5 5 metric_configuration = FactoryGirl.create(:metric_configuration,
6 6 {metric: FactoryGirl.build(:loc),
7 7 reading_group_id: reading_group.id,
8   - configuration_id: @kalibro_configuration.id,
9   - code: 'loc'})
  8 + kalibro_configuration_id: @kalibro_configuration.id})
10 9 end
11 10  
12 11 Given(/^I have a sample configuration with native metrics$/) do
13 12 reading_group = FactoryGirl.create(:reading_group)
14 13 reading = FactoryGirl.create(:reading, {reading_group_id: reading_group.id})
15 14  
16   - KalibroClient::Processor::MetricCollector.find('Analizo').supported_metrics.select { |x| not x.persisted? }.save
17   -
18   -
19 15 @kalibro_configuration = FactoryGirl.create(:kalibro_configuration)
20 16 metric_configuration = FactoryGirl.create(:metric_configuration,
21 17 {metric: FactoryGirl.build(:loc),
22 18 reading_group_id: reading_group.id,
23   - kalibro_configuration_id: @kalibro_configuration.id,
24   - code: 'loc'})
  19 + kalibro_configuration_id: @kalibro_configuration.id})
25 20 range = FactoryGirl.build(:kalibro_range, {reading_id: reading.id, beginning: '-INF', :end => 'INF', metric_configuration_id: metric_configuration.id})
26 21 range.save
27 22 end
28 23  
29 24 Given(/^I have a sample repository within the sample project$/) do
30 25 @repository = FactoryGirl.create(:repository, {project_id: @project.id,
31   - configuration_id: @kalibro_configuration.id, id: nil})
  26 + kalibro_configuration_id: @kalibro_configuration.id, id: nil})
32 27 end
33 28  
34 29 Given(/^I have a sample repository within the sample project named "(.+)"$/) do |name|
35 30 @repository = FactoryGirl.create(:repository, {project_id: @project.id,
36   - configuration_id: @kalibro_configuration.id, id: nil, name: name})
  31 + kalibro_configuration_id: @kalibro_configuration.id, id: nil, name: name})
37 32 end
38 33  
39 34 Given(/^I have a sample of an invalid repository within the sample project$/) do
40 35 @repository = FactoryGirl.create(:repository, {project_id: @project.id,
41   - configuration_id: @kalibro_configuration.id, id: nil, address: "https://invalidrepository.git"})
  36 + kalibro_configuration_id: @kalibro_configuration.id, id: nil, address: "https://invalidrepository.git"})
42 37 end
43 38  
44 39 Given(/^I start to process that repository$/) do
... ...
spec/controllers/concerns/ownership_authentication_spec.rb
... ... @@ -81,7 +81,7 @@ describe OwnershipAuthentication, type: :controller do
81 81 end
82 82  
83 83 describe 'project_owner?' do
84   - let(:project) { FactoryGirl.build(:project) }
  84 + let(:project) { FactoryGirl.build(:project_with_id) }
85 85  
86 86 context 'Not ProjectsController nor RepositoriesController' do
87 87 let!(:reading_group_controller) { ReadingGroupsController.new }
... ...
spec/controllers/projects_controller_spec.rb
... ... @@ -18,8 +18,8 @@ describe ProjectsController, :type =&gt; :controller do
18 18 end
19 19  
20 20 context 'with valid fields' do
21   - let(:project) { FactoryGirl.build(:project) }
22   - let(:subject_params) { Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers
  21 + let(:project) { FactoryGirl.build(:project_with_id) }
  22 + let(:subject_params) { project.to_hash }
23 23  
24 24 before :each do
25 25 Project.any_instance.expects(:save).returns(true)
... ... @@ -46,8 +46,8 @@ describe ProjectsController, :type =&gt; :controller do
46 46  
47 47 context 'with an invalid field' do
48 48 before :each do
49   - @subject = FactoryGirl.build(:project)
50   - @subject_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers
  49 + @subject = FactoryGirl.build(:project_with_id)
  50 + @subject_params = @subject.to_hash
51 51  
52 52 Project.expects(:new).at_least_once.with(@subject_params).returns(@subject)
53 53 Project.any_instance.expects(:save).returns(false)
... ... @@ -60,7 +60,7 @@ describe ProjectsController, :type =&gt; :controller do
60 60 end
61 61  
62 62 describe 'show' do
63   - let(:project) { FactoryGirl.build(:project) }
  63 + let(:project) { FactoryGirl.build(:project_with_id) }
64 64  
65 65 context 'when the project exists' do
66 66 let(:repository) { FactoryGirl.build(:repository) }
... ... @@ -85,7 +85,7 @@ describe ProjectsController, :type =&gt; :controller do
85 85  
86 86 describe 'destroy' do
87 87 before do
88   - @subject = FactoryGirl.build(:project)
  88 + @subject = FactoryGirl.build(:project_with_id)
89 89 end
90 90  
91 91 context 'with an User logged in' do
... ... @@ -141,7 +141,7 @@ describe ProjectsController, :type =&gt; :controller do
141 141  
142 142 describe 'index' do
143 143 before :each do
144   - @subject = FactoryGirl.build(:project)
  144 + @subject = FactoryGirl.build(:project_with_id)
145 145 Project.expects(:all).returns([@subject])
146 146 get :index
147 147 end
... ... @@ -151,7 +151,7 @@ describe ProjectsController, :type =&gt; :controller do
151 151  
152 152 describe 'edit' do
153 153 before do
154   - @subject = FactoryGirl.build(:project)
  154 + @subject = FactoryGirl.build(:project_with_id)
155 155 @project_image = FactoryGirl.create(:project_image)
156 156 end
157 157  
... ... @@ -206,8 +206,8 @@ describe ProjectsController, :type =&gt; :controller do
206 206 describe 'update' do
207 207 before do
208 208 @project_image = FactoryGirl.build(:project_image)
209   - @subject = FactoryGirl.build(:project)
210   - @subject_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }]
  209 + @subject = FactoryGirl.build(:project_with_id)
  210 + @subject_params = @subject.to_hash
211 211 end
212 212  
213 213 context 'when the user is logged in' do
... ...
spec/controllers/repositories_controller_spec.rb
1 1 require 'rails_helper'
2 2  
3 3 describe RepositoriesController, :type => :controller do
4   - let(:project) { FactoryGirl.build(:project) }
  4 + let(:project) { FactoryGirl.build(:project_with_id) }
5 5  
6 6 describe 'new' do
7 7 context 'with an User logged in' do
... ...
spec/factories/project_images.rb
... ... @@ -3,7 +3,7 @@
3 3 FactoryGirl.define do
4 4 factory :project_image do
5 5 project_id 1
6   - url "Example"
  6 + url "logo.png"
7 7 end
8 8  
9 9 factory :project_no_image, class: ProjectImage do
... ...
spec/factories/projects.rb
... ... @@ -2,9 +2,14 @@
2 2  
3 3 FactoryGirl.define do
4 4 factory :project do
5   - id 1
6 5 name "QT Calculator"
7 6 description "A simple calculator for us."
  7 +
  8 + trait :with_id do
  9 + id 1
  10 + end
  11 +
  12 + factory :project_with_id, traits: [:with_id]
8 13 end
9 14  
10 15 factory :another_project, class: Project do
... ...
spec/helpers/projects_helper_spec.rb
... ... @@ -4,7 +4,7 @@ describe ProjectsHelper, :type =&gt; :helper do
4 4  
5 5 describe 'project_owner?' do
6 6 before :each do
7   - @subject = FactoryGirl.build(:project)
  7 + @subject = FactoryGirl.build(:project_with_id)
8 8 end
9 9  
10 10 context 'returns false if not logged in' do
... ...
spec/models/project_ownership_spec.rb
... ... @@ -8,7 +8,7 @@ describe ProjectOwnership, :type =&gt; :model do
8 8 describe 'methods' do
9 9 describe 'project' do
10 10 subject {FactoryGirl.build(:project_ownership)}
11   - let(:project) {FactoryGirl.build(:project)}
  11 + let(:project) {FactoryGirl.build(:project_with_id)}
12 12  
13 13 before :each do
14 14 Project.expects(:find).with(subject.project_id).returns(project)
... ...
spec/models/project_spec.rb
... ... @@ -4,7 +4,7 @@ describe Project, :type =&gt; :model do
4 4 describe 'methods' do
5 5 describe 'latest' do
6 6 before :each do
7   - @qt = FactoryGirl.build(:project)
  7 + @qt = FactoryGirl.build(:project_with_id)
8 8 @kalibro = FactoryGirl.build(:another_project)
9 9  
10 10 Project.expects(:all).returns([@qt, @kalibro])
... ...
spec/models/user_spec.rb
... ... @@ -18,7 +18,7 @@ describe User, :type =&gt; :model do
18 18 describe 'methods' do
19 19 describe 'projects' do
20 20 subject { FactoryGirl.build(:user) }
21   - let(:project) {FactoryGirl.build(:project)}
  21 + let(:project) {FactoryGirl.build(:project_with_id)}
22 22 let(:project_ownership) {FactoryGirl.build(:project_ownership)}
23 23  
24 24 before :each do
... ...