class Shoulda::Matchers::ActiveRecord::SerializeMatcher
@private
def as(type)
def as(type) @options[:type] = type self end
def as_instance_of(type)
def as_instance_of(type) @options[:instance_type] = type self end
def attribute_is_serialized?
def attribute_is_serialized? !!serialization_coder end
def class_valid?
def class_valid? if @options[:type] klass = serialization_coder if klass == @options[:type] true elsif klass.respond_to?(:object_class) && klass.object_class == @options[:type] true else @missing = ":#{@name} should be a type of #{@options[:type]}" false end else true end end
def description
def description description = "serialize :#{@name}" if @options.key?(:type) description += " class_name => #{@options[:type]}" end description end
def expectation
def expectation expectation = "#{model_class.name} to serialize the attribute called"\ " :#{@name}" expectation += " with a type of #{@options[:type]}" if @options[:type] if @options[:instance_type] expectation += " with an instance of #{@options[:instance_type]}" end expectation end
def failure_message
def failure_message "Expected #{expectation} (#{@missing})" end
def failure_message_when_negated
def failure_message_when_negated "Did not expect #{expectation}" end
def initialize(name)
def initialize(name) @name = name.to_s @options = {} end
def instance_class_valid?
def instance_class_valid? if @options.key?(:instance_type) if serialization_coder.is_a?(@options[:instance_type]) true else @missing = ":#{@name} should be an instance of #{@options[:type]}" false end else true end end
def matches?(subject)
def matches?(subject) @subject = subject serialization_valid? && type_valid? end
def model
def model @subject.class end
def model_class
def model_class @subject.class end
def serialization_coder
def serialization_coder RailsShim.attribute_serialization_coder_for(model, @name) end
def serialization_valid?
def serialization_valid? if attribute_is_serialized? true else @missing = "no serialized attribute called :#{@name}" false end end
def type_valid?
def type_valid? class_valid? && instance_class_valid? end