mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
r4854@ks: jeremy | 2006-07-30 00:59:18 -0700
Attribute methods
r4877@ks: jeremy | 2006-07-30 20:23:53 -0700
Factor the attribute#{suffix} methods out of method_missing for easier extension.
r4878@ks: jeremy | 2006-07-30 20:42:23 -0700
More specific method naming, declare many attribute method suffixes, set up default suffixes at module include rather than lazily.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4632 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
30
activerecord/test/attribute_methods_test.rb
Executable file
30
activerecord/test/attribute_methods_test.rb
Executable file
@@ -0,0 +1,30 @@
|
||||
require 'abstract_unit'
|
||||
|
||||
class AttributeMethodsTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@target = Class.new(ActiveRecord::Base)
|
||||
@target.table_name = 'topics'
|
||||
end
|
||||
|
||||
def test_match_attribute_method_query_returns_match_data
|
||||
assert_not_nil md = @target.match_attribute_method?('title=')
|
||||
assert_equal 'title', md.pre_match
|
||||
assert_equal ['='], md.captures
|
||||
end
|
||||
|
||||
def test_declared_attribute_method_affects_respond_to_and_method_missing
|
||||
topic = @target.new(:title => 'Budget')
|
||||
assert topic.respond_to?('title')
|
||||
assert_equal 'Budget', topic.title
|
||||
assert !topic.respond_to?('title_hello_world')
|
||||
assert_raise(NoMethodError) { topic.title_hello_world }
|
||||
|
||||
@target.class_eval "def attribute_hello_world(*args) args end"
|
||||
@target.attribute_method_suffix '_hello_world'
|
||||
|
||||
assert topic.respond_to?('title_hello_world')
|
||||
assert_equal ['title'], topic.title_hello_world
|
||||
assert_equal ['title', 'a'], topic.title_hello_world('a')
|
||||
assert_equal ['title', 1, 2, 3], topic.title_hello_world(1, 2, 3)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user