summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblackst0ne <blackst0ne.ru@gmail.com>2018-04-06 13:39:55 +1100
committerblackst0ne <blackst0ne.ru@gmail.com>2018-04-06 13:39:55 +1100
commit59090f76c780c43c334cd75bf224afaf4f1cbb3c (patch)
treefdf23ce522b69341a79df1d95e75286b3ff54079
parentcfa716d6fe90802a05b5e130a271f404001c7916 (diff)
downloadgitlab-ce-blackst0ne-rails5-fix-type-cast-for-from-database.tar.gz
-rw-r--r--lib/gitlab/database/sha_attribute.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/gitlab/database/sha_attribute.rb b/lib/gitlab/database/sha_attribute.rb
index a658bb8928b..770ea19a947 100644
--- a/lib/gitlab/database/sha_attribute.rb
+++ b/lib/gitlab/database/sha_attribute.rb
@@ -24,12 +24,18 @@ module Gitlab
class ShaAttribute < BINARY_TYPE
PACK_FORMAT = 'H*'.freeze
- # It is called from activerecord-4.2.10/lib/active_record/attribute.rb
+ # It is called from activerecord-4.2.10/lib/active_record internal methods.
# Remove this method when upgraded to rails 5.0
def type_cast_from_database(value)
unpack_sha(super)
end
+ # It is called from activerecord-4.2.10/lib/active_record internal methods.
+ # Remove this method when upgraded to rails 5.0
+ def type_cast_for_database(value)
+ serialize(value)
+ end
+
# It is called from activerecord-5.0.6/lib/active_record/attribute.rb
# Remove this method when upgraded to rails 5.0.
def deserialize(value)
@@ -50,7 +56,7 @@ module Gitlab
def serialize(value)
arg = value ? [value].pack(PACK_FORMAT) : nil
- Gitlab.rails5? ? super(arg) : type_cast_for_database(arg)
+ Gitlab.rails5? ? super(arg) : method(:type_cast_for_database).super_method.call(arg)
end
end
end