Changeset 4635
- Timestamp:
- 07/31/06 06:54:06 (2 years ago)
- Files:
-
- trunk/activerecord/lib/active_record/base.rb (modified) (1 diff)
- trunk/activerecord/test/attribute_methods_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/base.rb
r4632 r4635 1764 1764 if @attributes.include?(method_name) or 1765 1765 (md = /\?$/.match(method_name) and 1766 @attributes.include?(method_name = md.pre_match)) 1766 @attributes.include?(query_method_name = md.pre_match) and 1767 method_name = query_method_name) 1767 1768 define_read_methods if self.class.read_methods.empty? && self.class.generate_read_methods 1768 1769 md ? query_attribute(method_name) : read_attribute(method_name) trunk/activerecord/test/attribute_methods_test.rb
r4632 r4635 3 3 class AttributeMethodsTest < Test::Unit::TestCase 4 4 def setup 5 @old_suffixes = ActiveRecord::Base.send(:attribute_method_suffixes).dup 5 6 @target = Class.new(ActiveRecord::Base) 6 7 @target.table_name = 'topics' 7 8 end 9 10 def teardown 11 ActiveRecord::Base.send(:attribute_method_suffixes).clear 12 ActiveRecord::Base.attribute_method_suffix *@old_suffixes 13 end 14 8 15 9 16 def test_match_attribute_method_query_returns_match_data … … 11 18 assert_equal 'title', md.pre_match 12 19 assert_equal ['='], md.captures 20 21 %w(_hello_world ist! _maybe?).each do |suffix| 22 @target.class_eval "def attribute#{suffix}(*args) args end" 23 @target.attribute_method_suffix suffix 24 25 assert_not_nil md = @target.match_attribute_method?("title#{suffix}") 26 assert_equal 'title', md.pre_match 27 assert_equal [suffix], md.captures 28 end 13 29 end 14 30 … … 20 36 assert_raise(NoMethodError) { topic.title_hello_world } 21 37 22 @target.class_eval "def attribute_hello_world(*args) args end" 23 @target.attribute_method_suffix '_hello_world' 38 %w(_hello_world _it! _candidate= able?).each do |suffix| 39 @target.class_eval "def attribute#{suffix}(*args) args end" 40 @target.attribute_method_suffix suffix 24 41 25 assert topic.respond_to?('title_hello_world') 26 assert_equal ['title'], topic.title_hello_world 27 assert_equal ['title', 'a'], topic.title_hello_world('a') 28 assert_equal ['title', 1, 2, 3], topic.title_hello_world(1, 2, 3) 42 meth = "title#{suffix}" 43 assert topic.respond_to?(meth) 44 assert_equal ['title'], topic.send(meth) 45 assert_equal ['title', 'a'], topic.send(meth, 'a') 46 assert_equal ['title', 1, 2, 3], topic.send(meth, 1, 2, 3) 47 end 29 48 end 30 49 end