aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorTeddy Wing2017-09-25 16:17:04 +0200
committerTeddy Wing2017-09-25 16:56:10 +0200
commit72806a4961e4240cff955c66fff1840e40301b89 (patch)
treec9caf1d9634a5665d9bd05c3d10121a145b09a4e /spec
parent972cbb129747feb15c3c6c5ab5eabea2d7c045e1 (diff)
downloadchouette-core-72806a4961e4240cff955c66fff1840e40301b89.tar.bz2
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
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/referential_suites.rb3
-rw-r--r--spec/factories/workbenches.rb1
-rw-r--r--spec/models/workbench_spec.rb2
-rw-r--r--spec/support/referential.rb10
4 files changed, 15 insertions, 1 deletions
diff --git a/spec/factories/referential_suites.rb b/spec/factories/referential_suites.rb
new file mode 100644
index 000000000..bb17b085c
--- /dev/null
+++ b/spec/factories/referential_suites.rb
@@ -0,0 +1,3 @@
+FactoryGirl.define do
+ factory :referential_suite
+end
diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb
index d55141513..57bef2203 100644
--- a/spec/factories/workbenches.rb
+++ b/spec/factories/workbenches.rb
@@ -5,5 +5,6 @@ FactoryGirl.define do
association :organisation
association :line_referential
association :stop_area_referential
+ association :output, factory: :referential_suite
end
end
diff --git a/spec/models/workbench_spec.rb b/spec/models/workbench_spec.rb
index 617f34bb1..f83342f75 100644
--- a/spec/models/workbench_spec.rb
+++ b/spec/models/workbench_spec.rb
@@ -20,6 +20,8 @@ RSpec.describe Workbench, :type => :model do
it { should have_many(:stop_areas).through(:stop_area_referential) }
+ it { should validate_presence_of(:output) }
+
context '.lines' do
let!(:ids) { ['STIF:CODIFLIGNE:Line:C00840', 'STIF:CODIFLIGNE:Line:C00086'] }
let!(:organisation) { create :organisation, sso_attributes: { functional_scope: ids.to_json } }
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