aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/workgroup_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/workgroup_spec.rb')
-rw-r--r--spec/models/workgroup_spec.rb28
1 files changed, 24 insertions, 4 deletions
diff --git a/spec/models/workgroup_spec.rb b/spec/models/workgroup_spec.rb
index 7d7b3cf87..ac8d3fc98 100644
--- a/spec/models/workgroup_spec.rb
+++ b/spec/models/workgroup_spec.rb
@@ -1,10 +1,30 @@
require 'rails_helper'
RSpec.describe Workgroup, type: :model do
- let( :workgroup ){ build_stubbed :workgroup }
+ context "associations" do
+ let( :workgroup ){ build_stubbed :workgroup, line_referential_id: 53, stop_area_referential_id: 42 }
- it 'is not valid without a stop_area_referential' do
- workgroup.line_referential_id = 42
- expect( workgroup ).not_to be_valid
+ 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