Sha256: 6e60d78dbc1d22c82fd7153aa34551a524dd832c8666d590b2712e2c8a336ea3

Contents?: true

Size: 967 Bytes

Versions: 133

Compression:

Stored size: 967 Bytes

Contents

# frozen_string_literal: true

module TimeZoneTestHelpers
  def with_tz_default(tz = nil)
    old_tz = Time.zone
    Time.zone = tz
    yield
  ensure
    Time.zone = old_tz
  end

  def with_env_tz(new_tz = "US/Eastern")
    old_tz, ENV["TZ"] = ENV["TZ"], new_tz
    yield
  ensure
    old_tz ? ENV["TZ"] = old_tz : ENV.delete("TZ")
  end

  def with_preserve_timezone(value)
    old_preserve_tz = ActiveSupport.to_time_preserves_timezone
    ActiveSupport.to_time_preserves_timezone = value
    yield
  ensure
    ActiveSupport.to_time_preserves_timezone = old_preserve_tz
  end

  def with_tz_mappings(mappings)
    old_mappings = ActiveSupport::TimeZone::MAPPING.dup
    ActiveSupport::TimeZone.clear
    ActiveSupport::TimeZone::MAPPING.clear
    ActiveSupport::TimeZone::MAPPING.merge!(mappings)

    yield
  ensure
    ActiveSupport::TimeZone.clear
    ActiveSupport::TimeZone::MAPPING.clear
    ActiveSupport::TimeZone::MAPPING.merge!(old_mappings)
  end
end

Version data entries

133 entries across 73 versions & 3 rubygems

Version Path
oj-3.16.9 test/activesupport6/time_zone_test_helpers.rb
oj-3.16.8 test/activesupport6/time_zone_test_helpers.rb
oj-3.16.7 test/activesupport6/time_zone_test_helpers.rb
oj-3.16.6 test/activesupport6/time_zone_test_helpers.rb
oj-3.16.5 test/activesupport6/time_zone_test_helpers.rb
oj-3.16.4 test/activesupport6/time_zone_test_helpers.rb
oj-3.16.3 test/activesupport6/time_zone_test_helpers.rb
oj-3.16.2 test/activesupport6/time_zone_test_helpers.rb
oj-3.16.1 test/activesupport6/time_zone_test_helpers.rb
oj-3.16.0 test/activesupport6/time_zone_test_helpers.rb
oj-3.15.1 test/activesupport6/time_zone_test_helpers.rb
oj-3.15.0 test/activesupport6/time_zone_test_helpers.rb
oj-3.14.3 test/activesupport6/time_zone_test_helpers.rb
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/oj-3.13.2/test/activesupport6/time_zone_test_helpers.rb
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/oj-3.13.2/test/activesupport5/time_zone_test_helpers.rb
oj-3.14.2 test/activesupport5/time_zone_test_helpers.rb
oj-3.14.2 test/activesupport6/time_zone_test_helpers.rb
oj-3.14.1 test/activesupport5/time_zone_test_helpers.rb
oj-3.14.1 test/activesupport6/time_zone_test_helpers.rb
oj-3.14.0 test/activesupport5/time_zone_test_helpers.rb