kristianmandrup / cantango

CanCan extension with role oriented permission management, rules caching and much more
MIT License
404 stars 45 forks source link

Concatenate lists to lists instead of appending them #27

Closed pcmantz closed 12 years ago

pcmantz commented 12 years ago

I was trying to figure out why @rules in the class CanCan::Abilility was in a list-of-lists; it turns out it was because engine_rules is appended instead of being concatenated in lib/cantango/ability/engine_helpers.rb:7.

I have not had the time to set up a testing environment to check this, but I suspect the elementary nature of the changes should speak for themselves.

I have not had a chance to look at cantango-permits and cantango-roles, do those modules have similar issues?

kristianmandrup commented 12 years ago

Awesome! I knew there was this kind of problem somewhere... it has been fixed in cantango-permits which has much cleaner design and better specs but sadly hasnt been finished yet.

kristianmandrup commented 12 years ago

Thanks a lot! Feel free to add more patches that you see fit ;)

quaternion commented 11 years ago

Simple example:

class Registry
  def registered
     @registered ||= []
  end

  def go
    registered += []
  end
end

Registry.new.go # => NoMethodError: undefined method '+' for nil:NilClass

This pull request over 90% consists of such code. Use self.registered += ... if attr_writer :registered defined.

kristianmandrup commented 11 years ago

I'm sorry, I have no time to patch and work on CanTango at this time. Feel free to tweak and improve it as you see fit. Thanks!