mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Fixed printing ActiveRecord::Base class ancestors
This commit is contained in:
parent
2e75a16387
commit
50152e17e9
2 changed files with 10 additions and 4 deletions
|
@ -26,7 +26,7 @@ module AwesomePrint
|
||||||
# Format ActiveRecord class object.
|
# Format ActiveRecord class object.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
def awesome_active_record_class(object)
|
def awesome_active_record_class(object)
|
||||||
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:columns)
|
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:columns) || object.to_s == "ActiveRecord::Base"
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -128,8 +128,11 @@ EOS
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "ActiveRecord class" do
|
describe "ActiveRecord class" do
|
||||||
it "should print the class" do
|
before do
|
||||||
@ap = AwesomePrint::Inspector.new(:plain => true)
|
@ap = AwesomePrint::Inspector.new(:plain => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should print the class" do
|
||||||
@ap.send(:awesome, User).should == <<-EOS.strip
|
@ap.send(:awesome, User).should == <<-EOS.strip
|
||||||
class User < ActiveRecord::Base {
|
class User < ActiveRecord::Base {
|
||||||
:id => :integer,
|
:id => :integer,
|
||||||
|
@ -141,8 +144,7 @@ class User < ActiveRecord::Base {
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print the class for non-direct subclasses of AR::Base" do
|
it "should print the class for non-direct subclasses of ActiveRecord::Base" do
|
||||||
@ap = AwesomePrint::Inspector.new(:plain => true)
|
|
||||||
@ap.send(:awesome, SubUser).should == <<-EOS.strip
|
@ap.send(:awesome, SubUser).should == <<-EOS.strip
|
||||||
class SubUser < User {
|
class SubUser < User {
|
||||||
:id => :integer,
|
:id => :integer,
|
||||||
|
@ -153,6 +155,10 @@ class SubUser < User {
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should print ActiveRecord::Base objects (ex. ancestors)" do
|
||||||
|
lambda { @ap.send(:awesome, User.ancestors) }.should_not raise_error
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue