spec/permission_spec.rb in access-granted-0.1.0 vs spec/permission_spec.rb in access-granted-0.1.1
- old
+ new
@@ -4,53 +4,68 @@
subject { AccessGranted::Permission }
describe "#matches_conditions?" do
it "matches when no conditions given" do
perm = subject.new(true, :read, String)
- perm.matches_conditions?(String).should be_true
+ expect(perm.matches_conditions?(String)).to eq(true)
end
it "matches proc conditions" do
sub = double("Element", published?: true)
perm = subject.new(true, :read, sub.class, {}, proc {|el| el.published? })
- perm.matches_conditions?(sub).should be_true
+ expect(perm.matches_conditions?(sub)).to eq(true)
end
end
describe "#matches_hash_conditions?" do
it "matches condition hash is empty" do
perm = subject.new(true, :read, String)
- perm.matches_hash_conditions?(String).should be_true
+ 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, { published: true })
- perm.matches_hash_conditions?(sub).should be_true
+ expect(perm.matches_hash_conditions?(sub)).to eq(true)
end
it "does not match if one of the conditions mismatches" do
sub = double("Element", published: true, readable: false)
perm = subject.new(true, :read, sub, { published: true, readable: true })
- perm.matches_hash_conditions?(sub).should be_false
+ 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)
- perm.matches_action?(:read).should be_true
+ 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)
- expect(perm.matches_subject? String).to be_true
+ expect(perm.matches_subject? String).to eq(true)
end
it "matches if class is equal to subject" do
perm = subject.new(true, :read, String)
- expect(perm.matches_subject? "test").to be_true
+ expect(perm.matches_subject? "test").to eq(true)
+ end
+
+ it "matches if superclass is equal to subject" do
+ perm = subject.new(true, :read, Object)
+ expect(perm.matches_subject? "test").to eq(true)
+ end
+
+ it "matches if any ancestor is equal to subject" do
+ perm = subject.new(true, :read, BasicObject)
+ expect(perm.matches_subject? "test").to eq(true)
+ end
+
+ 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
end