liufengyun/roles — pull request #2 by tyrauber (2013-09-27 17:37:06+00:00)
Title: STI instance should use base_class

Great Gem! I have used it in many apps. One issue I have run into on occasion is problems with STI models.

For example, imagine a company model with a whole bunch of sub-classes for various types of companies. If a company needs to change type, the roles will break. But they shouldn't have to break. It seems to me roles on STI instances could and should use instance base_class as resource_type as opposed to type. This would allow roles to be maintained on an instance, even if the instance type changes.

This wouldn't change the behavior at all for non-STI resources.

This should only happen on instances, where a resource_id is supplied. When dealing with assigning roles on an STI class, the class type should be respected. Otherwise, there could be unforeseen consequences: i.e. accidentally granting Class level roles across all subclasses.

I have implemented the above functionality and wrote spec coverage to address this functionality. The only thing that changes is how the Role module gets and sets resource_type for instances.