-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rescue from specific errors * fix codeclimate issues * add some changes to the rescues * add i18n prefix to MissingTranslationError * convert url to uri * rescue from Google::Apis::ClientError * reduce lines to 10 * add google api key and secret * stub google errors * add spec for server error * stub calendar uploader * add specs for update access token * use double quotes * fix typos and take the blame from Google :lol:
- Loading branch information
Showing
13 changed files
with
135 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ | |
# Table name: users | ||
# | ||
# id :integer not null, primary key | ||
# email :string default(""), not null | ||
# encrypted_password :string default(""), not null | ||
# email :string default(''), not null | ||
# encrypted_password :string default(''), not null | ||
# reset_password_token :string | ||
# reset_password_sent_at :datetime | ||
# remember_created_at :datetime | ||
|
@@ -150,4 +150,53 @@ | |
expect(result).to eq [group_only_ally_belongs_to] | ||
end | ||
end | ||
|
||
describe '#update_access_token' do | ||
let!(:user) do | ||
User.create(name: 'some name', | ||
email: '[email protected]', | ||
password: 'asdfasdf', | ||
token: 'some token') | ||
end | ||
|
||
request = { | ||
'refresh_token' => nil, | ||
'client_id' => ENV['GOOGLE_CLIENT_ID'], | ||
'client_secret' => ENV['GOOGLE_CLIENT_SECRET'], | ||
'grant_type' => 'refresh_token' | ||
} | ||
|
||
context 'when request is successful' do | ||
before do | ||
response = { | ||
'access_token': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', | ||
'token_type': 'bearer', | ||
'expires_in': 3600, | ||
'refresh_token': 'IwOGYzYTlmM2YxOTQ5MGE3YmNmMDFkNTVk', | ||
'scope': 'create' | ||
}.to_json | ||
|
||
Net::HTTP.stub(:post_form).with(URI.parse(User::OAUTH_TOKEN_URL), request) { double(body: response) } | ||
end | ||
|
||
it 'returns a new access token' do | ||
expect(user.update_access_token).to eq('MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3') | ||
end | ||
end | ||
|
||
context 'when request is unsuccessful' do | ||
before do | ||
response = { | ||
'error': 'invalid request', | ||
'error_description': 'Could not determine client ID from request.' | ||
}.to_json | ||
|
||
Net::HTTP.stub(:post_form).with(URI.parse(User::OAUTH_TOKEN_URL), request) { double(body: response) } | ||
end | ||
|
||
it 'returns a new access token' do | ||
expect { user.update_access_token }.to raise_error(NoMethodError) | ||
end | ||
end | ||
end | ||
end |