spec/permission_spec.rb in access-granted-1.1.2 vs spec/permission_spec.rb in access-granted-1.2.0
- old
+ new
@@ -1,34 +1,27 @@
require 'spec_helper'
describe AccessGranted::Permission do
subject { AccessGranted::Permission }
- describe "#matches_conditions?" do
- it "matches when no conditions given" do
- perm = subject.new(true, :read, String)
- expect(perm.matches_conditions?(String)).to eq(true)
- end
+ describe "#matches_proc_conditions?" do
- it "matches proc conditions" do
+ it "matches proc conditions when true" do
sub = double("Element", published?: true)
- perm = subject.new(true, :read, sub.class, nil, {}, proc {|el| el.published? })
+ perm = subject.new(true, :read, sub, nil, {}, proc {true})
expect(perm.matches_conditions?(sub)).to eq(true)
end
- it "does not match proc conditions when given a class instead of an instance" do
+ it "does not match proc conditions false" do
sub = double("Element", published?: true)
- perm = subject.new(true, :read, sub.class, nil, {}, proc {|el| el.published? })
- expect(perm.matches_conditions?(sub.class)).to eq(true)
+ perm = subject.new(true, :read, sub, nil, {}, proc {false})
+ expect(perm.matches_conditions?(sub)).to eq(false)
end
+
end
describe "#matches_hash_conditions?" do
- it "matches condition hash is empty" do
- perm = subject.new(true, :read, String)
- expect(perm.matches_hash_conditions?(String)).to eq(true)
- end
it "matches when conditions given" do
sub = double("Element", published: true)
perm = subject.new(true, :read, sub, nil, { published: true })
expect(perm.matches_hash_conditions?(sub)).to eq(true)
@@ -37,17 +30,19 @@
it "does not match if one of the conditions mismatches" do
sub = double("Element", published: true, readable: false)
perm = subject.new(true, :read, sub, nil, { published: true, readable: true })
expect(perm.matches_hash_conditions?(sub)).to eq(false)
end
+
end
describe "#matches_action?" do
it "matches if actions are identical" do
perm = subject.new(true, :read, String)
expect(perm.matches_action?(:read)).to_not be_nil
end
+
end
describe "#matches_subject?" do
it "matches if subjects are identical" do
perm = subject.new(true, :read, String)
@@ -71,7 +66,17 @@
it "does not match if any descendant is equal to subject" do
perm = subject.new(true, :read, String)
expect(perm.matches_subject? Object.new).to eq(false)
end
+
end
+
+ describe "#matches_empty_conditions?" do
+ it "matches when no conditions given" do
+ perm = subject.new(true, :read, String)
+ expect(perm.matches_conditions?(String)).to eq(true)
+ end
+
+ end
+
end