Sha256: a60c89ee853ac0331e129e48a0bb5b9cc15944d755b8044e54137a8dc84dde9f

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

describe Oauth2Provider::OauthAccess do
  before { @access = FactoryGirl.create(:oauth_access) }
  subject { @access }

  it { should validate_presence_of(:client_uri) }
  it { should validate_presence_of(:resource_owner_uri) }
  it { should_not be_blocked }

  context "#block!" do
    before { @authorization = FactoryGirl.create(:oauth_authorization) }
    before { @another_authorization = FactoryGirl.create(:oauth_authorization, client_uri: ANOTHER_CLIENT_URI) }
    before { @token = FactoryGirl.create(:oauth_token) }
    before { @another_token = FactoryGirl.create(:oauth_token, client_uri: ANOTHER_CLIENT_URI) }

    before { subject.block! }

    it { should be_blocked }
    it { @authorization.reload.should be_blocked }
    it { @another_authorization.reload.should_not be_blocked }
    it { @token.reload.should be_blocked }
    it { @another_token.reload.should_not be_blocked }

    context "#unblock!" do
      before { subject.unblock! }

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

  context "when increment access" do
    let(:today)    { Chronic.parse("today at midday") }
    let(:tomorrow) { Chronic.parse("tomorrow at midday") }

    it "should create or increment the daily requests counter" do
      Delorean.time_travel_to today
      3.times { @access.accessed! }
      @access.daily_requests.times.should == 3
      Delorean.time_travel_to tomorrow
      @access.accessed!
      @access.daily_requests.times.should == 1
    end
  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_access_spec.rb
oauth2_provider_engine-0.0.1 test/dummy/spec/models/oauth/oauth_access_spec.rb