Skip to content

Instantly share code, notes, and snippets.

@maxcal
Last active January 24, 2019 00:36
Show Gist options
  • Select an option

  • Save maxcal/f706fe09459a3d6c3dcca5d33c5850b3 to your computer and use it in GitHub Desktop.

Select an option

Save maxcal/f706fe09459a3d6c3dcca5d33c5850b3 to your computer and use it in GitHub Desktop.
Shared context for Pundit Policy specs
# spec/support/shared_contexts/policy.rb
# require this file from rails_helper.rb
require 'pundit/rspec'
RSpec.shared_context "Policy" do
let(:user) { build_stubbed(:user) }
subject { described_class }
let(:model_class) { described_class.to_s.chomp('Policy').constantize }
let(:permitted_attributes) do
described_class.new(User.new, model_class).permitted_attributes
end
let(:scope) { Pundit.policy_scope!(user, model_class) }
end
RSpec.configure do |config|
config.include_context "Policy", type: :policy
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment