Fix failing tests on rails 3.1 and higher

This commit is contained in:
Håkon Lerring 2012-03-16 11:27:12 +01:00 committed by Gabe Berke-Williams
parent d9906d84ce
commit 3b891cf704
1 changed files with 25 additions and 9 deletions

View File

@ -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