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.
|
||||
#------------------------------------------------------------------------------
|
||||
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|
|
||||
hash[c.name.to_sym] = c.type
|
||||
|
|
|
@ -128,8 +128,11 @@ EOS
|
|||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "ActiveRecord class" do
|
||||
it "should print the class" do
|
||||
before do
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true)
|
||||
end
|
||||
|
||||
it "should print the class" do
|
||||
@ap.send(:awesome, User).should == <<-EOS.strip
|
||||
class User < ActiveRecord::Base {
|
||||
:id => :integer,
|
||||
|
@ -141,8 +144,7 @@ class User < ActiveRecord::Base {
|
|||
EOS
|
||||
end
|
||||
|
||||
it "should print the class for non-direct subclasses of AR::Base" do
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true)
|
||||
it "should print the class for non-direct subclasses of ActiveRecord::Base" do
|
||||
@ap.send(:awesome, SubUser).should == <<-EOS.strip
|
||||
class SubUser < User {
|
||||
:id => :integer,
|
||||
|
@ -153,6 +155,10 @@ class SubUser < User {
|
|||
}
|
||||
EOS
|
||||
end
|
||||
|
||||
it "should print ActiveRecord::Base objects (ex. ancestors)" do
|
||||
lambda { @ap.send(:awesome, User.ancestors) }.should_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue