Skip to content

Commit

Permalink
Duplicacy of access_token is tested #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Pbasnal committed Jul 15, 2014
1 parent 74b7411 commit 69161ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 126 deletions.
2 changes: 1 addition & 1 deletion config/initializers/google_oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

OmniAuth.config.on_failure = Proc.new { |env|
OmniAuth::FailureEndpoint.new(env).redirect_to_failure
}
}
30 changes: 27 additions & 3 deletions spec/controllers/spreadsheets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
context 'GET User Permission' do
context 'User accepts' do
it 'redirects to new ' do
VCR.use_cassette 'controllers/api-permissions' do
VCR.use_cassette 'controllers/api-permissions-denied' do
=begin
data = {
name: 'google',
scope: 'userinfo.profile,userinfo.email,drive,https://spreadsheets.google.com/feeds',
prompt: 'consent',
access_type: 'offline',
redirect_uri: 'http://localhost:8080/auth/google/callback'
}
RestClient.post 'https://accounts.google.com/o/oauth2/auth', data
RestClient.get 'https://accounts.google.com/o/oauth2/auth',
name: 'google',
scope: 'userinfo.profile,userinfo.email,drive,https://spreadsheets.google.com/feeds',
prompt: 'consent',
access_type: 'offline',
redirect_uri: 'http://localhost:8080/auth/google/callback'
=end
end

end
Expand All @@ -36,6 +43,7 @@
end

context 'GET New' do
let(:sheet) { FactoryGirl.create(:spreadsheet)}
it 'creates new spreadsheet when no access_token given' do
VCR.use_cassette 'controllers/api-new_tokens' do
request.env['omniauth.auth'] = {
Expand All @@ -52,13 +60,29 @@
end
end

let(:sheet) { FactoryGirl.create(:spreadsheet)}
it 'does not creates new spreadsheet when access_token is given' do
VCR.use_cassette 'controllers/api-response' do
get(:new, access_token: sheet.access_token)
expect(response).to render_template(:new)
end
end

it 'does not creates new spreadsheet if access_token already present' do
sheet

VCR.use_cassette 'controllers/api-new_tokens' do
request.env['omniauth.auth'] = {
'credentials' => {
'token' => sheet[:access_token],
'refresh_token' => sheet[:refresh_token],
'expires_at' => Time.now,
'expires' => true
}
}
get :new
expect(assigns(:msg)).not_to be(nil)
end
end
end

context 'Get Edit' do
Expand Down
122 changes: 0 additions & 122 deletions spec/vcr/controllers/api-permissions.yml

This file was deleted.

0 comments on commit 69161ef

Please sign in to comment.