blob: 037537b60d38df8551174d38ea022a22ae92918c (
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
require 'rails_helper'
RSpec.describe Workbench, :type => :model do
it 'should have a valid factory' do
expect(FactoryGirl.build(:workbench)).to be_valid
end
it { should validate_presence_of(:name) }
it { should validate_presence_of(:organisation) }
it { should belong_to(:organisation) }
it { should belong_to(:line_referential) }
it { should belong_to(:stop_area_referential) }
it { should belong_to(:output).class_name('ReferentialSuite') }
it { should have_many(:lines).through(:line_referential) }
it { should have_many(:networks).through(:line_referential) }
it { should have_many(:companies).through(:line_referential) }
it { should have_many(:group_of_lines).through(:line_referential) }
it { should have_many(:stop_areas).through(:stop_area_referential) }
it do
# This callback interferes with the validation test
Workbench.skip_callback(:validation, :before, :initialize_output)
should validate_presence_of(:output)
Workbench.set_callback(:validation, :before, :initialize_output)
end
context '.lines' do
let!(:ids) { ['STIF:CODIFLIGNE:Line:C00840', 'STIF:CODIFLIGNE:Line:C00086'] }
let!(:organisation) { create :organisation, sso_attributes: { functional_scope: ids.to_json } }
let(:workbench) { create :workbench, organisation: organisation }
it 'should filter lines based on my organisation functional_scope' do
ids.insert('STIF:CODIFLIGNE:Line:0000').each do |id|
create :line, objectid: id, line_referential: workbench.line_referential
end
lines = workbench.lines
expect(lines.count).to eq 2
expect(lines.map(&:objectid)).to include(*ids)
end
end
describe ".create" do
it "must automatically create a ReferentialSuite when being created" do
workbench = Workbench.create
expect(workbench.output).to be_an_instance_of(ReferentialSuite)
end
it "must not overwrite a given ReferentialSuite" do
referential_suite = create(:referential_suite)
workbench = create(:workbench, output: referential_suite)
expect(workbench.output).to eq(referential_suite)
end
end
end
|