1
0
Fork 0
mirror of https://github.com/varvet/pundit.git synced 2022-11-09 12:30:11 -05:00

Use RSpec's described_class feature to specify the subject

Removes code duplication and makes it easier to rename policies.
This commit is contained in:
nTraum 2014-10-14 00:32:54 +02:00
parent 2214acf661
commit 2d36e93871
3 changed files with 5 additions and 5 deletions

View file

@ -430,7 +430,7 @@ create a special class which wraps up both user and IP and passes it to the poli
``` ruby ``` ruby
class UserContext class UserContext
attr_reader :user, :ip attr_reader :user, :ip
def initialize(user, ip) def initialize(user, ip)
@user = user @user = user
@ip = ip @ip = ip
@ -439,7 +439,7 @@ end
class ApplicationController class ApplicationController
include Pundit include Pundit
def pundit_user def pundit_user
UserContext.new(current_user, request.ip) UserContext.new(current_user, request.ip)
end end
@ -501,7 +501,7 @@ Then put your policy specs in `spec/policies`, and make them look somewhat like
``` ruby ``` ruby
describe PostPolicy do describe PostPolicy do
subject { PostPolicy } subject { described_class }
permissions :update? do permissions :update? do
it "denies access if post is published" do it "denies access if post is published" do

View file

@ -4,7 +4,7 @@ describe <%= class_name %>Policy do
let(:user) { User.new } let(:user) { User.new }
subject { <%= class_name %>Policy } subject { described_class }
permissions ".scope" do permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}" pending "add some examples to (or delete) #{__FILE__}"

View file

@ -4,7 +4,7 @@ describe PostPolicy do
let(:user) { double } let(:user) { double }
let(:own_post) { double(user: user) } let(:own_post) { double(user: user) }
let(:other_post) { double(user: double) } let(:other_post) { double(user: double) }
subject { PostPolicy } subject { described_class }
permissions :update?, :show? do permissions :update?, :show? do
it "is successful when all permissions match" do it "is successful when all permissions match" do