Fix #913 for Serialize Matcher error undefined method `cast_type' in Rails 5

This patch is based on the discussed held in issue #913, and a solution
that I've proposed and others have confirmed as good to go 👏.

Ref: https://github.com/thoughtbot/shoulda-matchers/issues/913#issuecomment-219187051
This commit is contained in:
Michael de Silva 2016-10-18 05:32:20 +05:30 committed by Elliot Winkler
parent 76e63b2638
commit df04f8704a
1 changed files with 4 additions and 2 deletions

View File

@ -23,9 +23,11 @@ module Shoulda
if defined?(::ActiveRecord::Type::Serialized)
# Rails 5+
model.columns.select do |column|
column.cast_type.is_a?(::ActiveRecord::Type::Serialized)
model.type_for_attribute(column.name).is_a?(
::ActiveRecord::Type::Serialized,
)
end.inject({}) do |hash, column|
hash[column.name.to_s] = column.cast_type.coder
hash[column.name.to_s] = model.type_for_attribute(column.name).coder
hash
end
else