Permalink
Browse files

Additional checks when model has no primary key and for factory_girl

  • Loading branch information...
1 parent a786d70 commit d9ca043c7e73ba27d1daeea370354435e495b25e @adie committed Jun 9, 2012
Showing with 2 additions and 2 deletions.
  1. +2 −2 lib/annotate/annotate_models.rb
@@ -82,7 +82,7 @@ def get_schema_info(klass, header, options = {})
attrs = []
attrs << "default(#{quote(col.default)})" unless col.default.nil?
attrs << "not null" unless col.null
- attrs << "primary key" if col.name.to_sym == klass.primary_key.to_sym
+ attrs << "primary key" if klass.primary_key && col.name.to_sym == klass.primary_key.to_sym
@alexch

alexch Jun 10, 2012

How does one create an ActiveRecord object with no primary key anyway? Can you write (or at least describe) a unit test for this?

col_type = (col.type || col.sql_type).to_s
if col_type == "decimal"
@@ -318,7 +318,7 @@ def get_model_class(file)
# Retrieve loaded model class by path to the file where it's supposed to be defined.
def get_loaded_model(model_path)
ObjectSpace.each_object.
- select { |c| c.is_a?(Class) && c.ancestors.include?(ActiveRecord::Base) }.
+ select { |c| Class === c && c.ancestors.respond_to?(:include?) && c.ancestors.include?(ActiveRecord::Base) }.
detect { |c| ActiveSupport::Inflector.underscore(c) == model_path }
end

0 comments on commit d9ca043

Please sign in to comment.