diff options
Diffstat (limited to 'activerecord/test/cases/attribute_methods')
-rw-r--r-- | activerecord/test/cases/attribute_methods/read_test.rb | 61 |
1 files changed, 61 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..d0a9028264 --- /dev/null +++ b/activerecord/test/cases/attribute_methods/read_test.rb @@ -0,0 +1,61 @@ +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 + 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 |