Class: ActiveModelSerializers::Test::Schema::AssertSchema

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

Direct Known Subclasses

AssertRequestSchema, AssertResponseSchema

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_path, request, response, message, payload = nil) ⇒ AssertSchema

Interface may change.


40
41
42
43
44
45
46
47
48
49
# File 'lib/active_model_serializers/test/schema.rb', line 40

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

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message


37
38
39
# File 'lib/active_model_serializers/test/schema.rb', line 37

def message
  @message
end

#payloadObject (readonly)

Returns the value of attribute payload


37
38
39
# File 'lib/active_model_serializers/test/schema.rb', line 37

def payload
  @payload
end

#requestObject (readonly)

Returns the value of attribute request


37
38
39
# File 'lib/active_model_serializers/test/schema.rb', line 37

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response


37
38
39
# File 'lib/active_model_serializers/test/schema.rb', line 37

def response
  @response
end

#schema_pathObject (readonly)

Returns the value of attribute schema_path


37
38
39
# File 'lib/active_model_serializers/test/schema.rb', line 37

def schema_path
  @schema_path
end

Instance Method Details

#callObject


51
52
53
54
55
56
# File 'lib/active_model_serializers/test/schema.rb', line 51

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