diff options
Diffstat (limited to 'spec/models')
| -rw-r--r-- | spec/models/organisation_spec.rb | 2 | ||||
| -rw-r--r-- | spec/models/user_spec.rb | 2 | ||||
| -rw-r--r-- | spec/models/workbench_spec.rb | 23 |
3 files changed, 24 insertions, 3 deletions
diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index c0aba2eb8..823ee7ea6 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -36,7 +36,7 @@ describe Organisation, :type => :model do it 'should retrieve functional scope' do Organisation.portail_sync org = Organisation.find_by(code: 'RATP') - expect(org.sso_attributes['functional_scope']).to eq "[STIF:CODIFLIGNE:Line:C00840, STIF:CODIFLIGNE:Line:C00086]" + expect(org.sso_attributes['functional_scope']).to eq "[\"STIF:CODIFLIGNE:Line:C00840\", \"STIF:CODIFLIGNE:Line:C00086\"]" end it 'should update existing organisations' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index c20e80ca1..bb43be63e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -36,7 +36,7 @@ describe User, :type => :model do it 'should store organisation functional_scope' do User.authenticate_with_cas_ticket(ticket) org = Organisation.find_by(code: ticket.extra_attributes[:organisation_code]) - expect(org.sso_attributes['functional_scope']).to eq "[STIF:CODIFLIGNE:Line:C00840, STIF:CODIFLIGNE:Line:C00086]" + expect(org.sso_attributes['functional_scope']).to eq "[\"STIF:CODIFLIGNE:Line:C00840\", \"STIF:CODIFLIGNE:Line:C00086\"]" end it 'should not create a new organisation if organisation is already present' do diff --git a/spec/models/workbench_spec.rb b/spec/models/workbench_spec.rb index 023a65ea2..84149ddb0 100644 --- a/spec/models/workbench_spec.rb +++ b/spec/models/workbench_spec.rb @@ -1,7 +1,6 @@ require 'rails_helper' RSpec.describe Workbench, :type => :model do - it 'should have a valid factory' do expect(FactoryGirl.build(:workbench)).to be_valid end @@ -12,4 +11,26 @@ 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 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) } + + 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 end |
