Sha256: 3058387593e29f176a795e5306739f3f624f06426777c5370a3035e56a27e272

Contents?: true

Size: 1.28 KB

Versions: 87

Compression:

Stored size: 1.28 KB

Contents

module Inferno
  module Repositories
    module ValidateRunnableReference
      REFERENCE_KEYS = [:test_id, :test_group_id, :test_suite_id].freeze

      def validate
        super
        reference_error_message = check_runnable_reference
        errors.add(reference_error_message[:key], reference_error_message[:message]) if reference_error_message
      end

      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

      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
    end
  end
end

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
inferno_core-0.5.0 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.44 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.43 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.42 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.41 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.40 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.39 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.38 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.35 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.34 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.33 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.32 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.31 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.30 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.29 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.28 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.27 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.26 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.25 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.4.24 lib/inferno/repositories/validate_runnable_reference.rb