Sha256: 804ba2c4fee6dd2b6ecaea6ae7efbf51f7ebb394178d3daa2797e2e6598c47a3

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

describe Oauth2Provider::OauthAuthorization do
  before  { @authorization = FactoryGirl.create(:oauth_authorization) }
  subject { @authorization }

  it { should validate_presence_of(:client_uri) }
  it { VALID_URIS.each{|uri| should allow_value(uri).for(:client_uri) } }
  it { should validate_presence_of(:resource_owner_uri) }
  it { VALID_URIS.each{|uri| should allow_value(uri).for(:resource_owner_uri) } }

  its(:code) { should_not be_nil }
  its(:expire_at) { should_not be_nil }

  it { should_not be_blocked }
  context "#block" do
    before { subject.block! }
    it { should be_blocked }
  end

  context ".block_client!" do
    before { @another_client_authorization = FactoryGirl.create(:oauth_authorization, client_uri: ANOTHER_CLIENT_URI) }
    before { Oauth2Provider::OauthAuthorization.block_client!(CLIENT_URI) }

    it { @authorization.reload.should be_blocked }
    it { @another_client_authorization.reload.should_not be_blocked }
  end

  context ".block_access!" do
    before { @another_client_authorization = FactoryGirl.create(:oauth_authorization, client_uri: ANOTHER_CLIENT_URI)}
    before { @another_owner_authorization  = FactoryGirl.create(:oauth_authorization, resource_owner_uri: ANOTHER_USER_URI) }
    before { Oauth2Provider::OauthAuthorization.block_access!(CLIENT_URI, USER_URI) }

    it { @authorization.reload.should be_blocked }
    it { @another_client_authorization.reload.should_not be_blocked }
    it { @another_owner_authorization.reload.should_not be_blocked }
  end

  it "#expired?" do
    subject.should_not be_expired
    Delorean.time_travel_to("in 151 seconds")
    subject.should be_expired
  end

  it ".where_code_and_client_uri" do
    result = Oauth2Provider::OauthAuthorization.where_code_and_client_uri(subject.code, subject.client_uri).first
    result.should == subject
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
oauth2_provider_engine-0.0.2 test/dummy/spec/models/oauth/oauth_authorization_spec.rb
oauth2_provider_engine-0.0.1 test/dummy/spec/models/oauth/oauth_authorization_spec.rb