Sha256: 62956b5d28a2333244f06d57720bd42726ccdb82d08c66fa567331c74a0e7c99

Contents?: true

Size: 1.46 KB

Versions: 13

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

module Constraints
  RAILS_VERSION = ActiveSupport.version.to_s.split('.')[0..1].join('.').freeze

  def min_driver_version(version)
    required_version = version.split('.').map(&:to_i)
    actual_version = driver_version(required_version.length)
    before(:all) do
      if (actual_version <=> required_version) < 0
        skip "Driver version #{version} or higher is required"
      end
    end
  end

  def max_driver_version(version)
    required_version = version.split('.').map(&:to_i)
    actual_version = driver_version(required_version.length)
    before(:all) do
      if (actual_version <=> required_version) > 0
        skip "Driver version #{version} or lower is required"
      end
    end
  end

  def driver_version(precision)
    Mongo::VERSION.split('.')[0...precision].map(&:to_i)
  end

  def min_rails_version(version)
    unless version =~ /\A\d+\.\d+\z/
      raise ArgumentError, "Version can only be major.minor: #{version}"
    end

    before(:all) do
      if version > RAILS_VERSION
        skip "Rails version #{version} or higher required, we have #{RAILS_VERSION}"
      end
    end
  end

  def max_rails_version(version)
    unless version =~ /\A\d+\.\d+\z/
      raise ArgumentError, "Version can only be major.minor: #{version}"
    end

    before(:all) do
      if version < RAILS_VERSION
        skip "Rails version #{version} or lower required, we have #{RAILS_VERSION}"
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mongoid-7.3.5 spec/support/constraints.rb
mongoid-7.3.4 spec/support/constraints.rb
mongoid-7.2.6 spec/support/constraints.rb
mongoid-7.3.3 spec/support/constraints.rb
mongoid-7.3.2 spec/support/constraints.rb
mongoid-7.2.5 spec/support/constraints.rb
mongoid-7.2.4 spec/support/constraints.rb
mongoid-7.3.1 spec/support/constraints.rb
mongoid-7.3.0 spec/support/constraints.rb
mongoid-7.2.3 spec/support/constraints.rb
mongoid-7.2.2 spec/support/constraints.rb
mongoid-7.2.1 spec/support/constraints.rb
mongoid-7.2.0 spec/support/constraints.rb