spec/mongoid/extensions/time_spec.rb in mongoid-8.0.8 vs spec/mongoid/extensions/time_spec.rb in mongoid-8.1.0

- old
+ new

@@ -48,19 +48,12 @@ end end context "when using the ActiveSupport time zone" do config_override :use_activesupport_time_zone, true + time_zone_override "Stockholm" - before do - Time.zone = "Stockholm" - end - - after do - Time.zone = nil - end - context "when demongoizing a Time" do it "returns an ActiveSupport::TimeWithZone" do expect(Time.demongoize(time).class).to eq(ActiveSupport::TimeWithZone) end @@ -121,23 +114,16 @@ expect(Time.demongoize(time.dup.utc).utc_offset).to eq(0) end context "when using the ActiveSupport time zone" do config_override :use_activesupport_time_zone, true + time_zone_override "Stockholm" let(:time) do Time.utc(2010, 11, 19, 0, 30) end - before do - Time.zone = "Stockholm" - end - - after do - Time.zone = nil - end - it "returns utc" do expect(Time.demongoize(time)).to eq( ActiveSupport::TimeZone['UTC'].local(2010, 11, 19, 0, 30) ) end @@ -853,24 +839,17 @@ expect(DateTime.mongoize(1.11).to_f).to eq(1.11) end context "when using the ActiveSupport time zone" do config_override :use_activesupport_time_zone, true + # if this is actually your time zone, the following tests are useless + time_zone_override "Stockholm" let(:datetime) do DateTime.new(2010, 11, 19) end - before do - # if this is actually your time zone, the following tests are useless - Time.zone = "Stockholm" - end - - after do - Time.zone = nil - end - it "assumes the given time is local" do expect(Time.mongoize(datetime)).to eq( Time.utc(2010, 11, 19) ) end @@ -943,24 +922,17 @@ expect(Time.mongoize(date).utc_offset).to eq(0) end context "when using the ActiveSupport time zone" do config_override :use_activesupport_time_zone, true + # if this is actually your time zone, the following tests are useless + time_zone_override "Stockholm" let(:date) do Date.new(2010, 11, 19) end - before do - # if this is actually your time zone, the following tests are useless - Time.zone = "Stockholm" - end - - after do - Time.zone = nil - end - it "assumes the given time is local" do expect(Time.mongoize(date)).to eq(Time.utc(2010, 11, 18, 23)) end end end @@ -975,18 +947,11 @@ expect(Time.mongoize(array)).to eq(Time.local(*array)) end context "when using the ActiveSupport time zone" do config_override :use_activesupport_time_zone, true - - before do - # if this is actually your time zone, the following tests are useless - Time.zone = "Stockholm" - end - - after do - Time.zone = nil - end + # if this is actually your time zone, the following tests are useless + time_zone_override "Stockholm" it "assumes the given time is local" do expect(Time.mongoize(array)).to eq( Time.utc(2010, 11, 18, 23, 24, 49) )