public-activity / public_activity

Easy activity tracking for models - similar to Github's Public Activity

Home Page:https://github.com/pokonski/public_activity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow for lazy Activity AR model instantiation

newportandy opened this issue · comments

Rails lazily creates connections so that things like asset precompilation can run without requiring a database being configured and running, this is really nice when building a docker image (my original problem).

There's currently there's a call to table_exists? in the class definition code for the Activity model in the ActiveRecord ORM code - which causes Rails to make a database connection. This means that we need a database connection just to load the class, throwing out the ability to precompile assets without a full blown database or a nullDB hack.

I have a patch that uses the ActiveSupport.on_load functionality in Rails to defer this check until runtime - passes all the tests*. Let me know if you'd like me to open a pull request for it.

newportandy@674d15d

* There's a test that fails the intermittently in this suite on mock assertions, looks like an ordering dependency. I haven't had time to debug it sorry.
PublicActivity::Activity Rendering::#render#test_0010_accepts a template root [/Users/newportandy/projects/public_activity/lib/public_activity/renderable.rb:133]: unexpected invocation: #<Mock:controller>.current_user()

Turns out this is necessary but not sufficient to solve the problem wholesale - I'm gonna close this until I have a full solution.