|
28 | 28 | end |
29 | 29 | end |
30 | 30 |
|
31 | | - describe 'OmniAuth::Configuration#add_rpi_mock' do |
32 | | - subject(:mock_auth) { OmniAuth.config.mock_auth[:rpi] } |
33 | | - |
34 | | - let(:args) { {} } |
| 31 | + shared_examples 'a mocked auth object' do |
| 32 | + let(:raw_info) { extra[:raw_info] } |
35 | 33 |
|
36 | | - before do |
37 | | - OmniAuth.config.add_rpi_mock(**args) |
| 34 | + it 'has the uid' do |
| 35 | + expect(mock_auth.uid).to eq(uid) |
38 | 36 | end |
39 | 37 |
|
40 | | - it 'has the default uid' do |
41 | | - expect(mock_auth.uid).to eq(RpiAuthBypass::DEFAULT_UID) |
| 38 | + it 'has the email from info' do |
| 39 | + expect(mock_auth.info.email).to eq(info[:email]) |
42 | 40 | end |
43 | 41 |
|
44 | | - it 'has the default email' do |
45 | | - expect(mock_auth.info.email).to eq(RpiAuthBypass::DEFAULT_EMAIL) |
| 42 | + it 'has the username from info' do |
| 43 | + expect(mock_auth.info.username).to eq(info[:username]) |
46 | 44 | end |
47 | 45 |
|
48 | | - it 'has the default username' do |
49 | | - expect(mock_auth.info.username).to eq(RpiAuthBypass::DEFAULT_USERNAME) |
| 46 | + it 'has the name from info' do |
| 47 | + expect(mock_auth.info.name).to eq info[:name] |
50 | 48 | end |
51 | 49 |
|
52 | | - it 'has the default name' do |
53 | | - expect(mock_auth.info.name).to eq(RpiAuthBypass::DEFAULT_NAME) |
| 50 | + it 'has the nickname from info' do |
| 51 | + expect(mock_auth.info.nickname).to eq info[:nickname] |
54 | 52 | end |
55 | 53 |
|
56 | | - it 'has the default nickname' do |
57 | | - expect(mock_auth.info.nickname).to eq(RpiAuthBypass::DEFAULT_NICKNAME) |
| 54 | + it 'has the image from info' do |
| 55 | + expect(mock_auth.info.image).to eq info[:image] |
58 | 56 | end |
59 | 57 |
|
60 | | - it 'has the default image' do |
61 | | - expect(mock_auth.info.image).to eq(RpiAuthBypass::DEFAULT_IMAGE) |
| 58 | + it 'has the email from raw_info' do |
| 59 | + expect(mock_auth.extra.raw_info.email).to eq raw_info[:email] |
62 | 60 | end |
63 | 61 |
|
64 | | - it 'has the default roles' do |
65 | | - expect(mock_auth.extra.raw_info.roles).to eq(RpiAuthBypass::DEFAULT_ROLES) |
| 62 | + it 'has the username from raw_info' do |
| 63 | + expect(mock_auth.extra.raw_info.username).to eq raw_info[:username] |
66 | 64 | end |
67 | 65 |
|
68 | | - it 'has the default avatar' do |
69 | | - expect(mock_auth.extra.raw_info.avatar).to eq(RpiAuthBypass::DEFAULT_IMAGE) |
| 66 | + it 'has the name from raw_info' do |
| 67 | + expect(mock_auth.extra.raw_info.name).to eq raw_info[:name] |
70 | 68 | end |
71 | 69 |
|
72 | | - it 'has the default profile' do |
73 | | - expect(mock_auth.extra.raw_info.profile).to eq(RpiAuthBypass::DEFAULT_PROFILE) |
| 70 | + it 'has the nickname from raw_info' do |
| 71 | + expect(mock_auth.extra.raw_info.nickname).to eq raw_info[:nickname] |
74 | 72 | end |
75 | 73 |
|
76 | | - it 'has the default country' do |
77 | | - expect(mock_auth.extra.raw_info.country).to eq(RpiAuthBypass::DEFAULT_COUNTRY) |
| 74 | + it 'has the roles from raw_info' do |
| 75 | + expect(mock_auth.extra.raw_info.roles).to eq raw_info[:roles] |
78 | 76 | end |
79 | 77 |
|
80 | | - it 'has the default country code' do |
81 | | - expect(mock_auth.extra.raw_info.country_code).to eq(RpiAuthBypass::DEFAULT_COUNTRY_CODE) |
| 78 | + it 'has the sub from raw_info' do |
| 79 | + expect(mock_auth.extra.raw_info.sub).to eq raw_info[:sub] |
82 | 80 | end |
83 | 81 |
|
84 | | - it 'has the default postcode' do |
85 | | - expect(mock_auth.extra.raw_info.postcode).to eq(RpiAuthBypass::DEFAULT_POSTCODE) |
| 82 | + it 'has the user from raw_info' do |
| 83 | + expect(mock_auth.extra.raw_info.user).to eq raw_info[:user] |
86 | 84 | end |
87 | 85 |
|
88 | | - context 'with info and extra specified' do # rubocop:disable RSpec/MultipleMemoizedHelpers |
89 | | - let(:uid) { '1d27cca2-fef3-4f79-bc64-b76e93db84a2' } |
90 | | - let(:name) { 'Robert Flemming' } |
91 | | - let(:nickname) { 'Bob' } |
92 | | - let(:email) { 'bob.flemming@example.com' } |
93 | | - let(:username) { 'bob.flemming' } |
94 | | - let(:roles) { 'gardener' } |
95 | | - let(:image) { 'https://my.avatar.com/image/1' } |
96 | | - let(:profile) { 'https://my.user.com/profile/1' } |
97 | | - let(:country) { 'United States' } |
98 | | - let(:country_code) { 'US' } |
99 | | - let(:postcode) { '123456' } |
100 | | - |
101 | | - let(:info) { { name: name, email: email, username: username, nickname: nickname, image: image } } |
102 | | - let(:extra) do |
103 | | - { raw_info: { |
104 | | - name: name, |
105 | | - email: email, |
106 | | - username: username, |
107 | | - nickname: nickname, |
108 | | - roles: roles, |
109 | | - avatar: image, |
110 | | - profile: profile, |
111 | | - country: country, |
112 | | - country_code: country_code, |
113 | | - postcode: postcode |
114 | | - } } |
115 | | - end |
116 | | - let(:args) { { uid: uid, info: info, extra: extra } } |
117 | | - |
118 | | - it 'has the uid' do |
119 | | - expect(mock_auth.uid).to eq(uid) |
120 | | - end |
121 | | - |
122 | | - it 'has the email from info' do |
123 | | - expect(mock_auth.info.email).to eq(email) |
124 | | - end |
125 | | - |
126 | | - it 'has the username from info' do |
127 | | - expect(mock_auth.info.username).to eq(username) |
128 | | - end |
129 | | - |
130 | | - it 'has the name from info' do |
131 | | - expect(mock_auth.info.name).to eq(name) |
132 | | - end |
133 | | - |
134 | | - it 'has the nickname from info' do |
135 | | - expect(mock_auth.info.nickname).to eq(nickname) |
136 | | - end |
| 86 | + it 'has the profile from raw_info' do |
| 87 | + expect(mock_auth.extra.raw_info.profile).to eq raw_info[:profile] |
| 88 | + end |
137 | 89 |
|
138 | | - it 'has the image from info' do |
139 | | - expect(mock_auth.info.image).to eq(image) |
140 | | - end |
| 90 | + it 'has the country from raw_info' do |
| 91 | + expect(mock_auth.extra.raw_info.country).to eq raw_info[:country] |
| 92 | + end |
141 | 93 |
|
142 | | - it 'has the email from extra' do |
143 | | - expect(mock_auth.extra.raw_info.email).to eq(email) |
144 | | - end |
| 94 | + it 'has the country_code from raw_info' do |
| 95 | + expect(mock_auth.extra.raw_info.country_code).to eq raw_info[:country_code] |
| 96 | + end |
145 | 97 |
|
146 | | - it 'has the username from extra' do |
147 | | - expect(mock_auth.extra.raw_info.username).to eq(username) |
148 | | - end |
| 98 | + it 'has the postcode from raw_info' do |
| 99 | + expect(mock_auth.extra.raw_info.postcode).to eq raw_info[:postcode] |
| 100 | + end |
| 101 | + end |
149 | 102 |
|
150 | | - it 'has the name from extra' do |
151 | | - expect(mock_auth.extra.raw_info.name).to eq(name) |
152 | | - end |
| 103 | + describe 'OmniAuth::Configuration#add_rpi_mock' do |
| 104 | + subject(:mock_auth) { OmniAuth.config.mock_auth[:rpi] } |
153 | 105 |
|
154 | | - it 'has the nickname from extra' do |
155 | | - expect(mock_auth.extra.raw_info.nickname).to eq(nickname) |
156 | | - end |
| 106 | + let(:args) { {} } |
| 107 | + let(:uid) { RpiAuthBypass::DEFAULT_UID } |
| 108 | + let(:info) { RpiAuthBypass::DEFAULT_INFO } |
| 109 | + let(:extra) { RpiAuthBypass::DEFAULT_EXTRA } |
157 | 110 |
|
158 | | - it 'has the roles from extra' do |
159 | | - expect(mock_auth.extra.raw_info.roles).to eq(roles) |
160 | | - end |
| 111 | + before do |
| 112 | + OmniAuth.config.add_rpi_mock(**args) |
| 113 | + end |
161 | 114 |
|
162 | | - it 'has the avatar from extra' do |
163 | | - expect(mock_auth.extra.raw_info.avatar).to eq(image) |
164 | | - end |
| 115 | + it_behaves_like 'a mocked auth object' |
165 | 116 |
|
166 | | - it 'has the profile from extra' do |
167 | | - expect(mock_auth.extra.raw_info.profile).to eq(profile) |
168 | | - end |
| 117 | + context 'with info and extra specified' do |
| 118 | + let(:uid) { '1d27cca2-fef3-4f79-bc64-b76e93db84a2' } |
169 | 119 |
|
170 | | - it 'has the country from extra' do |
171 | | - expect(mock_auth.extra.raw_info.country).to eq(country) |
| 120 | + let(:info) do |
| 121 | + { |
| 122 | + name: 'Robert Flemming', |
| 123 | + email: 'bob.flemming@example.com', |
| 124 | + username: 'bob.flemming', |
| 125 | + nickname: 'Bob', |
| 126 | + image: 'https://my.avatar.com/image/1' |
| 127 | + } |
172 | 128 | end |
173 | 129 |
|
174 | | - it 'has the country_code from extra' do |
175 | | - expect(mock_auth.extra.raw_info.country_code).to eq(country_code) |
| 130 | + let(:extra) do |
| 131 | + { raw_info: { |
| 132 | + country: 'US', |
| 133 | + country_code: 'United States', |
| 134 | + email: info[:email], |
| 135 | + name: info[:name], |
| 136 | + nickname: info[:nickname], |
| 137 | + postcode: '90210', |
| 138 | + profile: 'https://my.user.com/profile/1', |
| 139 | + roles: 'gardener', |
| 140 | + sub: uid, |
| 141 | + user: uid, |
| 142 | + username: info[:username] |
| 143 | + } } |
176 | 144 | end |
| 145 | + let(:args) { { uid: uid, info: info, extra: extra } } |
177 | 146 |
|
178 | | - it 'has the postcode from extra' do |
179 | | - expect(mock_auth.extra.raw_info.postcode).to eq(postcode) |
180 | | - end |
| 147 | + it_behaves_like 'a mocked auth object' |
181 | 148 | end |
182 | 149 | end |
183 | 150 | end |
0 commit comments