From 3b891cf7049a95160b095260ceb6a857dfb58e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Akon=20Lerring?= Date: Fri, 16 Mar 2012 11:27:12 +0100 Subject: [PATCH] Fix failing tests on rails 3.1 and higher --- .../active_record/serialize_matcher.rb | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/shoulda/matchers/active_record/serialize_matcher.rb b/lib/shoulda/matchers/active_record/serialize_matcher.rb index 0fd64751..3204f634 100644 --- a/lib/shoulda/matchers/active_record/serialize_matcher.rb +++ b/lib/shoulda/matchers/active_record/serialize_matcher.rb @@ -63,21 +63,36 @@ module Shoulda # :nodoc: false end end - + def class_valid? - if @type - model_class.serialized_attributes[@name] == @type - else + if(!@type) + return true + end + + klass = model_class.serialized_attributes[@name] + + if klass == @type true + else + if klass.respond_to?(:object_class) && klass.object_class == @type + true + else + @missing = ":#{@name} should be a type of #{@type}" + false + end end end - + def instance_class_valid? - if @instance_type - klass = model_class.serialized_attributes[@name].class - klass == @instance_type - else + if !@instance_type + return true + end + + if model_class.serialized_attributes[@name].class == @instance_type true + else + @missing = ":#{@name} should be an instance of #{@type}" + false end end @@ -88,6 +103,7 @@ module Shoulda # :nodoc: def expectation expectation = "#{model_class.name} to serialize the attribute called :#{@name}" expectation += " with a type of #{@type}" if @type + expectation += " with an instance of #{@instance_type}" if @instance_type expectation end end