Commit f9d8dc0f39c583ba16dc2b393e2f28e6f14dd0a9

Authored by Diego Camarinha
Committed by Rafael Manzo
1 parent b312147c

WIP: Fixing acceptance tests for reading creation

Signed off by: Daniel Alves <danpaulalves@gmail.com>
features/step_definitions/mezuro_range_steps.rb
1 Given(/^I have a sample range within the sample metric configuration with beginning "(.*?)"$/) do |beginning| 1 Given(/^I have a sample range within the sample metric configuration with beginning "(.*?)"$/) do |beginning|
2 - @mezuro_range = FactoryGirl.create(:mezuro_range, {beginning: beginning, metric_configuration_id: @metric_configuration.id, 2 + @mezuro_range = FactoryGirl.create(:mezuro_range, {beginning: beginning, metric_configuration_id: @metric_configuration.id,
3 reading_id: @reading.id, id: nil}) 3 reading_id: @reading.id, id: nil})
4 end 4 end
5 5
6 Given(/^I am at the Edit Mezuro Range page$/) do 6 Given(/^I am at the Edit Mezuro Range page$/) do
7 - visit edit_kalibro_configuration_metric_configuration_mezuro_range_path(@metric_configuration.configuration_id, @metric_configuration.id, @mezuro_range.id) 7 + visit edit_kalibro_configuration_metric_configuration_mezuro_range_path(@metric_configuration.kalibro_configuration_id, @metric_configuration.id, @mezuro_range.id)
8 end 8 end
9 9
10 Given(/^the select field "(.*?)" is set as "(.*?)"$/) do |field, text| 10 Given(/^the select field "(.*?)" is set as "(.*?)"$/) do |field, text|
@@ -12,17 +12,17 @@ Given(/^the select field &quot;(.*?)&quot; is set as &quot;(.*?)&quot;$/) do |field, text| @@ -12,17 +12,17 @@ Given(/^the select field &quot;(.*?)&quot; is set as &quot;(.*?)&quot;$/) do |field, text|
12 end 12 end
13 13
14 Given(/^I have a sample range within the sample metric configuration$/) do 14 Given(/^I have a sample range within the sample metric configuration$/) do
15 - @mezuro_range = FactoryGirl.create(:mezuro_range, {metric_configuration_id: @metric_configuration.id, 15 + @mezuro_range = FactoryGirl.create(:mezuro_range, {metric_configuration_id: @metric_configuration.id,
16 reading_id: @reading.id, id: nil}) 16 reading_id: @reading.id, id: nil})
17 end 17 end
18 18
19 Given(/^I have a sample range within the sample compound metric configuration$/) do 19 Given(/^I have a sample range within the sample compound metric configuration$/) do
20 - @mezuro_range = FactoryGirl.create(:mezuro_range, {metric_configuration_id: @compound_metric_configuration.id, 20 + @mezuro_range = FactoryGirl.create(:mezuro_range, {metric_configuration_id: @compound_metric_configuration.id,
21 reading_id: @reading.id, id: nil}) 21 reading_id: @reading.id, id: nil})
22 end 22 end
23 23
24 When(/^I am at the New Range page$/) do 24 When(/^I am at the New Range page$/) do
25 - visit kalibro_configuration_metric_configuration_new_mezuro_range_path(@metric_configuration.configuration_id, @metric_configuration.id) 25 + visit kalibro_configuration_metric_configuration_new_mezuro_range_path(@metric_configuration.kalibro_configuration_id, @metric_configuration.id)
26 end 26 end
27 27
28 Then(/^I should be at the New Range page$/) do 28 Then(/^I should be at the New Range page$/) do
features/step_definitions/reading_group_steps.rb
@@ -13,7 +13,7 @@ Given(/^I have a reading group named &quot;(.*?)&quot;$/) do |name| @@ -13,7 +13,7 @@ Given(/^I have a reading group named &quot;(.*?)&quot;$/) do |name|
13 end 13 end
14 14
15 Given(/^I have a sample reading within the sample reading group$/) do 15 Given(/^I have a sample reading within the sample reading group$/) do
16 - @reading = FactoryGirl.create(:reading, {group_id: @reading_group.id, id: nil}) 16 + @reading = FactoryGirl.create(:reading, {reading_group_id: @reading_group.id})
17 end 17 end
18 18
19 Given(/^I own a sample reading group$/) do 19 Given(/^I own a sample reading group$/) do
features/step_definitions/reading_steps.rb
1 Given(/^I have a sample reading within the module result$/) do 1 Given(/^I have a sample reading within the module result$/) do
2 - @reading = FactoryGirl.create(:reading, {group_id: @reading_group.id, id: nil}) 2 + @reading = FactoryGirl.create(:reading, {reading_group_id: @reading_group.id})
3 end 3 end
4 4
5 Given(/^I am at the New Reading page$/) do 5 Given(/^I am at the New Reading page$/) do
@@ -11,11 +11,11 @@ Given(/^I am at the Edit Reading page$/) do @@ -11,11 +11,11 @@ Given(/^I am at the Edit Reading page$/) do
11 end 11 end
12 12
13 Given(/^I have a sample reading within the sample reading group labeled "(.*?)"$/) do |label| 13 Given(/^I have a sample reading within the sample reading group labeled "(.*?)"$/) do |label|
14 - @reading = FactoryGirl.create(:reading, {label: label, group_id: @reading_group.id, id: nil}) 14 + @reading = FactoryGirl.create(:reading, {label: label, reading_group_id: @reading_group.id})
15 end 15 end
16 16
17 When(/^I click the "(.*?)" td$/) do |text| 17 When(/^I click the "(.*?)" td$/) do |text|
18 - p page.find('td', text: text).methods 18 + page.find('td', text: text).methods
19 end 19 end
20 20
21 When(/^I click on the center of the color picker$/) do 21 When(/^I click on the center of the color picker$/) do
features/step_definitions/repository_steps.rb
1 Given(/^I have a sample configuration with native metrics but without ranges$/) do 1 Given(/^I have a sample configuration with native metrics but without ranges$/) do
2 reading_group = FactoryGirl.create(:reading_group, id: nil) 2 reading_group = FactoryGirl.create(:reading_group, id: nil)
3 - reading = FactoryGirl.create(:reading, {id: nil, group_id: reading_group.id}) 3 + reading = FactoryGirl.create(:reading, {reading_group_id: reading_group.id})
4 @kalibro_configuration = FactoryGirl.create(:kalibro_configuration, id: nil) 4 @kalibro_configuration = FactoryGirl.create(:kalibro_configuration, id: nil)
5 metric_configuration = FactoryGirl.create(:metric_configuration, 5 metric_configuration = FactoryGirl.create(:metric_configuration,
6 {metric: FactoryGirl.build(:loc), 6 {metric: FactoryGirl.build(:loc),
@@ -11,7 +11,7 @@ end @@ -11,7 +11,7 @@ end
11 11
12 Given(/^I have a sample configuration with native metrics$/) do 12 Given(/^I have a sample configuration with native metrics$/) do
13 reading_group = FactoryGirl.create(:reading_group, id: nil) 13 reading_group = FactoryGirl.create(:reading_group, id: nil)
14 - reading = FactoryGirl.create(:reading, {id: nil, reading_group_id: reading_group.id}) 14 + reading = FactoryGirl.create(:reading, {reading_group_id: reading_group.id})
15 15
16 KalibroClient::Processor::MetricCollector.find('Analizo').supported_metrics.select { |x| not x.persisted? }.save 16 KalibroClient::Processor::MetricCollector.find('Analizo').supported_metrics.select { |x| not x.persisted? }.save
17 17
spec/controllers/mezuro_ranges_controller_spec.rb
@@ -111,7 +111,7 @@ describe MezuroRangesController, :type =&gt; :controller do @@ -111,7 +111,7 @@ describe MezuroRangesController, :type =&gt; :controller do
111 describe 'edit' do 111 describe 'edit' do
112 let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) } 112 let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
113 let(:mezuro_range) { FactoryGirl.build(:mezuro_range, id: 1, metric_configuration_id: metric_configuration.id) } 113 let(:mezuro_range) { FactoryGirl.build(:mezuro_range, id: 1, metric_configuration_id: metric_configuration.id) }
114 - let(:reading) { FactoryGirl.build(:reading, reading_group_id: metric_configuration.reading_group_id) } 114 + let(:reading) { FactoryGirl.build(:reading_with_id, reading_group_id: metric_configuration.reading_group_id) }
115 115
116 context 'with an User logged in' do 116 context 'with an User logged in' do
117 before do 117 before do
@@ -156,7 +156,7 @@ describe MezuroRangesController, :type =&gt; :controller do @@ -156,7 +156,7 @@ describe MezuroRangesController, :type =&gt; :controller do
156 let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) } 156 let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
157 let(:mezuro_range) { FactoryGirl.build(:mezuro_range, id: 1, metric_configuration_id: metric_configuration.id) } 157 let(:mezuro_range) { FactoryGirl.build(:mezuro_range, id: 1, metric_configuration_id: metric_configuration.id) }
158 let(:mezuro_range_params) { Hash[FactoryGirl.attributes_for(:mezuro_range).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 158 let(:mezuro_range_params) { Hash[FactoryGirl.attributes_for(:mezuro_range).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
159 - let(:reading) { FactoryGirl.build(:reading, reading_group_id: metric_configuration.reading_group_id) } 159 + let(:reading) { FactoryGirl.build(:reading_with_id, reading_group_id: metric_configuration.reading_group_id) }
160 160
161 context 'when the user is logged in' do 161 context 'when the user is logged in' do
162 before do 162 before do
spec/controllers/reading_groups_controller_spec.rb
@@ -60,7 +60,7 @@ describe ReadingGroupsController, :type =&gt; :controller do @@ -60,7 +60,7 @@ describe ReadingGroupsController, :type =&gt; :controller do
60 60
61 describe 'show' do 61 describe 'show' do
62 let!(:reading_group) { FactoryGirl.build(:reading_group) } 62 let!(:reading_group) { FactoryGirl.build(:reading_group) }
63 - let(:reading) { FactoryGirl.build(:reading) } 63 + let(:reading) { FactoryGirl.build(:reading_with_id) }
64 before :each do 64 before :each do
65 subject.expects(:find_resource).with(ReadingGroup, reading_group.id).returns(reading_group) 65 subject.expects(:find_resource).with(ReadingGroup, reading_group.id).returns(reading_group)
66 get :show, :id => reading_group.id 66 get :show, :id => reading_group.id
spec/controllers/readings_controller_spec.rb
@@ -29,8 +29,8 @@ describe ReadingsController, :type =&gt; :controller do @@ -29,8 +29,8 @@ describe ReadingsController, :type =&gt; :controller do
29 end 29 end
30 30
31 describe 'create' do 31 describe 'create' do
32 - let(:reading) { FactoryGirl.build(:reading) }  
33 - let(:reading_params) { Hash[FactoryGirl.attributes_for(:reading).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers 32 + let(:reading) { FactoryGirl.build(:reading_with_id) }
  33 + let(:reading_params) { reading.to_hash }
34 34
35 before do 35 before do
36 sign_in FactoryGirl.create(:user) 36 sign_in FactoryGirl.create(:user)
@@ -64,7 +64,7 @@ describe ReadingsController, :type =&gt; :controller do @@ -64,7 +64,7 @@ describe ReadingsController, :type =&gt; :controller do
64 end 64 end
65 65
66 describe 'edit' do 66 describe 'edit' do
67 - let(:reading) { FactoryGirl.build(:reading) } 67 + let(:reading) { FactoryGirl.build(:reading_with_id) }
68 68
69 context 'with an User logged in' do 69 context 'with an User logged in' do
70 before do 70 before do
@@ -102,8 +102,8 @@ describe ReadingsController, :type =&gt; :controller do @@ -102,8 +102,8 @@ describe ReadingsController, :type =&gt; :controller do
102 end 102 end
103 103
104 describe 'update' do 104 describe 'update' do
105 - let(:reading) { FactoryGirl.build(:reading, reading_group_id: reading_group.id) }  
106 - let(:reading_params) { Hash[FactoryGirl.attributes_for(:reading).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 105 + let(:reading) { FactoryGirl.build(:reading_with_id, reading_group_id: reading_group.id) }
  106 + let(:reading_params) { reading.to_hash }
107 107
108 context 'when the user is logged in' do 108 context 'when the user is logged in' do
109 before do 109 before do
@@ -158,7 +158,7 @@ describe ReadingsController, :type =&gt; :controller do @@ -158,7 +158,7 @@ describe ReadingsController, :type =&gt; :controller do
158 end 158 end
159 159
160 describe 'destroy' do 160 describe 'destroy' do
161 - let(:reading) { FactoryGirl.build(:reading) } 161 + let(:reading) { FactoryGirl.build(:reading_with_id) }
162 162
163 context 'with an User logged in' do 163 context 'with an User logged in' do
164 before do 164 before do
spec/factories/readings.rb
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 # it under the terms of the GNU General Public License as published by 5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or 6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version. 7 # (at your option) any later version.
8 -# 8 +#
9 # This program is distributed in the hope that it will be useful, 9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -16,10 +16,15 @@ @@ -16,10 +16,15 @@
16 16
17 FactoryGirl.define do 17 FactoryGirl.define do
18 factory :reading do 18 factory :reading do
19 - id 42  
20 label "Good" 19 label "Good"
21 grade 10.5 20 grade 10.5
22 - color "33DD33" 21 + color "33DD33"
23 reading_group_id 31 22 reading_group_id 31
24 - end 23 +
  24 + trait :with_id do
  25 + id 42
  26 + end
  27 +
  28 + factory :reading_with_id, traits: [:with_id]
  29 + end
25 end 30 end
spec/helpers/mezuro_ranges_helper_spec.rb
@@ -2,7 +2,7 @@ require &#39;rails_helper&#39; @@ -2,7 +2,7 @@ require &#39;rails_helper&#39;
2 2
3 describe MezuroRangesHelper, :type => :helper do 3 describe MezuroRangesHelper, :type => :helper do
4 describe 'readings_options' do 4 describe 'readings_options' do
5 - let(:reading) { FactoryGirl.build(:reading) } 5 + let(:reading) { FactoryGirl.build(:reading_with_id) }
6 it 'should return a pair with the reading label and id' do 6 it 'should return a pair with the reading label and id' do
7 expect(helper.readings_options([reading])).to eq [[reading.label, reading.id]] 7 expect(helper.readings_options([reading])).to eq [[reading.label, reading.id]]
8 end 8 end
spec/models/reading_group_spec.rb
@@ -37,7 +37,7 @@ describe ReadingGroup, :type =&gt; :model do @@ -37,7 +37,7 @@ describe ReadingGroup, :type =&gt; :model do
37 37
38 describe 'readings' do 38 describe 'readings' do
39 subject { FactoryGirl.build(:reading_group) } 39 subject { FactoryGirl.build(:reading_group) }
40 - let(:reading) { FactoryGirl.build(:reading) } 40 + let(:reading) { FactoryGirl.build(:reading_with_id) }
41 41
42 it 'should call readings_of on the Reading model' do 42 it 'should call readings_of on the Reading model' do
43 subject.expects(:readings).returns([reading]) 43 subject.expects(:readings).returns([reading])