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

Changeset 8156

Show
Ignore:
Timestamp:
11/16/07 20:31:24 (1 year ago)
Author:
bitsweat
Message:

attr_readonly behaves well with optimistic locking. Closes #10188.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r8138 r8156  
    11*SVN* 
     2 
     3* attr_readonly behaves well with optimistic locking.  #10188 [Nick Bugajski] 
    24 
    35* Base#to_xml supports the nil="true" attribute like Hash#to_xml.  #8268 [Catfish] 
  • trunk/activerecord/lib/active_record/locking/optimistic.rb

    r6843 r8156  
    7777            affected_rows = connection.update(<<-end_sql, "#{self.class.name} Update with optimistic locking") 
    7878              UPDATE #{self.class.table_name} 
    79               SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))} 
     79              SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false, false))} 
    8080              WHERE #{self.class.primary_key} = #{quote_value(id)} 
    8181              AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)} 
  • trunk/activerecord/test/locking_test.rb

    r7472 r8156  
    99  set_table_name :lock_without_defaults_cust 
    1010  set_locking_column :custom_lock_version 
     11end 
     12 
     13class ReadonlyFirstNamePerson < Person 
     14  attr_readonly :first_name 
    1115end 
    1216 
     
    9397    t1 = LockWithCustomColumnWithoutDefault.new 
    9498    assert_equal 0, t1.custom_lock_version 
     99  end 
     100 
     101  def test_readonly_attributes 
     102    assert_equal [ :first_name ], ReadonlyFirstNamePerson.readonly_attributes 
     103 
     104    p = ReadonlyFirstNamePerson.create(:first_name => "unchangeable name") 
     105    p.reload 
     106    assert_equal "unchangeable name", p.first_name 
     107 
     108    p.update_attributes(:first_name => "changed name") 
     109    p.reload 
     110    assert_equal "unchangeable name", p.first_name 
    95111  end 
    96112