Skip to content

Commit

Permalink
roles= accepts strings too
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislaw committed Oct 5, 2011
1 parent 660f908 commit 63427ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/simple_roles/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def real_roles
end

def roles= *rolez
rolez.flatten!
rolez.to_symbols!.flatten!
raise "Not a valid role!" if (rolez.to_a - SimpleRoles::Configuration.valid_roles).size > 0

base.db_roles = rolez.map do |rolle|
Expand Down
13 changes: 12 additions & 1 deletion spec/simple_roles/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
subject.roles.should == Set.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 = ['user', 'editor']
subject.roles.should == Set.new([:user, :editor])
end

it "#roles << should add roles" do
subject.roles << :admin
subject.roles.should == Set.new([:admin])
Expand Down Expand Up @@ -115,7 +122,11 @@
user.save!
User.find_by_name!("stanislaw").should be_kind_of(User)
end


pending "should not duplicate roles when adding" do

end

it "should all work" do
admin_role = Role.find_by_name("admin")
user = User.new(:name => "stanislaw")
Expand Down

0 comments on commit 63427ea

Please sign in to comment.