Skip to content

Instantly share code, notes, and snippets.

@mauriciomdea
Created June 24, 2014 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauriciomdea/e56427693ef9a025ea9b to your computer and use it in GitHub Desktop.
Save mauriciomdea/e56427693ef9a025ea9b to your computer and use it in GitHub Desktop.
Omniauth Unit Tests
require 'test_helper'
class UserTest < ActiveSupport::TestCase
setup do
@user_from_linkedin = User.from_omniauth(OmniAuth.config.mock_auth[:linkedin])
@user_from_google = User.from_omniauth(OmniAuth.config.mock_auth[:google])
end
test "should create new user from omniauth hash" do
assert_equal 1, User.all.size, "Wrong number of total users"
assert_equal "mauriciomdea@gmail.com", @user_from_linkedin.email, "User not found"
end
test "should create new authentication for same email/user" do
assert_equal @user_from_linkedin._id, @user_from_google._id, "Different users found"
assert_equal 2, @user_from_google.authentications.size, "Incorrent number of authentications for user"
end
test "should authenticate user with existing authentication" do
login_from_google = User.from_omniauth(OmniAuth.config.mock_auth[:google])
assert_equal 2, @user_from_google.authentications.size, "Incorrent number of authentications for user after second login"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment