Commit c150494b2c3f9b4ba0bb79955795ab888d29b4af
Committed by
Rafael Manzo
1 parent
f9d8dc0f
Exists in
colab
and in
4 other branches
Refactoring reading group factory
Signed off by: Diego Araújo <diegoamc90@gmail.com>
Showing
12 changed files
with
40 additions
and
30 deletions
Show diff stats
features/step_definitions/reading_group_steps.rb
| ... | ... | @@ -9,7 +9,7 @@ Given(/^I am at the New Reading Group page$/) do |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | 11 | Given(/^I have a reading group named "(.*?)"$/) do |name| |
| 12 | - @reading_group = FactoryGirl.create(:reading_group, {id: nil, name: name}) | |
| 12 | + @reading_group = FactoryGirl.create(:reading_group, {name: name}) | |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 15 | 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 |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | 19 | Given(/^I own a sample reading group$/) do |
| 20 | - @reading_group = FactoryGirl.create(:reading_group, {id: nil}) | |
| 20 | + @reading_group = FactoryGirl.create(:reading_group) | |
| 21 | 21 | FactoryGirl.create(:reading_group_ownership, {user_id: @user.id, reading_group_id: @reading_group.id}) |
| 22 | 22 | end |
| 23 | 23 | |
| 24 | 24 | Given(/^I have a sample reading group$/) do |
| 25 | - @reading_group = FactoryGirl.create(:reading_group, {id: nil}) | |
| 25 | + @reading_group = FactoryGirl.create(:reading_group) | |
| 26 | 26 | end |
| 27 | 27 | |
| 28 | 28 | Given(/^I visit the Sample Reading Group page$/) do |
| ... | ... | @@ -34,7 +34,7 @@ Given(/^I am at the sample reading group edit page$/) do |
| 34 | 34 | end |
| 35 | 35 | |
| 36 | 36 | Given(/^I own a reading group named "(.*?)"$/) do |name| |
| 37 | - @reading_group = FactoryGirl.create(:reading_group, {id: nil, name: name}) | |
| 37 | + @reading_group = FactoryGirl.create(:reading_group, {name: name}) | |
| 38 | 38 | FactoryGirl.create(:reading_group_ownership, {user_id: @user.id, reading_group_id: @reading_group.id}) |
| 39 | 39 | end |
| 40 | 40 | ... | ... |
features/step_definitions/repository_steps.rb
| 1 | 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) | |
| 3 | 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, |
| ... | ... | @@ -10,7 +10,7 @@ Given(/^I have a sample configuration with native metrics but without ranges$/) |
| 10 | 10 | end |
| 11 | 11 | |
| 12 | 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) | |
| 14 | 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 | ... | ... |
spec/controllers/base_metric_configurations_controller_spec.rb
| ... | ... | @@ -111,7 +111,7 @@ describe InheritsFromBaseMetricConfigurationsController, :type => :controller do |
| 111 | 111 | |
| 112 | 112 | describe 'show' do |
| 113 | 113 | let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) } |
| 114 | - let(:reading_group) { FactoryGirl.build(:reading_group) } | |
| 114 | + let(:reading_group) { FactoryGirl.build(:reading_group_with_id) } | |
| 115 | 115 | let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } |
| 116 | 116 | |
| 117 | 117 | context 'with a valid metric_configuration' do | ... | ... |
spec/controllers/compound_metric_configurations_controller_spec.rb
| ... | ... | @@ -71,7 +71,7 @@ describe CompoundMetricConfigurationsController, :type => :controller do |
| 71 | 71 | |
| 72 | 72 | describe 'show' do |
| 73 | 73 | let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration_with_id) } |
| 74 | - let(:reading_group) { FactoryGirl.build(:reading_group) } | |
| 74 | + let(:reading_group) { FactoryGirl.build(:reading_group_with_id) } | |
| 75 | 75 | let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } |
| 76 | 76 | |
| 77 | 77 | before :each do | ... | ... |
spec/controllers/concerns/ownership_authentication_spec.rb
| ... | ... | @@ -4,7 +4,7 @@ describe OwnershipAuthentication, type: :controller do |
| 4 | 4 | #TODO: test other methods |
| 5 | 5 | |
| 6 | 6 | describe 'reading_group_owner?' do |
| 7 | - let(:reading_group) { FactoryGirl.build(:reading_group) } | |
| 7 | + let(:reading_group) { FactoryGirl.build(:reading_group_with_id) } | |
| 8 | 8 | |
| 9 | 9 | context 'Not ReadingGroupsController nor ReadingsController' do |
| 10 | 10 | let!(:projects_controller) { ProjectsController.new } | ... | ... |
spec/controllers/metric_configurations_controller_spec.rb
| ... | ... | @@ -93,7 +93,7 @@ describe MetricConfigurationsController, :type => :controller do |
| 93 | 93 | |
| 94 | 94 | describe 'show' do |
| 95 | 95 | let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) } |
| 96 | - let(:reading_group) { FactoryGirl.build(:reading_group) } | |
| 96 | + let(:reading_group) { FactoryGirl.build(:reading_group_with_id) } | |
| 97 | 97 | let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } |
| 98 | 98 | |
| 99 | 99 | before :each do | ... | ... |
spec/controllers/reading_groups_controller_spec.rb
| ... | ... | @@ -17,8 +17,8 @@ describe ReadingGroupsController, :type => :controller do |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | 19 | context 'with valid fields' do |
| 20 | - let(:reading_group) { FactoryGirl.build(:reading_group) } | |
| 21 | - 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 | |
| 20 | + let(:reading_group) { FactoryGirl.build(:reading_group_with_id) } | |
| 21 | + let(:subject_params) { reading_group.to_hash } | |
| 22 | 22 | |
| 23 | 23 | before :each do |
| 24 | 24 | ReadingGroup.any_instance.expects(:save).returns(true) |
| ... | ... | @@ -45,8 +45,8 @@ describe ReadingGroupsController, :type => :controller do |
| 45 | 45 | |
| 46 | 46 | context 'with an invalid field' do |
| 47 | 47 | before :each do |
| 48 | - @subject = FactoryGirl.build(:reading_group) | |
| 49 | - @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 | |
| 48 | + @subject = FactoryGirl.build(:reading_group_with_id) | |
| 49 | + @subject_params = @subject.to_hash | |
| 50 | 50 | |
| 51 | 51 | ReadingGroup.expects(:new).at_least_once.with(@subject_params).returns(@subject) |
| 52 | 52 | ReadingGroup.any_instance.expects(:save).returns(false) |
| ... | ... | @@ -59,7 +59,7 @@ describe ReadingGroupsController, :type => :controller do |
| 59 | 59 | end |
| 60 | 60 | |
| 61 | 61 | describe 'show' do |
| 62 | - let!(:reading_group) { FactoryGirl.build(:reading_group) } | |
| 62 | + let!(:reading_group) { FactoryGirl.build(:reading_group_with_id) } | |
| 63 | 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) |
| ... | ... | @@ -71,7 +71,7 @@ describe ReadingGroupsController, :type => :controller do |
| 71 | 71 | |
| 72 | 72 | describe 'destroy' do |
| 73 | 73 | before do |
| 74 | - @subject = FactoryGirl.build(:reading_group) | |
| 74 | + @subject = FactoryGirl.build(:reading_group_with_id) | |
| 75 | 75 | end |
| 76 | 76 | |
| 77 | 77 | context 'with an User logged in' do |
| ... | ... | @@ -127,7 +127,7 @@ describe ReadingGroupsController, :type => :controller do |
| 127 | 127 | |
| 128 | 128 | describe 'index' do |
| 129 | 129 | before :each do |
| 130 | - @subject = FactoryGirl.build(:reading_group) | |
| 130 | + @subject = FactoryGirl.build(:reading_group_with_id) | |
| 131 | 131 | ReadingGroup.expects(:all).returns([@subject]) |
| 132 | 132 | get :index |
| 133 | 133 | end |
| ... | ... | @@ -137,7 +137,7 @@ describe ReadingGroupsController, :type => :controller do |
| 137 | 137 | |
| 138 | 138 | describe 'edit' do |
| 139 | 139 | before do |
| 140 | - @subject = FactoryGirl.build(:reading_group) | |
| 140 | + @subject = FactoryGirl.build(:reading_group_with_id) | |
| 141 | 141 | end |
| 142 | 142 | |
| 143 | 143 | context 'with an User logged in' do |
| ... | ... | @@ -168,7 +168,7 @@ describe ReadingGroupsController, :type => :controller do |
| 168 | 168 | |
| 169 | 169 | context 'when the user does not own the reading group' do |
| 170 | 170 | before do |
| 171 | - @subject = FactoryGirl.build(:another_reading_group) | |
| 171 | + @subject = FactoryGirl.build(:another_reading_group_with_id) | |
| 172 | 172 | @ownerships.expects(:find_by_reading_group_id).with("#{@subject.id}").returns(nil) |
| 173 | 173 | |
| 174 | 174 | get :edit, :id => @subject.id |
| ... | ... | @@ -190,8 +190,8 @@ describe ReadingGroupsController, :type => :controller do |
| 190 | 190 | |
| 191 | 191 | describe 'update' do |
| 192 | 192 | before do |
| 193 | - @subject = FactoryGirl.build(:reading_group) | |
| 194 | - @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 | |
| 193 | + @subject = FactoryGirl.build(:reading_group_with_id) | |
| 194 | + @subject_params = @subject.to_hash | |
| 195 | 195 | end |
| 196 | 196 | |
| 197 | 197 | context 'when the user is logged in' do | ... | ... |
spec/controllers/readings_controller_spec.rb
spec/factories/reading_groups.rb
| 1 | 1 | FactoryGirl.define do |
| 2 | 2 | factory :reading_group do |
| 3 | - id 1 | |
| 4 | 3 | name "Mussum" |
| 5 | 4 | description "Cacildis!" |
| 5 | + | |
| 6 | + trait :with_id do | |
| 7 | + id 1 | |
| 8 | + end | |
| 9 | + | |
| 10 | + factory :reading_group_with_id, traits: [:with_id] | |
| 6 | 11 | end |
| 7 | 12 | |
| 8 | 13 | factory :another_reading_group, class: ReadingGroup do |
| 9 | - id 2 | |
| 10 | 14 | name "My Reading Group" |
| 11 | 15 | description "The best one" |
| 16 | + | |
| 17 | + trait :with_id do | |
| 18 | + id 2 | |
| 19 | + end | |
| 20 | + | |
| 21 | + factory :another_reading_group_with_id, traits: [:with_id] | |
| 12 | 22 | end |
| 13 | 23 | end | ... | ... |
spec/helpers/metric_configurations_helper_spec.rb
| ... | ... | @@ -9,7 +9,7 @@ describe MetricConfigurationsHelper, :type => :helper do |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | 11 | describe 'reading_group_options' do |
| 12 | - let! (:reading_group) { FactoryGirl.build(:reading_group) } | |
| 12 | + let! (:reading_group) { FactoryGirl.build(:reading_group_with_id) } | |
| 13 | 13 | |
| 14 | 14 | before :each do |
| 15 | 15 | ReadingGroup.expects(:all).returns([reading_group]) | ... | ... |
spec/helpers/reading_groups_helper_spec.rb
| ... | ... | @@ -4,7 +4,7 @@ describe ReadingGroupsHelper, :type => :helper do |
| 4 | 4 | |
| 5 | 5 | describe 'reading_group_owner?' do |
| 6 | 6 | before :each do |
| 7 | - @subject = FactoryGirl.build(:reading_group) | |
| 7 | + @subject = FactoryGirl.build(:reading_group_with_id) | |
| 8 | 8 | end |
| 9 | 9 | |
| 10 | 10 | context 'returns false if not logged in' do | ... | ... |
spec/models/reading_group_spec.rb
| ... | ... | @@ -4,14 +4,14 @@ describe ReadingGroup, :type => :model do |
| 4 | 4 | describe 'methods' do |
| 5 | 5 | describe 'persisted?' do |
| 6 | 6 | before :each do |
| 7 | - @subject = FactoryGirl.build(:reading_group) | |
| 7 | + @subject = FactoryGirl.build(:reading_group_with_id) | |
| 8 | 8 | end |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | 11 | describe 'update' do |
| 12 | 12 | before :each do |
| 13 | - @qt = FactoryGirl.build(:reading_group) | |
| 14 | - @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 | |
| 13 | + @qt = FactoryGirl.build(:reading_group_with_id) | |
| 14 | + @qt_params = @qt.to_hash | |
| 15 | 15 | end |
| 16 | 16 | |
| 17 | 17 | context 'with valid attributes' do |
| ... | ... | @@ -36,7 +36,7 @@ describe ReadingGroup, :type => :model do |
| 36 | 36 | end |
| 37 | 37 | |
| 38 | 38 | describe 'readings' do |
| 39 | - subject { FactoryGirl.build(:reading_group) } | |
| 39 | + subject { FactoryGirl.build(:reading_group_with_id) } | |
| 40 | 40 | let(:reading) { FactoryGirl.build(:reading_with_id) } |
| 41 | 41 | |
| 42 | 42 | it 'should call readings_of on the Reading model' do | ... | ... |