Changeset 8510
- Timestamp:
- 12/29/07 19:43:07 (8 months ago)
- Files:
-
- trunk/activerecord/lib/active_record/aggregations.rb (modified) (1 diff)
- trunk/activerecord/test/aggregations_test.rb (modified) (2 diffs)
- trunk/activerecord/test/base_test.rb (modified) (3 diffs)
- trunk/activesupport/lib/active_support/core_ext/exception.rb (modified) (1 diff)
- trunk/activesupport/test/core_ext/exception_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/aggregations.rb
r8507 r8510 105 105 # 106 106 # The immutable requirement is enforced by Active Record by freezing any object assigned as a value object. Attempting to 107 # change it afterwards will result in a <tt> TypeError</tt>.107 # change it afterwards will result in a <tt>ActiveSupport::FrozenObjectError</tt>. 108 108 # 109 109 # Read more about value objects on http://c2.com/cgi/wiki?ValueObject and on the dangers of not keeping value objects trunk/activerecord/test/aggregations_test.rb
r8218 r8510 26 26 def test_immutable_value_objects 27 27 customers(:david).balance = Money.new(100) 28 assert_raise s(TypeError) {customers(:david).balance.instance_eval { @amount = 20 } }28 assert_raise(ActiveSupport::FrozenObjectError) { customers(:david).balance.instance_eval { @amount = 20 } } 29 29 end 30 30 … … 91 91 92 92 def test_nil_raises_error_when_allow_nil_is_false 93 assert_raise s(NoMethodError) { customers(:david).balance = nil }93 assert_raise(NoMethodError) { customers(:david).balance = nil } 94 94 end 95 95 trunk/activerecord/test/base_test.rb
r8455 r8510 744 744 assert client.frozen? 745 745 assert_kind_of Firm, client.firm 746 assert_raises( TypeError) { client.name = "something else" }746 assert_raises(ActiveSupport::FrozenObjectError) { client.name = "something else" } 747 747 end 748 748 … … 1683 1683 def test_except_attributes 1684 1684 assert_equal( 1685 %w( author_name type id approved replies_count bonus_time written_on content author_email_address parent_id last_read) ,1686 topics(:first).attributes(:except => :title).keys 1685 %w( author_name type id approved replies_count bonus_time written_on content author_email_address parent_id last_read).sort, 1686 topics(:first).attributes(:except => :title).keys.sort 1687 1687 ) 1688 1688 1689 1689 assert_equal( 1690 %w( replies_count bonus_time written_on content author_email_address parent_id last_read) ,1691 topics(:first).attributes(:except => [ :title, :id, :type, :approved, :author_name ]).keys 1690 %w( replies_count bonus_time written_on content author_email_address parent_id last_read).sort, 1691 topics(:first).attributes(:except => [ :title, :id, :type, :approved, :author_name ]).keys.sort 1692 1692 ) 1693 1693 end … … 1695 1695 def test_include_attributes 1696 1696 assert_equal(%w( title ), topics(:first).attributes(:only => :title).keys) 1697 assert_equal(%w( title author_name type id approved ) , topics(:first).attributes(:only => [ :title, :id, :type, :approved, :author_name ]).keys)1697 assert_equal(%w( title author_name type id approved ).sort, topics(:first).attributes(:only => [ :title, :id, :type, :approved, :author_name ]).keys.sort) 1698 1698 end 1699 1699 trunk/activesupport/lib/active_support/core_ext/exception.rb
r7474 r8510 1 module ActiveSupport 2 if RUBY_VERSION >= '1.9' 3 FrozenObjectError = RuntimeError 4 else 5 FrozenObjectError = TypeError 6 end 7 end 8 1 9 class Exception # :nodoc: 2 10 def clean_message trunk/activesupport/test/core_ext/exception_test.rb
r4885 r8510 62 62 assert_equal [], e.application_backtrace 63 63 end 64 65 def test_frozen_error 66 assert_raise(ActiveSupport::FrozenObjectError) { "foo".freeze.gsub!(/oo/,'aa') } 67 end 64 68 end