diff --git a/features/step_definitions/reading_group_steps.rb b/features/step_definitions/reading_group_steps.rb index 6919d85..5ef9f09 100644 --- a/features/step_definitions/reading_group_steps.rb +++ b/features/step_definitions/reading_group_steps.rb @@ -9,7 +9,7 @@ Given(/^I am at the New Reading Group page$/) do end Given(/^I have a reading group named "(.*?)"$/) do |name| - @reading_group = FactoryGirl.create(:reading_group, {id: nil, name: name}) + @reading_group = FactoryGirl.create(:reading_group, {name: name}) end Given(/^I have a sample reading within the sample reading group$/) do @@ -17,12 +17,12 @@ Given(/^I have a sample reading within the sample reading group$/) do end Given(/^I own a sample reading group$/) do - @reading_group = FactoryGirl.create(:reading_group, {id: nil}) + @reading_group = FactoryGirl.create(:reading_group) FactoryGirl.create(:reading_group_ownership, {user_id: @user.id, reading_group_id: @reading_group.id}) end Given(/^I have a sample reading group$/) do - @reading_group = FactoryGirl.create(:reading_group, {id: nil}) + @reading_group = FactoryGirl.create(:reading_group) end Given(/^I visit the Sample Reading Group page$/) do @@ -34,7 +34,7 @@ Given(/^I am at the sample reading group edit page$/) do end Given(/^I own a reading group named "(.*?)"$/) do |name| - @reading_group = FactoryGirl.create(:reading_group, {id: nil, name: name}) + @reading_group = FactoryGirl.create(:reading_group, {name: name}) FactoryGirl.create(:reading_group_ownership, {user_id: @user.id, reading_group_id: @reading_group.id}) end diff --git a/features/step_definitions/repository_steps.rb b/features/step_definitions/repository_steps.rb index e952496..385cc6e 100644 --- a/features/step_definitions/repository_steps.rb +++ b/features/step_definitions/repository_steps.rb @@ -1,5 +1,5 @@ Given(/^I have a sample configuration with native metrics but without ranges$/) do - reading_group = FactoryGirl.create(:reading_group, id: nil) + reading_group = FactoryGirl.create(:reading_group) reading = FactoryGirl.create(:reading, {reading_group_id: reading_group.id}) @kalibro_configuration = FactoryGirl.create(:kalibro_configuration, id: nil) metric_configuration = FactoryGirl.create(:metric_configuration, @@ -10,7 +10,7 @@ Given(/^I have a sample configuration with native metrics but without ranges$/) end Given(/^I have a sample configuration with native metrics$/) do - reading_group = FactoryGirl.create(:reading_group, id: nil) + reading_group = FactoryGirl.create(:reading_group) reading = FactoryGirl.create(:reading, {reading_group_id: reading_group.id}) KalibroClient::Processor::MetricCollector.find('Analizo').supported_metrics.select { |x| not x.persisted? }.save diff --git a/spec/controllers/base_metric_configurations_controller_spec.rb b/spec/controllers/base_metric_configurations_controller_spec.rb index f1a1156..16894bd 100644 --- a/spec/controllers/base_metric_configurations_controller_spec.rb +++ b/spec/controllers/base_metric_configurations_controller_spec.rb @@ -111,7 +111,7 @@ describe InheritsFromBaseMetricConfigurationsController, :type => :controller do describe 'show' do let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) } - let(:reading_group) { FactoryGirl.build(:reading_group) } + let(:reading_group) { FactoryGirl.build(:reading_group_with_id) } let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } context 'with a valid metric_configuration' do diff --git a/spec/controllers/compound_metric_configurations_controller_spec.rb b/spec/controllers/compound_metric_configurations_controller_spec.rb index 743a429..2000470 100644 --- a/spec/controllers/compound_metric_configurations_controller_spec.rb +++ b/spec/controllers/compound_metric_configurations_controller_spec.rb @@ -71,7 +71,7 @@ describe CompoundMetricConfigurationsController, :type => :controller do describe 'show' do let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration_with_id) } - let(:reading_group) { FactoryGirl.build(:reading_group) } + let(:reading_group) { FactoryGirl.build(:reading_group_with_id) } let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } before :each do diff --git a/spec/controllers/concerns/ownership_authentication_spec.rb b/spec/controllers/concerns/ownership_authentication_spec.rb index c38c1a0..d33848f 100644 --- a/spec/controllers/concerns/ownership_authentication_spec.rb +++ b/spec/controllers/concerns/ownership_authentication_spec.rb @@ -4,7 +4,7 @@ describe OwnershipAuthentication, type: :controller do #TODO: test other methods describe 'reading_group_owner?' do - let(:reading_group) { FactoryGirl.build(:reading_group) } + let(:reading_group) { FactoryGirl.build(:reading_group_with_id) } context 'Not ReadingGroupsController nor ReadingsController' do let!(:projects_controller) { ProjectsController.new } diff --git a/spec/controllers/metric_configurations_controller_spec.rb b/spec/controllers/metric_configurations_controller_spec.rb index 49934e1..ec8110a 100644 --- a/spec/controllers/metric_configurations_controller_spec.rb +++ b/spec/controllers/metric_configurations_controller_spec.rb @@ -93,7 +93,7 @@ describe MetricConfigurationsController, :type => :controller do describe 'show' do let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) } - let(:reading_group) { FactoryGirl.build(:reading_group) } + let(:reading_group) { FactoryGirl.build(:reading_group_with_id) } let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } before :each do diff --git a/spec/controllers/reading_groups_controller_spec.rb b/spec/controllers/reading_groups_controller_spec.rb index 78807df..9867618 100644 --- a/spec/controllers/reading_groups_controller_spec.rb +++ b/spec/controllers/reading_groups_controller_spec.rb @@ -17,8 +17,8 @@ describe ReadingGroupsController, :type => :controller do end context 'with valid fields' do - let(:reading_group) { FactoryGirl.build(:reading_group) } - let(:subject_params) { Hash[FactoryGirl.attributes_for(:reading_group).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 + let(:reading_group) { FactoryGirl.build(:reading_group_with_id) } + let(:subject_params) { reading_group.to_hash } before :each do ReadingGroup.any_instance.expects(:save).returns(true) @@ -45,8 +45,8 @@ describe ReadingGroupsController, :type => :controller do context 'with an invalid field' do before :each do - @subject = FactoryGirl.build(:reading_group) - @subject_params = Hash[FactoryGirl.attributes_for(:reading_group).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 + @subject = FactoryGirl.build(:reading_group_with_id) + @subject_params = @subject.to_hash ReadingGroup.expects(:new).at_least_once.with(@subject_params).returns(@subject) ReadingGroup.any_instance.expects(:save).returns(false) @@ -59,7 +59,7 @@ describe ReadingGroupsController, :type => :controller do end describe 'show' do - let!(:reading_group) { FactoryGirl.build(:reading_group) } + let!(:reading_group) { FactoryGirl.build(:reading_group_with_id) } let(:reading) { FactoryGirl.build(:reading_with_id) } before :each do subject.expects(:find_resource).with(ReadingGroup, reading_group.id).returns(reading_group) @@ -71,7 +71,7 @@ describe ReadingGroupsController, :type => :controller do describe 'destroy' do before do - @subject = FactoryGirl.build(:reading_group) + @subject = FactoryGirl.build(:reading_group_with_id) end context 'with an User logged in' do @@ -127,7 +127,7 @@ describe ReadingGroupsController, :type => :controller do describe 'index' do before :each do - @subject = FactoryGirl.build(:reading_group) + @subject = FactoryGirl.build(:reading_group_with_id) ReadingGroup.expects(:all).returns([@subject]) get :index end @@ -137,7 +137,7 @@ describe ReadingGroupsController, :type => :controller do describe 'edit' do before do - @subject = FactoryGirl.build(:reading_group) + @subject = FactoryGirl.build(:reading_group_with_id) end context 'with an User logged in' do @@ -168,7 +168,7 @@ describe ReadingGroupsController, :type => :controller do context 'when the user does not own the reading group' do before do - @subject = FactoryGirl.build(:another_reading_group) + @subject = FactoryGirl.build(:another_reading_group_with_id) @ownerships.expects(:find_by_reading_group_id).with("#{@subject.id}").returns(nil) get :edit, :id => @subject.id @@ -190,8 +190,8 @@ describe ReadingGroupsController, :type => :controller do describe 'update' do before do - @subject = FactoryGirl.build(:reading_group) - @subject_params = Hash[FactoryGirl.attributes_for(:reading_group).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 + @subject = FactoryGirl.build(:reading_group_with_id) + @subject_params = @subject.to_hash end context 'when the user is logged in' do diff --git a/spec/controllers/readings_controller_spec.rb b/spec/controllers/readings_controller_spec.rb index 57cfcc6..b3dabc4 100644 --- a/spec/controllers/readings_controller_spec.rb +++ b/spec/controllers/readings_controller_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe ReadingsController, :type => :controller do - let(:reading_group) { FactoryGirl.build(:reading_group) } + let(:reading_group) { FactoryGirl.build(:reading_group_with_id) } describe 'new' do before :each do diff --git a/spec/factories/reading_groups.rb b/spec/factories/reading_groups.rb index cdb1b2d..21b7312 100644 --- a/spec/factories/reading_groups.rb +++ b/spec/factories/reading_groups.rb @@ -1,13 +1,23 @@ FactoryGirl.define do factory :reading_group do - id 1 name "Mussum" description "Cacildis!" + + trait :with_id do + id 1 + end + + factory :reading_group_with_id, traits: [:with_id] end factory :another_reading_group, class: ReadingGroup do - id 2 name "My Reading Group" description "The best one" + + trait :with_id do + id 2 + end + + factory :another_reading_group_with_id, traits: [:with_id] end end diff --git a/spec/helpers/metric_configurations_helper_spec.rb b/spec/helpers/metric_configurations_helper_spec.rb index ed9662f..62b01ac 100644 --- a/spec/helpers/metric_configurations_helper_spec.rb +++ b/spec/helpers/metric_configurations_helper_spec.rb @@ -9,7 +9,7 @@ describe MetricConfigurationsHelper, :type => :helper do end describe 'reading_group_options' do - let! (:reading_group) { FactoryGirl.build(:reading_group) } + let! (:reading_group) { FactoryGirl.build(:reading_group_with_id) } before :each do ReadingGroup.expects(:all).returns([reading_group]) diff --git a/spec/helpers/reading_groups_helper_spec.rb b/spec/helpers/reading_groups_helper_spec.rb index 3ee7532..d7523d8 100644 --- a/spec/helpers/reading_groups_helper_spec.rb +++ b/spec/helpers/reading_groups_helper_spec.rb @@ -4,7 +4,7 @@ describe ReadingGroupsHelper, :type => :helper do describe 'reading_group_owner?' do before :each do - @subject = FactoryGirl.build(:reading_group) + @subject = FactoryGirl.build(:reading_group_with_id) end context 'returns false if not logged in' do diff --git a/spec/models/reading_group_spec.rb b/spec/models/reading_group_spec.rb index d63e40c..7da7d1a 100644 --- a/spec/models/reading_group_spec.rb +++ b/spec/models/reading_group_spec.rb @@ -4,14 +4,14 @@ describe ReadingGroup, :type => :model do describe 'methods' do describe 'persisted?' do before :each do - @subject = FactoryGirl.build(:reading_group) + @subject = FactoryGirl.build(:reading_group_with_id) end end describe 'update' do before :each do - @qt = FactoryGirl.build(:reading_group) - @qt_params = Hash[FactoryGirl.attributes_for(:reading_group).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 + @qt = FactoryGirl.build(:reading_group_with_id) + @qt_params = @qt.to_hash end context 'with valid attributes' do @@ -36,7 +36,7 @@ describe ReadingGroup, :type => :model do end describe 'readings' do - subject { FactoryGirl.build(:reading_group) } + subject { FactoryGirl.build(:reading_group_with_id) } let(:reading) { FactoryGirl.build(:reading_with_id) } it 'should call readings_of on the Reading model' do -- libgit2 0.21.2