From 13f0278b25f7cfc544be11fe1f7d103718cb2d46 Mon Sep 17 00:00:00 2001 From: Mauro George Date: Tue, 20 Jan 2015 14:23:20 -0200 Subject: [PATCH] Fix specs on Ruby 1.9.3 and Rails 3.2 and 4.2 ActiveRecord has a little different output when running on Ruby 1.9.3. --- spec/ext/active_record_spec.rb | 481 ++++++++++++++++++++++++++++++++- 1 file changed, 473 insertions(+), 8 deletions(-) diff --git a/spec/ext/active_record_spec.rb b/spec/ext/active_record_spec.rb index bdb48e2..5b4a6ec 100644 --- a/spec/ext/active_record_spec.rb +++ b/spec/ext/active_record_spec.rb @@ -79,7 +79,8 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }. out = @ap.send(:awesome, @diana) if activerecord_4_2? - str = <<-EOS.strip + if RUBY_VERSION > '1.9.3' + str = <<-EOS.strip #{ !ExtVerifier.has_rails? }. "rank" => nil } > - EOS + EOS + else + str = <<-EOS.strip +# false, + "created_at" => 1992-10-10 12:30:00 UTC, + "name" => "Diana", + "rank" => 1 + }, + @readonly = false, + @reflects_state = [ + [0] false + ], + @transaction_state = nil, + @txn = nil, + attr_accessor :attributes = # #, + attr_reader :value = false, + attr_reader :value_before_type_cast = false + >, + "created_at" => #, + attr_reader :value = 1992-10-10 12:30:00 UTC, + attr_reader :value_before_type_cast = "1992-10-10 12:30:00" + >, + "id" => #, + attr_reader :value = nil, + attr_reader :value_before_type_cast = nil + >, + "name" => #, + attr_reader :value = "Diana", + attr_reader :value_before_type_cast = "Diana" + >, + "rank" => #, + attr_reader :value = 1, + attr_reader :value_before_type_cast = 1 + > + }, + attr_reader :types = { + "admin" => #, + "created_at" => #, + "id" => #, + "name" => #, + "rank" => # + }, + attr_reader :values = { + "admin" => nil, + "created_at" => nil, + "id" => nil, + "name" => nil, + "rank" => nil + } + > + >, + attr_accessor :destroyed_by_association = nil, + attr_reader :association_cache = {}, + attr_reader :changed_attributes = { + "admin" => nil, + "created_at" => nil, + "name" => nil, + "rank" => nil + } +> + EOS + end elsif activerecord_4_1? str = <<-EOS.strip #{ !ExtVerifier.has_rails? }. > EOS elsif activerecord_3_2? - str = <<-EOS.strip + if RUBY_VERSION > '1.9.3' + str = <<-EOS.strip #{ !ExtVerifier.has_rails? }. "rank" => nil } > - EOS + EOS + else + str = <<-EOS.strip +# false, + "created_at" => "1992-10-10 12:30:00", + "id" => nil, + "name" => "Diana", + "rank" => 1 + }, + attr_reader :association_cache = {}, + attr_reader :changed_attributes = { + "admin" => nil, + "created_at" => nil, + "name" => nil, + "rank" => nil + }, + attr_reader :mass_assignment_options = nil +> + EOS + end end str.sub!('?', '1992-10-10 12:30:00') expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str) @@ -441,7 +598,8 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }. out = @ap.send(:awesome, [ @diana, @laura ]) if activerecord_4_2? - str = <<-EOS.strip + if RUBY_VERSION > '1.9.3' + str = <<-EOS.strip [ [0] #{ !ExtVerifier.has_rails? }. } > ] - EOS + EOS + else + str = <<-EOS.strip +[ + [0] # false, + "created_at" => 1992-10-10 12:30:00 UTC, + "name" => "Diana", + "rank" => 1 + }, + @readonly = false, + @reflects_state = [ + [0] false + ], + @transaction_state = nil, + @txn = nil, + attr_accessor :attributes = # #, + attr_reader :value = false, + attr_reader :value_before_type_cast = false + >, + "created_at" => #, + attr_reader :value = 1992-10-10 12:30:00 UTC, + attr_reader :value_before_type_cast = "1992-10-10 12:30:00" + >, + "id" => #, + attr_reader :value = nil, + attr_reader :value_before_type_cast = nil + >, + "name" => #, + attr_reader :value = "Diana", + attr_reader :value_before_type_cast = "Diana" + >, + "rank" => #, + attr_reader :value = 1, + attr_reader :value_before_type_cast = 1 + > + }, + attr_reader :types = { + "admin" => #, + "created_at" => #, + "id" => #, + "name" => #, + "rank" => # + }, + attr_reader :values = { + "admin" => nil, + "created_at" => nil, + "id" => nil, + "name" => nil, + "rank" => nil + } + > + >, + attr_accessor :destroyed_by_association = nil, + attr_reader :association_cache = {}, + attr_reader :changed_attributes = { + "admin" => nil, + "created_at" => nil, + "name" => nil, + "rank" => nil + } + >, + [1] # true, + "created_at" => 2003-05-26 14:15:00 UTC, + "name" => "Laura", + "rank" => 2 + }, + @readonly = false, + @reflects_state = [ + [0] false + ], + @transaction_state = nil, + @txn = nil, + attr_accessor :attributes = # #, + attr_reader :value = true, + attr_reader :value_before_type_cast = true + >, + "created_at" => #, + attr_reader :value = 2003-05-26 14:15:00 UTC, + attr_reader :value_before_type_cast = "2003-05-26 14:15:00" + >, + "id" => #, + attr_reader :value = nil, + attr_reader :value_before_type_cast = nil + >, + "name" => #, + attr_reader :value = "Laura", + attr_reader :value_before_type_cast = "Laura" + >, + "rank" => #, + attr_reader :value = 2, + attr_reader :value_before_type_cast = 2 + > + }, + attr_reader :types = { + "admin" => #, + "created_at" => #, + "id" => #, + "name" => #, + "rank" => # + }, + attr_reader :values = { + "admin" => nil, + "created_at" => nil, + "id" => nil, + "name" => nil, + "rank" => nil + } + > + >, + attr_accessor :destroyed_by_association = nil, + attr_reader :association_cache = {}, + attr_reader :changed_attributes = { + "admin" => nil, + "created_at" => nil, + "name" => nil, + "rank" => nil + } + > +] + EOS + end elsif activerecord_4_1? str = <<-EOS.strip [ @@ -1092,7 +1502,8 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }. ] EOS elsif activerecord_3_2? - str = <<-EOS.strip + if RUBY_VERSION > '1.9.3' + str = <<-EOS.strip [ [0] #{ !ExtVerifier.has_rails? }. } > ] - EOS + EOS + else + str = <<-EOS.strip +[ + [0] # false, + "created_at" => "1992-10-10 12:30:00", + "id" => nil, + "name" => "Diana", + "rank" => 1 + }, + attr_reader :association_cache = {}, + attr_reader :changed_attributes = { + "admin" => nil, + "created_at" => nil, + "name" => nil, + "rank" => nil + }, + attr_reader :mass_assignment_options = nil + >, + [1] # true, + "created_at" => "2003-05-26 14:15:00", + "id" => nil, + "name" => "Laura", + "rank" => 2 + }, + attr_reader :association_cache = {}, + attr_reader :changed_attributes = { + "admin" => nil, + "created_at" => nil, + "name" => nil, + "rank" => nil + }, + attr_reader :mass_assignment_options = nil + > +] + EOS + end end str.sub!('?', '1992-10-10 12:30:00') str.sub!('?', '2003-05-26 14:15:00')