aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert2017-10-23 10:12:14 +0200
committerRobert2017-10-23 10:12:14 +0200
commitc5e5e5bf1a7429dfa72bbd2f3d48eec7cac442a6 (patch)
tree9755ec73a3d6d1ede259209c82f0395d2e163be2
parentbeaa8e127e6b6104cb377c9a2be4a6e4ecae6da9 (diff)
downloadchouette-core-c5e5e5bf1a7429dfa72bbd2f3d48eec7cac442a6.tar.bz2
Faster Spex.
By using FactoryGirls's build strategy :build in associations the time penalty of using FactoryGirl instead of ActiveRecord stubs is down to a factor < 2.
-rw-r--r--spec/factories/referentials.rb21
-rw-r--r--spec/factories/workbenches.rb9
-rw-r--r--spec/models/faster_specs_spec.rb11
3 files changed, 33 insertions, 8 deletions
diff --git a/spec/factories/referentials.rb b/spec/factories/referentials.rb
index 5348ad96b..249d5831f 100644
--- a/spec/factories/referentials.rb
+++ b/spec/factories/referentials.rb
@@ -1,13 +1,24 @@
FactoryGirl.define do
- factory :referential do
+ factory :abstract_referential, class: Referential do
sequence(:name) { |n| "Test #{n}" }
sequence(:slug) { |n| "test_#{n}" }
sequence(:prefix) { |n| "test_#{n}" }
- association :organisation
- association :workbench
- association :line_referential
- association :stop_area_referential
+
time_zone "Europe/Paris"
ready { true }
+
+ factory :referential do
+ association :organisation
+ association :workbench
+ association :line_referential
+ association :stop_area_referential
+ end
+
+ factory :fast_referential do
+ association :organisation, strategy: :build
+ association :workbench, strategy: :build
+ association :line_referential, strategy: :build
+ association :stop_area_referential, strategy: :build
+ end
end
end
diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb
index 57bef2203..2e80b2869 100644
--- a/spec/factories/workbenches.rb
+++ b/spec/factories/workbenches.rb
@@ -7,4 +7,13 @@ FactoryGirl.define do
association :stop_area_referential
association :output, factory: :referential_suite
end
+
+ factory :fast_workbench, class: Workbench do
+ name "Fast Workbench"
+
+ association :organisation, strategy: :build
+ association :line_referential, strategy: :build
+ association :stop_area_referential, strategy: :build
+ association :output, factory: :referential_suite, strategy: :build
+ end
end
diff --git a/spec/models/faster_specs_spec.rb b/spec/models/faster_specs_spec.rb
index 5581eb076..1037e4487 100644
--- a/spec/models/faster_specs_spec.rb
+++ b/spec/models/faster_specs_spec.rb
@@ -31,8 +31,8 @@ RSpec.describe 'Faster Specs', type: :faster do
end
context 'with FactoryGirl' do
- let( :workbench ){ stub_model :workbench }
- let( :referential ){ stub_model( :referential, workbench: workbench ) }
+ let( :workbench ){ stub_model :fast_workbench }
+ let( :referential ){ stub_model( :fast_referential, workbench: workbench ) }
it_behaves_like 'correct behavior'
end
@@ -68,9 +68,14 @@ RSpec.describe 'Faster Specs', type: :faster do
end
context 'FactoryGirlMeta' do
- let( :workbench ){ stub_model :workbench }
+ let( :workbench ){ stub_model :fast_workbench }
it_behaves_like 'meta', :organisation
+ it 'check for associations in FactoryGirl' do
+ require 'pry'; binding.pry
+
+ end
+
end
end