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,7 +9,7 @@ Given(/^I am at the New Reading Group page$/) do | ||
9 | end | 9 | end |
10 | 10 | ||
11 | Given(/^I have a reading group named "(.*?)"$/) do |name| | 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 | 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 |
@@ -17,12 +17,12 @@ 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 | end | 17 | end |
18 | 18 | ||
19 | Given(/^I own a sample reading group$/) do | 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 | FactoryGirl.create(:reading_group_ownership, {user_id: @user.id, reading_group_id: @reading_group.id}) | 21 | FactoryGirl.create(:reading_group_ownership, {user_id: @user.id, reading_group_id: @reading_group.id}) |
22 | end | 22 | end |
23 | 23 | ||
24 | Given(/^I have a sample reading group$/) do | 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 | end | 26 | end |
27 | 27 | ||
28 | Given(/^I visit the Sample Reading Group page$/) do | 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,7 +34,7 @@ Given(/^I am at the sample reading group edit page$/) do | ||
34 | end | 34 | end |
35 | 35 | ||
36 | Given(/^I own a reading group named "(.*?)"$/) do |name| | 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 | FactoryGirl.create(:reading_group_ownership, {user_id: @user.id, reading_group_id: @reading_group.id}) | 38 | FactoryGirl.create(:reading_group_ownership, {user_id: @user.id, reading_group_id: @reading_group.id}) |
39 | end | 39 | end |
40 | 40 |
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) |
3 | reading = FactoryGirl.create(:reading, {reading_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, |
@@ -10,7 +10,7 @@ Given(/^I have a sample configuration with native metrics but without ranges$/) | @@ -10,7 +10,7 @@ Given(/^I have a sample configuration with native metrics but without ranges$/) | ||
10 | end | 10 | 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) |
14 | reading = FactoryGirl.create(:reading, {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 |
spec/controllers/base_metric_configurations_controller_spec.rb
@@ -111,7 +111,7 @@ describe InheritsFromBaseMetricConfigurationsController, :type => :controller do | @@ -111,7 +111,7 @@ describe InheritsFromBaseMetricConfigurationsController, :type => :controller do | ||
111 | 111 | ||
112 | describe 'show' do | 112 | describe 'show' do |
113 | let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) } | 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 | let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } | 115 | let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } |
116 | 116 | ||
117 | context 'with a valid metric_configuration' do | 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,7 +71,7 @@ describe CompoundMetricConfigurationsController, :type => :controller do | ||
71 | 71 | ||
72 | describe 'show' do | 72 | describe 'show' do |
73 | let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration_with_id) } | 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 | let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } | 75 | let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } |
76 | 76 | ||
77 | before :each do | 77 | before :each do |
spec/controllers/concerns/ownership_authentication_spec.rb
@@ -4,7 +4,7 @@ describe OwnershipAuthentication, type: :controller do | @@ -4,7 +4,7 @@ describe OwnershipAuthentication, type: :controller do | ||
4 | #TODO: test other methods | 4 | #TODO: test other methods |
5 | 5 | ||
6 | describe 'reading_group_owner?' do | 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 | context 'Not ReadingGroupsController nor ReadingsController' do | 9 | context 'Not ReadingGroupsController nor ReadingsController' do |
10 | let!(:projects_controller) { ProjectsController.new } | 10 | let!(:projects_controller) { ProjectsController.new } |
spec/controllers/metric_configurations_controller_spec.rb
@@ -93,7 +93,7 @@ describe MetricConfigurationsController, :type => :controller do | @@ -93,7 +93,7 @@ describe MetricConfigurationsController, :type => :controller do | ||
93 | 93 | ||
94 | describe 'show' do | 94 | describe 'show' do |
95 | let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) } | 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 | let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } | 97 | let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } |
98 | 98 | ||
99 | before :each do | 99 | before :each do |
spec/controllers/reading_groups_controller_spec.rb
@@ -17,8 +17,8 @@ describe ReadingGroupsController, :type => :controller do | @@ -17,8 +17,8 @@ describe ReadingGroupsController, :type => :controller do | ||
17 | end | 17 | end |
18 | 18 | ||
19 | context 'with valid fields' do | 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 | before :each do | 23 | before :each do |
24 | ReadingGroup.any_instance.expects(:save).returns(true) | 24 | ReadingGroup.any_instance.expects(:save).returns(true) |
@@ -45,8 +45,8 @@ describe ReadingGroupsController, :type => :controller do | @@ -45,8 +45,8 @@ describe ReadingGroupsController, :type => :controller do | ||
45 | 45 | ||
46 | context 'with an invalid field' do | 46 | context 'with an invalid field' do |
47 | before :each do | 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 | ReadingGroup.expects(:new).at_least_once.with(@subject_params).returns(@subject) | 51 | ReadingGroup.expects(:new).at_least_once.with(@subject_params).returns(@subject) |
52 | ReadingGroup.any_instance.expects(:save).returns(false) | 52 | ReadingGroup.any_instance.expects(:save).returns(false) |
@@ -59,7 +59,7 @@ describe ReadingGroupsController, :type => :controller do | @@ -59,7 +59,7 @@ describe ReadingGroupsController, :type => :controller do | ||
59 | end | 59 | end |
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_with_id) } |
63 | let(:reading) { FactoryGirl.build(:reading_with_id) } | 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) |
@@ -71,7 +71,7 @@ describe ReadingGroupsController, :type => :controller do | @@ -71,7 +71,7 @@ describe ReadingGroupsController, :type => :controller do | ||
71 | 71 | ||
72 | describe 'destroy' do | 72 | describe 'destroy' do |
73 | before do | 73 | before do |
74 | - @subject = FactoryGirl.build(:reading_group) | 74 | + @subject = FactoryGirl.build(:reading_group_with_id) |
75 | end | 75 | end |
76 | 76 | ||
77 | context 'with an User logged in' do | 77 | context 'with an User logged in' do |
@@ -127,7 +127,7 @@ describe ReadingGroupsController, :type => :controller do | @@ -127,7 +127,7 @@ describe ReadingGroupsController, :type => :controller do | ||
127 | 127 | ||
128 | describe 'index' do | 128 | describe 'index' do |
129 | before :each do | 129 | before :each do |
130 | - @subject = FactoryGirl.build(:reading_group) | 130 | + @subject = FactoryGirl.build(:reading_group_with_id) |
131 | ReadingGroup.expects(:all).returns([@subject]) | 131 | ReadingGroup.expects(:all).returns([@subject]) |
132 | get :index | 132 | get :index |
133 | end | 133 | end |
@@ -137,7 +137,7 @@ describe ReadingGroupsController, :type => :controller do | @@ -137,7 +137,7 @@ describe ReadingGroupsController, :type => :controller do | ||
137 | 137 | ||
138 | describe 'edit' do | 138 | describe 'edit' do |
139 | before do | 139 | before do |
140 | - @subject = FactoryGirl.build(:reading_group) | 140 | + @subject = FactoryGirl.build(:reading_group_with_id) |
141 | end | 141 | end |
142 | 142 | ||
143 | context 'with an User logged in' do | 143 | context 'with an User logged in' do |
@@ -168,7 +168,7 @@ describe ReadingGroupsController, :type => :controller do | @@ -168,7 +168,7 @@ describe ReadingGroupsController, :type => :controller do | ||
168 | 168 | ||
169 | context 'when the user does not own the reading group' do | 169 | context 'when the user does not own the reading group' do |
170 | before do | 170 | before do |
171 | - @subject = FactoryGirl.build(:another_reading_group) | 171 | + @subject = FactoryGirl.build(:another_reading_group_with_id) |
172 | @ownerships.expects(:find_by_reading_group_id).with("#{@subject.id}").returns(nil) | 172 | @ownerships.expects(:find_by_reading_group_id).with("#{@subject.id}").returns(nil) |
173 | 173 | ||
174 | get :edit, :id => @subject.id | 174 | get :edit, :id => @subject.id |
@@ -190,8 +190,8 @@ describe ReadingGroupsController, :type => :controller do | @@ -190,8 +190,8 @@ describe ReadingGroupsController, :type => :controller do | ||
190 | 190 | ||
191 | describe 'update' do | 191 | describe 'update' do |
192 | before do | 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 | end | 195 | end |
196 | 196 | ||
197 | context 'when the user is logged in' do | 197 | context 'when the user is logged in' do |
spec/controllers/readings_controller_spec.rb
1 | require 'rails_helper' | 1 | require 'rails_helper' |
2 | 2 | ||
3 | describe ReadingsController, :type => :controller do | 3 | describe ReadingsController, :type => :controller do |
4 | - let(:reading_group) { FactoryGirl.build(:reading_group) } | 4 | + let(:reading_group) { FactoryGirl.build(:reading_group_with_id) } |
5 | 5 | ||
6 | describe 'new' do | 6 | describe 'new' do |
7 | before :each do | 7 | before :each do |
spec/factories/reading_groups.rb
1 | FactoryGirl.define do | 1 | FactoryGirl.define do |
2 | factory :reading_group do | 2 | factory :reading_group do |
3 | - id 1 | ||
4 | name "Mussum" | 3 | name "Mussum" |
5 | description "Cacildis!" | 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 | end | 11 | end |
7 | 12 | ||
8 | factory :another_reading_group, class: ReadingGroup do | 13 | factory :another_reading_group, class: ReadingGroup do |
9 | - id 2 | ||
10 | name "My Reading Group" | 14 | name "My Reading Group" |
11 | description "The best one" | 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 | end | 22 | end |
13 | end | 23 | end |
spec/helpers/metric_configurations_helper_spec.rb
@@ -9,7 +9,7 @@ describe MetricConfigurationsHelper, :type => :helper do | @@ -9,7 +9,7 @@ describe MetricConfigurationsHelper, :type => :helper do | ||
9 | end | 9 | end |
10 | 10 | ||
11 | describe 'reading_group_options' do | 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 | before :each do | 14 | before :each do |
15 | ReadingGroup.expects(:all).returns([reading_group]) | 15 | ReadingGroup.expects(:all).returns([reading_group]) |
spec/helpers/reading_groups_helper_spec.rb
@@ -4,7 +4,7 @@ describe ReadingGroupsHelper, :type => :helper do | @@ -4,7 +4,7 @@ describe ReadingGroupsHelper, :type => :helper do | ||
4 | 4 | ||
5 | describe 'reading_group_owner?' do | 5 | describe 'reading_group_owner?' do |
6 | before :each do | 6 | before :each do |
7 | - @subject = FactoryGirl.build(:reading_group) | 7 | + @subject = FactoryGirl.build(:reading_group_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/reading_group_spec.rb
@@ -4,14 +4,14 @@ describe ReadingGroup, :type => :model do | @@ -4,14 +4,14 @@ describe ReadingGroup, :type => :model do | ||
4 | describe 'methods' do | 4 | describe 'methods' do |
5 | describe 'persisted?' do | 5 | describe 'persisted?' do |
6 | before :each do | 6 | before :each do |
7 | - @subject = FactoryGirl.build(:reading_group) | 7 | + @subject = FactoryGirl.build(:reading_group_with_id) |
8 | end | 8 | end |
9 | end | 9 | end |
10 | 10 | ||
11 | describe 'update' do | 11 | describe 'update' do |
12 | before :each do | 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 | end | 15 | end |
16 | 16 | ||
17 | context 'with valid attributes' do | 17 | context 'with valid attributes' do |
@@ -36,7 +36,7 @@ describe ReadingGroup, :type => :model do | @@ -36,7 +36,7 @@ describe ReadingGroup, :type => :model do | ||
36 | end | 36 | end |
37 | 37 | ||
38 | describe 'readings' do | 38 | describe 'readings' do |
39 | - subject { FactoryGirl.build(:reading_group) } | 39 | + subject { FactoryGirl.build(:reading_group_with_id) } |
40 | let(:reading) { FactoryGirl.build(:reading_with_id) } | 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 |