Module: Inferno::Repositories::ValidateRunnableReference
- Included in:
- Results::Model, TestRuns::Model
- Defined in:
- lib/inferno/repositories/validate_runnable_reference.rb
Constant Summary collapse
- REFERENCE_KEYS =
[:test_id, :test_group_id, :test_suite_id].freeze
Instance Method Summary collapse
- #check_runnable_reference ⇒ Object
- #runnable_reference_exists?(type, id) ⇒ Boolean
- #validate ⇒ Object
Instance Method Details
#check_runnable_reference ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/inferno/repositories/validate_runnable_reference.rb', line 12 def check_runnable_reference present_keys = REFERENCE_KEYS.select { |reference_key| send(reference_key) } if present_keys.length == 1 runnable_type = present_keys.first id = values[runnable_type] reference_exists = runnable_reference_exists?(runnable_type, id) return if reference_exists { key: runnable_type, message: "of #{id} does not exist" } else { key: :base, message: "must contain exactly one of 'test_id', 'test_group_id', or 'test_suite_id'" } end end |
#runnable_reference_exists?(type, id) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/inferno/repositories/validate_runnable_reference.rb', line 27 def runnable_reference_exists?(type, id) repo = case type when :test_id Inferno::Repositories::Tests.new when :test_group_id Inferno::Repositories::TestGroups.new when :test_suite_id Inferno::Repositories::TestSuites.new end repo.exists? id end |
#validate ⇒ Object
6 7 8 9 10 |
# File 'lib/inferno/repositories/validate_runnable_reference.rb', line 6 def validate super = check_runnable_reference errors.add([:key], [:message]) if end |