forked from lynndylanhurley/devise_token_auth
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,25 +146,28 @@ def get_parsed_data_json | |
end | ||
|
||
describe "oauth registration attr" do | ||
after do | ||
User.any_instance.unstub(:new_record?) | ||
end | ||
|
||
describe 'with new user' do | ||
before do | ||
User.any_instance.expects(:new_record?).returns(true).at_least_once | ||
end | ||
test 'registers the new user' do | ||
user_count = User.count | ||
assert_difference ->{ User.count }, 1 do | ||
get '/auth/facebook', params: { | ||
auth_origin_url: @redirect_url, | ||
omniauth_window_type: 'newWindow' | ||
} | ||
|
||
follow_all_redirects! | ||
end | ||
end | ||
|
||
test 'response contains oauth_registration attr' do | ||
get '/auth/facebook', params: { | ||
auth_origin_url: @redirect_url, | ||
omniauth_window_type: 'newWindow' | ||
} | ||
|
||
follow_all_redirects! | ||
|
||
assert_equal(user_count + 1, User.count) | ||
data = get_parsed_data_json | ||
assert(data['oauth_registration']) | ||
end | ||
|
||
test 'response contains correct attributes' do | ||
|
@@ -175,10 +178,11 @@ def get_parsed_data_json | |
|
||
follow_all_redirects! | ||
|
||
|
||
assert_equal(true, data['oauth_registration']) | ||
assert_equal('[email protected]', data['email']) | ||
assert_equal(@user.last.id, data['id']) | ||
@resource = assigns(:resource) | ||
data = get_parsed_data_json | ||
assert_equal('[email protected]', data['email']) | ||
assert_equal(@resource.email, data['email']) | ||
assert_equal(@resource.id, data['id']) | ||
end | ||
end | ||
|
||
|
@@ -194,23 +198,26 @@ def get_parsed_data_json | |
end | ||
|
||
test 'response does not contain oauth_registration attr' do | ||
get '/auth/facebook', | ||
params: { auth_origin_url: @redirect_url, | ||
omniauth_window_type: 'newWindow' } | ||
|
||
end | ||
|
||
test 'does not register a new user' do | ||
user_count = User.count | ||
|
||
get '/auth/facebook', params: { | ||
auth_origin_url: @redirect_url, | ||
omniauth_window_type: 'newWindow' | ||
} | ||
|
||
follow_all_redirects! | ||
|
||
assert_equal(user_count, User.count) | ||
data = get_parsed_data_json | ||
assert_nil(data['oauth_registration']) | ||
end | ||
|
||
test 'does not register a new user' do | ||
assert_no_difference ->{ User.count } do | ||
get '/auth/facebook', params: { | ||
auth_origin_url: @redirect_url, | ||
omniauth_window_type: 'newWindow' | ||
} | ||
|
||
follow_all_redirects! | ||
end | ||
end | ||
|
||
test 'response contains correct attributes' do | ||
|
@@ -223,7 +230,6 @@ def get_parsed_data_json | |
follow_all_redirects! | ||
|
||
data = get_parsed_data_json | ||
assert_equal(nil, data['oauth_registration']) | ||
assert_equal(@user.email, data['email']) | ||
assert_equal(@user.id, data['id']) | ||
end | ||
|