aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/workgroup_spec.rb
blob: 97fff3d866d32cf0e88c316d095a6bf9965d67bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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{ should validate_uniqueness_of(:stop_area_referential_id) }
    it{ should validate_uniqueness_of(:line_referential_id) }

    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