"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "activerecord/test/cases/yaml_serialization_test.rb" between
rails-6.1.3.2.tar.gz and rails-6.1.4.tar.gz

About: Ruby on Rails is a web application development framework (written in Ruby).

yaml_serialization_test.rb  (rails-6.1.3.2):yaml_serialization_test.rb  (rails-6.1.4)
skipping to change at line 22 skipping to change at line 22
def test_to_yaml_with_time_with_zone_should_not_raise_exception def test_to_yaml_with_time_with_zone_should_not_raise_exception
with_timezone_config aware_attributes: true, zone: "Pacific Time (US & Canad a)" do with_timezone_config aware_attributes: true, zone: "Pacific Time (US & Canad a)" do
topic = Topic.new(written_on: DateTime.now) topic = Topic.new(written_on: DateTime.now)
assert_nothing_raised { topic.to_yaml } assert_nothing_raised { topic.to_yaml }
end end
end end
def test_roundtrip def test_roundtrip
topic = Topic.first topic = Topic.first
assert topic assert topic
t = YAML.load YAML.dump topic t = yaml_load YAML.dump topic
assert_equal topic, t assert_equal topic, t
end end
def test_roundtrip_serialized_column def test_roundtrip_serialized_column
topic = Topic.new(content: { omg: :lol }) topic = Topic.new(content: { omg: :lol })
assert_equal({ omg: :lol }, YAML.load(YAML.dump(topic)).content) assert_equal({ omg: :lol }, yaml_load(YAML.dump(topic)).content)
end end
def test_psych_roundtrip def test_psych_roundtrip
topic = Topic.first topic = Topic.first
assert topic assert topic
t = Psych.load Psych.dump topic t = yaml_load Psych.dump topic
assert_equal topic, t assert_equal topic, t
end end
def test_psych_roundtrip_new_object def test_psych_roundtrip_new_object
topic = Topic.new topic = Topic.new
assert topic assert topic
t = Psych.load Psych.dump topic t = yaml_load Psych.dump topic
assert_equal topic.attributes, t.attributes assert_equal topic.attributes, t.attributes
end end
def test_active_record_relation_serialization def test_active_record_relation_serialization
[Topic.all].to_yaml [Topic.all].to_yaml
end end
def test_raw_types_are_not_changed_on_round_trip def test_raw_types_are_not_changed_on_round_trip
topic = Topic.new(parent_id: "123") topic = Topic.new(parent_id: "123")
assert_equal "123", topic.parent_id_before_type_cast assert_equal "123", topic.parent_id_before_type_cast
assert_equal "123", YAML.load(YAML.dump(topic)).parent_id_before_type_cast assert_equal "123", yaml_load(YAML.dump(topic)).parent_id_before_type_cast
end end
def test_cast_types_are_not_changed_on_round_trip def test_cast_types_are_not_changed_on_round_trip
topic = Topic.new(parent_id: "123") topic = Topic.new(parent_id: "123")
assert_equal 123, topic.parent_id assert_equal 123, topic.parent_id
assert_equal 123, YAML.load(YAML.dump(topic)).parent_id assert_equal 123, yaml_load(YAML.dump(topic)).parent_id
end end
def test_new_records_remain_new_after_round_trip def test_new_records_remain_new_after_round_trip
topic = Topic.new topic = Topic.new
assert topic.new_record?, "Sanity check that new records are new" assert topic.new_record?, "Sanity check that new records are new"
assert YAML.load(YAML.dump(topic)).new_record?, "Record should be new after deserialization" assert yaml_load(YAML.dump(topic)).new_record?, "Record should be new after deserialization"
topic.save! topic.save!
assert_not topic.new_record?, "Saved records are not new" assert_not topic.new_record?, "Saved records are not new"
assert_not YAML.load(YAML.dump(topic)).new_record?, "Saved record should not be new after deserialization" assert_not yaml_load(YAML.dump(topic)).new_record?, "Saved record should not be new after deserialization"
topic = Topic.select("title").last topic = Topic.select("title").last
assert_not topic.new_record?, "Loaded records without ID are not new" assert_not topic.new_record?, "Loaded records without ID are not new"
assert_not YAML.load(YAML.dump(topic)).new_record?, "Record should not be ne w after deserialization" assert_not yaml_load(YAML.dump(topic)).new_record?, "Record should not be ne w after deserialization"
end end
def test_types_of_virtual_columns_are_not_changed_on_round_trip def test_types_of_virtual_columns_are_not_changed_on_round_trip
author = Author.select("authors.*, count(posts.id) as posts_count") author = Author.select("authors.*, count(posts.id) as posts_count")
.joins(:posts) .joins(:posts)
.group("authors.id") .group("authors.id")
.first .first
dumped = YAML.load(YAML.dump(author)) dumped = yaml_load(YAML.dump(author))
assert_equal 5, author.posts_count assert_equal 5, author.posts_count
assert_equal 5, dumped.posts_count assert_equal 5, dumped.posts_count
end end
def test_a_yaml_version_is_provided_for_future_backwards_compat def test_a_yaml_version_is_provided_for_future_backwards_compat
coder = {} coder = {}
Topic.first.encode_with(coder) Topic.first.encode_with(coder)
assert coder["active_record_yaml_version"] assert coder["active_record_yaml_version"]
end end
def test_deserializing_rails_v2_yaml def test_deserializing_rails_v2_yaml
topic = YAML.load(yaml_fixture("rails_v2")) topic = yaml_load(yaml_fixture("rails_v2"))
assert_not_predicate topic, :new_record? assert_not_predicate topic, :new_record?
assert_equal 1, topic.id assert_equal 1, topic.id
assert_equal "The First Topic", topic.title assert_equal "The First Topic", topic.title
assert_equal "Have a nice day", topic.content assert_equal "Have a nice day", topic.content
end end
def test_deserializing_rails_v1_mysql_yaml def test_deserializing_rails_v1_mysql_yaml
topic = YAML.load(yaml_fixture("rails_v1_mysql")) topic = yaml_load(yaml_fixture("rails_v1_mysql"))
assert_not_predicate topic, :new_record? assert_not_predicate topic, :new_record?
assert_equal 1, topic.id assert_equal 1, topic.id
assert_equal "The First Topic", topic.title assert_equal "The First Topic", topic.title
assert_equal "Have a nice day", topic.content assert_equal "Have a nice day", topic.content
end end
def test_deserializing_rails_41_yaml def test_deserializing_rails_41_yaml
topic = assert_deprecated do topic = assert_deprecated do
YAML.load(yaml_fixture("rails_4_1")) yaml_load(yaml_fixture("rails_4_1"))
end end
assert_predicate topic, :new_record? assert_predicate topic, :new_record?
assert_nil topic.id assert_nil topic.id
assert_equal "The First Topic", topic.title assert_equal "The First Topic", topic.title
assert_equal({ omg: :lol }, topic.content) assert_equal({ omg: :lol }, topic.content)
end end
def test_deserializing_rails_4_2_0_yaml def test_deserializing_rails_4_2_0_yaml
topic = assert_deprecated do topic = assert_deprecated do
YAML.load(yaml_fixture("rails_4_2_0")) yaml_load(yaml_fixture("rails_4_2_0"))
end end
assert_not_predicate topic, :new_record? assert_not_predicate topic, :new_record?
assert_equal 1, topic.id assert_equal 1, topic.id
assert_equal "The First Topic", topic.title assert_equal "The First Topic", topic.title
assert_equal("Have a nice day", topic.content) assert_equal("Have a nice day", topic.content)
end end
def test_yaml_encoding_keeps_mutations def test_yaml_encoding_keeps_mutations
author = Author.first author = Author.first
author.name = "Sean" author.name = "Sean"
dumped = YAML.load(YAML.dump(author)) dumped = yaml_load(YAML.dump(author))
assert_equal "Sean", dumped.name assert_equal "Sean", dumped.name
assert_equal author.name_was, dumped.name_was assert_equal author.name_was, dumped.name_was
assert_equal author.changes, dumped.changes assert_equal author.changes, dumped.changes
end end
def test_yaml_encoding_keeps_false_values def test_yaml_encoding_keeps_false_values
topic = Topic.first topic = Topic.first
topic.approved = false topic.approved = false
dumped = YAML.load(YAML.dump(topic)) dumped = yaml_load(YAML.dump(topic))
assert_equal false, dumped.approved assert_equal false, dumped.approved
end end
private private
def yaml_load(payload)
YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(payload) : YAML.load(pay
load)
end
def yaml_fixture(file_name) def yaml_fixture(file_name)
path = File.expand_path( path = File.expand_path(
"support/yaml_compatibility_fixtures/#{file_name}.yml", "support/yaml_compatibility_fixtures/#{file_name}.yml",
TEST_ROOT TEST_ROOT
) )
File.read(path) File.read(path)
end end
end end
 End of changes. 17 change blocks. 
16 lines changed or deleted 21 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)