From 72806a4961e4240cff955c66fff1840e40301b89 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 25 Sep 2017 16:17:04 +0200 Subject: Workbench: Validate presence of `output` Ensure all workbenches always have an associated `ReferentialSuite` by validating presence of the `output` attribute. In order to pass the 'should have a valid factory' test, we need to define a `ReferentialSuite` factory and set up a default association on `output` in the `Workbench` factory. We also need to add set `output` when creating a `Workbench` in `spec/support/referential.rb`, otherwise we get a validation error that breaks the tests. Clean up the formatting of that call. In order to pass a `ReferentialSuite`, I just create one above, but I'm not sure if I should be using a `find_or_create` mechanism like the other associated objects do above. Refs #3520 --- spec/support/referential.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'spec/support/referential.rb') diff --git a/spec/support/referential.rb b/spec/support/referential.rb index 3b74cb639..9c7108eb9 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -52,7 +52,15 @@ RSpec.configure do |config| referential.add_member organisation, owner: true end - workbench = Workbench.create!(:name => "Gestion de l'offre", organisation: organisation, line_referential: line_referential, stop_area_referential: stop_area_referential) + referential_suite = ReferentialSuite.create + + workbench = Workbench.create!( + name: "Gestion de l'offre", + organisation: organisation, + line_referential: line_referential, + stop_area_referential: stop_area_referential, + output: referential_suite + ) referential = Referential.create! prefix: "first", name: "first", slug: "first", organisation: organisation, workbench: workbench end -- cgit v1.2.3 From e9a87b0fcc7c41174f50033f045c789f6a00f22f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 25 Sep 2017 17:36:38 +0200 Subject: spec/support/referential.rb: Remove `output` initialisation Since the `output` attribute is now initialised automatically in the `Workbench#initialize_output` `before_validation` callback, the one I added here before I created the callback can be removed. Instead we'll rely on the callback to create a new `ReferentialSuite` for us. Refs #3520 --- spec/support/referential.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'spec/support/referential.rb') diff --git a/spec/support/referential.rb b/spec/support/referential.rb index 9c7108eb9..37c3c0a82 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -52,14 +52,11 @@ RSpec.configure do |config| referential.add_member organisation, owner: true end - referential_suite = ReferentialSuite.create - workbench = Workbench.create!( name: "Gestion de l'offre", organisation: organisation, line_referential: line_referential, - stop_area_referential: stop_area_referential, - output: referential_suite + stop_area_referential: stop_area_referential ) referential = Referential.create! prefix: "first", name: "first", slug: "first", organisation: organisation, workbench: workbench end -- cgit v1.2.3 From d1bd434d78972d4f4156f3e3e864e075cad9e62d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 27 Sep 2017 12:54:53 +0200 Subject: spec/support/referential.rb: Use factories Instead of creating the objects directly in ActiveRecord, use our existing factories for these records as suggested by Robert. Refs #3520 --- spec/support/referential.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'spec/support/referential.rb') diff --git a/spec/support/referential.rb b/spec/support/referential.rb index 37c3c0a82..6f60bd86b 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -52,13 +52,21 @@ RSpec.configure do |config| referential.add_member organisation, owner: true end - workbench = Workbench.create!( + workbench = FactoryGirl.create( + :workbench, name: "Gestion de l'offre", organisation: organisation, line_referential: line_referential, stop_area_referential: stop_area_referential ) - referential = Referential.create! prefix: "first", name: "first", slug: "first", organisation: organisation, workbench: workbench + referential = FactoryGirl.create( + :referential, + prefix: "first", + name: "first", + slug: "first", + organisation: organisation, + workbench: workbench + ) end config.before(:each) do -- cgit v1.2.3