class Shoulda::Matchers::ActiveRecord::SerializeMatcher
@private
Public Class Methods
new(name)
click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 86 def initialize(name) @name = name.to_s @options = {} end
Public Instance Methods
as(type)
click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 91 def as(type) @options[:type] = type self end
as_instance_of(type)
click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 96 def as_instance_of(type) @options[:instance_type] = type self end
description()
click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 116 def description description = "serialize :#{@name}" description += " class_name => #{@options[:type]}" if @options.key?(:type) description end
failure_message()
click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 106 def failure_message "Expected #{expectation} (#{@missing})" end
Also aliased as: failure_message_for_should
failure_message_when_negated()
click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 111 def failure_message_when_negated "Did not expect #{expectation}" end
Also aliased as: failure_message_for_should_not
matches?(subject)
click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 101 def matches?(subject) @subject = subject serialization_valid? && type_valid? end
Protected Instance Methods
class_valid?()
click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 133 def class_valid? if @options[:type] klass = model_class.serialized_attributes[@name] if klass == @options[:type] true else if klass.respond_to?(:object_class) && klass.object_class == @options[:type] true else @missing = ":#{@name} should be a type of #{@options[:type]}" false end end else true end end
expectation()
click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 172 def expectation expectation = "#{model_class.name} to serialize the attribute called :#{@name}" expectation += " with a type of #{@options[:type]}" if @options[:type] expectation += " with an instance of #{@options[:instance_type]}" if @options[:instance_type] expectation end
instance_class_valid?()
click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 155 def instance_class_valid? if @options.key?(:instance_type) if model_class.serialized_attributes[@name].class == @options[:instance_type] true else @missing = ":#{@name} should be an instance of #{@options[:type]}" false end else true end end
model_class()
click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 151 def model_class @subject.class end
serialization_valid?()
click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 124 def serialization_valid? if model_class.serialized_attributes.keys.include?(@name) true else @missing = "no serialized attribute called :#{@name}" false end end
type_valid?()
click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 168 def type_valid? class_valid? && instance_class_valid? end