Class: ActiveModelSerializers::Test::Schema::AssertResponseSchema

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (AssertResponseSchema) initialize(schema_path, response, message)

Returns a new instance of AssertResponseSchema



23
24
25
26
27
28
29
30
# File 'lib/active_model_serializers/test/schema.rb', line 23

def initialize(schema_path, response, message)
  require_json_schema!
  @response = response
  @schema_path = schema_path || schema_path_default
  @message = message
  @document_store = JsonSchema::DocumentStore.new
  add_schema_to_document_store
end

Instance Attribute Details

- (Object) message (readonly)

Returns the value of attribute message



21
22
23
# File 'lib/active_model_serializers/test/schema.rb', line 21

def message
  @message
end

- (Object) response (readonly)

Returns the value of attribute response



21
22
23
# File 'lib/active_model_serializers/test/schema.rb', line 21

def response
  @response
end

- (Object) schema_path (readonly)

Returns the value of attribute schema_path



21
22
23
# File 'lib/active_model_serializers/test/schema.rb', line 21

def schema_path
  @schema_path
end

Instance Method Details

- (Object) call



32
33
34
35
36
37
# File 'lib/active_model_serializers/test/schema.rb', line 32

def call
  json_schema.expand_references!(store: document_store)
  status, errors = json_schema.validate(response_body)
  @message ||= errors.map(&:to_s).to_sentence
  status
end