From 994ce87bbda7cc4b0059c951b06cdd15dc26cb97 Mon Sep 17 00:00:00 2001 From: Iain Beeston Date: Mon, 3 Oct 2016 14:06:11 +0100 Subject: Moved database-specific ActiveModel types into ActiveRecord ie. DecimalWithoutScale, Text and UnsignedInteger --- activemodel/test/cases/type/unsigned_integer_test.rb | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 activemodel/test/cases/type/unsigned_integer_test.rb (limited to 'activemodel/test/cases') diff --git a/activemodel/test/cases/type/unsigned_integer_test.rb b/activemodel/test/cases/type/unsigned_integer_test.rb deleted file mode 100644 index 026cb08a06..0000000000 --- a/activemodel/test/cases/type/unsigned_integer_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "cases/helper" -require "active_model/type" - -module ActiveModel - module Type - class UnsignedIntegerTest < ActiveModel::TestCase - test "unsigned int max value is in range" do - assert_equal(4294967295, UnsignedInteger.new.serialize(4294967295)) - end - - test "minus value is out of range" do - assert_raises(ActiveModel::RangeError) do - UnsignedInteger.new.serialize(-1) - end - end - end - end -end -- cgit v1.2.3 From 0951306ca5edbaec10edf3440d5ba11062a4f2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 8 Dec 2016 16:20:07 -0500 Subject: Make ActiveModel::Errors backward compatible with 4.2 If a Error object was serialized in the database as YAML in the Rails 4.2 version, if we load in the Rails 5.0 version it will miss the @details instance variable so methods like #clear and #add will start to fail. --- activemodel/test/cases/errors_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'activemodel/test/cases') diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index fc840bf192..e868d20fc8 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -365,4 +365,24 @@ class ErrorsTest < ActiveModel::TestCase assert_equal errors.messages, serialized.messages assert_equal errors.details, serialized.details end + + test "errors are backward compatible with the Rails 4.2 format" do + yaml = <<-CODE.strip_heredoc + --- !ruby/object:ActiveModel::Errors + base: &1 !ruby/object:ErrorsTest::Person + errors: !ruby/object:ActiveModel::Errors + base: *1 + messages: {} + messages: {} + CODE + + errors = YAML.load(yaml) + errors.add(:name, :invalid) + assert_equal({ name: ["is invalid"] }, errors.messages) + assert_equal({ name: [{ error: :invalid }] }, errors.details) + + errors.clear + assert_equal({}, errors.messages) + assert_equal({}, errors.details) + end end -- cgit v1.2.3 From 414484f68dcace66d0a9fcec3c22db5847b12b42 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 12 Dec 2016 22:32:04 +0900 Subject: Missing require "yaml" --- activemodel/test/cases/errors_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activemodel/test/cases') diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index e868d20fc8..e6ba06301d 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -1,4 +1,5 @@ require "cases/helper" +require "yaml" class ErrorsTest < ActiveModel::TestCase class Person -- cgit v1.2.3 From 21e5fd4a2a1c162ad33708d3e01b1fda165f204d Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 19 Dec 2016 19:10:49 +0900 Subject: Describe what we are protecting --- activemodel/test/cases/attribute_assignment_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activemodel/test/cases') diff --git a/activemodel/test/cases/attribute_assignment_test.rb b/activemodel/test/cases/attribute_assignment_test.rb index 8eb389d331..fa41d1b95f 100644 --- a/activemodel/test/cases/attribute_assignment_test.rb +++ b/activemodel/test/cases/attribute_assignment_test.rb @@ -16,6 +16,8 @@ class AttributeAssignmentTest < ActiveModel::TestCase raise ErrorFromAttributeWriter end + # TODO Change this to private once we've dropped Ruby 2.2 support. + # Workaround for Ruby 2.2 "private attribute?" warning. protected attr_writer :metadata -- cgit v1.2.3 From e8ba0c0f21e2660b90f872fa4595156ca6190c77 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 25 Dec 2016 02:29:52 +0900 Subject: "Use assert_nil if expecting nil. This will fail in minitest 6." --- activemodel/test/cases/secure_password_test.rb | 2 +- activemodel/test/cases/type/binary_test.rb | 2 +- activemodel/test/cases/type/date_test.rb | 8 ++++---- activemodel/test/cases/type/date_time_test.rb | 8 ++++---- activemodel/test/cases/type/time_test.rb | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'activemodel/test/cases') diff --git a/activemodel/test/cases/secure_password_test.rb b/activemodel/test/cases/secure_password_test.rb index 9423df2c09..77ce86f392 100644 --- a/activemodel/test/cases/secure_password_test.rb +++ b/activemodel/test/cases/secure_password_test.rb @@ -179,7 +179,7 @@ class SecurePasswordTest < ActiveModel::TestCase test "setting a nil password should clear an existing password" do @existing_user.password = nil - assert_equal nil, @existing_user.password_digest + assert_nil @existing_user.password_digest end test "authenticate" do diff --git a/activemodel/test/cases/type/binary_test.rb b/activemodel/test/cases/type/binary_test.rb index e6a32dbeec..e9c2ccfca4 100644 --- a/activemodel/test/cases/type/binary_test.rb +++ b/activemodel/test/cases/type/binary_test.rb @@ -6,7 +6,7 @@ module ActiveModel class BinaryTest < ActiveModel::TestCase def test_type_cast_binary type = Type::Binary.new - assert_equal nil, type.cast(nil) + assert_nil type.cast(nil) assert_equal "1", type.cast("1") assert_equal 1, type.cast(1) end diff --git a/activemodel/test/cases/type/date_test.rb b/activemodel/test/cases/type/date_test.rb index 44e20a327b..0cc90e99d3 100644 --- a/activemodel/test/cases/type/date_test.rb +++ b/activemodel/test/cases/type/date_test.rb @@ -6,10 +6,10 @@ module ActiveModel class DateTest < ActiveModel::TestCase def test_type_cast_date type = Type::Date.new - assert_equal nil, type.cast(nil) - assert_equal nil, type.cast("") - assert_equal nil, type.cast(" ") - assert_equal nil, type.cast("ABC") + assert_nil type.cast(nil) + assert_nil type.cast("") + assert_nil type.cast(" ") + assert_nil type.cast("ABC") date_string = ::Time.now.utc.strftime("%F") assert_equal date_string, type.cast(date_string).strftime("%F") diff --git a/activemodel/test/cases/type/date_time_test.rb b/activemodel/test/cases/type/date_time_test.rb index fb82260d2b..75a7fc686e 100644 --- a/activemodel/test/cases/type/date_time_test.rb +++ b/activemodel/test/cases/type/date_time_test.rb @@ -6,10 +6,10 @@ module ActiveModel class DateTimeTest < ActiveModel::TestCase def test_type_cast_datetime_and_timestamp type = Type::DateTime.new - assert_equal nil, type.cast(nil) - assert_equal nil, type.cast("") - assert_equal nil, type.cast(" ") - assert_equal nil, type.cast("ABC") + assert_nil type.cast(nil) + assert_nil type.cast("") + assert_nil type.cast(" ") + assert_nil type.cast("ABC") datetime_string = ::Time.now.utc.strftime("%FT%T") assert_equal datetime_string, type.cast(datetime_string).strftime("%FT%T") diff --git a/activemodel/test/cases/type/time_test.rb b/activemodel/test/cases/type/time_test.rb index a6a79833e6..0cc4d33caa 100644 --- a/activemodel/test/cases/type/time_test.rb +++ b/activemodel/test/cases/type/time_test.rb @@ -6,9 +6,9 @@ module ActiveModel class TimeTest < ActiveModel::TestCase def test_type_cast_time type = Type::Time.new - assert_equal nil, type.cast(nil) - assert_equal nil, type.cast("") - assert_equal nil, type.cast("ABC") + assert_nil type.cast(nil) + assert_nil type.cast("") + assert_nil type.cast("ABC") time_string = ::Time.now.utc.strftime("%T") assert_equal time_string, type.cast(time_string).strftime("%T") -- cgit v1.2.3