Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix bug on users method of authorized object qhen the object has a st…

…ring primary key (i.e. uuid)

Add a test on users method of authorized object
  • Loading branch information...
commit 5057ebde66485fabf9809a7526de1d29cf64169d 1 parent 8fab879
Julien Bachmann authored be9 committed
View
2  lib/acl9/model_extensions.rb
@@ -83,7 +83,7 @@ def acts_as_authorization_object(options = {})
sql_where = <<-'EOS'
WHERE authorizable_type = '#{self.class.base_class.to_s}'
- AND authorizable_id = #{id}
+ AND authorizable_id = #{column_for_attribute(self.class.primary_key).text? ? "'#{id}'": id}
EOS
has_many :accepted_roles, :as => :authorizable, :class_name => role, :dependent => :destroy
View
18 test/roles_test.rb
@@ -14,6 +14,10 @@ class RolesTest < Test::Unit::TestCase
@user2 = User.create!
@foo = Foo.create!
@bar = Bar.create!
+ #create authorized object that has a string primary key
+ @uuid = Uuid.new
+ @uuid.uuid = "C41642EE-2780-0001-189F-17F3101B26E0"
+ @uuid.save
end
it "should not have any roles by default" do
@@ -221,6 +225,20 @@ class RolesTest < Test::Unit::TestCase
Role.count.should == 0
end
+ it "should be able to get users that have a role on a authorized object" do
+ @user.has_role!('owner', @bar)
+ @user2.has_role!('owner', @bar)
+
+ @bar.users.count.should == 2
+ end
+
+ it "should be able to get users that have a role on a authorized object with text primary key" do
+ @user.has_role!('owner', @uuid)
+ @user2.has_role!('owner', @uuid)
+
+ @uuid.users.count.should == 2
+ end
+
it "should accept :symbols as role names" do
@user.has_role! :admin
@user.has_role! :_3133t
View
5 test/support/models.rb
@@ -10,6 +10,11 @@ class Foo < ActiveRecord::Base
acts_as_authorization_object
end
+class Uuid < ActiveRecord::Base
+ set_primary_key "uuid"
+ acts_as_authorization_object
+end
+
class Bar < ActiveRecord::Base
acts_as_authorization_object
end
View
8 test/support/schema.rb
@@ -2,7 +2,7 @@
create_table "roles", :force => true do |t|
t.string "name", :limit => 40
t.string "authorizable_type", :limit => 40
- t.integer "authorizable_id"
+ t.string "authorizable_id"
t.datetime "created_at"
t.datetime "updated_at"
end
@@ -36,6 +36,12 @@
t.datetime "updated_at"
end
+ create_table "uuids", :id => false, :force => true do |t|
+ t.string "uuid"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "bars", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
Please sign in to comment.
Something went wrong with that request. Please try again.