spec/mongoid/extensions/time_spec.rb in mongoid-7.0.13 vs spec/mongoid/extensions/time_spec.rb in mongoid-7.1.0.rc0
- old
+ new
@@ -1,5 +1,8 @@
+# frozen_string_literal: true
+# encoding: utf-8
+
require "spec_helper"
describe Mongoid::Extensions::Time do
describe ".demongoize" do
@@ -456,8 +459,35 @@
expect(eom_time_mongoized.hour).to eq(eom_time.utc.hour)
expect(eom_time_mongoized.min).to eq(eom_time.utc.min)
expect(eom_time_mongoized.sec).to eq(eom_time.utc.sec)
expect(eom_time_mongoized.usec).to eq(eom_time.utc.usec)
expect(eom_time_mongoized.subsec.to_f.round(3)).to eq(eom_time.utc.subsec.to_f.round(3))
+ end
+ end
+
+ describe "__mongoize_time__" do
+
+ let(:time) do
+ Time.at(1543331265.123457)
+ end
+
+ let(:mongoized) do
+ time.__mongoize_time__
+ end
+
+ let(:expected_time) { time.in_time_zone }
+
+ context "when using active support's time zone" do
+ include_context 'using AS time zone'
+
+ it_behaves_like 'mongoizes to Time'
+ it_behaves_like 'maintains precision when mongoized'
+ end
+
+ context "when not using active support's time zone" do
+ include_context 'not using AS time zone'
+
+ it_behaves_like 'mongoizes to Time'
+ it_behaves_like 'maintains precision when mongoized'
end
end
end