class ActiveModelSerializers::Test::Serializer::AssertSerializer

Attributes

expectation[RW]
message[R]
response[RW]
serializers[R]

Public Class Methods

new() click to toggle source
# File lib/active_model_serializers/test/serializer.rb, line 45
def initialize
  @serializers = Set.new
  @_subscribers = []
end

Public Instance Methods

matches?() click to toggle source
# File lib/active_model_serializers/test/serializer.rb, line 54
def matches?
  # Force body to be read in case the template is being streamed.
  response.body

  case expectation
  when a_serializer? then matches_class?
  when Symbol        then matches_symbol?
  when String        then matches_string?
  when Regexp        then matches_regexp?
  when NilClass      then matches_nil?
  else fail ArgumentError, 'assert_serializer only accepts a String, Symbol, Regexp, ActiveModel::Serializer, or nil'
  end
end
message=(message) click to toggle source
# File lib/active_model_serializers/test/serializer.rb, line 50
def message=(message)
  @message = message || "expecting <#{expectation.inspect}> but rendering with <#{serializers.to_a}>"
end
subscribe() click to toggle source
# File lib/active_model_serializers/test/serializer.rb, line 68
def subscribe
  @_subscribers << ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, payload|
    serializer = payload[:serializer].name
    serializers << serializer
  end
end
unsubscribe() click to toggle source
# File lib/active_model_serializers/test/serializer.rb, line 75
def unsubscribe
  @_subscribers.each do |subscriber|
    ActiveSupport::Notifications.unsubscribe(subscriber)
  end
end

Private Instance Methods

a_serializer?() click to toggle source
# File lib/active_model_serializers/test/serializer.rb, line 106
def a_serializer?
  ->(exp) { exp.is_a?(Class) && exp < ActiveModel::Serializer }
end
event_name() click to toggle source
# File lib/active_model_serializers/test/serializer.rb, line 110
def event_name
  ::ActiveModelSerializers::Logging::RENDER_EVENT
end
matches_class?() click to toggle source
# File lib/active_model_serializers/test/serializer.rb, line 83
def matches_class?
  serializers.include?(expectation.name)
end
matches_nil?() click to toggle source
# File lib/active_model_serializers/test/serializer.rb, line 102
def matches_nil?
  serializers.empty?
end
matches_regexp?() click to toggle source
# File lib/active_model_serializers/test/serializer.rb, line 96
def matches_regexp?
  serializers.any? do |serializer|
    serializer.match(expectation)
  end
end
matches_string?() click to toggle source
# File lib/active_model_serializers/test/serializer.rb, line 92
def matches_string?
  !expectation.empty? && serializers.include?(expectation)
end
matches_symbol?() click to toggle source
# File lib/active_model_serializers/test/serializer.rb, line 87
def matches_symbol?
  camelize_expectation = expectation.to_s.camelize
  serializers.include?(camelize_expectation)
end