Sha256: d00ae8146fb8c54c54510743731f0bc83fde36be80fecf4edd90b5a60d517660

Contents?: true

Size: 730 Bytes

Versions: 1

Compression:

Stored size: 730 Bytes

Contents

require 'test_helper'

class ControllerTest < ActiveSupport::TestCase

  test 'can helper' do
    assert controller.send(:can?, :create, post)
  end

  test 'cannot helper' do
    assert controller.send(:cannot?, :read, post)
  end

  test 'authorize helper' do
    assert_nothing_raised do
      controller.send :authorize!, :create, post
    end
    assert_raises Abilities::AccessDenied do
      controller.send :authorize!, :read, post
    end
  end

  private

  def controller
    @controller ||= ActionController::Base.new.tap do |controller|
      controller.class_eval do
        define_method :current_user do
          @user ||= User.new
        end
      end
    end
  end

  def post
    @post ||= Post.new
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
abilities-0.1.1 test/controller_test.rb