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.



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

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.



39
40
41
# File 'lib/active_model_serializers/test/schema.rb', line 39

def message
  @message
end

#payloadObject (readonly)

Returns the value of attribute payload.



39
40
41
# File 'lib/active_model_serializers/test/schema.rb', line 39

def payload
  @payload
end

#requestObject (readonly)

Returns the value of attribute request.



39
40
41
# File 'lib/active_model_serializers/test/schema.rb', line 39

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



39
40
41
# File 'lib/active_model_serializers/test/schema.rb', line 39

def response
  @response
end

#schema_pathObject (readonly)

Returns the value of attribute schema_path.



39
40
41
# File 'lib/active_model_serializers/test/schema.rb', line 39

def schema_path
  @schema_path
end

Instance Method Details

#callObject



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

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