Permalink
Browse files

array instead of set - design still very bad

  • Loading branch information...
1 parent bee90ea commit 806e6136c9c194af46e09c1d39986df20b0ca2b8 @stanislaw committed Oct 13, 2011
Showing with 20 additions and 12 deletions.
  1. +2 −2 lib/simple_roles/roles_array.rb
  2. +18 −10 spec/simple_roles/base_spec.rb
@@ -1,5 +1,5 @@
module SimpleRoles
- class RolesArray < Set
+ class RolesArray < Array
attr_reader :base
@@ -41,7 +41,7 @@ def << *rolez
self.roles = self.to_a + rolez
end
- #alias_method :add, :<<
+ alias_method :add, :<<
def remove *rolez
rolez.flatten!
@@ -81,41 +81,49 @@
it "#roles= should set roles" do
subject.roles = :admin
- subject.roles.should == Set.new([:admin])
+ subject.roles.should == Array.new([:admin])
subject.roles = :user
- subject.roles.should == Set.new([:user])
+ subject.roles.should == Array.new([:user])
end
it "#roles= should set roles if array of strings passed (sh accept strings too!)" do
subject.roles = 'admin'
- subject.roles.should == Set.new([:admin])
+ subject.roles.should == Array.new([:admin])
subject.roles = ['user', 'editor']
- subject.roles.should == Set.new([:user, :editor])
+ subject.roles.should == Array.new([:user, :editor])
end
it "#roles << should add roles" do
subject.roles << :admin
- subject.roles.should == Set.new([:admin])
+ subject.roles.should == Array.new([:admin])
subject.roles << :user
- subject.roles.should == Set.new([:admin, :user])
+ subject.roles.should == Array.new([:admin, :user])
end
it "#remove_roles should remove roles" do
subject.roles << :admin
subject.roles << :user
subject.roles << :editor
- subject.roles.should == Set.new([:admin, :user, :editor])
+ subject.roles.should == Array.new([:admin, :user, :editor])
subject.remove_roles :admin
- subject.roles.should == Set.new([:user, :editor])
+ subject.roles.should == Array.new([:user, :editor])
subject.remove_roles :admin, :user, :editor
- subject.roles.should == Set.new([])
+ subject.roles.should == Array.new([])
end
end
context "Integration for roles methods" do
+ it "should work when #flatten is called over #roles" do
+ user = User.new(:name => "stanislaw")
+ user.roles << :admin
+
+ user.roles_list.should == Array.new([:admin])
+ user.roles_list.flatten.should == Array.new([:admin])
+ end
+
it "should add :roles to accessible_attributes if they are Whitelisted" do
user = User.new(:name => "stanislaw")
user.roles << :admin
@@ -161,7 +169,7 @@
user.save!
user.roles.should be_empty
user.roles = [:admin, :user]
- user.roles.should == Set.new([:admin, :user])
+ user.roles.should == Array.new([:admin, :user])
user.has_role?(:admin, :user).should be_true
user.has_roles?([:admin, :user]).should be_true
user.db_roles.size.should == 2

0 comments on commit 806e613

Please sign in to comment.