diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bc8f59..d639457 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/lib/rpi_auth/models/account_types.rb b/lib/rpi_auth/models/account_types.rb index 6d30cdc..d67bfca 100644 --- a/lib/rpi_auth/models/account_types.rb +++ b/lib/rpi_auth/models/account_types.rb @@ -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 diff --git a/spec/rpi_auth/models/account_types_spec.rb b/spec/rpi_auth/models/account_types_spec.rb index 339c7db..2d6181b 100644 --- a/spec/rpi_auth/models/account_types_spec.rb +++ b/spec/rpi_auth/models/account_types_spec.rb @@ -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