tests: drop timecop gem.

This commit is contained in:
evazion
2019-08-18 03:50:43 -05:00
parent b15fd6d017
commit 27a118dfc8
24 changed files with 38 additions and 42 deletions

View File

@@ -87,7 +87,6 @@ group :test do
gem "mocha", :require => "mocha/setup"
gem "ffaker"
gem "simplecov", :require => false
gem "timecop"
gem "webmock"
gem "minitest-ci"
gem "mock_redis"

View File

@@ -391,7 +391,6 @@ GEM
thor (0.19.4)
thread_safe (0.3.6)
tilt (2.0.9)
timecop (0.9.1)
tins (1.21.1)
twitter (6.2.0)
addressable (~> 2.3)
@@ -510,7 +509,6 @@ DEPENDENCIES
streamio-ffmpeg
stripe
term-ansicolor
timecop
twitter
unicorn
unicorn-worker-killer

View File

@@ -1,5 +1,4 @@
require 'set'
require 'timecop'
CurrentUser.ip_addr = "127.0.0.1"
Delayed::Worker.delay_jobs = false
@@ -40,7 +39,7 @@ end
if User.count == 0
puts "Creating users"
Timecop.travel(1.month.ago) do
begin
user = User.create(
:name => "admin",
:password => "password1",

View File

@@ -139,7 +139,7 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
should "update an artist" do
old_timestamp = @wiki_page.updated_at
travel_to(1.minute.from_now) do
travel(1.minute) do
put_auth artist_path(@artist.id), @user, params: {artist: {notes: "rex", url_string: "http://example.com\nhttp://monet.com"}}
end
@artist.reload
@@ -153,7 +153,7 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
old_timestamp = @wiki_page.updated_at
old_updater_id = @wiki_page.updater_id
travel_to(1.minutes.from_now) do
travel(1.minute) do
as(@another_user) do
@artist.update(notes: "testing")
end

View File

@@ -76,10 +76,10 @@ class NotesControllerTest < ActionDispatch::IntegrationTest
context "revert action" do
setup do
as_user do
travel_to(1.day.from_now) do
travel(1.day) do
@note.update(:body => "111")
end
travel_to(2.days.from_now) do
travel(2.days) do
@note.update(:body => "222")
end
end

View File

@@ -31,7 +31,7 @@ class PostReplacementsControllerTest < ActionDispatch::IntegrationTest
@post.reload
end
travel_to(Time.now + PostReplacement::DELETION_GRACE_PERIOD + 1.day) do
travel(PostReplacement::DELETION_GRACE_PERIOD + 1.day) do
Delayed::Worker.new.work_off
end

View File

@@ -10,10 +10,10 @@ class PostVersionsControllerTest < ActionDispatch::IntegrationTest
setup do
@user.as_current do
@post = create(:post)
travel_to(2.hours.from_now) do
travel(2.hours) do
@post.update(:tag_string => "1 2", :source => "xxx")
end
travel_to(4.hours.from_now) do
travel(4.hours) do
@post.update(:tag_string => "2 3", :rating => "e")
end
@versions = @post.versions

View File

@@ -167,10 +167,10 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
as_user do
@wiki_page = create(:wiki_page, :body => "1")
end
travel_to(1.day.from_now) do
travel(1.day) do
@wiki_page.update(:body => "1 2")
end
travel_to(2.days.from_now) do
travel(2.days) do
@wiki_page.update(:body => "1 2 3")
end
end

View File

@@ -71,7 +71,7 @@ class ArtistCommentaryTest < ActiveSupport::TestCase
end
should "create a new version if outside merge window" do
travel_to(2.hours.from_now) do
travel(2.hours) do
@artcomm.update(original_title: "bar")
assert_equal(2, @post.artist_commentary.versions.size)

View File

@@ -19,7 +19,7 @@ class ArtistTest < ActiveSupport::TestCase
context "An artist" do
setup do
user = Timecop.travel(1.month.ago) {FactoryBot.create(:user)}
user = travel_to(1.month.ago) {FactoryBot.create(:user)}
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -458,7 +458,7 @@ class ArtistTest < ActiveSupport::TestCase
assert_difference("ArtistVersion.count") do
artist.other_names = "xxx"
Timecop.travel(1.day.from_now) do
travel(1.day) do
artist.save
end
end

View File

@@ -143,7 +143,7 @@ class CommentTest < ActiveSupport::TestCase
Danbooru.config.stubs(:comment_threshold).returns(1)
p = FactoryBot.create(:post)
c1 = FactoryBot.create(:comment, :post => p)
Timecop.travel(2.seconds.from_now) do
travel(2.seconds) do
c2 = FactoryBot.create(:comment, :post => p)
end
p.reload
@@ -158,7 +158,7 @@ class CommentTest < ActiveSupport::TestCase
post.reload
assert_equal(c1.created_at.to_s, post.last_commented_at.to_s)
Timecop.travel(2.seconds.from_now) do
travel(2.seconds) do
c2 = FactoryBot.create(:comment, :post => post)
post.reload
assert_equal(c2.created_at.to_s, post.last_commented_at.to_s)

View File

@@ -80,7 +80,7 @@ class ForumPostTest < ActiveSupport::TestCase
9.times do
@posts << FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
end
Timecop.travel(2.seconds.from_now) do
travel(2.seconds) do
@posts << FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
end
end
@@ -135,7 +135,7 @@ class ForumPostTest < ActiveSupport::TestCase
should "update the topic when created" do
@original_topic_updated_at = @topic.updated_at
Timecop.travel(1.second.from_now) do
travel(1.second) do
post = FactoryBot.create(:forum_post, :topic_id => @topic.id)
end
@topic.reload
@@ -149,14 +149,14 @@ class ForumPostTest < ActiveSupport::TestCase
end
# updating the original post
Timecop.travel(1.second.from_now) do
travel(1.second) do
posts.first.update_attributes(:body => "xxx")
end
@topic.reload
assert_equal(posts.first.updated_at.to_s, @topic.updated_at.to_s)
# updating a non-original post
Timecop.travel(2.seconds.from_now) do
travel(2.seconds) do
posts.last.update_attributes(:body => "xxx")
end
assert_equal(posts.first.updated_at.to_s, @topic.updated_at.to_s)

View File

@@ -76,7 +76,7 @@ class NoteTest < ActiveSupport::TestCase
should "create a version" do
assert_difference("NoteVersion.count", 1) do
Timecop.travel(1.day.from_now) do
travel(1.day) do
@note = FactoryBot.create(:note, :post => @post)
end
end
@@ -135,7 +135,7 @@ class NoteTest < ActiveSupport::TestCase
should "create a version" do
assert_difference("NoteVersion.count", 1) do
Timecop.travel(1.day.from_now) do
travel(1.day) do
@note.update_attributes(:body => "fafafa")
end
end
@@ -181,7 +181,7 @@ class NoteTest < ActiveSupport::TestCase
assert_equal(2, NoteVersion.count)
assert_equal([1, 2], @note.versions.map(&:version))
assert_equal([@user.id, @vandal.id], @note.versions.map(&:updater_id))
Timecop.travel(1.day.from_now) do
travel(1.day) do
Note.undo_changes_by_user(@vandal.id)
end
@note.reload

View File

@@ -4,7 +4,7 @@ require 'test_helper'
class PoolTest < ActiveSupport::TestCase
setup do
Timecop.travel(1.month.ago) do
travel_to(1.month.ago) do
@user = FactoryBot.create(:user)
CurrentUser.user = @user
end
@@ -281,7 +281,7 @@ class PoolTest < ActiveSupport::TestCase
should "create new versions for each distinct user" do
assert_equal(1, @pool.versions.size)
user2 = Timecop.travel(1.month.ago) {FactoryBot.create(:user)}
user2 = travel_to(1.month.ago) {FactoryBot.create(:user)}
CurrentUser.scoped(user2, "127.0.0.2") do
@pool.post_ids = [@p1.id]

View File

@@ -49,7 +49,7 @@ class PostApprovalTest < ActiveSupport::TestCase
@post.approve!(@approver2)
assert_not_equal(@approver.id, @post.approver_id)
CurrentUser.user = @user3
travel_to(PostFlag::COOLDOWN_PERIOD.from_now + 1.minute) do
travel(PostFlag::COOLDOWN_PERIOD + 1.minute) do
@post.flag!("blah blah")
end

View File

@@ -5,7 +5,7 @@ class PostArchiveTest < ActiveSupport::TestCase
context "A post" do
setup do
Timecop.travel(1.month.ago) do
travel_to(1.month.ago) do
@user = FactoryBot.create(:user)
end
CurrentUser.user = @user

View File

@@ -52,7 +52,7 @@ class PostDisapprovalTest < ActiveSupport::TestCase
setup do
@post = FactoryBot.create(:post)
@user = FactoryBot.create(:user)
Timecop.travel(2.months.ago) do
travel_to(2.months.ago) do
@disapproval = PostDisapproval.create(:user => @user, :post => @post)
end
end

View File

@@ -4,7 +4,7 @@ class PostEventTest < ActiveSupport::TestCase
def setup
super
Timecop.travel(2.weeks.ago) do
travel_to(2.weeks.ago) do
CurrentUser.user = FactoryBot.create(:user)
CurrentUser.ip_addr = "127.0.0.1"
end

View File

@@ -8,7 +8,7 @@ class PostPrunerTest < ActiveSupport::TestCase
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
Timecop.travel(2.weeks.ago) do
travel_to(2.weeks.ago) do
@flagger = FactoryBot.create(:gold_user)
end
@old_post = FactoryBot.create(:post, :created_at => 5.days.ago, :is_pending => true)

View File

@@ -18,7 +18,7 @@ class PostTest < ActiveSupport::TestCase
def setup
super
Timecop.travel(2.weeks.ago) do
travel_to(2.weeks.ago) do
@user = FactoryBot.create(:user)
end
CurrentUser.user = @user
@@ -1278,7 +1278,7 @@ class PostTest < ActiveSupport::TestCase
should "create a new version if it's been over an hour since the last update" do
post = FactoryBot.create(:post)
Timecop.travel(6.hours.from_now) do
travel(6.hours) do
assert_difference("PostArchive.count", 1) do
post.update_attributes(:tag_string => "zzz")
end
@@ -2660,7 +2660,7 @@ class PostTest < ActiveSupport::TestCase
context "a post that is rating locked" do
setup do
@post = FactoryBot.create(:post, :rating => "s")
Timecop.travel(2.hours.from_now) do
travel(2.hours) do
@post.update(rating: "q", is_rating_locked: true)
end
end

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class PostVersionTest < ActiveSupport::TestCase
context "A post" do
setup do
Timecop.travel(1.month.ago) do
travel_to(1.month.ago) do
@user = FactoryBot.create(:user)
end
CurrentUser.user = @user
@@ -68,7 +68,7 @@ class PostVersionTest < ActiveSupport::TestCase
context "that has been updated" do
setup do
PostArchive.sqs_service.stubs(:merge?).returns(false)
Timecop.travel(1.minute.ago) do
travel_to(1.minute.ago) do
@post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
end
@post.update_attributes(:tag_string => "bbb ccc xxx", :source => "")

View File

@@ -5,7 +5,7 @@ class TagAliasTest < ActiveSupport::TestCase
setup do
@admin = FactoryBot.create(:admin_user)
Timecop.travel(1.month.ago) do
travel_to(1.month.ago) do
user = FactoryBot.create(:user)
CurrentUser.user = user
end

View File

@@ -16,7 +16,7 @@ class TagTest < ActiveSupport::TestCase
setup do
Tag.stubs(:trending_count_limit).returns(0)
Timecop.travel(1.week.ago) do
travel_to(1.week.ago) do
FactoryBot.create(:post, :tag_string => "aaa")
FactoryBot.create(:post, :tag_string => "bbb")
end

View File

@@ -84,7 +84,7 @@ class WikiPageTest < ActiveSupport::TestCase
assert_difference("WikiPageVersion.count") do
@wiki_page.title = "yyy"
Timecop.travel(1.day.from_now) do
travel(1.day) do
@wiki_page.save
end
end
@@ -92,7 +92,7 @@ class WikiPageTest < ActiveSupport::TestCase
should "revert to a prior version" do
@wiki_page.title = "yyy"
Timecop.travel(1.day.from_now) do
travel(1.day) do
@wiki_page.save
end
version = WikiPageVersion.first