Skip to content

Commit

Permalink
Merge pull request #48065 from nvasilevski/disallow-assertionless-tes…
Browse files Browse the repository at this point in the history
…ts-in-active-model

Disallow assertionless tests in Active Model
  • Loading branch information
rafaelfranca committed Jun 9, 2023
2 parents fdad62b + 2342f39 commit 3fc95e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions activemodel/test/cases/attribute_test.rb
Expand Up @@ -145,10 +145,16 @@ def serialize_cast_value(value)
end

test "duping does not eagerly type cast if we have not yet type cast" do
@type.define_singleton_method(:deserialize) { flunk }
attribute = Attribute.from_database(nil, "a value", @type)
deserialize_called = false
deserialize_called_with = nil
@type.define_singleton_method(:deserialize) do |value|
deserialize_called_with = value
deserialize_called = true
end
attribute = Attribute.from_database(nil, "my_attribute_value", @type)

attribute.dup
assert_not deserialize_called, "deserialize should not have been called, but was called with #{deserialize_called_with}"
end

class MyType
Expand Down
8 changes: 8 additions & 0 deletions activemodel/test/cases/helper.rb
Expand Up @@ -16,6 +16,14 @@
class ActiveModel::TestCase < ActiveSupport::TestCase
include ActiveSupport::Testing::MethodCallAssertions

class AssertionlessTest < StandardError; end

def after_teardown
super

raise AssertionlessTest, "No assertions made." if passed? && assertions.zero?
end

private
# Skips the current run on JRuby using Minitest::Assertions#skip
def jruby_skip(message = "")
Expand Down

0 comments on commit 3fc95e1

Please sign in to comment.