spec/role_spec.rb in access-granted-0.1.0 vs spec/role_spec.rb in access-granted-0.1.1

- old
+ new

@@ -5,91 +5,87 @@ it "requires a role name" do expect { subject.new }.to raise_error end - it "requires priority" do - expect { subject.new(:member) }.to raise_error - end - it "creates a default role without conditions" do - subject.new(:member, 1).conditions.should be_nil + expect(subject.new(:member).conditions).to be_nil end describe "#relevant_permissions?" do it "returns only matching permissions" do - role = subject.new(:member, 1) + role = subject.new(:member) role.can :read, String role.can :read, Hash - role.relevant_permissions(:read, String).should == [AccessGranted::Permission.new(true, :read, String)] + expect(role.relevant_permissions(:read, String)).to eq([AccessGranted::Permission.new(true, :read, String)]) end end describe "#applies_to?" do it "matches user when no conditions given" do - role = subject.new(:member, 1) + role = subject.new(:member) user = double("User") - role.applies_to?(user).should be_true + expect(role.applies_to?(user)).to eq(true) end it "matches user by hash conditions" do - role = subject.new(:moderator, 1, { is_moderator: true }) + role = subject.new(:moderator, { is_moderator: true }) user = double("User", is_moderator: true) - role.applies_to?(user).should be_true + expect(role.applies_to?(user)).to eq(true) end it "doesn't match user if any of hash conditions is not met" do - role = subject.new(:moderator, 1, { is_moderator: true, is_admin: true }) + role = subject.new(:moderator, { is_moderator: true, is_admin: true }) user = double("User", is_moderator: true, is_admin: false) - role.applies_to?(user).should be_false + expect(role.applies_to?(user)).to eq(false) end it "matches user by Proc conditions" do - role = subject.new(:moderator, 1, proc {|user| user.is_moderator? }) + role = subject.new(:moderator, proc {|user| user.is_moderator? }) user = double("User", is_moderator?: true) - role.applies_to?(user).should be_true + expect(role.applies_to?(user)).to eq(true) end end describe "#can" do before :each do - @role = AccessGranted::Role.new(:member, 1) + @role = AccessGranted::Role.new(:member) end it "forbids creating actions with the same name" do @role.can :read, String expect { @role.can :read, String }.to raise_error AccessGranted::DuplicatePermission end it "accepts :manage shortcut for CRUD actions" do @role.can :manage, String - @role.permissions.map(&:action).should include(:read, :create, :update, :destroy) + expect(@role.permissions.map(&:action)).to include(:read, :create, :update, :destroy) end describe "when action is an Array" do it "creates multiple permissions" do @role.can [:read, :create], String - @role.permissions.should have(2).items + expect(@role.permissions.size).to eq(2) end end describe "when no conditions given" do it "should be able to read a class" do @role.can :read, String - @role.find_permission(:read, String).should be_true + expect(@role.find_permission(:read, String)).to_not be_nil end it "should be able to read instance of class" do @role.can :read, String - @role.find_permission(:read, "text").should be_true + expect(@role.find_permission(:read, "text")).to_not be_nil end end describe "when conditions given" do it "should be able to read when conditions match" do sub = double("Element", published: true) @role.can :read, sub.class, { published: true } - @role.find_permission(:read, sub).should be_true + expect(@role.find_permission(:read, sub)).to_not be_nil end end end end