Skip to content

Instantly share code, notes, and snippets.

@rafaelrpbelo
Last active August 29, 2015 13:56
Show Gist options
  • Save rafaelrpbelo/9256942 to your computer and use it in GitHub Desktop.
Save rafaelrpbelo/9256942 to your computer and use it in GitHub Desktop.
Test facebook OAuth
#encoding: utf-8
require 'spec_helper'
describe "login com facebook" do
before do
request.env["devise.mapping"] = Devise.mappings[:user]
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook]
end
it "sets a session variable to the OmniAuth auth hash" do
request.env["omniauth.auth"]["provider"].should == :facebook
request.env["omniauth.auth"]['uid'].should == '1234'
request.env["omniauth.auth"]['uid'].should == '1234'
request.env["omniauth.auth"]['info']['name'].should == 'Jhon Doe'
request.env["omniauth.auth"]['info']['email'].should == 'jhondoe@email.com'
request.env["omniauth.auth"]['credentials']['token'].should == "testtoken234tsdf"
end
end
require 'simplecov'
SimpleCov.start 'rails'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.include Warden::Test::Helpers, :type => :feature
config.mock_with :rspec
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.screenshot_folder = 'tmp/errors'
config.screenshot_on_errors = false
config.screenshot_full = true
clear_screenshots_before_run = true
config.screenshot_on_errors = true
config.expect_with :rspec do |c|
c.syntax = :expect
end
end
# Config Omniauth Test
OmniAuth.config.test_mode = true
omniauth_hash =
{
:provider => "facebook",
:uid => "1234",
:info => {
:name => "John Doe",
:email => "johndoe@email.com"
},
:credentials => { :token => "testtoken234tsdf" }
}
OmniAuth.config.add_mock(:facebook, omniauth_hash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment