diff options
| author | Xinhui | 2016-08-03 15:56:12 +0200 |
|---|---|---|
| committer | Xinhui | 2016-08-03 15:56:12 +0200 |
| commit | 042fe3d039bdd91325bd8098cedcadc025713df6 (patch) | |
| tree | 6977a7691fea1f7cfc74d0172daca45badb05f56 /spec/models/user_spec.rb | |
| parent | 9aeb6fc4c44470541bbc09fc0831e23e3c77fa34 (diff) | |
| download | chouette-core-042fe3d039bdd91325bd8098cedcadc025713df6.tar.bz2 | |
Auto create user on SSO sign in
Diffstat (limited to 'spec/models/user_spec.rb')
| -rw-r--r-- | spec/models/user_spec.rb | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e22e53797..ea1170aa1 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,14 +1,49 @@ require 'spec_helper' describe User, :type => :model do - #it { should validate_uniqueness_of :email } - #it { should validate_presence_of :name } + # it { should validate_uniqueness_of :email } + # it { should validate_presence_of :name } + + describe "SSO" do + let(:ticket) do + CASClient::ServiceTicket.new("ST-test", nil).tap do |ticket| + ticket.extra_attributes = { + full_name: 'john doe', + username: 'xinhui.xu', + email: 'john.doe@af83.com', + organisation_code: '0083', + organisation_name: 'af83' + } + ticket.user = "xinhui.xu" + ticket.success = true + end + end + + it 'should create a new user if user is not registered' do + expect{User.authenticate_with_cas_ticket(ticket)}.to change{ User.count } + user = User.find_by(username: 'xinhui.xu') + expect(user.email).to eq(ticket.extra_attributes[:email]) + expect(user.name).to eq(ticket.extra_attributes[:full_name]) + end + + it 'should create a new organisation if organisation is not present' do + expect{User.authenticate_with_cas_ticket(ticket)}.to change{ Organisation.count } + end + + it 'should not create a new organisation if organisation is already present' do + organisation = create :organisation + ticket.extra_attributes[:organisation_name] = organisation.name + expect{User.authenticate_with_cas_ticket(ticket)}.not_to change{ Organisation.count } + end + end describe "#destroy" do let!(:organisation){create(:organisation)} let!(:user){create(:user, :organisation => organisation)} + context "user's organisation contains many user" do let!(:other_user){create(:user, :organisation => organisation)} + it "should destoy also user's organisation" do user.destroy expect(Organisation.where(:name => organisation.name).exists?).to be_truthy |
