Sha256: 97ce312abc4e04b98719f419aeba60f52a5c150b183250891947cea0742df23e

Contents?: true

Size: 1.93 KB

Versions: 11

Compression:

Stored size: 1.93 KB

Contents

module ModelHelper
  def client_exists(client_attributes = {})
    @client = FactoryGirl.create(:application, client_attributes)
  end

  def create_resource_owner
    @resource_owner = User.create!(name: 'Joe', password: 'sekret')
  end

  def authorization_code_exists(options = {})
    @authorization = FactoryGirl.create(:access_grant, options)
  end

  def access_grant_should_exist_for(client, resource_owner)
    grant = Doorkeeper::AccessGrant.first

    expect(grant.application).to have_attributes(id: client.id).
      and(be_instance_of(Doorkeeper::Application))

    expect(grant.resource_owner_id).to eq(resource_owner.id)
  end

  def access_token_should_exist_for(client, resource_owner)
    token = Doorkeeper::AccessToken.first

    expect(token.application).to have_attributes(id: client.id).
      and(be_instance_of(Doorkeeper::Application))

    expect(token.resource_owner_id).to eq(resource_owner.id)
  end

  def access_grant_should_not_exist
    expect(Doorkeeper::AccessGrant.all).to be_empty
  end

  def access_token_should_not_exist
    expect(Doorkeeper::AccessToken.all).to be_empty
  end

  def access_grant_should_have_scopes(*args)
    grant = Doorkeeper::AccessGrant.first
    expect(grant.scopes).to eq(Doorkeeper::OAuth::Scopes.from_array(args))
  end

  def access_token_should_have_scopes(*args)
    grant = Doorkeeper::AccessToken.last
    expect(grant.scopes).to eq(Doorkeeper::OAuth::Scopes.from_array(args))
  end

  def uniqueness_error
    case DOORKEEPER_ORM
    when :active_record
      ActiveRecord::RecordNotUnique
    when :sequel
      error_classes = [Sequel::UniqueConstraintViolation, Sequel::ValidationFailed]
      proc { |error| expect(error.class).to be_in(error_classes) }
    when :mongo_mapper
      MongoMapper::DocumentNotValid
    when /mongoid/
      Mongoid::Errors::Validations
    else
      raise "'#{DOORKEEPER_ORM}' ORM is not supported!"
    end
  end
end

RSpec.configuration.send :include, ModelHelper

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
doorkeeper-sequel-1.3.1 spec/support/helpers/model_helper.rb
doorkeeper-sequel-1.3.0 spec/support/helpers/model_helper.rb
doorkeeper-sequel-1.2.3 spec/support/helpers/model_helper.rb
doorkeeper-sequel-1.2.2 spec/support/helpers/model_helper.rb
doorkeeper-4.2.6 spec/support/helpers/model_helper.rb
doorkeeper-4.2.5 spec/support/helpers/model_helper.rb
doorkeeper-sequel-1.2.1 spec/support/helpers/model_helper.rb
doorkeeper-4.2.0 spec/support/helpers/model_helper.rb
doorkeeper-4.1.0 spec/support/helpers/model_helper.rb
doorkeeper-4.0.0 spec/support/helpers/model_helper.rb
doorkeeper-4.0.0.rc4 spec/support/helpers/model_helper.rb