diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-26 13:44:47 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-26 13:44:47 -0300 |
commit | 8b0753b4f0d0f66b73aac4cd26d6b575edc99fb6 (patch) | |
tree | b13c5df9e43fffc64484c38e946d5eeb9d164c8e /activerecord/test/cases/relation_test.rb | |
parent | 031588ebe6b449bcba6e3becfaff6978ba10464a (diff) | |
parent | 58d38d6df2d7f1c1730a3f691a78b3037defa9e7 (diff) | |
download | rails-8b0753b4f0d0f66b73aac4cd26d6b575edc99fb6.tar.gz rails-8b0753b4f0d0f66b73aac4cd26d6b575edc99fb6.tar.bz2 rails-8b0753b4f0d0f66b73aac4cd26d6b575edc99fb6.zip |
Merge pull request #15916 from sgrif/sg-test-update-all
Consolidate testing of update_all type casting
Diffstat (limited to 'activerecord/test/cases/relation_test.rb')
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index fb0b906c07..3280945d09 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -235,5 +235,33 @@ module ActiveRecord posts_with_special_comments_with_ratings = Post.group("posts.id").joins(:special_comments).merge(special_comments_with_ratings) assert_equal 3, authors(:david).posts.merge(posts_with_special_comments_with_ratings).count.length end + + class EnsureRoundTripTypeCasting < ActiveRecord::Type::Value + def type + :string + end + + def type_cast_from_database(value) + raise value unless value == "type cast for database" + "type cast from database" + end + + def type_cast_for_database(value) + raise value unless value == "value from user" + "type cast for database" + end + end + + class UpdateAllTestModel < ActiveRecord::Base + self.table_name = 'posts' + + attribute :body, EnsureRoundTripTypeCasting.new + end + + def test_update_all_goes_through_normal_type_casting + UpdateAllTestModel.update_all(body: "value from user", type: nil) # No STI + + assert_equal "type cast from database", UpdateAllTestModel.first.body + end end end |