Sha256: 12c6ca703489538512419f1dd53ef77af65484ccb09ca4cfa667d632d53aa7e4

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'

describe Models::Users::Authentication do
  it { should validate_presence_of(:application_id) }
  it { should validate_presence_of(:omniauth) }
  it { should validate_presence_of(:provider) }
  it { should validate_presence_of(:uid) }
  it { should validate_presence_of(:user_id) }

  it { should ensure_length_of(:provider).is_at_most(128) }
  it { should ensure_length_of(:uid).is_at_most(1024) }

  it { should belong_to(:user) }

  let(:application_id) { 123 }
  let(:omniauth) { {
    'provider' => 'twitter',
    'uid' => 'gavinjoyce',
    'email' => 'gavinjoyce@gmail.com'
  } }

  describe '#from_omniauth' do
    it "constructs a new Authentication" do
      authentication = subject.class.from_omniauth(application_id, omniauth)
      authentication.id.should == nil
      authentication.application_id.should == application_id
      authentication.provider.should == 'twitter'
      authentication.uid.should == 'gavinjoyce'
      authentication.omniauth.should == omniauth
    end
  end

  describe '#get_from_omniauth' do
    context "a valid omniauth" do
      before do
        @user_id = 999
        @auth = subject.class.from_omniauth(application_id, omniauth)
        @auth.user_id = @user_id
        @auth.save!
      end

      it "returns the correct authentication" do
        auth = subject.class.get_by_omniauth(application_id, @auth.omniauth)
        auth.id.should == @auth.id
        auth.user_id.should == @user_id
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
restpack_user_service-0.0.5 spec/models/authentication_spec.rb