Sha256: 88a47ea8645789e6ae7f5d0b59ecbd6f27ce5926e2d08c4b7d37dc14902eb3af

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'rails_helper'

feature "TwitterOAuthRegistration", :type => :feature do
  include Warden::Test::Helpers

  before do
    OmniAuth.config.test_mode = true
    sign_out :user
  end

  after do
    Warden.test_reset!
    Rails.application.env_config["omniauth.auth"] = nil
  end

  it "should create a new user for a twitter user" do
    OmniAuth.config.add_mock(:twitter,  {
      uid: '12345',
      info: {
        name: "Will Schenk",
        nickname: "wschenk",
      }
      });

    visit user_twitter_omniauth_callback_path

    i = Identity.first
    expect( i.uid ).to eq( '12345' )
    expect( i.nickname ).to eq( 'wschenk' )
    expect( i.name ).to eq( 'Will Schenk' )

    expect( page.body ).to include( 'Successfully authenticated from Twitter account.' )
  end

  it "should merge the identity if the user already exists" do
    u = create( :user )
    login_as u, scope: :user

    expect( User.count ).to eq(1)
    expect( Identity.count ).to eq(0)

    OmniAuth.config.add_mock(:twitter,  {
      uid: '12345',
      info: {
        name: "Will Schenk",
        nickname: "wschenk",
      }
      });

    visit user_twitter_omniauth_callback_path

    expect( User.count ).to eq(1)
    expect( Identity.count ).to eq(1)

    expect( Identity.first.user_id ).to eq( u.id )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
happy_seed-0.0.21 lib/generators/happy_seed/twitter/templates/spec/features/twitter_oauth_registration_spec.rb