aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorAlban Peignier2018-01-10 17:45:23 +0100
committerGitHub2018-01-10 17:45:23 +0100
commitdf77b06a42277b3c36627a2bfaa84ddf501d9f5f (patch)
tree7f3ba79ebb0a9e831749b69cdf03e4b4ec7c6e56 /spec
parente9f9757ea558f90ed125c0284b9cb98539764b75 (diff)
parent0bc79220fbce288102ea470fa57f865ee8fdfb47 (diff)
downloadchouette-core-df77b06a42277b3c36627a2bfaa84ddf501d9f5f.tar.bz2
Merge pull request #215 from af83/5499-workgroup-model
Provide Workgroup model. Refs #5499
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/workbenches.rb1
-rw-r--r--spec/factories/workgroups.rb7
-rw-r--r--spec/models/workbench_spec.rb1
-rw-r--r--spec/models/workgroup_spec.rb30
4 files changed, 39 insertions, 0 deletions
diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb
index 0f26559d8..98fdd6ad9 100644
--- a/spec/factories/workbenches.rb
+++ b/spec/factories/workbenches.rb
@@ -7,5 +7,6 @@ FactoryGirl.define do
association :line_referential
association :stop_area_referential
association :output, factory: :referential_suite
+ association :workgroup
end
end
diff --git a/spec/factories/workgroups.rb b/spec/factories/workgroups.rb
new file mode 100644
index 000000000..792deddf8
--- /dev/null
+++ b/spec/factories/workgroups.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+ factory :workgroup do
+ sequence(:name) { |n| "Workgroup ##{n}" }
+ association :line_referential
+ association :stop_area_referential
+ end
+end
diff --git a/spec/models/workbench_spec.rb b/spec/models/workbench_spec.rb
index caff00ae4..2f1fe39da 100644
--- a/spec/models/workbench_spec.rb
+++ b/spec/models/workbench_spec.rb
@@ -12,6 +12,7 @@ RSpec.describe Workbench, :type => :model do
it { should belong_to(:organisation) }
it { should belong_to(:line_referential) }
it { should belong_to(:stop_area_referential) }
+ it { should belong_to(:workgroup) }
it { should belong_to(:output).class_name('ReferentialSuite') }
it { should have_many(:lines).through(:line_referential) }
diff --git a/spec/models/workgroup_spec.rb b/spec/models/workgroup_spec.rb
new file mode 100644
index 000000000..ac8d3fc98
--- /dev/null
+++ b/spec/models/workgroup_spec.rb
@@ -0,0 +1,30 @@
+require 'rails_helper'
+
+RSpec.describe Workgroup, type: :model do
+ context "associations" do
+ let( :workgroup ){ build_stubbed :workgroup, line_referential_id: 53, stop_area_referential_id: 42 }
+
+ it{ should have_many(:workbenches) }
+ it{ should validate_uniqueness_of(:name) }
+
+ it 'is not valid without a stop_area_referential' do
+ workgroup.stop_area_referential_id = nil
+ expect( workgroup ).not_to be_valid
+ end
+ it 'is not valid without a line_referential' do
+ workgroup.line_referential_id = nil
+ expect( workgroup ).not_to be_valid
+ end
+ it 'is valid with both assoications' do
+ expect( workgroup ).to be_valid
+ end
+ end
+
+ context "find organisations" do
+ let( :workgroup ){ create :workgroup }
+ let!( :workbench1 ){ create :workbench, workgroup: workgroup }
+ let!( :workbench2 ){ create :workbench, workgroup: workgroup }
+
+ it{ expect( Set.new(workgroup.organisations) ).to eq(Set.new([ workbench1.organisation, workbench2.organisation ])) }
+ end
+end