aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-16 18:36:50 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-16 18:36:50 -0300
commit0728d3b5f8556306c3d48068d7b54924aa5ef52f (patch)
tree47c95a656a5b0aa0a8a6c72c1282832e13122004 /activerecord/test/cases
parent88714deb677f598fa40f6e7b61a083a5461d07fd (diff)
parent74af9f7fd781501e7f4a4746afd91b1bd5f77ddc (diff)
downloadrails-0728d3b5f8556306c3d48068d7b54924aa5ef52f.tar.gz
rails-0728d3b5f8556306c3d48068d7b54924aa5ef52f.tar.bz2
rails-0728d3b5f8556306c3d48068d7b54924aa5ef52f.zip
Merge pull request #15760 from sgrif/sg-decorate-matching
Promote time zone aware attributes to a first class type decorator
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/attribute_decorators_test.rb21
-rw-r--r--activerecord/test/cases/attribute_methods/read_test.rb1
2 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/test/cases/attribute_decorators_test.rb b/activerecord/test/cases/attribute_decorators_test.rb
index 35393753a2..bc3e9a8cf5 100644
--- a/activerecord/test/cases/attribute_decorators_test.rb
+++ b/activerecord/test/cases/attribute_decorators_test.rb
@@ -110,5 +110,26 @@ module ActiveRecord
assert_equal 'whatever decorated!', column.default
end
+
+ class Multiplier < SimpleDelegator
+ def type_cast_from_user(value)
+ return if value.nil?
+ value * 2
+ end
+ alias type_cast_from_database type_cast_from_user
+ end
+
+ test "decorating with a proc" do
+ Model.attribute :an_int, Type::Integer.new
+ type_is_integer = proc { |_, type| type.type == :integer }
+ Model.decorate_matching_attribute_types type_is_integer, :multiplier do |type|
+ Multiplier.new(type)
+ end
+
+ model = Model.new(a_string: 'whatever', an_int: 1)
+
+ assert_equal 'whatever', model.a_string
+ assert_equal 2, model.an_int
+ end
end
end
diff --git a/activerecord/test/cases/attribute_methods/read_test.rb b/activerecord/test/cases/attribute_methods/read_test.rb
index c0659fddef..4741ee8799 100644
--- a/activerecord/test/cases/attribute_methods/read_test.rb
+++ b/activerecord/test/cases/attribute_methods/read_test.rb
@@ -12,6 +12,7 @@ module ActiveRecord
@klass = Class.new do
def self.superclass; Base; end
def self.base_class; self; end
+ def self.decorate_matching_attribute_types(*); end
include ActiveRecord::AttributeMethods