Skip to content
Browse files

Merge pull request #53 from IndieGoGo/master

There was one more method where the old join_table was being used.
  • Loading branch information...
2 parents 782de8c + 8d0a89b commit 9e246cd7ef622f9657155c16eadd6a3faff7842b @be9 committed Mar 21, 2012
Showing with 20 additions and 13 deletions.
  1. +20 −13 lib/acl9/model_extensions.rb
View
33 lib/acl9/model_extensions.rb
@@ -33,10 +33,9 @@ module ClassMethods
# @see Acl9::ModelExtensions::Subject
#
def acts_as_authorization_subject(options = {})
- assoc = options[:association_name] || Acl9::config[:default_association_name]
+ assoc = options[:association_name] || Acl9::config[:default_association_name]
role = options[:role_class_name] || Acl9::config[:default_role_class_name]
- join_table = options[:join_table_name] || Acl9::config[:default_join_table_name] ||
- self.table_name_prefix + [undecorated_table_name(self.to_s), undecorated_table_name(role)].sort.join("_") + self.table_name_suffix
+ join_table = options[:join_table_name] || Acl9::config[:default_join_table_name] || self.table_name_prefix + [undecorated_table_name(self.to_s), undecorated_table_name(role)].sort.join("_") + self.table_name_suffix
has_and_belongs_to_many assoc, :class_name => role, :join_table => join_table
@@ -79,7 +78,15 @@ def acts_as_authorization_object(options = {})
role = options[:role_class_name] || Acl9::config[:default_role_class_name]
role_table = role.constantize.table_name
- join_table = options[:join_table_name] || ActiveRecord::Base.send(:join_table_name, role_table, subj_table)
+ join_table = options[:join_table_name]
+ join_table ||= ActiveRecord::Base.send(:join_table_name,
+ role_table, subj_table) if ActiveRecord::Base.private_methods \
+ .include?('join_table_name')
+ join_table ||= Acl9::config[:default_join_table_name]
+ join_table ||= self.table_name_prefix \
+ + [undecorated_table_name(self.to_s),
+ undecorated_table_name(role)].sort.join("_") \
+ + self.table_name_suffix
sql_tables = <<-EOS
FROM #{subj_table}
@@ -126,17 +133,17 @@ def acts_as_authorization_object(options = {})
# @see Acl9::ModelExtensions::Object#accepts_role?
# @see Acl9::ModelExtensions::Object#accepts_no_role!
def acts_as_authorization_role(options = {})
- subject = options[:subject_class_name] || Acl9::config[:default_subject_class_name]
- join_table = options[:join_table_name] || Acl9::config[:default_join_table_name] ||
- self.table_name_prefix + [undecorated_table_name(self.to_s), undecorated_table_name(subject)].sort.join("_") + self.table_name_suffix
- # comment out use deprecated API
- #join_table_name(undecorated_table_name(self.to_s), undecorated_table_name(subject))
+ subject = options[:subject_class_name] || Acl9::config[:default_subject_class_name]
+ join_table = options[:join_table_name] || Acl9::config[:default_join_table_name] ||
+ self.table_name_prefix + [undecorated_table_name(self.to_s), undecorated_table_name(subject)].sort.join("_") + self.table_name_suffix
+ # comment out use deprecated API
+ #join_table_name(undecorated_table_name(self.to_s), undecorated_table_name(subject))
- has_and_belongs_to_many subject.demodulize.tableize.to_sym,
- :class_name => subject,
- :join_table => join_table
+ has_and_belongs_to_many subject.demodulize.tableize.to_sym,
+ :class_name => subject,
+ :join_table => join_table
- belongs_to :authorizable, :polymorphic => true
+ belongs_to :authorizable, :polymorphic => true
end
end
end

0 comments on commit 9e246cd

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