Commit 9176570d13e730329cae5c5f11db8c0bc29ab6d7
Committed by
Rafael Manzo
1 parent
b787b495
Exists in
colab
and in
4 other branches
WIP: Working on Project's acceptance tests.
Also refactored Project's factory Signed off by: Daniel Alves <danpaulalves@gmail.com>
Showing
19 changed files
with
43 additions
and
43 deletions
Show diff stats
Gemfile.lock
1 | GIT | 1 | GIT |
2 | remote: https://github.com/mezuro/kalibro_client | 2 | remote: https://github.com/mezuro/kalibro_client |
3 | - revision: a4315323d18e70eb7161c4bce93227c614fce295 | 3 | + revision: 6288c9bb83557f3ced7cc3cb20bc857c1a6166af |
4 | specs: | 4 | specs: |
5 | kalibro_client (0.0.1) | 5 | kalibro_client (0.0.1) |
6 | activesupport (>= 2.2.1) | 6 | activesupport (>= 2.2.1) |
app/controllers/projects_controller.rb
@@ -84,7 +84,7 @@ class ProjectsController < ApplicationController | @@ -84,7 +84,7 @@ class ProjectsController < ApplicationController | ||
84 | format.json { render action: 'show', status: :created, location: @project } | 84 | format.json { render action: 'show', status: :created, location: @project } |
85 | else | 85 | else |
86 | format.html { render action: 'new' } | 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 | end | 88 | end |
89 | end | 89 | end |
90 | end | 90 | end |
app/views/projects/show.html.erb
@@ -46,7 +46,7 @@ | @@ -46,7 +46,7 @@ | ||
46 | <% @project_repositories.each do |repository| %> | 46 | <% @project_repositories.each do |repository| %> |
47 | <tr> | 47 | <tr> |
48 | <td><%= repository.name %></td> | 48 | <td><%= repository.name %></td> |
49 | - <td><%= repository.type %></td> | 49 | + <td><%= repository.scm_type %></td> |
50 | <td><%= repository.address %></td> | 50 | <td><%= repository.address %></td> |
51 | <td> | 51 | <td> |
52 | <% if project_owner? @project.id %> | 52 | <% if project_owner? @project.id %> |
app/views/repositories/_form.html.erb
@@ -42,8 +42,8 @@ | @@ -42,8 +42,8 @@ | ||
42 | 42 | ||
43 | <div class="form-row"> | 43 | <div class="form-row"> |
44 | <div class="field-container"> | 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 | </div> | 47 | </div> |
48 | <div class="help-container"> | 48 | <div class="help-container"> |
49 | <p> | 49 | <p> |
app/views/repositories/show.html.erb
app/views/shared/_form_errors.html.erb
1 | -<% if object.errors.any? %> | 1 | +<% if object.kalibro_errors.any? %> |
2 | <div id="error_explanation"> | 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 | <ul> | 5 | <ul> |
6 | - <% object.errors.full_messages.each do |msg| %> | 6 | + <% object.kalibro_errors.each do |msg| %> |
7 | <li><%= msg %></li> | 7 | <li><%= msg %></li> |
8 | <% end %> | 8 | <% end %> |
9 | </ul> | 9 | </ul> |
features/project/create.feature
@@ -27,7 +27,7 @@ Feature: Project Creation | @@ -27,7 +27,7 @@ Feature: Project Creation | ||
27 | And I fill the Name field with "Kalibro" | 27 | And I fill the Name field with "Kalibro" |
28 | And I fill the Description field with "Web Service to collect metrics" | 28 | And I fill the Description field with "Web Service to collect metrics" |
29 | When I press the Save button | 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 | Scenario: project creation with blank name | 32 | Scenario: project creation with blank name |
33 | Given I am a regular user | 33 | Given I am a regular user |
features/project/edition.feature
@@ -64,7 +64,7 @@ Feature: Project | @@ -64,7 +64,7 @@ Feature: Project | ||
64 | And I have a sample project_image | 64 | And I have a sample project_image |
65 | And I fill the Name field with "Qt-Calculator" | 65 | And I fill the Name field with "Qt-Calculator" |
66 | When I press the Save button | 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 | @kalibro_processor_restart | 69 | @kalibro_processor_restart |
70 | Scenario: Editing just the description | 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,7 +5,7 @@ Given(/^I am at the All Projects page$/) do | ||
5 | end | 5 | end |
6 | 6 | ||
7 | Given(/^I have a sample project$/) do | 7 | Given(/^I have a sample project$/) do |
8 | - @project = FactoryGirl.create(:project, {id: nil}) | 8 | + @project = FactoryGirl.create(:project) |
9 | end | 9 | end |
10 | 10 | ||
11 | Given(/^I have a sample project_image$/) do | 11 | Given(/^I have a sample project_image$/) do |
@@ -13,16 +13,16 @@ Given(/^I have a sample project_image$/) do | @@ -13,16 +13,16 @@ Given(/^I have a sample project_image$/) do | ||
13 | end | 13 | end |
14 | 14 | ||
15 | Given(/^I have a project named "(.*?)"$/) do |name| | 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 | end | 17 | end |
18 | 18 | ||
19 | Given(/^I own a sample project$/) do | 19 | Given(/^I own a sample project$/) do |
20 | - @project = FactoryGirl.create(:project, {id: nil}) | 20 | + @project = FactoryGirl.create(:project) |
21 | FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @project.id}) | 21 | FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @project.id}) |
22 | end | 22 | end |
23 | 23 | ||
24 | Given(/^I own a project named "(.*?)"$/) do |name| | 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 | FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @project.id}) | 26 | FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @project.id}) |
27 | end | 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,40 +5,35 @@ Given(/^I have a sample configuration with native metrics but without ranges$/) | ||
5 | metric_configuration = FactoryGirl.create(:metric_configuration, | 5 | metric_configuration = FactoryGirl.create(:metric_configuration, |
6 | {metric: FactoryGirl.build(:loc), | 6 | {metric: FactoryGirl.build(:loc), |
7 | reading_group_id: reading_group.id, | 7 | reading_group_id: reading_group.id, |
8 | - configuration_id: @kalibro_configuration.id, | ||
9 | - code: 'loc'}) | 8 | + kalibro_configuration_id: @kalibro_configuration.id}) |
10 | end | 9 | end |
11 | 10 | ||
12 | Given(/^I have a sample configuration with native metrics$/) do | 11 | Given(/^I have a sample configuration with native metrics$/) do |
13 | reading_group = FactoryGirl.create(:reading_group) | 12 | reading_group = FactoryGirl.create(:reading_group) |
14 | reading = FactoryGirl.create(:reading, {reading_group_id: reading_group.id}) | 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 | @kalibro_configuration = FactoryGirl.create(:kalibro_configuration) | 15 | @kalibro_configuration = FactoryGirl.create(:kalibro_configuration) |
20 | metric_configuration = FactoryGirl.create(:metric_configuration, | 16 | metric_configuration = FactoryGirl.create(:metric_configuration, |
21 | {metric: FactoryGirl.build(:loc), | 17 | {metric: FactoryGirl.build(:loc), |
22 | reading_group_id: reading_group.id, | 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 | range = FactoryGirl.build(:kalibro_range, {reading_id: reading.id, beginning: '-INF', :end => 'INF', metric_configuration_id: metric_configuration.id}) | 20 | range = FactoryGirl.build(:kalibro_range, {reading_id: reading.id, beginning: '-INF', :end => 'INF', metric_configuration_id: metric_configuration.id}) |
26 | range.save | 21 | range.save |
27 | end | 22 | end |
28 | 23 | ||
29 | Given(/^I have a sample repository within the sample project$/) do | 24 | Given(/^I have a sample repository within the sample project$/) do |
30 | @repository = FactoryGirl.create(:repository, {project_id: @project.id, | 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 | end | 27 | end |
33 | 28 | ||
34 | Given(/^I have a sample repository within the sample project named "(.+)"$/) do |name| | 29 | Given(/^I have a sample repository within the sample project named "(.+)"$/) do |name| |
35 | @repository = FactoryGirl.create(:repository, {project_id: @project.id, | 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 | end | 32 | end |
38 | 33 | ||
39 | Given(/^I have a sample of an invalid repository within the sample project$/) do | 34 | Given(/^I have a sample of an invalid repository within the sample project$/) do |
40 | @repository = FactoryGirl.create(:repository, {project_id: @project.id, | 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 | end | 37 | end |
43 | 38 | ||
44 | Given(/^I start to process that repository$/) do | 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,7 +81,7 @@ describe OwnershipAuthentication, type: :controller do | ||
81 | end | 81 | end |
82 | 82 | ||
83 | describe 'project_owner?' do | 83 | describe 'project_owner?' do |
84 | - let(:project) { FactoryGirl.build(:project) } | 84 | + let(:project) { FactoryGirl.build(:project_with_id) } |
85 | 85 | ||
86 | context 'Not ProjectsController nor RepositoriesController' do | 86 | context 'Not ProjectsController nor RepositoriesController' do |
87 | let!(:reading_group_controller) { ReadingGroupsController.new } | 87 | let!(:reading_group_controller) { ReadingGroupsController.new } |
spec/controllers/projects_controller_spec.rb
@@ -18,8 +18,8 @@ describe ProjectsController, :type => :controller do | @@ -18,8 +18,8 @@ describe ProjectsController, :type => :controller do | ||
18 | end | 18 | end |
19 | 19 | ||
20 | context 'with valid fields' do | 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 | before :each do | 24 | before :each do |
25 | Project.any_instance.expects(:save).returns(true) | 25 | Project.any_instance.expects(:save).returns(true) |
@@ -46,8 +46,8 @@ describe ProjectsController, :type => :controller do | @@ -46,8 +46,8 @@ describe ProjectsController, :type => :controller do | ||
46 | 46 | ||
47 | context 'with an invalid field' do | 47 | context 'with an invalid field' do |
48 | before :each do | 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 | Project.expects(:new).at_least_once.with(@subject_params).returns(@subject) | 52 | Project.expects(:new).at_least_once.with(@subject_params).returns(@subject) |
53 | Project.any_instance.expects(:save).returns(false) | 53 | Project.any_instance.expects(:save).returns(false) |
@@ -60,7 +60,7 @@ describe ProjectsController, :type => :controller do | @@ -60,7 +60,7 @@ describe ProjectsController, :type => :controller do | ||
60 | end | 60 | end |
61 | 61 | ||
62 | describe 'show' do | 62 | describe 'show' do |
63 | - let(:project) { FactoryGirl.build(:project) } | 63 | + let(:project) { FactoryGirl.build(:project_with_id) } |
64 | 64 | ||
65 | context 'when the project exists' do | 65 | context 'when the project exists' do |
66 | let(:repository) { FactoryGirl.build(:repository) } | 66 | let(:repository) { FactoryGirl.build(:repository) } |
@@ -85,7 +85,7 @@ describe ProjectsController, :type => :controller do | @@ -85,7 +85,7 @@ describe ProjectsController, :type => :controller do | ||
85 | 85 | ||
86 | describe 'destroy' do | 86 | describe 'destroy' do |
87 | before do | 87 | before do |
88 | - @subject = FactoryGirl.build(:project) | 88 | + @subject = FactoryGirl.build(:project_with_id) |
89 | end | 89 | end |
90 | 90 | ||
91 | context 'with an User logged in' do | 91 | context 'with an User logged in' do |
@@ -141,7 +141,7 @@ describe ProjectsController, :type => :controller do | @@ -141,7 +141,7 @@ describe ProjectsController, :type => :controller do | ||
141 | 141 | ||
142 | describe 'index' do | 142 | describe 'index' do |
143 | before :each do | 143 | before :each do |
144 | - @subject = FactoryGirl.build(:project) | 144 | + @subject = FactoryGirl.build(:project_with_id) |
145 | Project.expects(:all).returns([@subject]) | 145 | Project.expects(:all).returns([@subject]) |
146 | get :index | 146 | get :index |
147 | end | 147 | end |
@@ -151,7 +151,7 @@ describe ProjectsController, :type => :controller do | @@ -151,7 +151,7 @@ describe ProjectsController, :type => :controller do | ||
151 | 151 | ||
152 | describe 'edit' do | 152 | describe 'edit' do |
153 | before do | 153 | before do |
154 | - @subject = FactoryGirl.build(:project) | 154 | + @subject = FactoryGirl.build(:project_with_id) |
155 | @project_image = FactoryGirl.create(:project_image) | 155 | @project_image = FactoryGirl.create(:project_image) |
156 | end | 156 | end |
157 | 157 | ||
@@ -206,8 +206,8 @@ describe ProjectsController, :type => :controller do | @@ -206,8 +206,8 @@ describe ProjectsController, :type => :controller do | ||
206 | describe 'update' do | 206 | describe 'update' do |
207 | before do | 207 | before do |
208 | @project_image = FactoryGirl.build(:project_image) | 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 | end | 211 | end |
212 | 212 | ||
213 | context 'when the user is logged in' do | 213 | context 'when the user is logged in' do |
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 | - let(:project) { FactoryGirl.build(:project) } | 4 | + let(:project) { FactoryGirl.build(:project_with_id) } |
5 | 5 | ||
6 | describe 'new' do | 6 | describe 'new' do |
7 | context 'with an User logged in' do | 7 | context 'with an User logged in' do |
spec/factories/project_images.rb
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | FactoryGirl.define do | 3 | FactoryGirl.define do |
4 | factory :project_image do | 4 | factory :project_image do |
5 | project_id 1 | 5 | project_id 1 |
6 | - url "Example" | 6 | + url "logo.png" |
7 | end | 7 | end |
8 | 8 | ||
9 | factory :project_no_image, class: ProjectImage do | 9 | factory :project_no_image, class: ProjectImage do |
spec/factories/projects.rb
@@ -2,9 +2,14 @@ | @@ -2,9 +2,14 @@ | ||
2 | 2 | ||
3 | FactoryGirl.define do | 3 | FactoryGirl.define do |
4 | factory :project do | 4 | factory :project do |
5 | - id 1 | ||
6 | name "QT Calculator" | 5 | name "QT Calculator" |
7 | description "A simple calculator for us." | 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 | end | 13 | end |
9 | 14 | ||
10 | factory :another_project, class: Project do | 15 | factory :another_project, class: Project do |
spec/helpers/projects_helper_spec.rb
@@ -4,7 +4,7 @@ describe ProjectsHelper, :type => :helper do | @@ -4,7 +4,7 @@ describe ProjectsHelper, :type => :helper do | ||
4 | 4 | ||
5 | describe 'project_owner?' do | 5 | describe 'project_owner?' do |
6 | before :each do | 6 | before :each do |
7 | - @subject = FactoryGirl.build(:project) | 7 | + @subject = FactoryGirl.build(:project_with_id) |
8 | end | 8 | end |
9 | 9 | ||
10 | context 'returns false if not logged in' do | 10 | context 'returns false if not logged in' do |
spec/models/project_ownership_spec.rb
@@ -8,7 +8,7 @@ describe ProjectOwnership, :type => :model do | @@ -8,7 +8,7 @@ describe ProjectOwnership, :type => :model do | ||
8 | describe 'methods' do | 8 | describe 'methods' do |
9 | describe 'project' do | 9 | describe 'project' do |
10 | subject {FactoryGirl.build(:project_ownership)} | 10 | subject {FactoryGirl.build(:project_ownership)} |
11 | - let(:project) {FactoryGirl.build(:project)} | 11 | + let(:project) {FactoryGirl.build(:project_with_id)} |
12 | 12 | ||
13 | before :each do | 13 | before :each do |
14 | Project.expects(:find).with(subject.project_id).returns(project) | 14 | Project.expects(:find).with(subject.project_id).returns(project) |
spec/models/project_spec.rb
@@ -4,7 +4,7 @@ describe Project, :type => :model do | @@ -4,7 +4,7 @@ describe Project, :type => :model do | ||
4 | describe 'methods' do | 4 | describe 'methods' do |
5 | describe 'latest' do | 5 | describe 'latest' do |
6 | before :each do | 6 | before :each do |
7 | - @qt = FactoryGirl.build(:project) | 7 | + @qt = FactoryGirl.build(:project_with_id) |
8 | @kalibro = FactoryGirl.build(:another_project) | 8 | @kalibro = FactoryGirl.build(:another_project) |
9 | 9 | ||
10 | Project.expects(:all).returns([@qt, @kalibro]) | 10 | Project.expects(:all).returns([@qt, @kalibro]) |
spec/models/user_spec.rb
@@ -18,7 +18,7 @@ describe User, :type => :model do | @@ -18,7 +18,7 @@ describe User, :type => :model do | ||
18 | describe 'methods' do | 18 | describe 'methods' do |
19 | describe 'projects' do | 19 | describe 'projects' do |
20 | subject { FactoryGirl.build(:user) } | 20 | subject { FactoryGirl.build(:user) } |
21 | - let(:project) {FactoryGirl.build(:project)} | 21 | + let(:project) {FactoryGirl.build(:project_with_id)} |
22 | let(:project_ownership) {FactoryGirl.build(:project_ownership)} | 22 | let(:project_ownership) {FactoryGirl.build(:project_ownership)} |
23 | 23 | ||
24 | before :each do | 24 | before :each do |