Sha256: ce515bc80c029d84959556e38ef87d631f92b637310ec4a8a3f64a2cae6635b0

Contents?: true

Size: 1.44 KB

Versions: 18

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

require 'spec_helper'

describe 'Time zone querying' do
  let(:collection) { authorized_client[:time_zone_querying] }

  before do
    collection.delete_many
    collection.insert_many([
      {id: 1, created_at: Time.utc(2020, 10, 1, 23)},
      {id: 2, created_at: Time.utc(2020, 10, 2, 0)},
      {id: 3, created_at: Time.utc(2020, 10, 2, 1)},
    ])
  end

  context 'UTC time' do
    let(:time) { Time.utc(2020, 10, 1, 23, 22) }

    it 'finds correctly' do
      view = collection.find({created_at: {'$gt' => time}})
      expect(view.count).to eq(2)
      expect(view.map { |doc| doc[:id] }.sort).to eq([2, 3])
    end
  end

  context 'local time with zone' do
    let(:time) { Time.parse('2020-10-01T19:30:00-0500') }

    it 'finds correctly' do
      view = collection.find({created_at: {'$gt' => time}})
      expect(view.count).to eq(1)
      expect(view.first[:id]).to eq(3)
    end
  end

  context 'when ActiveSupport support is enabled' do
    before do
      unless SpecConfig.instance.active_support?
        skip "ActiveSupport support is not enabled"
      end
    end

    context 'ActiveSupport::TimeWithZone' do
      let(:time) { Time.parse('2020-10-01T19:30:00-0500').in_time_zone('America/New_York') }

      it 'finds correctly' do
        view = collection.find({created_at: {'$gt' => time}})
        expect(view.count).to eq(1)
        expect(view.first[:id]).to eq(3)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mongo-2.16.4 spec/integration/time_zone_querying_spec.rb
mongo-2.17.4 spec/integration/time_zone_querying_spec.rb
mongo-2.18.3 spec/integration/time_zone_querying_spec.rb
mongo-2.18.2 spec/integration/time_zone_querying_spec.rb
mongo-2.17.3 spec/integration/time_zone_querying_spec.rb
mongo-2.18.1 spec/integration/time_zone_querying_spec.rb
mongo-2.18.0 spec/integration/time_zone_querying_spec.rb
mongo-2.17.2 spec/integration/time_zone_querying_spec.rb
mongo-2.16.3 spec/integration/time_zone_querying_spec.rb
mongo-2.18.0.beta1 spec/integration/time_zone_querying_spec.rb
mongo-2.16.2 spec/integration/time_zone_querying_spec.rb
mongo-2.17.1 spec/integration/time_zone_querying_spec.rb
mongo-2.16.1 spec/integration/time_zone_querying_spec.rb
mongo-2.17.0 spec/integration/time_zone_querying_spec.rb
mongo-2.16.0 spec/integration/time_zone_querying_spec.rb
mongo-2.15.1 spec/integration/time_zone_querying_spec.rb
mongo-2.16.0.alpha1 spec/integration/time_zone_querying_spec.rb
mongo-2.15.0 spec/integration/time_zone_querying_spec.rb