1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Fix printing abstract classes in ActiveRecord 3

This commit is contained in:
Joshua Priddle 2014-01-12 00:18:25 -05:00 committed by James Cox
parent 9ce54b5557
commit 84bfda9d07
2 changed files with 9 additions and 0 deletions

View file

@ -56,6 +56,7 @@ module AwesomePrint
#------------------------------------------------------------------------------
def awesome_active_record_class(object)
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:columns) || object.to_s == "ActiveRecord::Base"
return awesome_class(object) if object.respond_to?(:abstract_class?) && object.abstract_class?
data = object.columns.inject(::ActiveSupport::OrderedHash.new) do |hash, c|
hash[c.name.to_sym] = c.type

View file

@ -56,6 +56,10 @@ begin
end
end
class AbstractClass < ActiveRecord::Base
self.abstract_class = true
end
describe "AwesomePrint/ActiveRecord" do
before do
stub_dotfile!
@ -399,6 +403,10 @@ EOS
it "should print ActiveRecord::Base objects (ex. ancestors)" do
expect { @ap.send(:awesome, User.ancestors) }.not_to raise_error
end
it "should print an abstract class" do
@ap.send(:awesome, AbstractClass).should == "AbstractClass(abstract) < ActiveRecord::Base"
end
end
#------------------------------------------------------------------------------