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

Merged
merged 1 commit into from May 22, 2012

Projects

None yet

2 participants

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

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

Owner
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
Owner

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] $
Owner

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

Owner

Thanks @rafaelfranca !

@rafaelfranca rafaelfranca merged commit ff3cddf into rails:3-2-stable May 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment