Merge pull request #539 from Retrospring/acab

replace Timecop with ActiveSupport::Testing::TimeHelpers
This commit is contained in:
Georg Gadinger 2022-07-19 17:28:28 +02:00 committed by GitHub
commit 929e951b2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 16 deletions

View File

@ -98,7 +98,6 @@ group :development, :test do
gem "simplecov", require: false
gem "simplecov-cobertura", require: false
gem "simplecov-json", require: false
gem "timecop"
end
group :production do

View File

@ -516,7 +516,6 @@ GEM
thor (1.2.1)
thread_safe (0.3.6)
tilt (2.0.10)
timecop (0.9.5)
turbo-rails (1.1.1)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
@ -637,7 +636,6 @@ DEPENDENCIES
simplecov-cobertura
simplecov-json
spring (~> 4.0)
timecop
turbolinks (~> 2.5.3)
twitter
twitter-text

View File

@ -4,6 +4,8 @@
require "rails_helper"
describe Ajax::ModerationController, :ajax_controller, type: :controller do
include ActiveSupport::Testing::TimeHelpers
shared_examples "fails when report does not exist" do
let(:report_id) { "Burgenland" }
let(:expected_response) do
@ -147,7 +149,7 @@ describe Ajax::ModerationController, :ajax_controller, type: :controller do
let(:duration_unit) { 'hours' }
it "bans the user for 3 hours" do
Timecop.freeze do
freeze_time do
expect { subject }.to change { target_user.reload.banned? }.from(false).to(true)
expect(target_user.bans.current.first.reason).to eq("just a prank, bro")
expect(target_user.bans.current.first.expires_at.to_i).to eq((Time.now.utc + 3.hours).to_i)

View File

@ -3,6 +3,8 @@
require "rails_helper"
describe Settings::TwoFactorAuthentication::OtpAuthenticationController, type: :controller do
include ActiveSupport::Testing::TimeHelpers
let(:user) do
FactoryBot.create :user,
otp_module: :disabled,
@ -47,7 +49,7 @@ describe Settings::TwoFactorAuthentication::OtpAuthenticationController, type: :
end
it "shows an error if the user enters the incorrect code" do
Timecop.freeze(Time.at(1603290888).utc) do
travel_to(Time.at(1603290888).utc) do
subject
expect(response).to redirect_to :settings_two_factor_authentication_otp_authentication
expect(flash[:error]).to eq("The code you entered was invalid.")
@ -63,7 +65,7 @@ describe Settings::TwoFactorAuthentication::OtpAuthenticationController, type: :
end
it "enables 2FA for the logged in user and generates recovery keys" do
Timecop.freeze(Time.at(1603290888).utc) do
travel_to(Time.at(1603290888).utc) do
subject
expect(response).to have_rendered(:recovery_keys)
@ -72,7 +74,7 @@ describe Settings::TwoFactorAuthentication::OtpAuthenticationController, type: :
end
it "shows an error if the user attempts to use the code once it has expired" do
Timecop.freeze(Time.at(1603290950).utc) do
travel_to(Time.at(1603290950).utc) do
subject
expect(response).to redirect_to :settings_two_factor_authentication_otp_authentication
expect(flash[:error]).to eq(I18n.t("errors.invalid_otp"))

View File

@ -1,6 +1,8 @@
require "rails_helper"
describe BootstrapHelper, :type => :helper do
include ActiveSupport::Testing::TimeHelpers
describe '#nav_entry' do
it 'should return a HTML navigation item which links to a given address' do
allow(self).to receive(:current_page?).and_return(false)
@ -88,9 +90,9 @@ describe BootstrapHelper, :type => :helper do
describe "#time_tooltip" do
it 'should return a tooltip with proper time values' do
Timecop.freeze(Time.utc(1984)) do
travel_to(Time.utc(1984)) do
@user = FactoryBot.create(:user)
Timecop.travel(Time.now.utc + 10.minutes)
travel 10.minutes
expect(time_tooltip(@user)).to eq("<span title=\"Sun, 01 Jan 1984 00:00:00 +0000\" data-toggle=\"tooltip\" data-placement=\"bottom\">10 minutes</span>")
end
@ -102,4 +104,4 @@ describe BootstrapHelper, :type => :helper do
expect(hidespan("Hidden Text", "d-none")).to eq("<span class=\"d-none\">Hidden Text</span>")
end
end
end
end

View File

@ -4,6 +4,8 @@ require "rails_helper"
require "exporter"
RSpec.describe Exporter do
include ActiveSupport::Testing::TimeHelpers
let(:user_params) do
{
answered_count: 144,
@ -311,7 +313,7 @@ RSpec.describe Exporter do
subject { instance.send(:publish) }
it "publishes an archive" do
Timecop.freeze do
freeze_time do
expect { subject }.to change { user.export_processing }.from(true).to(false)
expect(File.exist?("#{fake_rails_root}/public/export/#{name}.tar.gz")).to eq(true)
expect(user.export_url).to eq("https://example.com/export/#{name}.tar.gz")

View File

@ -3,6 +3,8 @@
require "rails_helper"
RSpec.describe(Announcement, type: :model) do
include ActiveSupport::Testing::TimeHelpers
let!(:user) { FactoryBot.create :user }
let!(:me) do
Announcement.new(
@ -19,15 +21,15 @@ RSpec.describe(Announcement, type: :model) do
end
it "returns false when the current time is before starts_at" do
Timecop.freeze(me.starts_at - 1.second)
travel_to(me.starts_at - 1.second)
expect(me.active?).to be(false)
Timecop.return
travel_back
end
it "returns false when the current time is after ends_at" do
Timecop.freeze(me.ends_at)
travel_to(me.ends_at + 1.second)
expect(me.active?).to be(false)
Timecop.return
travel_back
end
end
@ -44,4 +46,4 @@ RSpec.describe(Announcement, type: :model) do
expect(me.link_present?).to be(false)
end
end
end
end