magiclabs/alchemy_cms — pull request #558 by jasonyork (2014-06-02 19:29:40+00:00)
Title: Removing an ActiveRecord dependency

This pull request actually fixes three things.
1. There is an implicit dependence on Rpec version 2, so I've added an explicit reference in the gemspec
2. I fixed a somewhat obscure bug caused by a namespace collision. The reference to Alchemy::Page::Users was actually getting a reference to my top-level scoped "Users" module in my app. After a lot of research, I discovered that this is actually an "expected" behavior of Ruby. Reading these articles helped my understanding a lot:
http://stackoverflow.com/questions/6254496/is-it-possible-to-give-a-sub-module-the-same-name-as-a-top-level-class
http://makandracards.com/makandra/20633-ruby-constant-lookup-the-good-the-bad-and-the-ugly
So, as a fix, I've renamed the Alchemy::Page::Users module to Alchemy::Page::Editors. This is still will not avoid a future collision, but it's probably much more likely to have a top level "Users" module than "Editors." A more permanent fix might be to prefix all of those modules with "Alchemy" (eg: Alchemy::Page::AlchemyEditors) but I didn't really like that either.
3. I currently use Alchemy with a user model that does not extend ActiveRecord. I think with the recent Alchemy changes it seems that the intent is to allow for this. However, I found some code in the relation between Alchemy::Page and the user model that expects an ActiveRecord relation via the 'locker'. I've removed the relation and replaced it with an instance method that only expects the user model to optionally have a 'find' method. I've made a similar change for 'creator' and 'updater'. Finally, I started a dashboard feature spec. This exercised the functionality that was breaking for me. By making my changes, I made the tests pass.