From 91c1d6a63ee80a1c024da45cf40451dac3aa9bed Mon Sep 17 00:00:00 2001 From: Michael de Silva Date: Tue, 18 Oct 2016 05:32:20 +0530 Subject: [PATCH] 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 :clap:. Ref: https://github.com/thoughtbot/shoulda-matchers/issues/913#issuecomment-219187051 --- lib/shoulda/matchers/rails_shim.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb index 7eb10b688..5c6b0caec 100644 --- a/lib/shoulda/matchers/rails_shim.rb +++ b/lib/shoulda/matchers/rails_shim.rb @@ -23,9 +23,11 @@ def self.serialized_attributes_for(model) 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