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.3.0 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.3.0.rc1 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.2.0 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.2.0.rc4 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.2.0.rc3 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.2.0.rc2 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.2.0.rc1 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.1.4.pre lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.1.3 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.1.3.pre2 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.1.3.pre lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.1.2 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.1.2.pre lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.1.1 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.1.1.pre lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.1.0 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.1.0.pre lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.0.8 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.0.8.pre2 lib/inferno/repositories/validate_runnable_reference.rb
inferno_core-0.0.8.pre lib/inferno/repositories/validate_runnable_reference.rb