test/canard/ability_test.rb in canard-0.3.6 vs test/canard/ability_test.rb in canard-0.3.7

- old
+ new

@@ -32,11 +32,11 @@ subject.user.must_equal user end end - describe "for a user with author role" do + describe "with a user that has author role" do let(:user) { User.create(:roles => [:author]) } let(:member) { Member.create(:user => user) } let(:other_member) { Member.new(:user => User.create) } subject { Ability.new(user) } @@ -62,11 +62,11 @@ subject.cannot?(:destroy, Post).must_equal true end end - describe "for a user with admin and author role" do + describe "with a user that has admin and author roles" do let(:user) { User.create(:roles => [:author, :admin]) } let(:member) { Member.create(:user => user) } let(:other_user) { User.create } let(:other_member) { Member.new(:user => other_user) } @@ -91,11 +91,11 @@ subject.cannot?(:destroy, user).must_equal true end end - describe "for a guest" do + describe "with no user" do subject { Ability.new } it "applies the guest abilities" do subject.can?(:index, Post) @@ -106,9 +106,48 @@ subject.cannot?(:destroy, Post) subject.cannot?(:show, User) subject.cannot?(:show, Member) end + end + + describe "with an instance of an anonymous class that has author role" do + + let(:klass) do + Class.new do + extend Canard::UserModel + attr_accessor :roles_mask + acts_as_user :roles => [:author, :admin] + def initialize(*roles); self.roles = roles; end + end + end + let(:instance) { klass.new(:author) } + + describe "for base class abilities" do + + it "does nothing" do + proc { Ability.new(instance) }.must_be_silent + end + end + + describe "for assigned roles" do + + subject { Ability.new(instance) } + + it "has all the abilities of an author" do + subject.can?(:new, Post).must_equal true + subject.can?(:create, Post).must_equal true + subject.can?(:edit, Post).must_equal true + subject.can?(:update, Post).must_equal true + subject.can?(:show, Post).must_equal true + subject.can?(:index, Post).must_equal true + end + + it "has no admin abilities" do + subject.cannot?(:destroy, Post).must_equal true + end + end + end end end