From f218771d3e9240337cd309d8396b5479d9ff555d Mon Sep 17 00:00:00 2001 From: Marcel Molina Date: Fri, 7 Oct 2005 00:53:05 +0000 Subject: 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 --- activerecord/test/base_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'activerecord/test') 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 -- cgit v1.2.3