Sha256: 9d6528d505d896c17ea8059de8129ffdcb6ee6baa20f2944c33d08eb33734ff2

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require 'acceptance_spec_helper'

feature 'Expose helper', %q{
   In order to change views dependent on permissions
   as a developer
   I want to be able to query permissions in views
}, type: :helper do

  given(:service_object){
    Class.new() do
      include AccessPolicy

      def self.policy_class
        Struct.new(:current_user, :service_object) do
          def create?
            !!(current_user && current_user.create_allowed?)
          end

          def show?
            !!(current_user && current_user.show_allowed?)
          end
        end
      end

    end.new
  }

  given(:a_user){
    double('user', create_allowed?: false, show_allowed?: true)
  }

  scenario 'action is allowed' do
    allow(controller).to receive(:current_user).and_return a_user
    expect(helper.policy_for(service_object).allow?(:show)).to be_truthy
  end

  scenario 'action is forbidden' do
    allow(controller).to receive(:current_user).and_return a_user
    expect(helper.policy_for(service_object).allow?(:create)).to be_falsy
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
access_policy_rails-0.0.2 spec/acceptance/expose_as_helper_spec.rb