Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed printing ActiveRecord::Base class ancestors

  • Loading branch information...
commit 50152e17e9fab7fcf039c24dfafa8d571a5d73aa 1 parent 2e75a16
@michaeldv authored
View
2  lib/awesome_print/ext/active_record.rb
@@ -26,7 +26,7 @@ def cast_with_active_record(object, type)
# 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
View
12 spec/ext/active_record_spec.rb
@@ -128,8 +128,11 @@ def self.columns
#------------------------------------------------------------------------------
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
Please sign in to comment.
Something went wrong with that request. Please try again.