aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-06-07 13:12:56 +0200
committerTeddy Wing2017-06-07 13:19:05 +0200
commit073ac0eb3330787532f551d20abe4600a0615446 (patch)
tree718a94ffce47975414d9d0fce39f247f4b4ea0ad
parentf3ae5267d8b38f6c1ba3ab4e4ba2a0b4f0313e48 (diff)
downloadchouette-core-073ac0eb3330787532f551d20abe4600a0615446.tar.bz2
factories/workbenches: Add a new `:with_referential` trait
This new trait allows us to create a referential association along with the workbench. Works like this: create(:workbench, :with_referential) We do this to allow us to reuse the `organisation`, `line_referential`, and `stop_area_referential` associations to ensure that the values of those fields are consistent in both the resulting workbench and referential objects. If we need to create multiple referentials, we could add an `amount` later. Left in some commented code describing my earlier attempts at this. Fortunately, found this Stack Overflow post that pointed me in the right direction: https://stackoverflow.com/questions/20685322/how-to-create-an-association-in-factorygirl-with-a-value-lazy-evaluated-from-ano I need this for a new `spec/helpers/table_builder_helper_spec.rb` spec, wherein I'm trying to test building a table of workspaces, but having trouble with code I copied from the app that tries to get `#validity_period` from workbenches. Thought at first that adding a referential (which does have this field) could help get past that, but it didn't quite work. Needs more investigation. Refs #3479
-rw-r--r--spec/factories/workbenches.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb
index f51e7d94c..154482213 100644
--- a/spec/factories/workbenches.rb
+++ b/spec/factories/workbenches.rb
@@ -5,5 +5,24 @@ FactoryGirl.define do
association :organisation, :factory => :organisation
association :line_referential
association :stop_area_referential
+
+ trait :with_referential do
+ # TODO: change all => to :
+ # association :referential,
+ # organisation: { organisation }
+
+ # after(:stub) do |workbench, evaluator|
+ #
+ # end
+
+ referentials do |workbench|
+ [association(
+ :referential,
+ organisation: workbench.organisation,
+ line_referential: workbench.line_referential,
+ stop_area_referential: workbench.stop_area_referential
+ )]
+ end
+ end
end
end