From d9ca043c7e73ba27d1daeea370354435e495b25e Mon Sep 17 00:00:00 2001 From: Anton Dieterle Date: Sat, 9 Jun 2012 18:34:07 +0400 Subject: [PATCH] Additional checks when model has no primary key and for factory_girl --- lib/annotate/annotate_models.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index b4ddfb485..cb39cebfc 100644 --- a/lib/annotate/annotate_models.rb +++ b/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 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