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

Made specs pass with ActiveRecord 2.x

This commit is contained in:
Mike Dvorkin 2011-11-23 22:48:51 -08:00
parent b6a02f200b
commit fc23c998bb

View file

@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
begin begin
require 'active_record' require 'active_record'
require 'awesome_print/ext/active_record' require 'awesome_print/ext/active_record'
return if !defined?(ActiveRecord::VERSION::MAJOR) || ActiveRecord::VERSION::MAJOR < 2
# Create tableless ActiveRecord model. # Create tableless ActiveRecord model.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -48,7 +49,8 @@ begin
it "display single record" do it "display single record" do
out = @ap.send(:awesome, @diana) out = @ap.send(:awesome, @diana)
str = <<-EOS.strip if ActiveRecord::VERSION::MAJOR == 3
str = <<-EOS.strip
#<User:0x01234567 #<User:0x01234567
@attributes_cache = {}, @attributes_cache = {},
@destroyed = false, @destroyed = false,
@ -70,13 +72,34 @@ begin
} }
> >
EOS EOS
else # ActiveRecord 2.x
str = <<-EOS.strip
#<User:0x01234567
@attributes_cache = {},
@changed_attributes = {
"admin" => nil,
"created_at" => nil,
"name" => nil,
"rank" => nil
},
@new_record = true,
attr_accessor :attributes = {
"admin" => false,
"created_at" => "1992-10-10 12:30:00",
"name" => "Diana",
"rank" => 1
}
>
EOS
end
str.sub!('?', '1992-10-10 12:30:00') str.sub!('?', '1992-10-10 12:30:00')
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
end end
it "display multiple records" do it "display multiple records" do
out = @ap.send(:awesome, [ @diana, @laura ]) out = @ap.send(:awesome, [ @diana, @laura ])
str = <<-EOS.strip if ActiveRecord::VERSION::MAJOR == 3
str = <<-EOS.strip
[ [
[0] #<User:0x01234567 [0] #<User:0x01234567
@attributes_cache = {}, @attributes_cache = {},
@ -120,6 +143,44 @@ EOS
> >
] ]
EOS EOS
else # ActiveRecord 2.x
str = <<-EOS.strip
[
[0] #<User:0x01234567
@attributes_cache = {},
@changed_attributes = {
"admin" => nil,
"created_at" => nil,
"name" => nil,
"rank" => nil
},
@new_record = true,
attr_accessor :attributes = {
"admin" => false,
"created_at" => "1992-10-10 12:30:00",
"name" => "Diana",
"rank" => 1
}
>,
[1] #<User:0x01234567
@attributes_cache = {},
@changed_attributes = {
"admin" => nil,
"created_at" => nil,
"name" => nil,
"rank" => nil
},
@new_record = true,
attr_accessor :attributes = {
"admin" => true,
"created_at" => "2003-05-26 14:15:00",
"name" => "Laura",
"rank" => 2
}
>
]
EOS
end
str.sub!('?', '1992-10-10 12:30:00') str.sub!('?', '1992-10-10 12:30:00')
str.sub!('?', '2003-05-26 14:15:00') str.sub!('?', '2003-05-26 14:15:00')
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str