Class: PlanMyStuff::TestingProjectItem

Inherits:
BaseProjectItem show all
Defined in:
lib/plan_my_stuff/testing_project_item.rb

Overview

A project item belonging to a TestingProject. Extends BaseProjectItem with testing-specific field updaters and pass/fail sign-off logic.

Instance Attribute Summary

Attributes inherited from ApplicationRecord

#github_response

Instance Method Summary collapse

Methods inherited from BaseProjectItem

#as_json, assign, #assign!, #body, build, #content_node_id, create!, delete_item, #destroy!, #draft?, #field_values, #id, #issue, #issue=, #metadata, move_item, #move_to!, #number, #project, #raw_body, #repo, #state, #status, #title, #type, update_date_field!, update_field!, #update_field!, update_single_select_field!, #url

Methods inherited from ApplicationRecord

#destroyed?, #initialize, #new_record?, #persisted?, read_field

Constructor Details

This class inherits a constructor from PlanMyStuff::ApplicationRecord

Instance Method Details

#mark_failed!(user, result_notes:) ⇒ void

This method returns an undefined value.

Records user_id as having failed this item, writes result_notes, and moves the item to the Failed status.

Parameters:

  • user (Object)

    PMS user object of the tester failing the item

  • result_notes (String)

    required explanation of the failure

Raises:



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/plan_my_stuff/testing_project_item.rb', line 136

def mark_failed!(user, result_notes:)
  raise(PMS::ValidationError, 'Result notes are required when failing an item.') if result_notes.blank?
  raise(PMS::ValidationError, 'No user configured for sign-off.') if user.blank?

  update_result_notes!(result_notes)

  user_id = PMS::UserResolver.user_id(user).to_s
  current = user_ids_from_field('Failed By')
  return if current.include?(user_id)

  new_failed_by = current + [user_id]
  update_failed_by!(new_failed_by)
  field_values['Failed By'] = new_failed_by.join(', ')

  move_to!('Failed')
end

#mark_passed!(user) ⇒ void

This method returns an undefined value.

Appends user_id to the Passed By field and, when the pass_mode condition is satisfied, moves the item to the Passed status.

pass_mode “all” - flips to Passed when every tester has signed off. pass_mode “any” - flips to Passed as soon as one tester signs off.

No-op when the user has already signed off on this item.

Parameters:

  • user (Object)

    PMS user object of the tester signing off

Raises:



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/plan_my_stuff/testing_project_item.rb', line 99

def mark_passed!(user)
  raise(PMS::ValidationError, 'No user configured for sign-off.') if user.blank?

  user_id = PMS::UserResolver.user_id(user).to_s
  current = user_ids_from_field('Passed By')
  return if current.include?(user_id)

  new_passed_by = current + [user_id]
  update_passed_by!(new_passed_by)
  field_values['Passed By'] = new_passed_by.join(', ')

  testers = user_ids_from_field('Testers')
  pass_mode = field_values['Pass Mode']

  should_pass =
    case pass_mode
    when 'any' then true
    when 'all' then new_passed_by.sort == testers.sort
    else false
    end

  return unless should_pass

  update_passed_at!(Time.now.utc)
  move_to!('Passed')
end

#update_deadline_miss_reason!(reason) ⇒ Hash

Updates the Deadline Miss Reason field on this testing project item.

Parameters:

  • reason (String)

Returns:

  • (Hash)

    mutation result



83
84
85
# File 'lib/plan_my_stuff/testing_project_item.rb', line 83

def update_deadline_miss_reason!(reason)
  update_field!('Deadline Miss Reason', reason)
end

#update_due_date!(date) ⇒ Hash

Updates the due date field on this testing project item.

Parameters:

  • date (Date, String)

Returns:

  • (Hash)

    mutation result



28
29
30
31
32
33
34
35
# File 'lib/plan_my_stuff/testing_project_item.rb', line 28

def update_due_date!(date)
  self.class.update_date_field!(
    project_number: project.number,
    item_id: id,
    field_name: 'Due Date',
    date: date,
  )
end

#update_pass_mode!(value) ⇒ Hash

Updates the Pass Mode single-select field on this testing project item.

Parameters:

  • value (String)

    “all” or “any”

Returns:

  • (Hash)

    mutation result



13
14
15
16
17
18
19
20
# File 'lib/plan_my_stuff/testing_project_item.rb', line 13

def update_pass_mode!(value)
  self.class.update_single_select_field!(
    project_number: project.number,
    item_id: id,
    field_name: 'Pass Mode',
    value: value,
  )
end

#update_passed_at!(time) ⇒ Hash

Records the timestamp when this item was passed as an ISO 8601 string.

Parameters:

  • time (Time)

Returns:

  • (Hash)

    mutation result



73
74
75
# File 'lib/plan_my_stuff/testing_project_item.rb', line 73

def update_passed_at!(time)
  update_field!('Passed At', time.utc.iso8601)
end

#update_result_notes!(notes) ⇒ Hash

Updates the Result Notes field on this testing project item.

Parameters:

  • notes (String)

Returns:

  • (Hash)

    mutation result



63
64
65
# File 'lib/plan_my_stuff/testing_project_item.rb', line 63

def update_result_notes!(notes)
  update_field!('Result Notes', notes)
end

#update_testers!(user_ids) ⇒ Hash

Updates the Testers field (comma-joined user IDs) on this item.

Parameters:

  • user_ids (Integer, String, Array<Integer, String>)

Returns:

  • (Hash)

    mutation result



43
44
45
# File 'lib/plan_my_stuff/testing_project_item.rb', line 43

def update_testers!(user_ids)
  update_field!('Testers', Array.wrap(user_ids).join(', '))
end

#update_watchers!(user_ids) ⇒ Hash

Updates the Watchers field (comma-joined user IDs) on this item.

Parameters:

  • user_ids (Integer, String, Array<Integer, String>)

Returns:

  • (Hash)

    mutation result



53
54
55
# File 'lib/plan_my_stuff/testing_project_item.rb', line 53

def update_watchers!(user_ids)
  update_field!('Watchers', Array.wrap(user_ids).join(', '))
end