Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8510

Show
Ignore:
Timestamp:
12/29/07 19:43:07 (8 months ago)
Author:
bitsweat
Message:

Ruby 1.9 compat: introduce ActiveSupport::FrozenObjectError normalize TypeError vs RuntimeError handling. Closes #10645 [Frederick Cheung]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/aggregations.rb

    r8507 r8510  
    105105    # 
    106106    # 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>. 
    108108    #  
    109109    # 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  
    2626  def test_immutable_value_objects 
    2727    customers(:david).balance = Money.new(100) 
    28     assert_raises(TypeError) { customers(:david).balance.instance_eval { @amount = 20 } } 
     28    assert_raise(ActiveSupport::FrozenObjectError) { customers(:david).balance.instance_eval { @amount = 20 } } 
    2929  end   
    3030   
     
    9191   
    9292  def test_nil_raises_error_when_allow_nil_is_false 
    93     assert_raises(NoMethodError) { customers(:david).balance = nil } 
     93    assert_raise(NoMethodError) { customers(:david).balance = nil } 
    9494  end 
    9595 
  • trunk/activerecord/test/base_test.rb

    r8455 r8510  
    744744    assert client.frozen? 
    745745    assert_kind_of Firm, client.firm 
    746     assert_raises(TypeError) { client.name = "something else" } 
     746    assert_raises(ActiveSupport::FrozenObjectError) { client.name = "something else" } 
    747747  end 
    748748   
     
    16831683  def test_except_attributes 
    16841684    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 
    16871687    ) 
    16881688 
    16891689    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 
    16921692    ) 
    16931693  end 
     
    16951695  def test_include_attributes 
    16961696    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
    16981698  end 
    16991699   
  • trunk/activesupport/lib/active_support/core_ext/exception.rb

    r7474 r8510  
     1module ActiveSupport 
     2  if RUBY_VERSION >= '1.9' 
     3    FrozenObjectError = RuntimeError 
     4  else 
     5    FrozenObjectError = TypeError 
     6  end 
     7end 
     8 
    19class Exception # :nodoc: 
    210  def clean_message 
  • trunk/activesupport/test/core_ext/exception_test.rb

    r4885 r8510  
    6262    assert_equal [], e.application_backtrace 
    6363  end 
     64 
     65  def test_frozen_error 
     66    assert_raise(ActiveSupport::FrozenObjectError) { "foo".freeze.gsub!(/oo/,'aa') } 
     67  end 
    6468end