Skip to content

Commit fd6e958

Browse files
committed
Duplicacy of access_token is tested #5
1 parent cb93ea9 commit fd6e958

File tree

3 files changed

+28
-126
lines changed

3 files changed

+28
-126
lines changed

config/initializers/google_oauth.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010

1111
OmniAuth.config.on_failure = Proc.new { |env|
1212
OmniAuth::FailureEndpoint.new(env).redirect_to_failure
13-
}
13+
}

spec/controllers/spreadsheets_controller_spec.rb

+27-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@
66
context 'GET User Permission' do
77
context 'User accepts' do
88
it 'redirects to new ' do
9-
VCR.use_cassette 'controllers/api-permissions' do
9+
VCR.use_cassette 'controllers/api-permissions-denied' do
10+
=begin
1011
data = {
1112
name: 'google',
1213
scope: 'userinfo.profile,userinfo.email,drive,https://spreadsheets.google.com/feeds',
1314
prompt: 'consent',
1415
access_type: 'offline',
1516
redirect_uri: 'http://localhost:8080/auth/google/callback'
1617
}
17-
RestClient.post 'https://accounts.google.com/o/oauth2/auth', data
18+
RestClient.get 'https://accounts.google.com/o/oauth2/auth',
19+
name: 'google',
20+
scope: 'userinfo.profile,userinfo.email,drive,https://spreadsheets.google.com/feeds',
21+
prompt: 'consent',
22+
access_type: 'offline',
23+
redirect_uri: 'http://localhost:8080/auth/google/callback'
24+
=end
1825
end
1926

2027
end
@@ -36,6 +43,7 @@
3643
end
3744

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

55-
let(:sheet) { FactoryGirl.create(:spreadsheet)}
5663
it 'does not creates new spreadsheet when access_token is given' do
5764
VCR.use_cassette 'controllers/api-response' do
5865
get(:new, access_token: sheet.access_token)
5966
expect(response).to render_template(:new)
6067
end
6168
end
69+
70+
it 'does not creates new spreadsheet if access_token already present' do
71+
sheet
72+
73+
VCR.use_cassette 'controllers/api-new_tokens' do
74+
request.env['omniauth.auth'] = {
75+
'credentials' => {
76+
'token' => sheet[:access_token],
77+
'refresh_token' => sheet[:refresh_token],
78+
'expires_at' => Time.now,
79+
'expires' => true
80+
}
81+
}
82+
get :new
83+
expect(assigns(:msg)).not_to be(nil)
84+
end
85+
end
6286
end
6387

6488
context 'Get Edit' do

spec/vcr/controllers/api-permissions.yml

-122
This file was deleted.

0 commit comments

Comments
 (0)