Please sign in to comment.
Allow policy.rb to be parsed without documents table.
Before this commit, using rake to drop and create databases, and to migrate those databases would fail (`rake db:drop:all db:create:all db:migrate`). This is because we now have the SupportingPageSearchIndexObserver which observes :policy, causing policy.rb to be evaluated at Rails app initialisation time. There were two problems with evaluating policy.rb when the documents table didn't exist: * The `scope :stub` line caused active record to inspect the documents table schema, which didn't exist. Interestingly, `scope` only exhibits this behaviour when the model is derived from another model. If we change Policy so that it derives from ActiveRecord::Base then `scope` doesn't cause active record to inspect the database schema. * The `define_attribute_methods` line caused active record to inspect the documents table schema in order to generate the model accessor methods. This was only required so that we could then call `alias_method_chain :title, :stub`. By introducing explicit `#title_without_stub` and `#title` methods we can avoid the use of both `alias_method_chain` and `define_attribute_methods`. This commit makes it possible to evaluate policy.rb even when the documents table is missing, which in turn allows us to schema:load and migrate an empty database.
- Loading branch information...