Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Return boolean from `AccountTypes#student_account?` (#91)

### Removed

## [v4.2.1]
Expand Down
4 changes: 3 additions & 1 deletion lib/rpi_auth/models/account_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module AccountTypes
include Authenticatable

def student_account?
user_id =~ /^#{STUDENT_PREFIX}/o
return false if user_id.blank?

user_id.start_with?(STUDENT_PREFIX)
end
end
end
Expand Down
16 changes: 12 additions & 4 deletions spec/rpi_auth/models/account_types_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@
context "when user_id has the 'student:' prefix" do
let(:user_id) { RpiAuth::Models::AccountTypes::STUDENT_PREFIX + SecureRandom.uuid }

it 'returns truthy' do
expect(user).to be_student_account
it 'returns true' do
expect(user.student_account?).to be(true)
end
end

context "when user_id does not have the 'student:' prefix" do
let(:user_id) { SecureRandom.uuid }

it 'returns falsey' do
expect(user).not_to be_student_account
it 'returns false' do
expect(user.student_account?).to be(false)
end
end

context 'when user_id is not set' do
let(:user_id) { nil }

it 'returns false' do
expect(user.student_account?).to be(false)
end
end
end
Expand Down