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.


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

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

Instance Attribute Details

#expectationObject

Returns the value of attribute expectation


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

def expectation
  @expectation
end

#messageObject

Returns the value of attribute message


40
41
42
# File 'lib/active_model_serializers/test/serializer.rb', line 40

def message
  @message
end

#responseObject

Returns the value of attribute response


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

def response
  @response
end

#serializersObject (readonly)

Returns the value of attribute serializers


40
41
42
# File 'lib/active_model_serializers/test/serializer.rb', line 40

def serializers
  @serializers
end

Instance Method Details

#matches?Boolean

Returns:

  • (Boolean)

52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/active_model_serializers/test/serializer.rb', line 52

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


66
67
68
69
70
71
# File 'lib/active_model_serializers/test/serializer.rb', line 66

def subscribe
  @_subscribers << ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, payload|
    serializer = payload[:serializer].name
    serializers << serializer
  end
end

#unsubscribeObject


73
74
75
76
77
# File 'lib/active_model_serializers/test/serializer.rb', line 73

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