Last active
January 24, 2019 00:36
-
-
Save maxcal/f706fe09459a3d6c3dcca5d33c5850b3 to your computer and use it in GitHub Desktop.
Shared context for Pundit Policy specs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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