aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2005-10-07 00:53:05 +0000
committerMarcel Molina <marcel@vernix.org>2005-10-07 00:53:05 +0000
commitf218771d3e9240337cd309d8396b5479d9ff555d (patch)
treefff575cdb78a46551457ed60578d28eb8b37d56e /activerecord/test
parentc0899bca10af443d3aba00d75c554b96d4bccdab (diff)
downloadrails-f218771d3e9240337cd309d8396b5479d9ff555d.tar.gz
rails-f218771d3e9240337cd309d8396b5479d9ff555d.tar.bz2
rails-f218771d3e9240337cd309d8396b5479d9ff555d.zip
Add option (true by default) to generate reader methods for each attribute of a record to avoid the overhead of calling method missing. In partial fullfilment of #1236.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2483 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/base_test.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 35c608d809..aeb9ac970a 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -196,6 +196,19 @@ class BasicsTest < Test::Unit::TestCase
assert !topic.approved?, "approved should be false"
end
+ def test_reader_generation
+ Topic.find(:first).title
+ Firm.find(:first).name
+ Client.find(:first).name
+ if ActiveRecord::Base.generate_read_methods
+ assert_readers(Topic, %w(type replies_count))
+ assert_readers(Firm, %w(type))
+ assert_readers(Client, %w(type))
+ else
+ [Topic, Firm, Client].each {|klass| assert_equal klass.read_methods, {}}
+ end
+ end
+
def test_preserving_date_objects
# SQL Server doesn't have a separate column type just for dates, so all are returned as time
if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter
@@ -913,4 +926,11 @@ class BasicsTest < Test::Unit::TestCase
assert_equal firm.clients.collect{ |x| x.name }.sort, clients.collect{ |x| x.name }.sort
end
+
+ private
+
+ def assert_readers(model, exceptions)
+ expected_readers = model.column_names - (model.serialized_attributes.keys + exceptions + ['id'])
+ assert_equal expected_readers.sort, model.read_methods.keys.sort
+ end
end