Skip to content

Commit

Permalink
Merge pull request #31525 from yahonda/5-1-stable_backport_31520
Browse files Browse the repository at this point in the history
Handle `FrozenError` if it is available to 5-1-stable
  • Loading branch information
kamipo authored and rafaelfranca committed Dec 22, 2017
1 parent 867d3ad commit a02a8d7
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion activerecord/test/cases/aggregations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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
4 changes: 4 additions & 0 deletions activerecord/test/cases/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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
11 changes: 6 additions & 5 deletions activerecord/test/cases/transactions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,12 @@ 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 }
assert_match(/frozen/i, e.message) # Not good enough, but we can't do much
# about it since there is no specific error
# for frozen objects.
assert !topic.persisted?, 'not persisted'
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.
assert_match(/frozen/i, e.message)
assert !topic.persisted?, "not persisted"
assert_nil topic.id
assert topic.frozen?, 'not frozen'
end
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 @@ -36,4 +36,8 @@ def jruby_skip(message = '')

class ActiveSupport::TestCase
include ActiveSupport::Testing::MethodCallAssertions

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 @@ -998,7 +998,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 @@ -216,7 +216,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 @@ -321,6 +321,10 @@ class ActiveSupport::TestCase
include ActiveSupport::Testing::Stream

self.test_order = :sorted

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

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

0 comments on commit a02a8d7

Please sign in to comment.