Class: ActiveModelSerializers::Test::Serializer::AssertSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/active_model_serializers/test/serializer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAssertSerializer

Returns a new instance of AssertSerializer.



45
46
47
48
# File 'lib/active_model_serializers/test/serializer.rb', line 45

def initialize
  @serializers = Set.new
  @_subscribers = []
end

Instance Attribute Details

#expectationObject

Returns the value of attribute expectation.



43
44
45
# File 'lib/active_model_serializers/test/serializer.rb', line 43

def expectation
  @expectation
end

#messageObject

Returns the value of attribute message.



42
43
44
# File 'lib/active_model_serializers/test/serializer.rb', line 42

def message
  @message
end

#responseObject

Returns the value of attribute response.



43
44
45
# File 'lib/active_model_serializers/test/serializer.rb', line 43

def response
  @response
end

#serializersObject (readonly)

Returns the value of attribute serializers.



42
43
44
# File 'lib/active_model_serializers/test/serializer.rb', line 42

def serializers
  @serializers
end

Instance Method Details

#matches?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
64
65
66
# 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

#subscribeObject



68
69
70
71
72
73
# 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

#unsubscribeObject



75
76
77
78
79
# File 'lib/active_model_serializers/test/serializer.rb', line 75

def unsubscribe
  @_subscribers.each do |subscriber|
    ActiveSupport::Notifications.unsubscribe(subscriber)
  end
end