Class: JiraMetrics::Testing::MockChangeItem

Inherits:
Object
  • Object
show all
Defined in:
lib/jirametrics/testing/mock_change_item.rb

Overview

Builds a ChangeItem for tests without going through Jira's changelog format.

Normalises the arguments a caller is likely to get slightly wrong (a status given as a name when an id is wanted, a time given as a string) and, for status changes with an issue, validates the status against that issue's board so a typo surfaces loudly rather than silently passing.

Instance Method Summary collapse

Constructor Details

#initialize(field:, value:, time:, value_id: nil, old_value: nil, old_value_id: nil, artificial: false, issue: nil, field_id: nil) ⇒ MockChangeItem

Returns a new instance of MockChangeItem.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jirametrics/testing/mock_change_item.rb', line 11

def initialize(
  field:, value:, time:, value_id: nil, old_value: nil, old_value_id: nil,
  artificial: false, issue: nil, field_id: nil
)
  @field = field
  @value = value
  # Callers write dates as strings far more often than as Times.
  @time = JiraMetrics::Testing.to_time time
  @value_id = value_id
  @old_value = old_value
  @old_value_id = old_value_id
  @artificial = artificial
  @issue = issue
  @field_id = field_id
end

Instance Method Details

#to_change_itemObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jirametrics/testing/mock_change_item.rb', line 27

def to_change_item
  normalize_status_arguments
  validate_status_change if @field == 'status' && @issue

  ChangeItem.new time: @time, artificial: @artificial, author_raw: nil, raw: {
    'field' => @field,
    'to' => @value_id,
    'toString' => @value,
    'from' => @old_value_id,
    'fromString' => @old_value,
    'fieldId' => @field_id
  }
end