diff options
| -rw-r--r-- | app/models/organisation.rb | 3 | ||||
| -rw-r--r-- | spec/models/organisation_spec.rb | 13 | ||||
| -rw-r--r-- | spec/models/user_spec.rb | 7 | 
3 files changed, 15 insertions, 8 deletions
| diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 7a5678ef0..4d93b0ba6 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -44,7 +44,8 @@ class Organisation < ActiveRecord::Base      org = Organisation.find_or_initialize_by(code: code)      if scope        org.sso_attributes ||= {} -      org.sso_attributes[:functional_scope] = scope +      org.sso_attributes['functional_scope'] = scope +      org.sso_attributes_will_change!      end      org.name      = name      org.synced_at = Time.now diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 5cf2ded01..9b4235755 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -1,7 +1,6 @@  require 'spec_helper'  describe Organisation, :type => :model do -    it { should validate_presence_of(:name) }    it { should validate_uniqueness_of(:code) } @@ -40,13 +39,13 @@ describe Organisation, :type => :model do      end      it 'should update existing organisations' do -      create :organisation, name: 'dummy_name', code:'RATP', updated_at: 10.days.ago +      create :organisation, name: 'dummy_name', code:'RATP', updated_at: 10.days.ago, sso_attributes: {functional_scope: "[\"STIF:CODIFLIGNE:Line:C00840\"]"}        Organisation.portail_sync -      Organisation.find_by(code: 'RATP').tap do |org| -        expect(org.name).to eq('RATP') -        expect(org.updated_at.utc).to be_within(1.second).of Time.now -        expect(org.synced_at.utc).to be_within(1.second).of Time.now -      end +      org = Organisation.find_by(code: 'RATP') +      expect(org.name).to eq('RATP') +      expect(org.updated_at.utc).to be_within(1.second).of Time.now +      expect(org.synced_at.utc).to be_within(1.second).of Time.now +      expect(org.sso_attributes['functional_scope']).to eq "[\"STIF:CODIFLIGNE:Line:C00840\", \"STIF:CODIFLIGNE:Line:C00086\"]"      end      it 'should not create organisation if code is already present' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index bb43be63e..7d0a548c1 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -39,6 +39,13 @@ describe User, :type => :model do          expect(org.sso_attributes['functional_scope']).to eq "[\"STIF:CODIFLIGNE:Line:C00840\", \"STIF:CODIFLIGNE:Line:C00086\"]"        end +      it 'should update organisation functional_scope' do +        create :organisation, code: ticket.extra_attributes[:organisation_code], sso_attributes: {functional_scope: "[\"STIF:CODIFLIGNE:Line:C00840\"]"} +        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\"]" +      end +        it 'should not create a new organisation if organisation is already present' do          ticket.extra_attributes[:organisation_code] = create(:organisation).code          expect{User.authenticate_with_cas_ticket(ticket)}.not_to change{ Organisation.count } | 
