Skip to content

Commit

Permalink
Adds user.rb tests to boost coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
danschmidt5189 committed Jan 28, 2025
1 parent ee52d76 commit f47fa99
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
class User < ApplicationRecord

# Connects this user object to Blacklights Bookmarks.
include Blacklight::User

# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :omniauthable, omniauth_providers: [:calnet]

class << self
# Finds or creates a user record given data from the omniauth request hash
def from_calnet(auth)
Expand All @@ -21,6 +22,7 @@ def fake_email
"fake-#{SecureRandom.hex[0, 16]}@noemail.com"
end
end

# Method added by Blacklight; Blacklight uses #to_s on your
# user class to get a user-displayable login/identifier for
# the account.
Expand Down
19 changes: 19 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'rails_helper'

RSpec.describe User do
describe 'initialization from calnet' do
# @todo Is this still valid since the switch from berkeleyEduOfficialEmail?
it 'assigns the user their berkeleyEduOfficialEmail' do
uid = 12_345
User.from_calnet(OmniAuth::AuthHash.new({
'uid' => uid,
'extra' => {
'berkeleyEduOfficialEmail' => '[email protected]'
}
}))

user = User.find_by(calnet_uid: uid)
expect(user.email).to eq '[email protected]'
end
end
end

0 comments on commit f47fa99

Please sign in to comment.