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:
parent
9ce54b5557
commit
84bfda9d07
2 changed files with 9 additions and 0 deletions
|
@ -56,6 +56,7 @@ module AwesomePrint
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
def awesome_active_record_class(object)
|
def awesome_active_record_class(object)
|
||||||
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:columns) || object.to_s == "ActiveRecord::Base"
|
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|
|
data = object.columns.inject(::ActiveSupport::OrderedHash.new) do |hash, c|
|
||||||
hash[c.name.to_sym] = c.type
|
hash[c.name.to_sym] = c.type
|
||||||
|
|
|
@ -56,6 +56,10 @@ begin
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class AbstractClass < ActiveRecord::Base
|
||||||
|
self.abstract_class = true
|
||||||
|
end
|
||||||
|
|
||||||
describe "AwesomePrint/ActiveRecord" do
|
describe "AwesomePrint/ActiveRecord" do
|
||||||
before do
|
before do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
|
@ -399,6 +403,10 @@ EOS
|
||||||
it "should print ActiveRecord::Base objects (ex. ancestors)" do
|
it "should print ActiveRecord::Base objects (ex. ancestors)" do
|
||||||
expect { @ap.send(:awesome, User.ancestors) }.not_to raise_error
|
expect { @ap.send(:awesome, User.ancestors) }.not_to raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should print an abstract class" do
|
||||||
|
@ap.send(:awesome, AbstractClass).should == "AbstractClass(abstract) < ActiveRecord::Base"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue