Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes the build break caused by 9ee8528 in #6445. #6451

Merged
merged 1 commit into from

2 participants

@chancancode
Owner

Ruby 1.8 raises a TypeError when trying to modify a frozen Hash, while
Ruby 1.9 raises a RuntimeError instead. Also, Ruby < 1.9.3 uses a
lowercase 'hash' in the exception message while Ruby >= 1.9.3 uses an
uppercase 'Hash' instead. This commit normalizes those issues in the
test case.

@chancancode chancancode Fixes the build break caused by 9ee8528 in #6445.
Ruby 1.8 raises a TypeError when trying to modify a frozen Hash, while
Ruby 1.9 raises a RuntimeError instead. Also, Ruby < 1.9.3 uses a
lowercase 'hash' in the exception message while Ruby >= 1.9.3 uses an
uppercase 'Hash' instead. This commit normalizes those issues in the
test case.
d3715f6
@rafaelfranca

This looks good but doesn't solve the problem with Ruby 1.9.2.

mbp:activerecord godfrey [3-2-stable_restore_frozen_state_on_rollback] $ rvm use 1.9.2-p180
Using /Users/godfrey/.rvm/gems/ruby-1.9.2-p180
mbp:activerecord godfrey [3-2-stable_restore_frozen_state_on_rollback] $ ARCONN=postgresql ruby -Itest test/cases/transactions_test.rb 
Using postgresql with Identity Map off
Loaded suite test/cases/transactions_test
Started
......................................................
Finished in 5.065494 seconds.

54 tests, 202 assertions, 0 failures, 0 errors, 0 skips

Test run options: --seed 36381
mbp:activerecord godfrey [3-2-stable_restore_frozen_state_on_rollback] $ 

It worked fine for me locally. I am comparing the lowercased error message to normalize things. Is there another problem I missed?

But with 1.9.3 it will break

[1.9.3 activerecord (3-2-stable *)]$ be ruby -Itest:lib test/cases/transactions_test.rb 
Using sqlite3 with Identity Map off
Run options: 

# Running tests:

...............F........

Finished tests in 1.816716s, 13.2107 tests/s, 46.7877 assertions/s.

  1) Failure:
test_rollback_when_saving_a_frozen_record(TransactionTest) [test/cases/transactions_test.rb:369]:
<"can't modify frozen hash"> expected but was
<"can't modify frozen Hash">.

I did this change in your code and now it works in all the ruby versions.

-    assert_equal "can't modify frozen Hash", e.message
+    assert_match /can't modify frozen hash/i, e.message

That's weird. It works for me locally:

mbp:activerecord godfrey [3-2-stable_restore_frozen_state_on_rollback] $ rvm 1.9.3
mbp:activerecord godfrey [3-2-stable_restore_frozen_state_on_rollback] $ ARCONN=postgresql ruby -Itest test/cases/transactions_test.rb 
Using postgresql with Identity Map off
Run options: 

# Running tests:

......................................................

Finished tests in 6.376307s, 8.4689 tests/s, 31.6798 assertions/s.

54 tests, 202 assertions, 0 failures, 0 errors, 0 skips
mbp:activerecord godfrey [3-2-stable_restore_frozen_state_on_rollback] $

Oh, did you pull in a different commit? Cause in this commit I changed this it to compare the downcased message:

-    assert_equal "can't modify frozen Hash", e.message
+    assert_equal "can't modify frozen hash", e.message.downcase

ok. You can open a pull request now

@chancancode
Owner

Thanks @rafaelfranca !

@rafaelfranca rafaelfranca merged commit ff3cddf into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 22, 2012
  1. @chancancode

    Fixes the build break caused by 9ee8528 in #6445.

    chancancode authored
    Ruby 1.8 raises a TypeError when trying to modify a frozen Hash, while
    Ruby 1.9 raises a RuntimeError instead. Also, Ruby < 1.9.3 uses a
    lowercase 'hash' in the exception message while Ruby >= 1.9.3 uses an
    uppercase 'Hash' instead. This commit normalizes those issues in the
    test case.
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 2 deletions.
  1. +4 −2 activerecord/test/cases/transactions_test.rb
View
6 activerecord/test/cases/transactions_test.rb
@@ -363,10 +363,12 @@ def test_rollback_when_commit_raises
end
def test_rollback_when_saving_a_frozen_record
+ expected_raise = (RUBY_VERSION < '1.9') ? TypeError : RuntimeError
+
topic = Topic.new(:title => 'test')
topic.freeze
- e = assert_raise(RuntimeError) { topic.save }
- assert_equal "can't modify frozen Hash", e.message
+ e = assert_raise(expected_raise) { topic.save }
+ assert_equal "can't modify frozen hash", e.message.downcase
assert !topic.persisted?, 'not persisted'
assert_nil topic.id
assert topic.frozen?, 'not frozen'
Something went wrong with that request. Please try again.