Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to make scopes work similarly to singular policies. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions spec/pundit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@
end
end

describe ".authorize_scope" do
it "infers and applies a scope based on it"
end

describe ".policy_scope" do
it "becomes a call to #authorized_scope(scope, :resolve)"

it "returns an instantiated policy scope given a plain model class" do
expect(Pundit.policy_scope(user, Post)).to eq :published
end
Expand Down Expand Up @@ -88,6 +94,14 @@
end
end

describe ".scope_policy" do
it "returns an instantiated scope policy given a scope"
end

describe ".scope_policy!" do
it "does whatever it have to be done"
end

describe ".policy" do
it "returns an instantiated policy given a plain model instance" do
policy = Pundit.policy(user, post)
Expand Down Expand Up @@ -296,6 +310,19 @@
end
end

describe "#verify_scope_authorized" do
it "does nothing when policy_scope is used" do
pending
controller.authorize_scope(Post)
controller.verify_scope_authorized
end

it "raises an exception when policy_scope is not used" do
pending
expect { controller.verify_scope_authorized }.to raise_error(Pundit::PolicyScopingNotPerformedError)
end
end

describe "#verify_policy_scoped" do
it "does nothing when policy_scope is used" do
controller.policy_scope(Post)
Expand Down Expand Up @@ -329,6 +356,19 @@
end
end

describe "#pundit_scope_policy_authorized?" do
it "is true when policy_scope is used" do
pending
controller.authorize_scope(Post)
expect(controller.pundit_policy_scope_authorized?).to be true
end

it "is false when policy scope is not used" do
pending
expect(controller.pundit_policy_scope_authorized?).to be false
end
end

describe "#authorize" do
it "infers the policy name and authorizes based on it" do
expect(controller.authorize(post)).to be_truthy
Expand Down Expand Up @@ -374,6 +414,14 @@
end
end

describe "#authorize_scope" do
it "infers the policy name and authorizes based on it"
end

describe "#skip_scope_authorization" do
it "disables scope policy verification"
end

describe "#skip_policy_scope" do
it "disables policy scope verification" do
controller.skip_policy_scope
Expand Down Expand Up @@ -406,7 +454,13 @@
end
end

describe "#scope_policy" do
it "returns an instantiated scope policy"
end

describe "#policy_scope" do
it "becomes a call to #authorized_scope(scope, :resolve)"

it "returns an instantiated policy scope" do
expect(controller.policy_scope(Post)).to eq :published
end
Expand Down