Class: TestPlan

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/test_plan.rb

Overview

This is the base type for test plans. To add a new test plan type you must subclass TestPlan and declare a name using test_name:

class MyAwesomeTestPlan < TestPlan
  test_name "My Awesome Test"
end

To use the test plan you need to add it to the global list:

Laika::TEST_PLAN_TYPES[MyAwesomeTestPlan.test_name] = MyAwesomeTestPlan

This list is initialized in config/initializers/load_test_plan_types.rb. If you want to add a new test plan type to Laika you should add it there.

Test plans use an internal state machine to track progress. All test plans start out in the pending state. You can use the methods pass or fail to change the state:

plan = TestPlan.new
plan.state             #=> 'pending'
plan.tap(&:pass).state #=> 'passed'

You cannot change the state of a plan once it has passed or failed, so you can only pass or fail pending tests.

However, we have added force_pass, force_fail events as manual overrides which will ensure a transition to either 'passed' or 'failed', respectively, regardless of whether test is currently pending.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.completed_actions(actions = nil) ⇒ Object

Used to get and set the actions for a completed test plan.



183
184
185
186
187
188
189
# File 'app/models/test_plan.rb', line 183

def self.completed_actions actions = nil
  if actions.nil?
    @completed_actions ||= {}
  else
    @completed_actions = actions
  end
end

.manual_inspection(flag = true) ⇒ Object

Use this in the body of sub-classes to specify that inspection is done manually.



140
141
142
# File 'app/models/test_plan.rb', line 140

def self.manual_inspection flag = true
  @manual_inspection = flag
end

.manual_inspection?true, false

Return true if this test calls for manual inspection, false otherwise.



147
148
149
# File 'app/models/test_plan.rb', line 147

def self.manual_inspection?
  !!@manual_inspection
end

.normalize_name(name) ⇒ String

Normalize the given name for easy comparison.



216
217
218
# File 'app/models/test_plan.rb', line 216

def self.normalize_name name
  name.strip.downcase.gsub('_','-').gsub(/\ba?nd?\b|&/i, '-and-').gsub(/\W+/, '-')
end

.pending_actions(actions = nil) ⇒ Object

Used to get and set the actions for a pending test plan.



199
200
201
202
203
204
205
# File 'app/models/test_plan.rb', line 199

def self.pending_actions actions = nil
  if actions.nil?
    @pending_actions ||= {}
  else
    @pending_actions = actions
  end
end

.test_name(name = nil) ⇒ Object

Get or set the test name.



159
160
161
162
163
164
165
# File 'app/models/test_plan.rb', line 159

def self.test_name name = nil
  if name.nil?
    @test_name
  else
    @test_name = name
  end
end

.test_typesArray

Accessor for the test plan type registry.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/models/test_plan.rb', line 118

def self.test_types
  unless @test_types
    @test_types = Laika::TEST_PLAN_TYPES.clone
    unless Laika.use_xds
      @test_types.delete(XdsProvideAndRegisterPlan.test_name)
      @test_types.delete(XdsQueryAndRetrievePlan.test_name)
    end
    unless Laika.use_pix_pdq
      @test_types.delete(PdqQueryPlan.test_name)
      @test_types.delete(PixQueryPlan.test_name)
      @test_types.delete(PixFeedPlan.test_name)
    end
    @test_types.delete(C62InspectionPlan.test_name) unless Laika.use_c62
    @test_types.delete(NhinDisplayAndFilePlan.test_name) unless Laika.use_nhin
  end
  @test_types
end

Instance Method Details

#cloneObject

Create and save an identical test plan based on the receiver. A new patient is cloned and the state is set to “pending”.



222
223
224
225
226
227
228
229
230
# File 'app/models/test_plan.rb', line 222

def clone
  cloned = super
  new_patient = patient.clone
  new_patient.save!
  cloned.patient = new_patient
  cloned.update_attribute(:state, 'pending')
  cloned.save!
  cloned
end

#completed_actionsObject

Convenience method to get the actions for a completed test plan.



192
193
194
# File 'app/models/test_plan.rb', line 192

def completed_actions
  self.class.completed_actions
end

#count_errorsNumber

Count the errors in the content_errors.



60
61
62
# File 'app/models/test_plan.rb', line 60

def count_errors
  content_errors.count(:conditions => {:msg_type => 'error'})
end

#count_warningsNumber

Count the warnings in the content_errors.



67
68
69
# File 'app/models/test_plan.rb', line 67

def count_warnings
  content_errors.count(:conditions => {:msg_type => 'warning'})
end

#manual_inspection?true, false

Return true if this test calls for manual inspection, false otherwise.



154
155
156
# File 'app/models/test_plan.rb', line 154

def manual_inspection?
  self.class.manual_inspection?
end

#override_state!(state_options) ⇒ Object

Manually override test plan state to either passed or failed, and set a reason.

ActiveRecord error per save!



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/test_plan.rb', line 92

def override_state!(state_options)
  state = state_options['state']
  reason = state_options['status_override_reason']
  case state
    when 'passed'
      self.status_override_reason = reason 
      force_pass!
    when 'failed'
      self.status_override_reason = reason 
      force_fail!
    else
      false
  end
end

#parameterized_nameString

Return the normalized name of this test plan, but with underscores instead of dashes. Useful for building URLs and file paths.



111
112
113
# File 'app/models/test_plan.rb', line 111

def parameterized_name
  self.class.normalize_name(test_name).gsub('-','_')
end

#pending_actionsObject

Convenience method to get the actions for a pending test plan.



208
209
210
# File 'app/models/test_plan.rb', line 208

def pending_actions
  self.class.pending_actions
end

#test_actionsObject

Return either pending_actions or completed_actions depending on the test plan state.



176
177
178
# File 'app/models/test_plan.rb', line 176

def test_actions
  pending? ? pending_actions : completed_actions
end

#test_nameString

Get the test name.



170
171
172
# File 'app/models/test_plan.rb', line 170

def test_name
  self.class.test_name
end

#to_sObject

Quick and dirty human-readable stringification, useful for debugging or prototyping.



53
54
55
# File 'app/models/test_plan.rb', line 53

def to_s
  "#{vendor}: #{test_name} of #{patient.name} (#{state})"
end