Sha256: 99719f5e810c51461e9281576e83f1b5429f16d62a51153c16be8bab9b042c0b

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

require "cases/helper"

class Mysql2DatetimePrecisionQuotingTest < ActiveRecord::Mysql2TestCase
  setup do
    @connection = ActiveRecord::Base.connection
  end

  test 'microsecond precision for MySQL gte 5.6.4' do
    stub_version '5.6.4'
    assert_microsecond_precision
  end

  test 'no microsecond precision for MySQL lt 5.6.4' do
    stub_version '5.6.3'
    assert_no_microsecond_precision
  end

  test 'microsecond precision for MariaDB gte 5.3.0' do
    stub_version '5.5.5-10.1.8-MariaDB-log'
    assert_microsecond_precision
  end

  test 'no microsecond precision for MariaDB lt 5.3.0' do
    stub_version '5.2.9-MariaDB'
    assert_no_microsecond_precision
  end

  private
    def assert_microsecond_precision
      assert_match_quoted_microsecond_datetime(/\.000001\z/)
    end

    def assert_no_microsecond_precision
      assert_match_quoted_microsecond_datetime(/\d\z/)
    end

    def assert_match_quoted_microsecond_datetime(match)
      assert_match match, @connection.quoted_date(Time.now.change(usec: 1))
    end

    def stub_version(full_version_string)
      @connection.stubs(:full_version).returns(full_version_string)
      @connection.remove_instance_variable(:@version) if @connection.instance_variable_defined?(:@version)
    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ibm_db-5.2.0-x86-mingw32 test/cases/adapters/mysql2/datetime_precision_quoting_test.rb
ibm_db-5.1.0-x86-mingw32 test/cases/adapters/mysql2/datetime_precision_quoting_test.rb
ibm_db-5.0.5-x86-mingw32 test/cases/adapters/mysql2/datetime_precision_quoting_test.rb
ibm_db-5.0.4-x86-mingw32 test/cases/adapters/mysql2/datetime_precision_quoting_test.rb
ibm_db-5.0.3-x86-mingw32 test/cases/adapters/mysql2/datetime_precision_quoting_test.rb
ibm_db-5.0.2-x86-mingw32 test/cases/adapters/mysql2/datetime_precision_quoting_test.rb