Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle FrozenError if it is available #31520

Merged
merged 1 commit into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion activerecord/test/cases/aggregations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_change_single_value_object

def test_immutable_value_objects
customers(:david).balance = Money.new(100)
assert_raise(RuntimeError) { customers(:david).balance.instance_eval { @amount = 20 } }
assert_raise(frozen_error_class) { customers(:david).balance.instance_eval { @amount = 20 } }
end

def test_inferred_mapping
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/query_cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def test_query_cache_does_not_allow_sql_key_mutation
payload[:sql].downcase!
end

assert_raises RuntimeError do
assert_raises frozen_error_class do
ActiveRecord::Base.cache do
assert_queries(1) { Task.find(1); Task.find(1) }
end
Expand Down
4 changes: 4 additions & 0 deletions activerecord/test/cases/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def has_column?(model, column_name)
model.reset_column_information
model.column_names.include?(column_name.to_s)
end

def frozen_error_class
Object.const_defined?(:FrozenError) ? FrozenError : RuntimeError
end
end

class PostgreSQLTestCase < TestCase
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/transactions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def test_rollback_when_commit_raises
def test_rollback_when_saving_a_frozen_record
topic = Topic.new(title: "test")
topic.freeze
e = assert_raise(RuntimeError) { topic.save }
e = assert_raise(frozen_error_class) { topic.save }
# Not good enough, but we can't do much
# about it since there is no specific error
# for frozen objects.
Expand Down
4 changes: 4 additions & 0 deletions activesupport/test/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ class ActiveSupport::TestCase
private def jruby_skip(message = "")
skip message if defined?(JRUBY_VERSION)
end

def frozen_error_class
Object.const_defined?(:FrozenError) ? FrozenError : RuntimeError
end
end
2 changes: 1 addition & 1 deletion activesupport/test/core_ext/hash_ext_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def test_except_with_original_frozen
original.freeze
assert_nothing_raised { original.except(:a) }

assert_raise(RuntimeError) { original.except!(:a) }
assert_raise(frozen_error_class) { original.except!(:a) }
end

def test_except_does_not_delete_values_in_original
Expand Down
2 changes: 1 addition & 1 deletion railties/test/application/middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def app

test "can't change middleware after it's built" do
boot!
assert_raise RuntimeError do
assert_raise frozen_error_class do
app.config.middleware.use Rack::Config
end
end
Expand Down
4 changes: 4 additions & 0 deletions railties/test/isolation/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ class ActiveSupport::TestCase
include TestHelpers::Rack
include TestHelpers::Generation
include ActiveSupport::Testing::Stream

def frozen_error_class
Object.const_defined?(:FrozenError) ? FrozenError : RuntimeError
end
end

# Create a scope and build a fixture rails app
Expand Down