lomba/schema_plus — pull request #119 by tovodeverett (2013-08-14 21:43:30+00:00)
Title: Added support for Rails Edge 4.1.0beta

Refactoring to support the migrations of add_column_options! between
Rails 3.2, 4.0, and 4.1.
* Rails 3.2 uses #aco! in the module AR::CA::SchemaStatements that
gets included into AR::CA.
* Rails 4.0 uses #aco! in the class AR::CA::AbstractAdapter::SchemaCreation
to call #aco! against AR::CA which includes #aco! from the module
AR::CA::SchemaStatements.
* Rails 4.1 does away with the #aco! in AR::CA::SchemaStatements and
simply implements all of the functionality in the class
AR::CA::AbstractAdapter::SchemaCreation.

With this in mind, our #aco! (along with the methods upon which it
depends) was moved into its own module which could then be injected
as needed. In addition, since we need to be able to inject into a
class that directly implements the functionality and to hang on to the
underlying functionality, our #aco! functionality was implemented
using alias_method_chain.
* The module AddColumnOptions was extracted in
SchemaPlus::ActiveRecord::ConnectionAdapters::AbstractAdapter and
now includes #add_column_options_with_schema_plus!,
#default_expr_valid?, and #sql_for_function. In situations where an
expression is generated using sql_for_function, our code is 100%
responsible for making all changes to sql. In all other situations,
it punts to add_column_options_without_schema_plus! thus retaining
base functionality.
* Because #default_expr_valid? and #sql_for_function had to move so
that #add_column_options_with_schema_plus! could access them when
it gets added to the SchemaCreation class, the adapter-specific
modules had to be modified as well to extract those functions into
new AddColumnOptions modules as well.
* In order to get those new adapter-specific modules injected into
the correct locations, AbstractAdapter#initialize_with_schema_plus
was modified to handle that injection and to vary it based on the
version of Rails.
* SchemaPlus.insert_connection_adapters was modified to inject
SP::AR::CA::AbstractAdapter::AddColumnOptions into the appropriate
location depending upon the version of Rails.

To make the #visit_TableDefinition code more similar to the #aco!
implementation, SP::AR::CA::AbstractAdapter::SchemaCreation was
renamed to ::VisitTableDefinition.

Finally, spec/column_definition_spec.rb had to be modified since it
assumed that #aco! was implemented on the connection object, whereas
in Rails 4.1 it has now moved to the new SchemaCreation object (and is
now private). In addition, there was some missing test coverage due
to not testing the combination of :default with null: false, so those
tests were added.