Commit f9d8dc0f39c583ba16dc2b393e2f28e6f14dd0a9
Committed by
Rafael Manzo
1 parent
b312147c
Exists in
colab
and in
4 other branches
WIP: Fixing acceptance tests for reading creation
Signed off by: Daniel Alves <danpaulalves@gmail.com>
Showing
10 changed files
with
31 additions
and
26 deletions
Show diff stats
features/step_definitions/mezuro_range_steps.rb
| 1 | 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 | 3 | reading_id: @reading.id, id: nil}) |
| 4 | 4 | end |
| 5 | 5 | |
| 6 | 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 | 8 | end |
| 9 | 9 | |
| 10 | 10 | Given(/^the select field "(.*?)" is set as "(.*?)"$/) do |field, text| |
| ... | ... | @@ -12,17 +12,17 @@ Given(/^the select field "(.*?)" is set as "(.*?)"$/) do |field, text| |
| 12 | 12 | end |
| 13 | 13 | |
| 14 | 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 | 16 | reading_id: @reading.id, id: nil}) |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | 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 | 21 | reading_id: @reading.id, id: nil}) |
| 22 | 22 | end |
| 23 | 23 | |
| 24 | 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 | 26 | end |
| 27 | 27 | |
| 28 | 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 "(.*?)"$/) do |name| |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 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 | 17 | end |
| 18 | 18 | |
| 19 | 19 | Given(/^I own a sample reading group$/) do | ... | ... |
features/step_definitions/reading_steps.rb
| 1 | 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 | 3 | end |
| 4 | 4 | |
| 5 | 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 | end |
| 12 | 12 | |
| 13 | 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 | 15 | end |
| 16 | 16 | |
| 17 | 17 | When(/^I click the "(.*?)" td$/) do |text| |
| 18 | - p page.find('td', text: text).methods | |
| 18 | + page.find('td', text: text).methods | |
| 19 | 19 | end |
| 20 | 20 | |
| 21 | 21 | When(/^I click on the center of the color picker$/) do | ... | ... |
features/step_definitions/repository_steps.rb
| 1 | 1 | Given(/^I have a sample configuration with native metrics but without ranges$/) do |
| 2 | 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 | 4 | @kalibro_configuration = FactoryGirl.create(:kalibro_configuration, id: nil) |
| 5 | 5 | metric_configuration = FactoryGirl.create(:metric_configuration, |
| 6 | 6 | {metric: FactoryGirl.build(:loc), |
| ... | ... | @@ -11,7 +11,7 @@ end |
| 11 | 11 | |
| 12 | 12 | Given(/^I have a sample configuration with native metrics$/) do |
| 13 | 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 | 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 => :controller do |
| 111 | 111 | describe 'edit' do |
| 112 | 112 | let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) } |
| 113 | 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 | 116 | context 'with an User logged in' do |
| 117 | 117 | before do |
| ... | ... | @@ -156,7 +156,7 @@ describe MezuroRangesController, :type => :controller do |
| 156 | 156 | let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) } |
| 157 | 157 | let(:mezuro_range) { FactoryGirl.build(:mezuro_range, id: 1, metric_configuration_id: metric_configuration.id) } |
| 158 | 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 | 161 | context 'when the user is logged in' do |
| 162 | 162 | before do | ... | ... |
spec/controllers/reading_groups_controller_spec.rb
| ... | ... | @@ -60,7 +60,7 @@ describe ReadingGroupsController, :type => :controller do |
| 60 | 60 | |
| 61 | 61 | describe 'show' do |
| 62 | 62 | let!(:reading_group) { FactoryGirl.build(:reading_group) } |
| 63 | - let(:reading) { FactoryGirl.build(:reading) } | |
| 63 | + let(:reading) { FactoryGirl.build(:reading_with_id) } | |
| 64 | 64 | before :each do |
| 65 | 65 | subject.expects(:find_resource).with(ReadingGroup, reading_group.id).returns(reading_group) |
| 66 | 66 | get :show, :id => reading_group.id | ... | ... |
spec/controllers/readings_controller_spec.rb
| ... | ... | @@ -29,8 +29,8 @@ describe ReadingsController, :type => :controller do |
| 29 | 29 | end |
| 30 | 30 | |
| 31 | 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 | 35 | before do |
| 36 | 36 | sign_in FactoryGirl.create(:user) |
| ... | ... | @@ -64,7 +64,7 @@ describe ReadingsController, :type => :controller do |
| 64 | 64 | end |
| 65 | 65 | |
| 66 | 66 | describe 'edit' do |
| 67 | - let(:reading) { FactoryGirl.build(:reading) } | |
| 67 | + let(:reading) { FactoryGirl.build(:reading_with_id) } | |
| 68 | 68 | |
| 69 | 69 | context 'with an User logged in' do |
| 70 | 70 | before do |
| ... | ... | @@ -102,8 +102,8 @@ describe ReadingsController, :type => :controller do |
| 102 | 102 | end |
| 103 | 103 | |
| 104 | 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 | 108 | context 'when the user is logged in' do |
| 109 | 109 | before do |
| ... | ... | @@ -158,7 +158,7 @@ describe ReadingsController, :type => :controller do |
| 158 | 158 | end |
| 159 | 159 | |
| 160 | 160 | describe 'destroy' do |
| 161 | - let(:reading) { FactoryGirl.build(:reading) } | |
| 161 | + let(:reading) { FactoryGirl.build(:reading_with_id) } | |
| 162 | 162 | |
| 163 | 163 | context 'with an User logged in' do |
| 164 | 164 | before do | ... | ... |
spec/factories/readings.rb
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | # it under the terms of the GNU General Public License as published by |
| 6 | 6 | # the Free Software Foundation, either version 3 of the License, or |
| 7 | 7 | # (at your option) any later version. |
| 8 | -# | |
| 8 | +# | |
| 9 | 9 | # This program is distributed in the hope that it will be useful, |
| 10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| ... | ... | @@ -16,10 +16,15 @@ |
| 16 | 16 | |
| 17 | 17 | FactoryGirl.define do |
| 18 | 18 | factory :reading do |
| 19 | - id 42 | |
| 20 | 19 | label "Good" |
| 21 | 20 | grade 10.5 |
| 22 | - color "33DD33" | |
| 21 | + color "33DD33" | |
| 23 | 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 | 30 | end | ... | ... |
spec/helpers/mezuro_ranges_helper_spec.rb
| ... | ... | @@ -2,7 +2,7 @@ require 'rails_helper' |
| 2 | 2 | |
| 3 | 3 | describe MezuroRangesHelper, :type => :helper do |
| 4 | 4 | describe 'readings_options' do |
| 5 | - let(:reading) { FactoryGirl.build(:reading) } | |
| 5 | + let(:reading) { FactoryGirl.build(:reading_with_id) } | |
| 6 | 6 | it 'should return a pair with the reading label and id' do |
| 7 | 7 | expect(helper.readings_options([reading])).to eq [[reading.label, reading.id]] |
| 8 | 8 | end | ... | ... |
spec/models/reading_group_spec.rb
| ... | ... | @@ -37,7 +37,7 @@ describe ReadingGroup, :type => :model do |
| 37 | 37 | |
| 38 | 38 | describe 'readings' do |
| 39 | 39 | subject { FactoryGirl.build(:reading_group) } |
| 40 | - let(:reading) { FactoryGirl.build(:reading) } | |
| 40 | + let(:reading) { FactoryGirl.build(:reading_with_id) } | |
| 41 | 41 | |
| 42 | 42 | it 'should call readings_of on the Reading model' do |
| 43 | 43 | subject.expects(:readings).returns([reading]) | ... | ... |