Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow AR objects to survive an `include Pacecar` if the table doesn't…

… exist yet

* Problem exposes itself when an AR object includes Pacecar, and also has an
Observer tied to it (loading the model early).  Upon an initial db:migrate, by
loading the model early, Pacecar would raise an error that the table doesn't
exist when defining the order scopes.
* The `column_names` method in Pacecar::Helpers::ClassMethods was inaccessible
because AR::Base already defines it.
  • Loading branch information...
commit a8dadf029205e32dd333e49b379d7d2c31a0e676 1 parent c8c4669
@rmm5t authored
View
4 lib/pacecar/helpers.rb
@@ -21,10 +21,6 @@ def safe_columns
end
end
- def column_names
- safe_columns.collect(&:name)
- end
-
def column_names_for_type(*types)
safe_columns.select { |column| types.include? column.type }.collect(&:name)
end
View
2  lib/pacecar/order.rb
@@ -12,7 +12,7 @@ def self.extended(base)
protected
def define_order_scopes
- column_names.each do |name|
+ safe_columns.collect(&:name).each do |name|
named_scope "by_#{name}".to_sym, lambda { |*args|
{ :order => "#{quoted_table_name}.#{name} #{args.flatten.first || 'asc'}" }
}
View
5 test/helpers_test.rb
@@ -10,6 +10,11 @@ class HelpersTest < Test::Unit::TestCase
columns = @class.send :safe_columns
assert_equal [], columns
end
+ should "survive an include of Pacecar" do
+ assert_nothing_raised do
+ @class.send :include, Pacecar
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.