diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-07-31 03:43:03 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-07-31 03:43:03 +0000 |
commit | 2b3cc2478fff77fdada9adeabc32ecea0605d7bd (patch) | |
tree | 7aa6ba106ffefa4c571eb7edfe7ca1eabb31b41d /activerecord/test | |
parent | efff453148b4bd2d35d91a3d8344a7bad56da7c3 (diff) | |
download | rails-2b3cc2478fff77fdada9adeabc32ecea0605d7bd.tar.gz rails-2b3cc2478fff77fdada9adeabc32ecea0605d7bd.tar.bz2 rails-2b3cc2478fff77fdada9adeabc32ecea0605d7bd.zip |
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
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/attribute_methods_test.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/activerecord/test/attribute_methods_test.rb b/activerecord/test/attribute_methods_test.rb new file mode 100755 index 0000000000..8dcca2fc4a --- /dev/null +++ b/activerecord/test/attribute_methods_test.rb @@ -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 |