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

Fix outdated ActiveRecord tests

Update the Rails 4.2 ActiveRecord tests to test for the current
format of AR models

Prior to this change the tests were broken
This commit is contained in:
Gerard Caulfield 2016-05-10 06:12:59 +10:00
parent c5e8669e9c
commit e41d317e51
No known key found for this signature in database
GPG key ID: 623B327128A9BEC3
4 changed files with 24 additions and 105 deletions

View file

@ -126,9 +126,6 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
"rank" => 1
},
@readonly = false,
@reflects_state = [
[0] false
],
@transaction_state = nil,
@txn = nil,
attr_accessor :attributes = #<ActiveRecord::AttributeSet:placeholder_id
@ -154,21 +151,10 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
>,
attr_reader :value = 1992-10-10 12:30:00 UTC,
attr_reader :value_before_type_cast = "1992-10-10 12:30:00"
>,
"id" => #<ActiveRecord::Attribute::FromDatabase:placeholder_id
attr_reader :name = "id",
attr_reader :type = #<ActiveRecord::Type::Integer:placeholder_id
@range = -2147483648...2147483648,
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
>,
attr_reader :value = nil,
attr_reader :value_before_type_cast = nil
>,
"name" => #<ActiveRecord::Attribute::FromUser:placeholder_id
attr_reader :name = "name",
attr_reader :type = #<ActiveRecord::ConnectionAdapters::SQLite3String:placeholder_id
attr_reader :type = #<ActiveRecord::Type::String:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
@ -206,7 +192,7 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
attr_reader :precision = nil,
attr_reader :scale = nil
>,
"name" => #<ActiveRecord::ConnectionAdapters::SQLite3String:placeholder_id
"name" => #<ActiveRecord::Type::String:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
@ -252,9 +238,6 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
"rank" => 1
},
@readonly = false,
@reflects_state = [
[0] false
],
@transaction_state = nil,
@txn = nil,
attr_accessor :attributes = #<ActiveRecord::AttributeSet:placeholder_id
@ -281,21 +264,10 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
>,
attr_reader :value = 1992-10-10 12:30:00 UTC,
attr_reader :value_before_type_cast = "1992-10-10 12:30:00"
>,
"id" => #<ActiveRecord::Attribute::FromDatabase:placeholder_id
attr_reader :name = "id",
attr_reader :type = #<ActiveRecord::Type::Integer:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :range = -2147483648...2147483648,
attr_reader :scale = nil
>,
attr_reader :value = nil,
attr_reader :value_before_type_cast = nil
>,
"name" => #<ActiveRecord::Attribute::FromUser:placeholder_id
attr_reader :name = "name",
attr_reader :type = #<ActiveRecord::ConnectionAdapters::SQLite3String:placeholder_id
attr_reader :type = #<ActiveRecord::Type::String:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
@ -332,7 +304,7 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
attr_reader :range = -2147483648...2147483648,
attr_reader :scale = nil
>,
"name" => #<ActiveRecord::ConnectionAdapters::SQLite3String:placeholder_id
"name" => #<ActiveRecord::Type::String:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
@ -646,9 +618,6 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
"rank" => 1
},
@readonly = false,
@reflects_state = [
[0] false
],
@transaction_state = nil,
@txn = nil,
attr_accessor :attributes = #<ActiveRecord::AttributeSet:placeholder_id
@ -674,21 +643,10 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
>,
attr_reader :value = 1992-10-10 12:30:00 UTC,
attr_reader :value_before_type_cast = "1992-10-10 12:30:00"
>,
"id" => #<ActiveRecord::Attribute::FromDatabase:placeholder_id
attr_reader :name = "id",
attr_reader :type = #<ActiveRecord::Type::Integer:placeholder_id
@range = -2147483648...2147483648,
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
>,
attr_reader :value = nil,
attr_reader :value_before_type_cast = nil
>,
"name" => #<ActiveRecord::Attribute::FromUser:placeholder_id
attr_reader :name = "name",
attr_reader :type = #<ActiveRecord::ConnectionAdapters::SQLite3String:placeholder_id
attr_reader :type = #<ActiveRecord::Type::String:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
@ -726,7 +684,7 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
attr_reader :precision = nil,
attr_reader :scale = nil
>,
"name" => #<ActiveRecord::ConnectionAdapters::SQLite3String:placeholder_id
"name" => #<ActiveRecord::Type::String:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
@ -769,9 +727,6 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
"rank" => 2
},
@readonly = false,
@reflects_state = [
[0] false
],
@transaction_state = nil,
@txn = nil,
attr_accessor :attributes = #<ActiveRecord::AttributeSet:placeholder_id
@ -797,21 +752,10 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
>,
attr_reader :value = 2003-05-26 14:15:00 UTC,
attr_reader :value_before_type_cast = "2003-05-26 14:15:00"
>,
"id" => #<ActiveRecord::Attribute::FromDatabase:placeholder_id
attr_reader :name = "id",
attr_reader :type = #<ActiveRecord::Type::Integer:placeholder_id
@range = -2147483648...2147483648,
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
>,
attr_reader :value = nil,
attr_reader :value_before_type_cast = nil
>,
"name" => #<ActiveRecord::Attribute::FromUser:placeholder_id
attr_reader :name = "name",
attr_reader :type = #<ActiveRecord::ConnectionAdapters::SQLite3String:placeholder_id
attr_reader :type = #<ActiveRecord::Type::String:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
@ -849,7 +793,7 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
attr_reader :precision = nil,
attr_reader :scale = nil
>,
"name" => #<ActiveRecord::ConnectionAdapters::SQLite3String:placeholder_id
"name" => #<ActiveRecord::Type::String:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
@ -897,9 +841,6 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
"rank" => 1
},
@readonly = false,
@reflects_state = [
[0] false
],
@transaction_state = nil,
@txn = nil,
attr_accessor :attributes = #<ActiveRecord::AttributeSet:placeholder_id
@ -926,21 +867,10 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
>,
attr_reader :value = 1992-10-10 12:30:00 UTC,
attr_reader :value_before_type_cast = "1992-10-10 12:30:00"
>,
"id" => #<ActiveRecord::Attribute::FromDatabase:placeholder_id
attr_reader :name = "id",
attr_reader :type = #<ActiveRecord::Type::Integer:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :range = -2147483648...2147483648,
attr_reader :scale = nil
>,
attr_reader :value = nil,
attr_reader :value_before_type_cast = nil
>,
"name" => #<ActiveRecord::Attribute::FromUser:placeholder_id
attr_reader :name = "name",
attr_reader :type = #<ActiveRecord::ConnectionAdapters::SQLite3String:placeholder_id
attr_reader :type = #<ActiveRecord::Type::String:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
@ -977,7 +907,7 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
attr_reader :range = -2147483648...2147483648,
attr_reader :scale = nil
>,
"name" => #<ActiveRecord::ConnectionAdapters::SQLite3String:placeholder_id
"name" => #<ActiveRecord::Type::String:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
@ -1020,9 +950,6 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
"rank" => 2
},
@readonly = false,
@reflects_state = [
[0] false
],
@transaction_state = nil,
@txn = nil,
attr_accessor :attributes = #<ActiveRecord::AttributeSet:placeholder_id
@ -1049,21 +976,10 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
>,
attr_reader :value = 2003-05-26 14:15:00 UTC,
attr_reader :value_before_type_cast = "2003-05-26 14:15:00"
>,
"id" => #<ActiveRecord::Attribute::FromDatabase:placeholder_id
attr_reader :name = "id",
attr_reader :type = #<ActiveRecord::Type::Integer:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :range = -2147483648...2147483648,
attr_reader :scale = nil
>,
attr_reader :value = nil,
attr_reader :value_before_type_cast = nil
>,
"name" => #<ActiveRecord::Attribute::FromUser:placeholder_id
attr_reader :name = "name",
attr_reader :type = #<ActiveRecord::ConnectionAdapters::SQLite3String:placeholder_id
attr_reader :type = #<ActiveRecord::Type::String:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil
@ -1100,7 +1016,7 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
attr_reader :range = -2147483648...2147483648,
attr_reader :scale = nil
>,
"name" => #<ActiveRecord::ConnectionAdapters::SQLite3String:placeholder_id
"name" => #<ActiveRecord::Type::String:placeholder_id
attr_reader :limit = nil,
attr_reader :precision = nil,
attr_reader :scale = nil

View file

@ -193,7 +193,7 @@ class Parent < Object {
out = @ap.send(:awesome, parent)
str = <<-EOS.strip
#<Parent:placeholder_id> {
"_id" => placeholder_bison_id,
"_id" => placeholder_bson_id,
"name" => "test"
}
EOS
@ -222,7 +222,7 @@ class Parent < Object {
out = @ap.send(:awesome, parent)
str = <<-EOS.strip
#<Parent:placeholder_id> {
"_id" => placeholder_bison_id,
"_id" => placeholder_bson_id,
"name" => "test",
"child" => embeds one Child,
"sibling" => one Sibling
@ -247,10 +247,10 @@ class Parent < Object {
out = @ap.send(:awesome, parent)
str = <<-EOS.strip
#<Parent:placeholder_id> {
"_id" => placeholder_bison_id,
"_id" => placeholder_bson_id,
"name" => "test",
"child" => embedded #<Child:placeholder_id> {
"_id" => placeholder_bison_id,
"_id" => placeholder_bson_id,
"data" => 5
},
"sibling" => one Sibling

View file

@ -35,7 +35,7 @@ RSpec.describe "AwesomePrint/Mongoid", skip: ->{ !ExtVerifier.has_mongoid? }.cal
:last_name => "Capone"
}
EOS
expect(out).to be_similar_to(str)
expect(out).to be_similar_to(str, {:skip_bson => true})
end
it "should print the class" do

View file

@ -51,9 +51,10 @@ end
# parts (such as object IDs) with simple placeholder strings before doing a
# comparison with a given string. It's important that this method only matches
# a string which strictly conforms to the expected object ID format.
RSpec::Matchers.define :be_similar_to do |expected|
RSpec::Matchers.define :be_similar_to do |expected, options|
match do |actual|
@actual = normalize_object_strings(actual)
options ||= {}
@actual = normalize_object_id_strings(actual, options)
values_match? expected, @actual
end
@ -63,8 +64,10 @@ end
# Override the Object IDs with a placeholder so that we are only checking
# that an ID is present and not that it matches a certain value. This is
# necessary as the Object IDs are not deterministic.
def normalize_object_strings(str)
str.gsub(/#<(.*?):0x[a-f\d]+/, '#<\1:placeholder_id')
def normalize_object_id_strings(str, options)
str = str.gsub(/#<(.*?):0x[a-f\d]+/, '#<\1:placeholder_id') unless options[:skip_standard]
str = str.gsub(/BSON::ObjectId\('[a-f\d]{24}'\)/, 'placeholder_bson_id') unless options[:skip_bson]
str
end
def stub_dotfile!