33 lines
1.4 KiB
Diff
33 lines
1.4 KiB
Diff
|
|
From df04f8704abc3754c63c488433dac8c30573da6b Mon Sep 17 00:00:00 2001
|
||
|
|
From: Michael de Silva <michael@mwdesilva.com>
|
||
|
|
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 5159468c..471d9049 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
|