aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/aggregations.rb2
-rw-r--r--activerecord/test/aggregations_test.rb4
-rwxr-xr-xactiverecord/test/base_test.rb12
-rw-r--r--activesupport/lib/active_support/core_ext/exception.rb8
-rw-r--r--activesupport/test/core_ext/exception_test.rb4
5 files changed, 21 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb
index 56c6fb9893..f0f34e9a99 100644
--- a/activerecord/lib/active_record/aggregations.rb
+++ b/activerecord/lib/active_record/aggregations.rb
@@ -104,7 +104,7 @@ module ActiveRecord
# changed through means other than the writer method.
#
# The immutable requirement is enforced by Active Record by freezing any object assigned as a value object. Attempting to
- # change it afterwards will result in a <tt>TypeError</tt>.
+ # change it afterwards will result in a <tt>ActiveSupport::FrozenObjectError</tt>.
#
# Read more about value objects on http://c2.com/cgi/wiki?ValueObject and on the dangers of not keeping value objects
# immutable on http://c2.com/cgi/wiki?ValueObjectsShouldBeImmutable
diff --git a/activerecord/test/aggregations_test.rb b/activerecord/test/aggregations_test.rb
index ea0339c63a..caa26a2091 100644
--- a/activerecord/test/aggregations_test.rb
+++ b/activerecord/test/aggregations_test.rb
@@ -25,7 +25,7 @@ class AggregationsTest < Test::Unit::TestCase
def test_immutable_value_objects
customers(:david).balance = Money.new(100)
- assert_raises(TypeError) { customers(:david).balance.instance_eval { @amount = 20 } }
+ assert_raise(ActiveSupport::FrozenObjectError) { customers(:david).balance.instance_eval { @amount = 20 } }
end
def test_inferred_mapping
@@ -90,7 +90,7 @@ class AggregationsTest < Test::Unit::TestCase
end
def test_nil_raises_error_when_allow_nil_is_false
- assert_raises(NoMethodError) { customers(:david).balance = nil }
+ assert_raise(NoMethodError) { customers(:david).balance = nil }
end
def test_allow_nil_address_loaded_when_only_some_attributes_are_nil
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index e3bc6ac398..8b3a279287 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -743,7 +743,7 @@ class BasicsTest < Test::Unit::TestCase
client.destroy
assert client.frozen?
assert_kind_of Firm, client.firm
- assert_raises(TypeError) { client.name = "something else" }
+ assert_raises(ActiveSupport::FrozenObjectError) { client.name = "something else" }
end
def test_update_attribute
@@ -1682,19 +1682,19 @@ class BasicsTest < Test::Unit::TestCase
def test_except_attributes
assert_equal(
- %w( author_name type id approved replies_count bonus_time written_on content author_email_address parent_id last_read),
- topics(:first).attributes(:except => :title).keys
+ %w( author_name type id approved replies_count bonus_time written_on content author_email_address parent_id last_read).sort,
+ topics(:first).attributes(:except => :title).keys.sort
)
assert_equal(
- %w( replies_count bonus_time written_on content author_email_address parent_id last_read),
- topics(:first).attributes(:except => [ :title, :id, :type, :approved, :author_name ]).keys
+ %w( replies_count bonus_time written_on content author_email_address parent_id last_read).sort,
+ topics(:first).attributes(:except => [ :title, :id, :type, :approved, :author_name ]).keys.sort
)
end
def test_include_attributes
assert_equal(%w( title ), topics(:first).attributes(:only => :title).keys)
- assert_equal(%w( title author_name type id approved ), topics(:first).attributes(:only => [ :title, :id, :type, :approved, :author_name ]).keys)
+ assert_equal(%w( title author_name type id approved ).sort, topics(:first).attributes(:only => [ :title, :id, :type, :approved, :author_name ]).keys.sort)
end
def test_type_name_with_module_should_handle_beginning
diff --git a/activesupport/lib/active_support/core_ext/exception.rb b/activesupport/lib/active_support/core_ext/exception.rb
index 14cd577066..57c8568334 100644
--- a/activesupport/lib/active_support/core_ext/exception.rb
+++ b/activesupport/lib/active_support/core_ext/exception.rb
@@ -1,3 +1,11 @@
+module ActiveSupport
+ if RUBY_VERSION >= '1.9'
+ FrozenObjectError = RuntimeError
+ else
+ FrozenObjectError = TypeError
+ end
+end
+
class Exception # :nodoc:
def clean_message
Pathname.clean_within message
diff --git a/activesupport/test/core_ext/exception_test.rb b/activesupport/test/core_ext/exception_test.rb
index b1ea564a0c..6a60c91380 100644
--- a/activesupport/test/core_ext/exception_test.rb
+++ b/activesupport/test/core_ext/exception_test.rb
@@ -61,4 +61,8 @@ class ExceptionExtTests < Test::Unit::TestCase
assert_kind_of Exception, e
assert_equal [], e.application_backtrace
end
+
+ def test_frozen_error
+ assert_raise(ActiveSupport::FrozenObjectError) { "foo".freeze.gsub!(/oo/,'aa') }
+ end
end