Parent

Class/Module Index [+]

Quicksearch

Shoulda::Matchers::ActiveRecord::SerializeMatcher

@private

Public Class Methods

new(name) click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 94
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 99
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 104
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 124
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 114
def failure_message
  "Expected #{expectation} (#{@missing})"
end
Also aliased as: failure_message_for_should
failure_message_for_should() click to toggle source
Alias for: failure_message
failure_message_for_should_not() click to toggle source
failure_message_when_negated() click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 119
def failure_message_when_negated
  "Did not expect #{expectation}"
end
matches?(subject) click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 109
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 141
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 180
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 163
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 159
def model_class
  @subject.class
end
serialization_valid?() click to toggle source
# File lib/shoulda/matchers/active_record/serialize_matcher.rb, line 132
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 176
def type_valid?
  class_valid? && instance_class_valid?
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.