Skip to content

Commit

Permalink
Fix failing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan-M committed Feb 13, 2018
1 parent 3b3444b commit 90e1270
Showing 1 changed file with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 90e1270

Please sign in to comment.