Class: Dragnet::Exporters::Serializers::TestRecordSerializer

Inherits:
Object
  • Object
show all
Includes:
Helpers::RepositoryHelper
Defined in:
lib/dragnet/exporters/serializers/test_record_serializer.rb

Overview

Serializes a TestRecord object into a Hash.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::RepositoryHelper

#relative_to_repo, #repo_base, #shorten_sha1

Constructor Details

#initialize(test_record, repository) ⇒ TestRecordSerializer

Returns a new instance of TestRecordSerializer.

Parameters:

  • test_record (Dragnet::TestRecord)

    The TestRecord object to serialize.

  • repository (Dragnet::RepositoryBase)

    The Repository object associated with the TestRecord. Used to render file paths relative to the repository instead of as absolute paths.



24
25
26
27
# File 'lib/dragnet/exporters/serializers/test_record_serializer.rb', line 24

def initialize(test_record, repository)
  @test_record = test_record
  @repository = repository
end

Instance Attribute Details

#repositoryObject (readonly)

Returns the value of attribute repository.



17
18
19
# File 'lib/dragnet/exporters/serializers/test_record_serializer.rb', line 17

def repository
  @repository
end

#test_recordObject (readonly)

Returns the value of attribute test_record.



17
18
19
# File 'lib/dragnet/exporters/serializers/test_record_serializer.rb', line 17

def test_record
  @test_record
end

Instance Method Details

#serializeHash

Returns A Hash representing the given TestRecord object.

Returns:

  • (Hash)

    A Hash representing the given TestRecord object.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dragnet/exporters/serializers/test_record_serializer.rb', line 35

def serialize
  {
    refs: Array(test_record.id),
    result: test_record.result,
    review_status: render_review_status,
    mtr_file: relative_to_repo(test_record.source_file).to_s,
    verification_result: serialized_verification_result,

    # TODO: Remove the started_at and finished_at attributes after solving
    #   https://esrlabs.atlassian.net/browse/JAY-493
    started_at: serialized_verification_result[:started_at],
    finished_at: serialized_verification_result[:finished_at]
  }.tap do |hash|
    hash[:sha1] = test_record.sha1 if test_record.sha1.present?
    hash[:owner] = Array(test_record.name).join(', ') if test_record.name.present?
    hash[:description] = test_record.description if test_record.description.present?
    hash[:test_method] = Array(test_record.test_method) if test_record.test_method.present?

    if test_record.tc_derivation_method.present?
      hash[:tc_derivation_method] = Array(test_record.tc_derivation_method)
    end

    hash[:review_comments] = test_record.review_comments if test_record.review_comments.present?
    hash[:findings] = test_record.findings if test_record.findings?
    hash[:files] = serialize_files if test_record.files.present?
    hash[:repos] = serialize_repos if test_record.repos.present?
  end
end