Skip to content

Commit 75e87fb

Browse files
committed
Improvements to User.from_omniauth spec setup
Previously this spec was making use of a `User` model and the `User#serializable_hash` method. However, I'm pretty sure that was just a convenience and there is nothing actually tying the attributes returned from OmniAuth to the `User` model attributes. I've changed the setup so it uses an explicit `Hash` derived from observing the attributes that OmniAuth actually provides. This seems more realistic and I'm hoping it will make it easier to apply an unrelated fix in a subsequent commit. I've also changed the assertions to be more explicit and like those in the specs for `User.from_userinfo` & `User.from_token`.
1 parent dce64da commit 75e87fb

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

spec/models/user_spec.rb

+21-5
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,22 @@
151151
describe '.from_omniauth' do
152152
subject(:auth_subject) { described_class.from_omniauth(auth) }
153153

154-
let(:user) { build(:user) }
155-
let(:info) { user.serializable_hash(except: :id) }
154+
let(:id) { 'f80ba5b2-2eee-457d-9f75-872b5c09be84' }
155+
let(:info) do
156+
{
157+
'id' => id,
158+
'email' => '[email protected]',
159+
'name' => 'John Doe',
160+
'roles' => 'school-student'
161+
}
162+
end
163+
let(:user) { described_class.new(info) }
156164

157165
let(:auth) do
158166
OmniAuth::AuthHash.new(
159167
{
160168
provider: 'rpi',
161-
uid: user.id,
169+
uid: id,
162170
extra: {
163171
raw_info: info
164172
}
@@ -170,8 +178,16 @@
170178
expect(auth_subject).to be_a described_class
171179
end
172180

173-
it 'sets the user attributes correctly' do
174-
expect(auth_subject.serializable_hash).to eq user.serializable_hash
181+
it 'returns a user with the correct ID' do
182+
expect(auth_subject.id).to eq id
183+
end
184+
185+
it 'returns a user with the correct name' do
186+
expect(auth_subject.name).to eq 'John Doe'
187+
end
188+
189+
it 'returns a user with the correct email' do
190+
expect(user.email).to eq '[email protected]'
175191
end
176192

177193
context 'with unusual keys in info' do

0 commit comments

Comments
 (0)