summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2018-06-14 09:01:36 +0000
committerRémy Coutable <remy@rymai.me>2018-06-14 09:01:36 +0000
commited366cc23a099a567bdaf412acb0258bd1dda68a (patch)
treed8df2bae607425d7d65cba3a438c185123979736
parent201843f7f1beb593084d0d94b010d5dc3b251acb (diff)
parent6d902e07d908769a909db0bf93d84f5be28720af (diff)
downloadgitlab-ce-ed366cc23a099a567bdaf412acb0258bd1dda68a.tar.gz
Merge branch 'jprovazn-rails5-shoulda' into 'master'
Fix shoulda-matchers in Rails 5 Closes #47639 See merge request gitlab-org/gitlab-ce!19749
-rw-r--r--spec/support/shoulda/matchers/rails_shim.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/support/shoulda/matchers/rails_shim.rb b/spec/support/shoulda/matchers/rails_shim.rb
new file mode 100644
index 00000000000..8d70598beb5
--- /dev/null
+++ b/spec/support/shoulda/matchers/rails_shim.rb
@@ -0,0 +1,27 @@
+# monkey patch which fixes serialization matcher in Rails 5
+# https://github.com/thoughtbot/shoulda-matchers/issues/913
+# This can be removed when a new version of shoulda-matchers
+# is released
+module Shoulda
+ module Matchers
+ class RailsShim
+ def self.serialized_attributes_for(model)
+ if defined?(::ActiveRecord::Type::Serialized)
+ # Rails 5+
+ serialized_columns = model.columns.select do |column|
+ model.type_for_attribute(column.name).is_a?(
+ ::ActiveRecord::Type::Serialized
+ )
+ end
+
+ serialized_columns.inject({}) do |hash, column| # rubocop:disable Style/EachWithObject
+ hash[column.name.to_s] = model.type_for_attribute(column.name).coder
+ hash
+ end
+ else
+ model.serialized_attributes
+ end
+ end
+ end
+ end
+end