Sha256: dc553558158ff16daea732be59504c252519388023e6bfc7a22358dc96ad4432

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'
require 'support/ability_model'
require 'support/user'

describe Authority::Authorizer do

  before :each do
    @ability_model = AbilityModel.new
    @authorizer    = @ability_model.authorizer
    @user          = User.new
  end

  it "should take a resource instance in its initializer" do
    @authorizer.resource.should eq(@ability_model)
  end

  describe "instance methods" do

    Authority.adjectives.each do |adjective|
      method_name = "#{adjective}_by?"

      it "should respond to `#{method_name}`" do
        @authorizer.should respond_to(method_name)
      end

      it "should delegate `#{method_name}` to the corresponding class method by default" do
        @authorizer.class.should_receive(method_name).with(@user)
        @authorizer.send(method_name, @user)
      end

    end

  end

  describe "class methods" do

    Authority.adjectives.each do |adjective|
      method_name = "#{adjective}_by?"

      it "should respond to `#{method_name}`" do
        Authority::Authorizer.should respond_to(method_name)
      end

      it "should delegate `#{method_name}` to the authorizer's `default` method by default" do
        able = method_name.sub('_by?', '').to_sym
        Authority::Authorizer.should_receive(:default).with(able, @user)
        Authority::Authorizer.send(method_name, @user)
      end

    end

  end

  describe "the default method" do

    it "should call the configured `default_strategy` proc by default" do
      Authority.configuration.default_strategy.should_receive(:call).with(
        :implodable, Authority::Authorizer, @user
      )
      Authority::Authorizer.default(:implodable, @user)
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authority-1.1.0 spec/authority/authorizer_spec.rb