aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_methods/read_test.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-02-18 15:51:39 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-02-18 15:51:39 -0800
commit30679bc705c74fcf1d26df275134f7b655a288a8 (patch)
tree09ee3ea20859f5d9469c8235ebd6bd3fffb0f608 /activerecord/test/cases/attribute_methods/read_test.rb
parentce76cfc61f86931d5acc6db3c2c438cd5ea98255 (diff)
downloadrails-30679bc705c74fcf1d26df275134f7b655a288a8.tar.gz
rails-30679bc705c74fcf1d26df275134f7b655a288a8.tar.bz2
rails-30679bc705c74fcf1d26df275134f7b655a288a8.zip
AR::AttributeMethods does not need to be included in an AR::Base class.
Diffstat (limited to 'activerecord/test/cases/attribute_methods/read_test.rb')
-rw-r--r--activerecord/test/cases/attribute_methods/read_test.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/activerecord/test/cases/attribute_methods/read_test.rb b/activerecord/test/cases/attribute_methods/read_test.rb
new file mode 100644
index 0000000000..3dc69ea35e
--- /dev/null
+++ b/activerecord/test/cases/attribute_methods/read_test.rb
@@ -0,0 +1,62 @@
+require "cases/helper"
+
+module ActiveRecord
+ module AttributeMethods
+ class ReadTest < ActiveRecord::TestCase
+ class FakeColumn < Struct.new(:name)
+ def type_cast_code(var)
+ var
+ end
+
+ def type; :integer; end
+ end
+
+ def setup
+ @klass = Class.new do
+ include ActiveRecord::AttributeMethods
+ include ActiveRecord::AttributeMethods::Read
+
+ def self.column_names
+ %w{ one two three }
+ end
+
+ def self.primary_key
+ end
+
+ def self.columns
+ column_names.map { FakeColumn.new(name) }
+ end
+
+ def self.columns_hash
+ puts caller
+ Hash[column_names.map { |name|
+ [name, FakeColumn.new(name)]
+ }]
+ end
+
+ def self.serialized_attributes; {}; end
+ end
+ end
+
+ def test_define_attribute_methods
+ instance = @klass.new
+
+ @klass.column_names.each do |name|
+ assert ! instance.methods.map(&:to_s).include?(name)
+ end
+
+ @klass.define_attribute_methods
+
+ @klass.column_names.each do |name|
+ assert(instance.methods.map(&:to_s).include?(name), "#{name} is not defined")
+ end
+ end
+
+ def test_attribute_methods_generated?
+ assert(!@klass.attribute_methods_generated?, 'attribute_methods_generated?')
+ @klass.define_attribute_methods
+ assert(@klass.attribute_methods_generated?, 'attribute_methods_generated?')
+ end
+ end
+ end
+end