Skip to content
Browse files

added #has_only_role? methods and fixed a few spec bugs in Read API

  • Loading branch information...
1 parent aac3261 commit 4f5069a4befaf16733f2643187100549839c1d24 @kristianmandrup committed
Showing with 47 additions and 8 deletions.
  1. +6 −2 Changelog.textile
  2. +1 −1 VERSION
  3. +8 −0 lib/roles_generic/generic/user/implementation.rb
  4. +32 −5 lib/roles_generic/rspec/api/read_api.rb
View
8 Changelog.textile
@@ -1,6 +1,10 @@
h1. Changelog
-h2. V. 0.3.7.3
+h2. May 10, 2011
+
+Version 0.3.9
+
+* Added #has_only_role? method which tests that the role subject only has the single role passed as argument
+ alias methods: #is_only? #has_only?
-* Feb 9/2011 - merged johanlunds/master to support Rubygems 1.5 and resolve dependencies
View
2 VERSION
@@ -1 +1 @@
-0.3.8
+0.3.9
View
8 lib/roles_generic/generic/user/implementation.rb
@@ -118,6 +118,14 @@ def roles
alias_method :has?, :has_role?
alias_method :is?, :has_roles?
+
+ def has_only_role? arg
+ raise ArgumentError, "Must take only a single argument that is a role name" if arg.send(:size) > 1 && arg.kind_of?(Array)
+ has_roles? [arg].flatten.first
+ end
+
+ alias_method :has_only?, :has_only_role?
+ alias_method :is_only?, :has_only_role?
protected
View
37 lib/roles_generic/rspec/api/read_api.rb
@@ -51,8 +51,8 @@ class Role
end
describe '#has_roles?' do
- it "should be true that the normal user has the roles :guest and :user" do
- @normal_user.has_roles?(:guest, :user).should be_true
+ it "should be true that the normal user has the roles :guest and :user" do
+ @normal_user.has_roles?(:user).should be_true
end
it "should NOT be true that the normal user has the roles :guest and :admin" do
@@ -64,13 +64,40 @@ class Role
end
end
- describe '#has_roles?' do
+ describe '#has_only_role?' do
+ it "should be false that the normal user has only the role :guest" do
+ @normal_user.has_only_role?(:guest).should be_false
+ end
+
+ it "should Raise Error if passed an Array of roles" do
+ lambda { @normal_user.has_only_role?(:guest, :admin)}.should raise_error
+ end
+
+ it "should be true that the Guest user has only the role :guest" do
+ @guest_user.has_only_role?(:guest).should be_true
+ end
+ end
+
+ describe '#has_only?' do
+ it "should be true that the Guest user only has the role :guest" do
+ @guest_user.has_only?(:guest).should be_true
+ end
+ end
+
+ describe '#is_only?' do
+ it "should be true that the Guest user only is in the role :guest" do
+ @guest_user.is_only?(:guest).should be_true
+ end
+ end
+
+
+ describe '#has_any_role?' do
it "should be true that the normal user has the roles :guest and :user" do
@normal_user.has_any_role?(:guest, :user).should be_true
end
- it "should be true that the normal user has one of the roles :guest or :admin" do
- @normal_user.has_any_role?(:guest, :admin).should be_true
+ it "should be true that the normal user has one of the roles :user or :admin" do
+ @normal_user.has_any_role?(:user, :admin).should be_true
end
it "should NOT be true that the user has the roles :admin" do

0 comments on commit 4f5069a

Please sign in to comment.
Something went wrong with that request. Please try again.