Changeset 7500
- Timestamp:
- 09/17/07 09:29:02 (1 year ago)
- Files:
-
- trunk/activerecord/lib/active_record/attribute_methods.rb (modified) (2 diffs)
- trunk/activerecord/test/base_test.rb (modified) (1 diff)
- trunk/activerecord/test/fixtures/topic.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/attribute_methods.rb
r7406 r7500 59 59 return if generated_methods? 60 60 columns_hash.each do |name, column| 61 unless instance_method s.include?(name)61 unless instance_method_already_defined?(name) 62 62 if self.serialized_attributes[name] 63 63 define_read_method_for_serialized_attribute(name) … … 67 67 end 68 68 69 unless instance_method s.include?("#{name}=")69 unless instance_method_already_defined?("#{name}=") 70 70 define_write_method(name.to_sym) 71 71 end 72 72 73 unless instance_method s.include?("#{name}?")73 unless instance_method_already_defined?("#{name}?") 74 74 define_question_method(name) 75 75 end 76 76 end 77 77 end 78 79 def instance_method_already_defined?(method_name) 80 method_defined?(method_name) || 81 private_method_defined?(method_name) || 82 protected_method_defined?(method_name) 83 end 84 78 85 alias :define_read_methods :define_attribute_methods 79 86 trunk/activerecord/test/base_test.rb
r7371 r7500 395 395 end 396 396 end 397 398 def test_custom_mutator 399 topic = Topic.find(1) 400 # This mutator is protected in the class definition 401 topic.send(:approved=, true) 402 assert topic.instance_variable_get("@custom_approved") 403 end 397 404 398 405 def test_destroy trunk/activerecord/test/fixtures/topic.rb
r4909 r7500 14 14 id 15 15 end 16 16 17 17 18 protected 19 def approved=(val) 20 @custom_approved = val 21 write_attribute(:approved, val) 22 end 23 18 24 def default_written_on 19 25 self.written_on = Time.now unless attribute_present?("written_on")