test/test_canhaz.rb in rails-canhaz-0.1.2 vs test/test_canhaz.rb in rails-canhaz-0.2.0

- old
+ new

@@ -149,7 +149,72 @@ assert bar.include?(s2) == true assert bar.include?(s3) == false end + + def test_drop_all + subject = SubjectModel.new + subject.save + + subject2 = SubjectModel.new + subject2.save + + object1 = ObjectModel.new + object1.save + + object2 = ObjectModel.new + object2.save + + subject.can(:foo, object1) + subject.can(:bar, object1) + subject.can(:foo, object2) + subject.can(:bar, object2) + + subject2.can(:foo, object1) + + subject.can_do_nothing + + subject.reload + + assert subject.cannot?(:foo, object1) + assert subject.cannot?(:bar, object1) + assert subject.cannot?(:foo, object2) + assert subject.cannot?(:bar, object2) + + assert subject2.reload.can?(:foo, object1) + + end + + def test_multiple + s1 = SubjectModel.new + s2 = SubjectModel.new + + o1 = ObjectModel.new + o2 = ObjectModel.new + + s1.save + s2.save + o1.save + o2.save + + s1.can(:foo, o1) + s1.can(:foo, o2) + s1.can(:bar, o2) + + s2.can(:bar, o1) + s2.can(:foo, o2) + + result = CanHazPermission.can?([s1, s2], :foo, [o1, o2]) + + assert result[s1.id] == [o1, o2] + assert result[s2.id] == [o2] + + result = CanHazPermission.can?([s1, s2], :bar, [o1, o2]) + + assert result[s1.id] == [o2] + assert result[s2.id] == [o1] + + end + end