Sha256: 5eb9b5ba3a6ee6e12e24f7856525934300b1fa45c91c6f16c8dbc3495cc00314

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require "consent"

require_relative "rspec/consent_action"
require_relative "rspec/consent_view"

module Consent
  # RSpec helpers for consent. Given permissions are loaded,
  # gives you the ability of defining permission specs like
  #
  # Given "users" permissions
  # Consent.define :users, "User management" do
  #   view :department, "Same department only" do |user|
  #     { department_id: user.department_id }
  #   end
  #   action :read, "Can view users"
  #   action :update, "Can edit existing user", views: :department
  # end
  #
  # RSpec.describe "User permissions" do
  #   include Consent::Rspec
  #   let(:user) { double(department_id: 15) }
  #
  #   it do
  #     is_expected.to(
  #       consent_view(:department)
  #         .with_conditions(department_id: 15)
  #         .to(user)
  #     )
  #   end
  #   it { is_expected.to consent_action(:read) }
  #   it { is_expected.to consent_action(:update).with_views(:department) }
  # end
  #
  # Find more examples at:
  # https://github.com/powerhome/consent
  module Rspec
    def consent_view(view_key, conditions = nil)
      ConsentView.new(view_key, conditions)
    end

    def consent_action(action_key)
      ConsentAction.new(action_key)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
consent-2.0.0 lib/consent/rspec.rb