aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/user_spec.rb
diff options
context:
space:
mode:
authorXinhui2016-08-04 11:24:07 +0200
committerXinhui2016-08-04 11:47:56 +0200
commit3baf4f5de6ed6023adb4daa4c6c06f03b204ec1c (patch)
tree621f2784a317c0bbb473ac57436dc8bc8655535d /spec/models/user_spec.rb
parent3dc76115b605dd69c3bc0e24a48860ab874228b8 (diff)
downloadchouette-core-3baf4f5de6ed6023adb4daa4c6c06f03b204ec1c.tar.bz2
Refactoring user cas_extra_attributes
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r--spec/models/user_spec.rb49
1 files changed, 31 insertions, 18 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 9c9efce4b..5d88fb209 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -8,32 +8,45 @@ describe User, :type => :model 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'
+ :full_name => 'john doe',
+ :username => 'john.doe',
+ :email => 'john.doe@af83.com',
+ :organisation_code => '0083',
+ :organisation_name => 'af83'
}
- ticket.user = "xinhui.xu"
+ ticket.user = "john.doe"
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
+ context 'First time sign on' do
+ 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: 'john.doe')
+ 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 }
+ expect(Organisation.find_by(code: ticket.extra_attributes[:organisation_code])).to be_truthy
+ end
- it 'should create a new organisation if organisation is not present' do
- expect{User.authenticate_with_cas_ticket(ticket)}.to change{ Organisation.count }
+ 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 }
+ end
end
- it 'should not create a new organisation if organisation is already present' do
- organisation = create :organisation
- ticket.extra_attributes[:organisation_code] = organisation.code
- expect{User.authenticate_with_cas_ticket(ticket)}.not_to change{ Organisation.count }
+ context 'Update attributes on sign on' do
+ let!(:organisation) { create(:organisation) }
+ let!(:user) { create(:user, username: 'john.doe', name:'fake name' , email: 'test@example.com', :organisation => organisation) }
+
+ it 'should update user attributes on sign on' do
+ User.authenticate_with_cas_ticket(ticket)
+ expect(user.reload.email).to eq(ticket.extra_attributes[:email])
+ expect(user.reload.name).to eq(ticket.extra_attributes[:full_name])
+ end
end
end