175 | 175 |
subject.raw_info['ohai'].should eq('thar')
|
176 | 176 |
end
|
177 | 177 |
end
|
|
178 |
|
|
179 |
describe '#credentials' do
|
|
180 |
before :each do
|
|
181 |
@access_token = double('OAuth2::AccessToken')
|
|
182 |
@access_token.stub(:token)
|
|
183 |
@access_token.stub(:expires?)
|
|
184 |
@access_token.stub(:expires_at)
|
|
185 |
@access_token.stub(:refresh_token)
|
|
186 |
subject.stub(:access_token) { @access_token }
|
|
187 |
end
|
|
188 |
|
|
189 |
it 'returns a Hash' do
|
|
190 |
subject.credentials.should be_a(Hash)
|
|
191 |
end
|
|
192 |
|
|
193 |
it 'returns the token' do
|
|
194 |
@access_token.stub(:token) { '123' }
|
|
195 |
subject.credentials['token'].should eq('123')
|
|
196 |
end
|
|
197 |
|
|
198 |
it 'returns the expiry status' do
|
|
199 |
@access_token.stub(:expires?) { true }
|
|
200 |
subject.credentials['expires'].should eq(true)
|
|
201 |
|
|
202 |
@access_token.stub(:expires?) { false }
|
|
203 |
subject.credentials['expires'].should eq(false)
|
|
204 |
end
|
|
205 |
|
|
206 |
it 'returns the refresh token and expiry time when expiring' do
|
|
207 |
ten_mins_from_now = (Time.now + 360).to_i
|
|
208 |
@access_token.stub(:expires?) { true }
|
|
209 |
@access_token.stub(:refresh_token) { '321' }
|
|
210 |
@access_token.stub(:expires_at) { ten_mins_from_now }
|
|
211 |
subject.credentials['refresh_token'].should eq('321')
|
|
212 |
subject.credentials['expires_at'].should eq(ten_mins_from_now)
|
|
213 |
end
|
|
214 |
|
|
215 |
# FIXME omniauth does not behave like this atm.
|
|
216 |
pending 'does not return the refresh token when it is nil and expiring' do
|
|
217 |
@access_token.stub(:expires?) { true }
|
|
218 |
@access_token.stub(:refresh_token) { nil }
|
|
219 |
subject.credentials['refresh_token'].should be_nil
|
|
220 |
subject.credentials.should_not have_key('refresh_token')
|
|
221 |
end
|
|
222 |
|
|
223 |
it 'does not return the refresh token when not expiring' do
|
|
224 |
@access_token.stub(:expires?) { false }
|
|
225 |
@access_token.stub(:refresh_token) { 'XXX' }
|
|
226 |
subject.credentials['refresh_token'].should be_nil
|
|
227 |
subject.credentials.should_not have_key('refresh_token')
|
|
228 |
end
|
|
229 |
end
|
|
230 |
|
|
231 |
describe '#extra' do
|
|
232 |
before :each do
|
|
233 |
@raw_info = { 'name' => 'Fred Smith' }
|
|
234 |
subject.stub(:raw_info) { @raw_info }
|
|
235 |
end
|
|
236 |
|
|
237 |
it 'returns a Hash' do
|
|
238 |
subject.extra.should be_a(Hash)
|
|
239 |
end
|
|
240 |
|
|
241 |
it 'contains raw info' do
|
|
242 |
subject.extra.should eq({ 'raw_info' => @raw_info })
|
|
243 |
end
|
|
244 |
end
|
178 | 245 |
end
|