A platform for community discussion. Free, open, simple.
DEV: Improve flaky time-sensitive specs (#9141)
Jarek Radosz29b35aa64c6e
diff --git a/plugins/poll/spec/controllers/posts_controller_spec.rb b/plugins/poll/spec/controllers/posts_controller_spec.rbindex 8f9dae14a2a..3cedf9017f0 100644--- a/plugins/poll/spec/controllers/posts_controller_spec.rb+++ b/plugins/poll/spec/controllers/posts_controller_spec.rb@@ -11,7 +11,6 @@ describe PostsController doenddescribe "polls" do-it "works" dopost :create, params: {title: title, raw: "[poll]\n- A\n- B\n[/poll]"@@ -39,7 +38,7 @@ describe PostsController doit "schedules auto-close job" dofreeze_timename = "auto_close"- close_date = 1.month.from_now+ close_date = 1.month.from_now.roundexpect dopost :create, params: {@@ -53,7 +52,7 @@ describe PostsController dojson = ::JSON.parse(response.body)post_id = json["id"]- expect(Poll.find_by(post_id: post_id).close_at).to be_within_one_second_of(1.month.from_now)+ expect(Poll.find_by(post_id: post_id).close_at).to eq_time(close_date)job = Jobs::ClosePoll.jobs.firstjob_args = job["args"].firstdiff --git a/plugins/poll/spec/db/post_migrate/migrate_polls_data_spec.rb b/plugins/poll/spec/db/post_migrate/migrate_polls_data_spec.rbindex 50bc5d75caf..018f50ded8d 100644--- a/plugins/poll/spec/db/post_migrate/migrate_polls_data_spec.rb+++ b/plugins/poll/spec/db/post_migrate/migrate_polls_data_spec.rb@@ -267,7 +267,7 @@ RSpec.describe MigratePollsData dopoll = Poll.find_by(name: "poll")expect(poll.post_id).to eq(post.id)- expect(poll.close_at).to eq("2018-10-08T00:00:00.000Z")+ expect(poll.close_at).to eq_time(Time.parse("2018-10-08T00:00:00.000Z"))expect(poll.regular?).to eq(true)expect(poll.open?).to eq(true)diff --git a/spec/components/auth/default_current_user_provider_spec.rb b/spec/components/auth/default_current_user_provider_spec.rbindex 5495d4e46dc..2e0650cf30f 100644--- a/spec/components/auth/default_current_user_provider_spec.rb+++ b/spec/components/auth/default_current_user_provider_spec.rb@@ -411,7 +411,7 @@ describe Auth::DefaultCurrentUserProvider doprovider2 = provider("/", "HTTP_COOKIE" => "_t=#{unhashed_token}")u = provider2.current_useru.reload- expect(u.last_seen_at).to eq_time(Time.now)+ expect(u.last_seen_at).to eq_time(Time.zone.now)freeze_time 20.minutes.from_nowdiff --git a/spec/components/composer_messages_finder_spec.rb b/spec/components/composer_messages_finder_spec.rbindex 6b8214ea750..00cb9ac9952 100644--- a/spec/components/composer_messages_finder_spec.rb+++ b/spec/components/composer_messages_finder_spec.rb@@ -157,9 +157,11 @@ describe ComposerMessagesFinder doSiteSetting.educate_until_posts = 10user.stubs(:post_count).returns(11)- Fabricate(:post, topic: topic, user: user)- Fabricate(:post, topic: topic, user: user)- Fabricate(:post, topic: topic, user: user, post_type: Post.types[:small_action])+ freeze_time(5.minutes.ago) do+ Fabricate(:post, topic: topic, user: user)+ Fabricate(:post, topic: topic, user: user)+ Fabricate(:post, topic: topic, user: user, post_type: Post.types[:small_action])+ endSiteSetting.sequential_replies_threshold = 2enddiff --git a/spec/components/concern/second_factor_manager_spec.rb b/spec/components/concern/second_factor_manager_spec.rbindex 5a049e2c41b..e19d75e02f1 100644--- a/spec/components/concern/second_factor_manager_spec.rb+++ b/spec/components/concern/second_factor_manager_spec.rb@@ -69,7 +69,7 @@ RSpec.describe SecondFactorManager dotoken = user.user_second_factors.totps.first.totp_object.nowexpect(user.authenticate_totp(token)).to eq(true)- expect(user.user_second_factors.totps.first.last_used).to eq_time(DateTime.now)+ expect(user.user_second_factors.totps.first.last_used).to eq_time(Time.zone.now)expect(user.authenticate_totp(token)).to eq(false)endenddiff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rbindex 5406d146df5..799e3a3cd3a 100644--- a/spec/components/cooked_post_processor_spec.rb+++ b/spec/components/cooked_post_processor_spec.rb@@ -1777,14 +1777,14 @@ describe CookedPostProcessor dosmall_action = Fabricate(:post, topic: topic, post_type: Post.types[:small_action])reply = Fabricate(:post, topic: topic, raw: raw)- freeze_time Time.zone.now do+ freeze_time dotopic.bumped_at = 1.day.agoCookedPostProcessor.new(reply).remove_full_quote_on_direct_replyexpect(topic.ordered_posts.pluck(:id)).to eq([post.id, hidden.id, small_action.id, reply.id])- expect(topic.bumped_at).to eq(1.day.ago)+ expect(topic.bumped_at).to eq_time(1.day.ago)expect(reply.raw).to eq("and this is the third reply")expect(reply.revisions.count).to eq(1)expect(reply.revisions.first.modifications["raw"]).to eq([raw, reply.raw])diff --git a/spec/components/discourse_updates_spec.rb b/spec/components/discourse_updates_spec.rbindex d57493d672d..8e9ef2596b4 100644--- a/spec/components/discourse_updates_spec.rb+++ b/spec/components/discourse_updates_spec.rb@@ -24,7 +24,8 @@ describe DiscourseUpdates docontext 'a good version check request happened recently' docontext 'and server is up-to-date' do- before { stub_data(Discourse::VERSION::STRING, 0, false, 12.hours.ago) }+ let(:time) { 12.hours.ago }+ before { stub_data(Discourse::VERSION::STRING, 0, false, time) }it 'returns all the version fields' doexpect(subject.latest_version).to eq(Discourse::VERSION::STRING)@@ -35,12 +36,13 @@ describe DiscourseUpdates doendit 'returns the timestamp of the last version check' do- expect(subject.updated_at).to be_within_one_second_of(12.hours.ago)+ expect(subject.updated_at).to eq_time(time)endendcontext 'and server is not up-to-date' do- before { stub_data('0.9.0', 2, false, 12.hours.ago) }+ let(:time) { 12.hours.ago }+ before { stub_data('0.9.0', 2, false, time) }it 'returns all the version fields' doexpect(subject.latest_version).to eq('0.9.0')@@ -50,7 +52,7 @@ describe DiscourseUpdates doendit 'returns the timestamp of the last version check' do- expect(subject.updated_at).to be_within_one_second_of(12.hours.ago)+ expect(subject.updated_at).to eq_time(time)endendenddiff --git a/spec/components/distributed_mutex_spec.rb b/spec/components/distributed_mutex_spec.rbindex 97c3d0096c8..23bfd908127 100644--- a/spec/components/distributed_mutex_spec.rb+++ b/spec/components/distributed_mutex_spec.rb@@ -99,7 +99,7 @@ describe DistributedMutex do}.to raise_error(Discourse::ReadOnly)expect(done).to eq(false)- expect(Time.now - start).to be < (1.second)+ expect(Time.now - start).to be <= 1.secondendenddiff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rbindex a7dd5e6b71c..7644d6df06a 100644--- a/spec/components/email/receiver_spec.rb+++ b/spec/components/email/receiver_spec.rb@@ -656,8 +656,11 @@ describe Email::Receiver doendit "ensures posts aren't dated in the future" do+ # PostCreator doesn't provide sub-second accuracy for created_at+ now = freeze_time Time.zone.now.round+expect { process(:from_the_future) }.to change { topic.posts.count }- expect(topic.posts.last.created_at).to be_within(1.minute).of(DateTime.now)+ expect(topic.posts.last.created_at).to eq_time(now)endit "accepts emails with wrong reply key if the system knows about the forwarded email" dodiff --git a/spec/components/post_action_creator_spec.rb b/spec/components/post_action_creator_spec.rbindex acc31fa5b3f..ad013f82f5b 100644--- a/spec/components/post_action_creator_spec.rb+++ b/spec/components/post_action_creator_spec.rb@@ -145,6 +145,7 @@ describe PostActionCreator dobefore { reviewable.perform(admin, :ignore) }it "fails because the post was recently reviewed" do+ freeze_time 10.seconds.from_nowresult = PostActionCreator.create(user, post, :inappropriate)expect(result.success?).to eq(false)diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rbindex 07ec76bb787..1fae7727526 100644--- a/spec/components/post_creator_spec.rb+++ b/spec/components/post_creator_spec.rb@@ -145,19 +145,26 @@ describe PostCreator do_reply = PostCreator.new(admin, raw: "this is my test reply 123 testing", topic_id: created_post.topic_id).createend+ messages.filter! { |m| m.channel != "/distributed_hash" }++ channels = messages.map { |m| m.channel }.sort+# 2 for topic, one to notify of new topic another for tracking state- expect(messages.map { |m| m.channel }.sort).to eq([ "/new",- "/u/#{admin.username}",- "/u/#{admin.username}",- "/unread/#{admin.id}",- "/unread/#{admin.id}",- "/latest",- "/latest",- "/topic/#{created_post.topic_id}",- "/topic/#{created_post.topic_id}"- ].sort)- admin_ids = [Group[:admins].id]+ expect(channels).to eq(+ [+ "/new",+ "/u/#{admin.username}",+ "/u/#{admin.username}",+ "/unread/#{admin.id}",+ "/unread/#{admin.id}",+ "/latest",+ "/latest",+ "/topic/#{created_post.topic_id}",+ "/topic/#{created_post.topic_id}"+ ].sort+ )+ admin_ids = [Group[:admins].id]expect(messages.any? { |m| m.group_ids != admin_ids && m.user_ids != [admin.id] }).to eq(false)end@@ -312,7 +319,7 @@ describe PostCreator dofirst_post = creator.createtopic = first_post.topic.reload- expect(topic.last_posted_at).to be_within(1.seconds).of(first_post.created_at)+ expect(topic.last_posted_at).to eq_time(first_post.created_at)expect(topic.last_post_user_id).to eq(first_post.user_id)expect(topic.word_count).to eq(4)end@@ -351,8 +358,8 @@ describe PostCreator dotopic.reloadtopic_status_update = TopicTimer.last- expect(topic_status_update.execute_at).to be_within(1.second).of(Time.zone.now + 12.hours)- expect(topic_status_update.created_at).to be_within(1.second).of(Time.zone.now)+ expect(topic_status_update.execute_at).to eq_time(12.hours.from_now)+ expect(topic_status_update.created_at).to eq_time(Time.zone.now)enddescribe "topic's auto close based on last post" do@@ -484,7 +491,6 @@ describe PostCreator dofab!(:topic) { Fabricate(:topic, user: user) }it 'whispers do not mess up the public view' do-# turns out this can fail on leap years if we don't do thisfreeze_time DateTime.parse('2010-01-01 12:00')@@ -538,7 +544,7 @@ describe PostCreator doexpect(topic.reply_count).to eq(0)expect(topic.posts_count).to eq(1)expect(topic.highest_staff_post_number).to eq(3)- expect(topic.last_posted_at).to be_within(1.seconds).of(first.created_at)+ expect(topic.last_posted_at).to eq_time(first.created_at)expect(topic.last_post_user_id).to eq(first.user_id)expect(topic.word_count).to eq(5)@@ -554,7 +560,7 @@ describe PostCreator dotopic.reloadexpect(topic.highest_post_number).to eq(1)expect(topic.posts_count).to eq(1)- expect(topic.last_posted_at).to eq(first.created_at)+ expect(topic.last_posted_at).to eq_time(first.created_at)expect(topic.highest_staff_post_number).to eq(3)endend@@ -684,7 +690,7 @@ describe PostCreator dopost = creator.createtopic.reload- expect(topic.last_posted_at).to be_within(1.seconds).of(post.created_at)+ expect(topic.last_posted_at).to eq_time(post.created_at)expect(topic.last_post_user_id).to eq(post.user_id)expect(topic.word_count).to eq(6)end@@ -695,7 +701,7 @@ describe PostCreator dopost = creator.createtopic.reload- expect(topic.last_posted_at).to be_within(1.seconds).of(post.created_at)+ expect(topic.last_posted_at).to eq_time(post.created_at)expect(topic.last_post_user_id).to eq(post.user_id)expect(topic.word_count).to eq(6)end@@ -960,9 +966,9 @@ describe PostCreator docreated_at: 1.week.ago)- expect(post1.created_at).to be_within(1.second).of(1.week.ago)- expect(post2.created_at).to be_within(1.second).of(1.week.ago)- expect(topic.created_at).to be_within(1.second).of(1.week.ago)+ expect(post1.created_at).to eq_time(1.week.ago)+ expect(post2.created_at).to eq_time(1.week.ago)+ expect(topic.created_at).to eq_time(1.week.ago)endit 'supports strings' do@@ -983,9 +989,9 @@ describe PostCreator docreated_at: '2019-09-02 00:00:00 UTC')- expect(post1.created_at).to be_within(1.second).of(time)- expect(post2.created_at).to be_within(1.second).of(time)- expect(topic.created_at).to be_within(1.second).of(time)+ expect(post1.created_at).to eq_time(time)+ expect(post2.created_at).to eq_time(time)+ expect(topic.created_at).to eq_time(time)endenddiff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rbindex 7d4f4fc74a1..e5467f44e89 100644--- a/spec/components/post_revisor_spec.rb+++ b/spec/components/post_revisor_spec.rb@@ -138,7 +138,7 @@ describe PostRevisor doexpect(post.version).to eq(1)expect(post.public_version).to eq(1)expect(post.revisions.size).to eq(0)- expect(post.last_version_at).to eq(first_version_at)+ expect(post.last_version_at).to eq_time(first_version_at)expect(subject.category_changed).to be_blankend@@ -209,6 +209,7 @@ describe PostRevisor doendit "resets the edit_reason attribute in post model" do+ freeze_timeSiteSetting.editing_grace_period = 5post = Fabricate(:post, raw: 'hello world')revisor = PostRevisor.new(post)@@ -216,7 +217,7 @@ describe PostRevisor dopost.reloadexpect(post.edit_reason).to eq('this is my reason')- revisor.revise!(post.user, { raw: 'hello world4321' }, revised_at: post.updated_at + 6.second)+ revisor.revise!(post.user, { raw: 'hello world4321' }, revised_at: post.updated_at + 7.seconds)post.reloadexpect(post.edit_reason).not_to be_presentenddiff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rbindex c4578148d7c..3f89e63cf3e 100644--- a/spec/components/search_spec.rb+++ b/spec/components/search_spec.rb@@ -374,9 +374,9 @@ describe Search docontext 'search within topic' do- def new_post(raw, topic = nil)+ def new_post(raw, topic = nil, created_at: nil)topic ||= Fabricate(:topic)- Fabricate(:post, topic: topic, topic_id: topic.id, user: topic.user, raw: raw)+ Fabricate(:post, topic: topic, topic_id: topic.id, user: topic.user, raw: raw, created_at: created_at)endit 'works in Chinese' do@@ -391,13 +391,13 @@ describe Search dotopic = Fabricate(:topic)topic2 = Fabricate(:topic)- new_post('this is the other post I am posting', topic2)- new_post('this is my fifth post I am posting', topic2)+ new_post('this is the other post I am posting', topic2, created_at: 6.minutes.ago)+ new_post('this is my fifth post I am posting', topic2, created_at: 5.minutes.ago)- post1 = new_post('this is the other post I am posting', topic)- post2 = new_post('this is my first post I am posting', topic)- post3 = new_post('this is a real long and complicated bla this is my second post I am Posting birds with more stuff bla bla', topic)- post4 = new_post('this is my fourth post I am posting', topic)+ post1 = new_post('this is the other post I am posting', topic, created_at: 4.minutes.ago)+ post2 = new_post('this is my first post I am posting', topic, created_at: 3.minutes.ago)+ post3 = new_post('this is a real long and complicated bla this is my second post I am Posting birds with more stuff bla bla', topic, created_at: 2.minutes.ago)+ post4 = new_post('this is my fourth post I am posting', topic, created_at: 1.minute.ago)# update posts_counttopic.reload@@ -681,8 +681,8 @@ describe Search doit "should return posts in the right order" doraw = "The pure genuine evian"- post = Fabricate(:post, topic: category.topic, raw: raw)- post2 = Fabricate(:post, topic: category2.topic, raw: raw)+ post = freeze_time(10.seconds.from_now) { Fabricate(:post, topic: category.topic, raw: raw) }+ post2 = freeze_time(20.seconds.from_now) { Fabricate(:post, topic: category2.topic, raw: raw) }search = Search.execute(raw)@@ -1145,9 +1145,8 @@ describe Search doit 'can find by latest' dotopic1 = Fabricate(:topic, title: 'I do not like that Sam I am')- post1 = Fabricate(:post, topic: topic1)-- post2 = Fabricate(:post, raw: 'that Sam I am, that Sam I am')+ post1 = Fabricate(:post, topic: topic1, created_at: 10.minutes.ago)+ post2 = Fabricate(:post, raw: 'that Sam I am, that Sam I am', created_at: 5.minutes.ago)expect(Search.execute('sam').posts.map(&:id)).to eq([post1.id, post2.id])expect(Search.execute('sam order:latest').posts.map(&:id)).to eq([post2.id, post1.id])@@ -1332,8 +1331,8 @@ describe Search docat1 = Fabricate(:category_with_definition, name: 'food')topic6 = Fabricate(:topic, tags: [tag1, tag2], category: cat1)topic7 = Fabricate(:topic, tags: [tag1, tag2, tag3], category: cat1)- post7 = Fabricate(:post, topic: topic6, raw: "Wakey, wakey, eggs and bakey.", like_count: 5)- post8 = Fabricate(:post, topic: topic7, raw: "Bakey, bakey, eggs to makey.", like_count: 2)+ post7 = Fabricate(:post, topic: topic6, raw: "Wakey, wakey, eggs and bakey.", like_count: 5, created_at: 2.minutes.ago)+ post8 = Fabricate(:post, topic: topic7, raw: "Bakey, bakey, eggs to makey.", like_count: 2, created_at: 1.minute.ago)expect(Search.execute('bakey tags:lunch order:latest').posts.map(&:id)).to eq([post8.id, post7.id])diff --git a/spec/components/topic_creator_spec.rb b/spec/components/topic_creator_spec.rbindex d13d48c3f0d..9d7230ece14 100644--- a/spec/components/topic_creator_spec.rb+++ b/spec/components/topic_creator_spec.rb@@ -246,8 +246,8 @@ describe TopicCreator dopinned_at: 3.days.ago))- expect(topic.created_at).to be_within(1.second).of(1.week.ago)- expect(topic.pinned_at).to be_within(1.second).of(3.days.ago)+ expect(topic.created_at).to eq_time(1.week.ago)+ expect(topic.pinned_at).to eq_time(3.days.ago)endit 'supports strings' do@@ -261,8 +261,8 @@ describe TopicCreator dopinned_at: '2020-03-10 15:17'))- expect(topic.created_at).to be_within(1.second).of(time1)- expect(topic.pinned_at).to be_within(1.second).of(time2)+ expect(topic.created_at).to eq_time(time1)+ expect(topic.pinned_at).to eq_time(time2)endendenddiff --git a/spec/components/topic_publisher_spec.rb b/spec/components/topic_publisher_spec.rbindex c684d3de779..1b2c14bfa2d 100644--- a/spec/components/topic_publisher_spec.rb+++ b/spec/components/topic_publisher_spec.rb@@ -33,8 +33,8 @@ describe TopicPublisher dotopic.reloadexpect(topic.category).to eq(category)expect(topic).to be_visible- expect(topic.created_at).to eq(published_at)- expect(topic.updated_at).to eq(published_at)+ expect(topic.created_at).to eq_time(published_at)+ expect(topic.updated_at).to eq_time(published_at)expect(topic.shared_draft).to be_blankexpect(UserHistory.where(@@ -48,9 +48,9 @@ describe TopicPublisher doexpect(op.revisions.size).to eq(0)expect(op.version).to eq(1)expect(op.public_version).to eq(1)- expect(op.created_at).to eq(published_at)- expect(op.updated_at).to eq(published_at)- expect(op.last_version_at).to eq(published_at)+ expect(op.created_at).to eq_time(published_at)+ expect(op.updated_at).to eq_time(published_at)+ expect(op.last_version_at).to eq_time(published_at)endendenddiff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rbindex 3793da75799..0bafbbb1b34 100644--- a/spec/components/topic_query_spec.rb+++ b/spec/components/topic_query_spec.rb@@ -75,15 +75,13 @@ describe TopicQuery doendcontext "prioritize_pinned_topics" do-it "does the pagination correctly" do-num_topics = 15per_page = 3topics = [](num_topics - 1).downto(0).each do |i|- topics[i] = Fabricate(:topic)+ topics[i] = freeze_time(i.seconds.ago) { Fabricate(:topic) }endtopic_query = TopicQuery.new(user)@@ -99,7 +97,6 @@ describe TopicQuery dopage: 1)).to eq(topics[per_page...num_topics])end-endcontext 'bookmarks' do@@ -926,7 +923,7 @@ describe TopicQuery dolet!(:user) { group_user }it 'should return the group topics' do- expect(suggested_topics).to eq([private_group_topic.id, private_message.id])+ expect(suggested_topics).to match_array([private_group_topic.id, private_message.id])endenddiff --git a/spec/integration/topic_auto_close_spec.rb b/spec/integration/topic_auto_close_spec.rbindex bd231687a4c..8dcc2721e23 100644--- a/spec/integration/topic_auto_close_spec.rb+++ b/spec/integration/topic_auto_close_spec.rb@@ -41,7 +41,7 @@ describe Topic dotopic_status_update = TopicTimer.lastexpect(topic_status_update.topic).to eq(topic)- expect(topic.public_topic_timer.execute_at).to be_within_one_second_of(2.hours.from_now)+ expect(topic.public_topic_timer.execute_at).to eq_time(2.hours.from_now)args = job_klass.jobs.last['args'].first@@ -59,7 +59,7 @@ describe Topic dotopic_status_update = TopicTimer.lastexpect(topic_status_update.topic).to eq(staff_topic)- expect(topic_status_update.execute_at).to be_within_one_second_of(2.hours.from_now)+ expect(topic_status_update.execute_at).to eq_time(2.hours.from_now)expect(topic_status_update.user).to eq(admin)args = job_klass.jobs.last['args'].first@@ -70,14 +70,12 @@ describe Topic docontext 'topic is closed manually' doit 'should remove the schedule to auto-close the topic' do- freeze_time-topic_timer_id = staff_topic.public_topic_timer.idstaff_topic.update_status('closed', true, admin)expect(TopicTimer.with_deleted.find(topic_timer_id).deleted_at)- .to be_within(1.second).of(Time.zone.now)+ .to eq_time(Time.zone.now)endendend@@ -92,7 +90,7 @@ describe Topic dotopic_status_update = TopicTimer.lastexpect(topic_status_update.topic).to eq(regular_user_topic)- expect(topic_status_update.execute_at).to be_within_one_second_of(2.hours.from_now)+ expect(topic_status_update.execute_at).to eq_time(2.hours.from_now)expect(topic_status_update.user).to eq(Discourse.system_user)args = job_klass.jobs.last['args'].firstdiff --git a/spec/integration/user_api_keys_spec.rb b/spec/integration/user_api_keys_spec.rbindex e094ed3a848..8cd4edcd7a8 100644--- a/spec/integration/user_api_keys_spec.rb+++ b/spec/integration/user_api_keys_spec.rb@@ -3,16 +3,16 @@require 'rails_helper'describe 'user api keys integration' do-fab!(:user_api_key) { Fabricate(:readonly_user_api_key) }it 'updates last used time on use' do- user_api_key.update_columns(last_used_at: 7.days.ago)-freeze_time++ user_api_key.update_columns(last_used_at: 7.days.ago)get '/session/current.json', headers: {HTTP_USER_API_KEY: user_api_key.key,}+expect(user_api_key.reload.last_used_at).to eq_time(Time.zone.now)endenddiff --git a/spec/integrity/coding_style_spec.rb b/spec/integrity/coding_style_spec.rbindex 864ff1d5a62..49a5737844f 100644--- a/spec/integrity/coding_style_spec.rb+++ b/spec/integrity/coding_style_spec.rb@@ -1,5 +1,7 @@# frozen_string_literal: true+require "rails_helper"+def list_files(base_dir, pattern = '*')Dir[File.join("#{base_dir}", pattern)]enddiff --git a/spec/jobs/auto_expire_user_api_keys_spec.rb b/spec/jobs/auto_expire_user_api_keys_spec.rbindex ef490a113e2..13c7df6a066 100644--- a/spec/jobs/auto_expire_user_api_keys_spec.rb+++ b/spec/jobs/auto_expire_user_api_keys_spec.rb@@ -7,7 +7,6 @@ RSpec.describe Jobs::AutoExpireUserApiKeys dofab!(:key2) { Fabricate(:readonly_user_api_key) }context 'when user api key is unused in last 1 days' do-before doSiteSetting.expire_user_api_keys_days = 1end@@ -16,10 +15,9 @@ RSpec.describe Jobs::AutoExpireUserApiKeys dofreeze_timekey1.update!(last_used_at: 2.days.ago)-described_class.new.execute({})- expect(key1.reload.revoked_at).to be_within(1.second).of(Time.zone.now)+ expect(key1.reload.revoked_at).to eq_time(Time.zone.now)expect(key2.reload.revoked_at).to eq(nil)endenddiff --git a/spec/jobs/periodical_updates_spec.rb b/spec/jobs/periodical_updates_spec.rbindex 52729471d4a..40504960e87 100644--- a/spec/jobs/periodical_updates_spec.rb+++ b/spec/jobs/periodical_updates_spec.rb@@ -33,6 +33,6 @@ describe Jobs::PeriodicalUpdates do# does not rebakeJobs::PeriodicalUpdates.new.executepost.reload- expect(post.baked_at).to eq(baked)+ expect(post.baked_at).to eq_time(baked)endenddiff --git a/spec/jobs/publish_topic_to_category_spec.rb b/spec/jobs/publish_topic_to_category_spec.rbindex 3602eaa5b3e..559065f750e 100644--- a/spec/jobs/publish_topic_to_category_spec.rb+++ b/spec/jobs/publish_topic_to_category_spec.rb@@ -22,7 +22,7 @@ RSpec.describe Jobs::PublishTopicToCategory dodescribe 'when topic has been deleted' doit 'should not publish the topic to the new category' do- freeze_time 1.hour.ago+ created_at = freeze_time 1.hour.agotopicfreeze_time 1.hour.from_now@@ -32,7 +32,7 @@ RSpec.describe Jobs::PublishTopicToCategory dotopic.reloadexpect(topic.category).to eq(category)- expect(topic.created_at).to be_within(1.second).of(Time.zone.now - 1.hour)+ expect(topic.created_at).to eq_time(created_at)endend@@ -41,6 +41,8 @@ RSpec.describe Jobs::PublishTopicToCategory dotopic.update!(visible: false)end+ now = freeze_time+message = MessageBus.track_publish dodescribed_class.new.execute(topic_timer_id: topic.public_topic_timer.id)end.find do |m|@@ -54,19 +56,19 @@ RSpec.describe Jobs::PublishTopicToCategory doexpect(message.channel).to eq("/topic/#{topic.id}")%w{created_at bumped_at updated_at last_posted_at}.each do |attribute|- expect(topic.public_send(attribute)).to be_within(1.second).of(Time.zone.now)+ expect(topic.public_send(attribute)).to eq_time(now)endenddescribe 'when topic is a private message' do- before do+ it 'should publish the topic to the new category' dofreeze_time 1.hour.ago doexpect { topic.convert_to_private_message(Discourse.system_user) }.to change { topic.private_message? }.to(true)end- end- it 'should publish the topic to the new category' do+ now = freeze_time+message = MessageBus.track_publish dodescribed_class.new.execute(topic_timer_id: topic.public_topic_timer.id)end.last@@ -77,7 +79,7 @@ RSpec.describe Jobs::PublishTopicToCategory doexpect(topic.private_message?).to eq(false)%w{created_at bumped_at updated_at last_posted_at}.each do |attribute|- expect(topic.public_send(attribute)).to be_within(1.second).of(Time.zone.now)+ expect(topic.public_send(attribute)).to eq_time(now)endexpect(message.data[:reload_topic]).to be_present@@ -86,11 +88,10 @@ RSpec.describe Jobs::PublishTopicToCategory doenddescribe 'when new category has a default auto-close' do- before do- another_category.update!(auto_close_hours: 5)- end-it 'should apply the auto-close timer upon publishing' do+ freeze_time++ another_category.update!(auto_close_hours: 5)topicdescribed_class.new.execute(topic_timer_id: topic.public_topic_timer.id)@@ -99,7 +100,7 @@ RSpec.describe Jobs::PublishTopicToCategory dotopic_timer = topic.public_topic_timerexpect(topic.category).to eq(another_category)expect(topic_timer.status_type).to eq(TopicTimer.types[:close])- expect(topic_timer.execute_at).to be_within(1.second).of(5.hours.from_now)+ expect(topic_timer.execute_at).to eq_time(5.hours.from_now)endendenddiff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rbindex 6e3a21ca9a7..de87e7e1533 100644--- a/spec/jobs/pull_hotlinked_images_spec.rb+++ b/spec/jobs/pull_hotlinked_images_spec.rb@@ -44,7 +44,7 @@ describe Jobs::PullHotlinkedImages dofreeze_time 1.week.from_nowJobs::PullHotlinkedImages.new.execute(post_id: post.id)- expect(orig).to be_within(1.second).of(post.reload.updated_at)+ expect(orig).to eq_time(post.reload.updated_at)endit 'replaces images' dodiff --git a/spec/jobs/truncate_user_flag_stats_spec.rb b/spec/jobs/truncate_user_flag_stats_spec.rbindex b7e23fbb8b8..9dc28c2a8bb 100644--- a/spec/jobs/truncate_user_flag_stats_spec.rb+++ b/spec/jobs/truncate_user_flag_stats_spec.rb@@ -37,15 +37,24 @@ describe Jobs::TruncateUserFlagStats dop2 = Fabricate(:post, user: user)p3 = Fabricate(:post)+ freeze_time 10.minutes.agor0 = PostActionCreator.spam(user, p0).reviewable+ freeze_time 1.minute.from_nowr1 = PostActionCreator.spam(user, p1).reviewable+ freeze_time 1.minute.from_nowr2 = PostActionCreator.spam(user, p2).reviewable+ freeze_time 1.minute.from_nowr3 = PostActionCreator.spam(user, p3).reviewable+ freeze_time 1.minute.from_nowPostActionCreator.spam(other_user, p3).reviewable+ freeze_time 1.minute.from_nowPostActionCreator.spam(other_user, p2).reviewable+ freeze_time 1.minute.from_nowPostActionCreator.spam(other_user, p1).reviewable+ unfreeze_time+r0.perform(Discourse.system_user, :agree_and_keep)r1.perform(Discourse.system_user, :disagree)r2.perform(Discourse.system_user, :ignore)diff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rbindex 263adba7e3d..e6def350b2f 100644--- a/spec/jobs/user_email_spec.rb+++ b/spec/jobs/user_email_spec.rb@@ -192,18 +192,21 @@ describe Jobs::UserEmail doendcontext "email_log" do- fab!(:post) { Fabricate(:post) }+ fab!(:post) { Fabricate(:post, created_at: 30.seconds.ago) }before doSiteSetting.editing_grace_period = 0- postendit "creates an email log when the mail is sent (via Email::Sender)" do- last_emailed_at = user.last_emailed_at+ freeze_time++ last_emailed_at = 7.days.ago+ user.update!(last_emailed_at: last_emailed_at)+ Topic.last.update(created_at: 1.minute.ago)expect do- Jobs::UserEmail.new.execute(type: :digest, user_id: user.id,)+ Jobs::UserEmail.new.execute(type: :digest, user_id: user.id)end.to change { EmailLog.count }.by(1)email_log = EmailLog.last@@ -211,12 +214,17 @@ describe Jobs::UserEmail doexpect(email_log.user).to eq(user)expect(email_log.post).to eq(nil)# last_emailed_at should have changed- expect(email_log.user.last_emailed_at).to_not eq(last_emailed_at)+ expect(email_log.user.last_emailed_at).to_not eq_time(last_emailed_at)endit "creates a skipped email log when the mail is skipped" do- last_emailed_at = user.last_emailed_at- user.update_columns(suspended_till: 1.year.from_now)+ freeze_time++ last_emailed_at = 7.days.ago+ user.update!(+ last_emailed_at: last_emailed_at,+ suspended_till: 1.year.from_now+ )expect doJobs::UserEmail.new.execute(type: :digest, user_id: user.id)@@ -231,7 +239,7 @@ describe Jobs::UserEmail do)).to eq(true)# last_emailed_at doesn't change- expect(user.last_emailed_at).to eq(last_emailed_at)+ expect(user.last_emailed_at).to eq_time(last_emailed_at)endit "creates a skipped email log when the user isn't allowed to see the post" dodiff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rbindex 300fc5561e8..68f037bf572 100644--- a/spec/models/category_spec.rb+++ b/spec/models/category_spec.rb@@ -535,15 +535,15 @@ describe Category dodescribe 'latest' doit 'should be updated correctly' do- category = Fabricate(:category_with_definition)- post = create_post(category: category.id)+ category = freeze_time(1.minute.ago) { Fabricate(:category_with_definition) }+ post = create_post(category: category.id, created_at: 15.seconds.ago)category.reloadexpect(category.latest_post_id).to eq(post.id)expect(category.latest_topic_id).to eq(post.topic_id)- post2 = create_post(category: category.id)- post3 = create_post(topic_id: post.topic_id, category: category.id)+ post2 = create_post(category: category.id, created_at: 10.seconds.ago)+ post3 = create_post(topic_id: post.topic_id, category: category.id, created_at: 5.seconds.ago)category.reloadexpect(category.latest_post_id).to eq(post3.id)@@ -858,22 +858,18 @@ describe Category doendit 'should correctly automatically bump topics' do- freeze_time 1.second.ago- category = Fabricate(:category_with_definition)+ freeze_time+ category = Fabricate(:category_with_definition, created_at: 1.minute.ago)category.clear_auto_bump_cache!- freeze_time 1.second.from_now- post1 = create_post(category: category)- freeze_time 1.second.from_now- _post2 = create_post(category: category)- freeze_time 1.second.from_now- _post3 = create_post(category: category)+ post1 = create_post(category: category, created_at: 15.seconds.ago)+ _post2 = create_post(category: category, created_at: 10.seconds.ago)+ _post3 = create_post(category: category, created_at: 5.seconds.ago)# no limits on post creation or category creation pleaseRateLimiter.enable- time = 1.month.from_now- freeze_time time+ time = freeze_time 1.month.from_nowexpect(category.auto_bump_topic!).to eq(false)expect(Topic.where(bumped_at: time).count).to eq(0)@@ -886,8 +882,7 @@ describe Category do# our extra bump messageexpect(post1.topic.reload.posts_count).to eq(2)- time = time + 13.hours- freeze_time time+ time = freeze_time 13.hours.from_nowexpect(category.auto_bump_topic!).to eq(true)expect(Topic.where(bumped_at: time).count).to eq(1)@@ -895,8 +890,7 @@ describe Category doexpect(category.auto_bump_topic!).to eq(false)expect(Topic.where(bumped_at: time).count).to eq(1)- time = 1.month.from_now- freeze_time time+ time = freeze_time 1.month.from_nowcategory.auto_bump_limiter.clear!expect(Category.auto_bump_topic!).to eq(true)@@ -909,18 +903,16 @@ describe Category doendit 'should not automatically bump topics with a bump scheduled' do- freeze_time 1.second.ago- category = Fabricate(:category_with_definition)+ freeze_time+ category = Fabricate(:category_with_definition, created_at: 1.second.ago)category.clear_auto_bump_cache!- freeze_time 1.second.from_nowpost1 = create_post(category: category)# no limits on post creation or category creation pleaseRateLimiter.enable- time = 1.month.from_now- freeze_time time+ time = freeze_time 1.month.from_nowexpect(category.auto_bump_topic!).to eq(false)expect(Topic.where(bumped_at: time).count).to eq(0)diff --git a/spec/models/invite_spec.rb b/spec/models/invite_spec.rbindex 15a6b9d0c01..fab7da26904 100644--- a/spec/models/invite_spec.rb+++ b/spec/models/invite_spec.rb@@ -125,13 +125,14 @@ describe Invite doendit 'updates timestamp of existing invite' do+ freeze_timeinvite.update!(created_at: 10.days.ago)resend_invite = Invite.invite_by_email('[email protected]', inviter, topic)- expect(resend_invite.created_at).to be_within(1.minute).of(Time.zone.now)+ expect(resend_invite.created_at).to eq_time(Time.zone.now)endit 'returns a new invite if the other has expired' dodiff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rbindex 82b10a871e7..8cdc6591a1f 100644--- a/spec/models/post_action_spec.rb+++ b/spec/models/post_action_spec.rb@@ -729,7 +729,7 @@ describe PostAction dotopic_status_update = TopicTimer.lastexpect(topic_status_update.topic).to eq(topic)- expect(topic_status_update.execute_at).to be_within(1.second).of(1.hour.from_now)+ expect(topic_status_update.execute_at).to eq_time(1.hour.from_now)expect(topic_status_update.status_type).to eq(TopicTimer.types[:open])end@@ -772,7 +772,7 @@ describe PostAction doJobs::ToggleTopicClosed.new.execute(topic_timer_id: timer.id, state: false)expect(topic.reload.closed).to eq(true)- expect(timer.reload.execute_at).to eq(1.hour.from_now)+ expect(timer.reload.execute_at).to eq_time(1.hour.from_now)freeze_time timer.execute_atSiteSetting.num_flaggers_to_close_topic = 10diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rbindex 7ae87eab6a4..d198e2d33cd 100644--- a/spec/models/post_mover_spec.rb+++ b/spec/models/post_mover_spec.rb@@ -24,10 +24,12 @@ describe PostMover dodescribe 'move_posts' docontext 'topics' do+ before { freeze_time }+fab!(:user) { Fabricate(:user, admin: true) }fab!(:another_user) { evil_trout }fab!(:category) { Fabricate(:category, user: user) }- fab!(:topic) { Fabricate(:topic, user: user) }+ fab!(:topic) { Fabricate(:topic, user: user, created_at: 4.hours.ago) }fab!(:p1) { Fabricate(:post, topic: topic, user: user, created_at: 3.hours.ago, reply_count: 2) }fab!(:p2) do@@ -37,14 +39,15 @@ describe PostMover douser: another_user,raw: "Has a link to [evil trout](http://eviltrout.com) which is a cool site.",reply_to_post_number: p1.post_number,- reply_count: 1+ reply_count: 1,+ created_at: 2.hours.ago)end- fab!(:p3) { Fabricate(:post, topic: topic, reply_to_post_number: p1.post_number, user: user) }- fab!(:p4) { Fabricate(:post, topic: topic, reply_to_post_number: p2.post_number, user: user) }- fab!(:p5) { Fabricate(:post) }- let(:p6) { Fabricate(:post, topic: topic) }+ fab!(:p3) { Fabricate(:post, topic: topic, reply_to_post_number: p1.post_number, user: user, created_at: 1.hour.ago) }+ fab!(:p4) { Fabricate(:post, topic: topic, reply_to_post_number: p2.post_number, user: user, created_at: 45.minutes.ago) }+ fab!(:p5) { Fabricate(:post, created_at: 30.minutes.ago) }+ let(:p6) { Fabricate(:post, topic: topic, created_at: 15.minutes.ago) }before doSiteSetting.tagging_enabled = true@@ -135,8 +138,6 @@ describe PostMover dobefore doTopicUser.update_last_read(user, topic.id, p4.post_number, p4.post_number, 0)TopicLink.extract_from(p2)-- freeze_time Time.nowenddef create_post_timing(post, user, msecs)@@ -216,7 +217,6 @@ describe PostMover doendcontext "to a new topic" do-it "works correctly" dotopic.expects(:add_moderator_post).oncenew_topic = topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name", category_id: category.id, tags: ["tag1", "tag2"])@@ -238,8 +238,8 @@ describe PostMover dop4.reloadexpect(new_topic.last_post_user_id).to eq(p4.user_id)- expect(new_topic.last_posted_at).to eq(p4.created_at)- expect(new_topic.bumped_at).to be_within(1.second).of(Time.now)+ expect(new_topic.last_posted_at).to eq_time(p4.created_at)+ expect(new_topic.bumped_at).to eq_time(Time.zone.now)p2.reloadexpect(p2.sort_order).to eq(1)@@ -511,8 +511,8 @@ describe PostMover doexpect(moved_to.category_id).to eq(SiteSetting.uncategorized_category_id)p4.reloadexpect(moved_to.last_post_user_id).to eq(p4.user_id)- expect(moved_to.last_posted_at).to eq(p4.created_at)- expect(moved_to.bumped_at).to be_within(1.second).of(Time.now)+ expect(moved_to.last_posted_at).to eq_time(p4.created_at)+ expect(moved_to.bumped_at).to eq_time(Time.zone.now)# Posts should be re-orderedp2.reload@@ -822,8 +822,8 @@ describe PostMover dop4.reloadexpect(new_topic.last_post_user_id).to eq(p4.user_id)- expect(new_topic.last_posted_at).to eq(p4.created_at)- expect(new_topic.bumped_at).to be_within(1.second).of(Time.now)+ expect(new_topic.last_posted_at).to eq_time(p4.created_at)+ expect(new_topic.bumped_at).to eq_time(Time.zone.now)p2.reloadexpect(p2.sort_order).to eq(1)@@ -920,7 +920,6 @@ describe PostMover doendcontext "moving the first post" do-it "copies the OP, doesn't delete it" dotopic.expects(:add_moderator_post).oncenew_topic = topic.move_posts(user, [p1.id, p2.id], title: "new testing topic name")@@ -940,7 +939,7 @@ describe PostMover do# New first postnew_first = new_topic.posts.where(post_number: 1).firstexpect(new_first.reply_count).to eq(1)- expect(new_first.created_at).to be_within(1.second).of(p1.created_at)+ expect(new_first.created_at).to eq_time(p1.created_at)# Second post is in a new topicp2.reload@@ -1074,13 +1073,12 @@ describe PostMover dofab!(:user) { Fabricate(:user) }fab!(:another_user) { Fabricate(:user) }fab!(:regular_user) { Fabricate(:trust_level_4) }- fab!(:topic) { Fabricate(:topic) }fab!(:personal_message) { Fabricate(:private_message_topic, user: evil_trout) }- fab!(:p1) { Fabricate(:post, topic: personal_message, user: user) }- fab!(:p2) { Fabricate(:post, topic: personal_message, reply_to_post_number: p1.post_number, user: another_user) }- fab!(:p3) { Fabricate(:post, topic: personal_message, reply_to_post_number: p1.post_number, user: user) }- fab!(:p4) { Fabricate(:post, topic: personal_message, reply_to_post_number: p2.post_number, user: user) }- fab!(:p5) { Fabricate(:post, topic: personal_message, user: evil_trout) }+ fab!(:p1) { Fabricate(:post, topic: personal_message, user: user, created_at: 4.hours.ago) }+ fab!(:p2) { Fabricate(:post, topic: personal_message, reply_to_post_number: p1.post_number, user: another_user, created_at: 3.hours.ago) }+ fab!(:p3) { Fabricate(:post, topic: personal_message, reply_to_post_number: p1.post_number, user: user, created_at: 2.hours.ago) }+ fab!(:p4) { Fabricate(:post, topic: personal_message, reply_to_post_number: p2.post_number, user: user, created_at: 1.hour.ago) }+ fab!(:p5) { Fabricate(:post, topic: personal_message, user: evil_trout, created_at: 30.minutes.ago) }let(:another_personal_message) doFabricate(:private_message_topic, user: user, topic_allowed_users: [Fabricate.build(:topic_allowed_user, user: admin)@@ -1181,6 +1179,8 @@ describe PostMover doendit "does not allow moving regular topic posts in personal message" do+ topic = Fabricate(:topic, created_at: 4.hours.ago)+expect {personal_message.move_posts(admin, [p2.id, p5.id], destination_topic_id: topic.id)}.to raise_error(Discourse::InvalidParameters)diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rbindex 325f4febccb..b09245460b7 100644--- a/spec/models/post_spec.rb+++ b/spec/models/post_spec.rb@@ -1132,7 +1132,7 @@ describe Post doSiteSetting.newuser_spam_host_threshold = 1SiteSetting.newuser_max_links = 3user = Fabricate(:user, staged: true, trust_level: 0)- user.created_at = 1.day.ago+ user.created_at = 2.days.agouser.unstagepost = Fabricate(:post, raw: raw, user: user)expect(post.has_host_spam?).to eq(false)@@ -1224,7 +1224,7 @@ describe Post dobaked = post.baked_atPost.rebake_old(100)post.reload- expect(post.baked_at).to eq(baked)+ expect(post.baked_at).to eq_time(baked)endit "will rate limit globally" do@@ -1475,10 +1475,7 @@ describe Post doenddef updates_topic_updated_at-- freeze_time 1.day.from_now- time = Time.now-+ time = freeze_time 1.day.from_nowresult = yieldtopic.reloaddiff --git a/spec/models/quoted_post_spec.rb b/spec/models/quoted_post_spec.rbindex a40025400e2..35082b5af27 100644--- a/spec/models/quoted_post_spec.rb+++ b/spec/models/quoted_post_spec.rb@@ -84,7 +84,6 @@ describe QuotedPost doquote.reloadexpect(original_date).to eq_time(quote.created_at)-expect(post2.reply_quoted).to eq(false)endenddiff --git a/spec/models/remote_theme_spec.rb b/spec/models/remote_theme_spec.rbindex 59d026a18b2..6f5bab1df19 100644--- a/spec/models/remote_theme_spec.rb+++ b/spec/models/remote_theme_spec.rb@@ -103,7 +103,7 @@ describe RemoteTheme doexpect(@theme.settings.length).to eq(1)expect(@theme.settings.first.value).to eq(true)- expect(remote.remote_updated_at).to eq(time)+ expect(remote.remote_updated_at).to eq_time(time)scheme = ColorScheme.find_by(theme_id: @theme.id)expect(scheme.name).to eq("Amazing")@@ -150,7 +150,7 @@ describe RemoteTheme doexpect(@theme.settings.length).to eq(1)expect(@theme.settings.first.value).to eq(32)- expect(remote.remote_updated_at).to eq(time)+ expect(remote.remote_updated_at).to eq_time(time)expect(remote.about_url).to eq("https://newsite.com/about")# It should be able to remove old colors as welldiff --git a/spec/models/screened_email_spec.rb b/spec/models/screened_email_spec.rbindex bb2bc0c4be5..aeefe195d32 100644--- a/spec/models/screened_email_spec.rb+++ b/spec/models/screened_email_spec.rb@@ -80,9 +80,9 @@ describe ScreenedEmail doshared_examples "when a ScreenedEmail record matches" doit "updates statistics" do- freeze_time(Time.zone.now) do+ freeze_time doexpect { subject }.to change { screened_email.reload.match_count }.by(1)- expect(screened_email.last_match_at).to be_within_one_second_of(Time.zone.now)+ expect(screened_email.last_match_at).to eq_time(Time.zone.now)endendenddiff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rbindex e882c3fd052..17d49606ff0 100644--- a/spec/models/topic_spec.rb+++ b/spec/models/topic_spec.rb@@ -988,7 +988,7 @@ describe Topic dofab!(:topic) { Fabricate(:topic, bumped_at: 1.hour.ago) }before do- @original_bumped_at = topic.bumped_at.to_f+ @original_bumped_at = topic.bumped_at@user = topic.user@user.admin = trueend@@ -1000,7 +1000,7 @@ describe Topic dotopic.reloadexpect(topic).not_to be_visibleexpect(topic.moderator_posts_count).to eq(1)- expect(topic.bumped_at.to_f).to be_within(1e-4).of(@original_bumped_at)+ expect(topic.bumped_at).to eq_time(@original_bumped_at)endit 'removes itself as featured topic on user profiles' do@@ -1022,7 +1022,7 @@ describe Topic doit 'should be visible with correct counts' doexpect(topic).to be_visibleexpect(topic.moderator_posts_count).to eq(1)- expect(topic.bumped_at.to_f).to be_within(1e-4).of(@original_bumped_at)+ expect(topic.bumped_at).to eq_time(@original_bumped_at)endendend@@ -1037,7 +1037,7 @@ describe Topic doit "doesn't have a pinned_at but has correct dates" doexpect(topic.pinned_at).to be_blankexpect(topic.moderator_posts_count).to eq(1)- expect(topic.bumped_at.to_f).to be_within(1e-4).of(@original_bumped_at)+ expect(topic.bumped_at).to eq_time(@original_bumped_at)endend@@ -1050,7 +1050,7 @@ describe Topic doit 'should enable correctly' doexpect(topic.pinned_at).to be_present- expect(topic.bumped_at.to_f).to be_within(1e-4).of(@original_bumped_at)+ expect(topic.bumped_at).to eq_time(@original_bumped_at)expect(topic.moderator_posts_count).to eq(1)end@@ -1061,14 +1061,14 @@ describe Topic docontext 'disable' dobefore do@archived_topic = Fabricate(:topic, archived: true, bumped_at: 1.hour.ago)- @original_bumped_at = @archived_topic.bumped_at.to_f+ @original_bumped_at = @archived_topic.bumped_at@archived_topic.update_status('archived', false, @user)@archived_topic.reloadendit 'should archive correctly' doexpect(@archived_topic).not_to be_archived- expect(@archived_topic.bumped_at.to_f).to be_within(1e-4).of(@original_bumped_at)+ expect(@archived_topic.bumped_at).to eq_time(@original_bumped_at)expect(@archived_topic.moderator_posts_count).to eq(1)endend@@ -1083,7 +1083,7 @@ describe Topic doit 'should be archived' doexpect(topic).to be_archivedexpect(topic.moderator_posts_count).to eq(1)- expect(topic.bumped_at.to_f).to be_within(1e-4).of(@original_bumped_at)+ expect(topic.bumped_at).to eq_time(@original_bumped_at)endendend@@ -1092,7 +1092,7 @@ describe Topic docontext 'disable' dobefore do@closed_topic = Fabricate(:topic, closed: true, bumped_at: 1.hour.ago)- @original_bumped_at = @closed_topic.bumped_at.to_f+ @original_bumped_at = @closed_topic.bumped_at@closed_topic.update_status(status, false, @user)@closed_topic.reloadend@@ -1100,7 +1100,7 @@ describe Topic doit 'should not be pinned' doexpect(@closed_topic).not_to be_closedexpect(@closed_topic.moderator_posts_count).to eq(1)- expect(@closed_topic.bumped_at.to_f).not_to be_within(1e-4).of(@original_bumped_at)+ expect(@closed_topic.bumped_at).not_to eq_time(@original_bumped_at)endend@@ -1113,7 +1113,7 @@ describe Topic doit 'should be closed' doexpect(topic).to be_closed- expect(topic.bumped_at.to_f).to be_within(1e-4).of(@original_bumped_at)+ expect(topic.bumped_at).to eq_time(@original_bumped_at)expect(topic.moderator_posts_count).to eq(1)expect(topic.topic_timers.first).to eq(nil)end@@ -1473,6 +1473,8 @@ describe Topic doendit 'should set a topic timer' do+ freeze_time+expect { topic.change_category_to_id(new_category.id) }.to change { TopicTimer.count }.by(1)@@ -1481,7 +1483,7 @@ describe Topic dotopic_timer = TopicTimer.lastexpect(topic_timer.topic).to eq(topic)- expect(topic_timer.execute_at).to be_within(1.second).of(Time.zone.now + 5.hours)+ expect(topic_timer.execute_at).to eq_time(5.hours.from_now)enddescribe 'when topic is already closed' do@@ -1506,11 +1508,8 @@ describe Topic dotopic.change_category_to_id(new_category.id)expect(topic.reload.category).to eq(new_category)-expect(topic.public_topic_timer).to eq(topic_timer)-- expect(topic.public_topic_timer.execute_at)- .to be_within(1.second).of(topic_timer.execute_at)+ expect(topic.public_topic_timer.execute_at).to eq_time(topic_timer.execute_at)endendend@@ -1628,32 +1627,32 @@ describe Topic dofreeze_time nowtopic.set_or_create_timer(TopicTimer.types[:close], 72, by_user: admin)- expect(topic.topic_timers.first.execute_at).to eq(3.days.from_now)+ expect(topic.topic_timers.first.execute_at).to eq_time(3.days.from_now)endit 'can take a number of hours as a string' dofreeze_time nowtopic.set_or_create_timer(TopicTimer.types[:close], '18', by_user: admin)- expect(topic.topic_timers.first.execute_at).to eq(18.hours.from_now)+ expect(topic.topic_timers.first.execute_at).to eq_time(18.hours.from_now)endit 'can take a number of hours as a string and can handle based on last post' dofreeze_time nowtopic.set_or_create_timer(TopicTimer.types[:close], '18', by_user: admin, based_on_last_post: true)- expect(topic.topic_timers.first.execute_at).to eq(18.hours.from_now)+ expect(topic.topic_timers.first.execute_at).to eq_time(18.hours.from_now)endit "can take a timestamp for a future time" dofreeze_time nowtopic.set_or_create_timer(TopicTimer.types[:close], '2013-11-22 5:00', by_user: admin)- expect(topic.topic_timers.first.execute_at).to eq(Time.zone.local(2013, 11, 22, 5, 0))+ expect(topic.topic_timers.first.execute_at).to eq_time(Time.zone.local(2013, 11, 22, 5, 0))endit "sets a validation error when given a timestamp in the past" dofreeze_time nowtopic.set_or_create_timer(TopicTimer.types[:close], '2013-11-19 5:00', by_user: admin)- expect(topic.topic_timers.first.execute_at).to eq(Time.zone.local(2013, 11, 19, 5, 0))+ expect(topic.topic_timers.first.execute_at).to eq_time(Time.zone.local(2013, 11, 19, 5, 0))expect(topic.topic_timers.first.errors[:execute_at]).to be_presentend@@ -1672,7 +1671,7 @@ describe Topic doit "can take a timestamp with timezone" dofreeze_time nowtopic.set_or_create_timer(TopicTimer.types[:close], '2013-11-25T01:35:00-08:00', by_user: admin)- expect(topic.topic_timers.first.execute_at).to eq(Time.utc(2013, 11, 25, 9, 35))+ expect(topic.topic_timers.first.execute_at).to eq_time(Time.utc(2013, 11, 25, 9, 35))endit 'sets topic status update user to given user if it is a staff or TL4 user' do@@ -1716,7 +1715,7 @@ describe Topic doit 'updates topic status update execute_at if it was already set to close' dofreeze_time nowclosing_topic.set_or_create_timer(TopicTimer.types[:close], 48)- expect(closing_topic.reload.public_topic_timer.execute_at).to eq(2.days.from_now)+ expect(closing_topic.reload.public_topic_timer.execute_at).to eq_time(2.days.from_now)endit 'should not delete topic_timer of another status_type' do@@ -1735,7 +1734,7 @@ describe Topic doTopicTimer.types[:publish_to_category], 72, by_user: admin)- expect(topic_timer.execute_at).to eq(3.days.from_now)+ expect(topic_timer.execute_at).to eq_time(3.days.from_now)endit "does not update topic's topic status created_at it was already set to close" do@@ -1792,7 +1791,7 @@ describe Topic dotopic.set_or_create_timer(TopicTimer.types[:reminder], 11, by_user: admin)}.to_not change { TopicTimer.count }reminder.reload- expect(reminder.execute_at).to eq(11.hours.from_now)+ expect(reminder.execute_at).to eq_time(11.hours.from_now)endendend@@ -1810,19 +1809,19 @@ describe Topic doendit "doesn't return category topics" do- Fabricate(:category_with_definition)+ Fabricate(:category_with_definition, created_at: 1.minute.ago)expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blankendit "returns regular topics" do- topic = Fabricate(:topic)+ topic = Fabricate(:topic, created_at: 1.minute.ago)expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to eq([topic])endit "doesn't return topics from muted categories" douser = Fabricate(:user)- category = Fabricate(:category_with_definition)- Fabricate(:topic, category: category)+ category = Fabricate(:category_with_definition, created_at: 2.minutes.ago)+ Fabricate(:topic, category: category, created_at: 1.minute.ago)CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id)@@ -1830,7 +1829,7 @@ describe Topic doendit "doesn't return topics that a user has muted" do- topic = Fabricate(:topic)+ topic = Fabricate(:topic, created_at: 1.minute.ago)user = Fabricate(:user)Fabricate(:topic_user,@@ -1844,8 +1843,8 @@ describe Topic doit "doesn't return topics from suppressed categories" douser = Fabricate(:user)- category = Fabricate(:category_with_definition)- Fabricate(:topic, category: category)+ category = Fabricate(:category_with_definition, created_at: 2.minutes.ago)+ Fabricate(:topic, category: category, created_at: 1.minute.ago)SiteSetting.digest_suppress_categories = "#{category.id}"@@ -1854,20 +1853,20 @@ describe Topic doit "doesn't return topics from TL0 users" donew_user = Fabricate(:user, trust_level: 0)- Fabricate(:topic, user: new_user)+ Fabricate(:topic, user: new_user, created_at: 1.minute.ago)expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blankendit "returns topics from TL0 users if given include_tl0" donew_user = Fabricate(:user, trust_level: 0)- topic = Fabricate(:topic, user_id: new_user.id)+ topic = Fabricate(:topic, user_id: new_user.id, created_at: 1.minute.ago)expect(Topic.for_digest(user, 1.year.ago, top_order: true, include_tl0: true)).to eq([topic])endit "returns topics from TL0 users if enabled in preferences" donew_user = Fabricate(:user, trust_level: 0)- topic = Fabricate(:topic, user: new_user)+ topic = Fabricate(:topic, user: new_user, created_at: 1.minute.ago)u = Fabricate(:user)u.user_option.include_tl0_in_digests = true@@ -1879,7 +1878,7 @@ describe Topic douser = Fabricate(:user)tag = Fabricate(:tag)TagUser.change(user.id, tag.id, TagUser.notification_levels[:muted])- Fabricate(:topic, tags: [tag])+ Fabricate(:topic, tags: [tag], created_at: 1.minute.ago)expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blankend@@ -1888,7 +1887,7 @@ describe Topic douser = Fabricate(:user)muted_tag, other_tag = Fabricate(:tag), Fabricate(:tag)TagUser.change(user.id, muted_tag.id, TagUser.notification_levels[:muted])- topic = Fabricate(:topic, tags: [muted_tag, other_tag])+ topic = Fabricate(:topic, tags: [muted_tag, other_tag], created_at: 1.minute.ago)expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to eq([topic])end@@ -1897,32 +1896,34 @@ describe Topic douser = Fabricate(:user)muted_tag = Fabricate(:tag)TagUser.change(user.id, muted_tag.id, TagUser.notification_levels[:muted])- _topic1 = Fabricate(:topic, tags: [muted_tag])- topic2 = Fabricate(:topic, tags: [Fabricate(:tag), Fabricate(:tag)])- topic3 = Fabricate(:topic)-+ _topic1 = Fabricate(:topic, tags: [muted_tag], created_at: 1.minute.ago)+ topic2 = Fabricate(:topic, tags: [Fabricate(:tag), Fabricate(:tag)], created_at: 1.minute.ago)+ topic3 = Fabricate(:topic, created_at: 1.minute.ago)topics = Topic.for_digest(user, 1.year.ago, top_order: true)+expect(topics.size).to eq(2)expect(topics).to contain_exactly(topic2, topic3)endit "sorts by category notification levels" do- category1, category2 = Fabricate(:category_with_definition), Fabricate(:category_with_definition)- 2.times { |i| Fabricate(:topic, category: category1) }- topic1 = Fabricate(:topic, category: category2)- 2.times { |i| Fabricate(:topic, category: category1) }+ category1, category2 = Fabricate(:category_with_definition), Fabricate(:category_with_definition, created_at: 2.minutes.ago)+ 2.times { |i| Fabricate(:topic, category: category1, created_at: 1.minute.ago) }+ topic1 = Fabricate(:topic, category: category2, created_at: 1.minute.ago)+ 2.times { |i| Fabricate(:topic, category: category1, created_at: 1.minute.ago) }CategoryUser.create(user: user, category: category2, notification_level: CategoryUser.notification_levels[:watching])for_digest = Topic.for_digest(user, 1.year.ago, top_order: true)+expect(for_digest.first).to eq(topic1)endit "sorts by topic notification levels" dotopics = []- 3.times { |i| topics << Fabricate(:topic) }+ 3.times { |i| topics << Fabricate(:topic, created_at: 1.minute.ago) }user = Fabricate(:user)TopicUser.create(user_id: user.id, topic_id: topics[0].id, notification_level: TopicUser.notification_levels[:tracking])TopicUser.create(user_id: user.id, topic_id: topics[2].id, notification_level: TopicUser.notification_levels[:watching])for_digest = Topic.for_digest(user, 1.year.ago, top_order: true).pluck(:id)+expect(for_digest).to eq([topics[2].id, topics[0].id, topics[1].id])endend@@ -2090,7 +2091,7 @@ describe Topic dotopic_embed = TopicEmbed.create!(topic_id: topic.id, embed_url: "https://blog.codinghorror.com/password-rules-are-bullshit", post_id: post.id, deleted_at: 1.day.ago)topic.recover!topic_embed.reload- expect(topic_embed.deleted_at).to eq(nil)+ expect(topic_embed.deleted_at).to be_nilendend@@ -2256,7 +2257,6 @@ describe Topic doendit 'allows users to normalize counts' do-topic = Fabricate(:topic, last_posted_at: 1.year.ago)post1 = Fabricate(:post, topic: topic, post_number: 1)post2 = Fabricate(:post, topic: topic, post_type: Post.types[:whisper], post_number: 2)@@ -2267,7 +2267,7 @@ describe Topic doexpect(topic.posts_count).to eq(1)expect(topic.highest_post_number).to eq(post1.post_number)expect(topic.highest_staff_post_number).to eq(post2.post_number)- expect(topic.last_posted_at).to be_within(1.second).of (post1.created_at)+ expect(topic.last_posted_at).to eq_time(post1.created_at)endcontext 'featured link' dodiff --git a/spec/models/topic_tracking_state_spec.rb b/spec/models/topic_tracking_state_spec.rbindex e19c696eb79..a68239512d3 100644--- a/spec/models/topic_tracking_state_spec.rb+++ b/spec/models/topic_tracking_state_spec.rb@@ -458,6 +458,7 @@ describe TopicTrackingState doendit "correctly handles seen categories" do+ freeze_time 1.minute.agouser = Fabricate(:user)post@@ -473,6 +474,7 @@ describe TopicTrackingState doreport = TopicTrackingState.report(user)expect(report.length).to eq(0)+ unfreeze_timepost.topic.touch(:created_at)report = TopicTrackingState.report(user)diff --git a/spec/models/user_action_spec.rb b/spec/models/user_action_spec.rbindex de0e3f1cdc2..f4485f1c4c3 100644--- a/spec/models/user_action_spec.rb+++ b/spec/models/user_action_spec.rb@@ -226,22 +226,19 @@ describe UserAction doenddescribe 'when a user posts a new topic' do- def process_alerts(post)- PostAlerter.post_created(post)- end-before do- @post = create_post(created_at: DateTime.now - 100)- process_alerts(@post)+ freeze_time(100.days.ago) do+ @post = create_post+ PostAlerter.post_created(@post)+ endenddescribe 'topic action' do- before do- @action = @post.user.user_actions.find_by(action_type: UserAction::NEW_TOPIC)- endit 'should exist' do+ @action = @post.user.user_actions.find_by(action_type: UserAction::NEW_TOPIC)+expect(@action).not_to eq(nil)- expect(@action.created_at).to be_within(1).of(@post.topic.created_at)+ expect(@action.created_at).to eq_time(@post.topic.created_at)endend@@ -256,7 +253,7 @@ describe UserAction do@response = PostCreator.new(@other_user, reply_to_post_number: 1, topic_id: @post.topic_id, raw: "perhaps @#{@mentioned.username} knows how this works?").create- process_alerts(@response)+ PostAlerter.post_created(@response)endit 'should log user actions correctly' dodiff --git a/spec/models/user_auth_token_spec.rb b/spec/models/user_auth_token_spec.rbindex e9d17c84eca..27448880b4a 100644--- a/spec/models/user_auth_token_spec.rb+++ b/spec/models/user_auth_token_spec.rb@@ -83,23 +83,21 @@ describe UserAuthToken doendit "expires correctly" do-+ freeze_time Time.zone.nowuser = Fabricate(:user)-user_token = UserAuthToken.generate!(user_id: user.id,user_agent: "some user agent 2",client_ip: "1.1.2.3")UserAuthToken.lookup(user_token.unhashed_auth_token, seen: true)- freeze_time (SiteSetting.maximum_session_age.hours - 1).from_now+ freeze_time SiteSetting.maximum_session_age.hours.from_now - 1.seconduser_token.reload-user_token.rotate!UserAuthToken.lookup(user_token.unhashed_auth_token, seen: true)- freeze_time (SiteSetting.maximum_session_age.hours - 1).from_now+ freeze_time SiteSetting.maximum_session_age.hours.from_now - 1.secondstill_good = UserAuthToken.lookup(user_token.unhashed_auth_token, seen: true)expect(still_good).not_to eq(nil)@@ -111,7 +109,7 @@ describe UserAuthToken doendit "can properly rotate tokens" do-+ freeze_time 3.days.agouser = Fabricate(:user)user_token = UserAuthToken.generate!(user_id: user.id,@@ -126,12 +124,14 @@ describe UserAuthToken douser_token.update_columns(auth_token_seen: true)+ rotation_time = freeze_time 1.day.from_now+rotated = user_token.rotate!(user_agent: "a new user agent", client_ip: "1.1.2.4")expect(rotated).to eq(true)user_token.reload- expect(user_token.rotated_at).to be_within(5.second).of(Time.zone.now)+ expect(user_token.rotated_at).to eq_time(rotation_time)expect(user_token.client_ip).to eq("1.1.2.4")expect(user_token.user_agent).to eq("a new user agent")expect(user_token.auth_token_seen).to eq(false)@@ -139,17 +139,17 @@ describe UserAuthToken doexpect(user_token.prev_auth_token).to eq(prev_auth_token)# ability to auth using an old token- freeze_time+ seen_at = freeze_time 1.day.from_nowlooked_up = UserAuthToken.lookup(user_token.unhashed_auth_token, seen: true)expect(looked_up.id).to eq(user_token.id)expect(looked_up.auth_token_seen).to eq(true)- expect(looked_up.seen_at).to be_within(1.second).of(Time.zone.now)+ expect(looked_up.seen_at).to eq_time(seen_at)looked_up = UserAuthToken.lookup(unhashed_prev, seen: true)expect(looked_up.id).to eq(user_token.id)- freeze_time(2.minute.from_now)+ freeze_time 2.minutes.from_nowlooked_up = UserAuthToken.lookup(unhashed_prev)expect(looked_up).not_to eq(nil)diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex d23451fcfa8..ef6b64d511a 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -863,7 +863,6 @@ describe User doenddescribe "previous_visit_at" do-let(:user) { Fabricate(:user) }let!(:first_visit_date) { Time.zone.now }let!(:second_visit_date) { 2.hours.from_now }@@ -889,36 +888,36 @@ describe User do# second visituser.update_last_seen!(second_visit_date)user.reload- expect(user.previous_visit_at).to be_within_one_second_of(first_visit_date)+ expect(user.previous_visit_at).to eq_time(first_visit_date)# third visituser.update_last_seen!(third_visit_date)user.reload- expect(user.previous_visit_at).to be_within_one_second_of(second_visit_date)+ expect(user.previous_visit_at).to eq_time(second_visit_date)endenddescribe "update_last_seen!" do- let (:user) { Fabricate(:user) }+ let(:user) { Fabricate(:user) }let!(:first_visit_date) { Time.zone.now }let!(:second_visit_date) { 2.hours.from_now }it "should update the last seen value" doexpect(user.last_seen_at).to eq niluser.update_last_seen!(first_visit_date)- expect(user.reload.last_seen_at).to be_within_one_second_of(first_visit_date)+ expect(user.reload.last_seen_at).to eq_time(first_visit_date)endit "should update the first seen value if it doesn't exist" douser.update_last_seen!(first_visit_date)- expect(user.reload.first_seen_at).to be_within_one_second_of(first_visit_date)+ expect(user.reload.first_seen_at).to eq_time(first_visit_date)endit "should not update the first seen value if it doesn't exist" douser.update_last_seen!(first_visit_date)user.update_last_seen!(second_visit_date)- expect(user.reload.first_seen_at).to be_within_one_second_of(first_visit_date)+ expect(user.reload.first_seen_at).to eq_time(first_visit_date)endend@@ -976,58 +975,51 @@ describe User doenddescribe 'with no previous values' do- let!(:date) { Time.zone.now }-- before do- freeze_time date- user.update_last_seen!- end-after doDiscourse.redis.flushallendit "updates last_seen_at" do- expect(user.last_seen_at).to be_within_one_second_of(date)+ date = freeze_time+ user.update_last_seen!++ expect(user.last_seen_at).to eq_time(date)endit "should have 0 for days_visited" do+ user.update_last_seen!user.reload+expect(user.user_stat.days_visited).to eq(1)endit "should log a user_visit with the date" do- expect(user.user_visits.first.visited_at).to eq(date.to_date)+ date = freeze_time+ user.update_last_seen!++ expect(user.user_visits.first.visited_at).to eq_time(date.to_date)endcontext "called twice" do-- before do- freeze_time date+ it "doesn't increase days_visited twice" do+ freeze_timeuser.update_last_seen!user.update_last_seen!user.reload- end- it "doesn't increase days_visited twice" doexpect(user.user_stat.days_visited).to eq(1)end-enddescribe "after 3 days" do- let!(:future_date) { 3.days.from_now }-- before do- freeze_time future_date+ it "should log a second visited_at record when we log an update later" do+ user.update_last_seen!+ future_date = freeze_time(3.days.from_now)user.update_last_seen!- end- it "should log a second visited_at record when we log an update later" doexpect(user.user_visits.count).to eq(2)endend-endenddiff --git a/spec/models/user_stat_spec.rb b/spec/models/user_stat_spec.rbindex d5c563770a2..946e0fe3a14 100644--- a/spec/models/user_stat_spec.rb+++ b/spec/models/user_stat_spec.rb@@ -86,7 +86,7 @@ describe UserStat doUserStat.ensure_consistency!post.user.user_stat.reload- expect(post.user.user_stat.first_unread_at).to eq_time(Time.now)+ expect(post.user.user_stat.first_unread_at).to eq_time(Time.zone.now)endenddiff --git a/spec/models/watched_word_spec.rb b/spec/models/watched_word_spec.rbindex 31d4f2fae63..e58a9432b67 100644--- a/spec/models/watched_word_spec.rb+++ b/spec/models/watched_word_spec.rb@@ -71,7 +71,7 @@ describe WatchedWord doexpect {w = described_class.create_or_update_word(word: existing.word, action_key: :flag)expect(w.id).to eq(existing.id)- expect(w.updated_at).to eq(w.updated_at)+ expect(w.updated_at).to eq_time(w.updated_at)}.to_not change { described_class.count }enddiff --git a/spec/rails_helper.rb b/spec/rails_helper.rbindex 447a08d681e..4bc237ab276 100644--- a/spec/rails_helper.rb+++ b/spec/rails_helper.rb@@ -353,6 +353,8 @@ def freeze_time(now = Time.now)ensureunfreeze_timeend+ else+ timeendenddiff --git a/spec/requests/admin/email_controller_spec.rb b/spec/requests/admin/email_controller_spec.rbindex 9b6a77b8ce8..eb632bcbe1c 100644--- a/spec/requests/admin/email_controller_spec.rb+++ b/spec/requests/admin/email_controller_spec.rb@@ -90,8 +90,8 @@ describe Admin::EmailController dodescribe '#skipped' dofab!(:user) { Fabricate(:user) }- fab!(:log1) { Fabricate(:skipped_email_log, user: user) }- fab!(:log2) { Fabricate(:skipped_email_log) }+ fab!(:log1) { Fabricate(:skipped_email_log, user: user, created_at: 20.minutes.ago) }+ fab!(:log2) { Fabricate(:skipped_email_log, created_at: 10.minutes.ago) }it "succeeds" doget "/admin/email/skipped.json"diff --git a/spec/requests/groups_controller_spec.rb b/spec/requests/groups_controller_spec.rbindex fa07869b542..e6326ccc565 100644--- a/spec/requests/groups_controller_spec.rb+++ b/spec/requests/groups_controller_spec.rb@@ -1367,7 +1367,7 @@ describe GroupsController doexpect(response.status).to eq(200)- result = JSON.parse(response.body)["logs"].last+ result = JSON.parse(response.body)["logs"].find { |entry| entry["subject"] == "public_exit" }expect(result["action"]).to eq(GroupHistory.actions[1].to_s)expect(result["subject"]).to eq('public_exit')diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rbindex 59042ed8e80..dd3afa7cf0b 100644--- a/spec/requests/posts_controller_spec.rb+++ b/spec/requests/posts_controller_spec.rb@@ -415,12 +415,14 @@ describe PostsController doendit "won't update bump date if post is a whisper" do+ created_at = freeze_time 1.day.agopost = Fabricate(:post, post_type: Post.types[:whisper], user: user)+ unfreeze_timeput "/posts/#{post.id}.json", params: update_params- expect(response.status).to eq(200)- expect(post.topic.reload.bumped_at).to be < post.created_at+ expect(response.status).to eq(200)+ expect(post.topic.reload.bumped_at).to eq_time(created_at)endend@@ -1314,10 +1316,10 @@ describe PostsController docontext "topic bump" doshared_examples "it works" do- let(:original_bumped_at) { 1.day.ago }- let!(:topic) { Fabricate(:topic, bumped_at: original_bumped_at) }-it "should be able to skip topic bumping" do+ original_bumped_at = 1.day.ago+ topic = Fabricate(:topic, bumped_at: original_bumped_at)+post "/posts.json", params: {raw: 'this is the test content',topic_id: topic.id,@@ -1325,7 +1327,7 @@ describe PostsController do}expect(response.status).to eq(200)- expect(topic.reload.bumped_at).to be_within_one_second_of(original_bumped_at)+ expect(topic.reload.bumped_at).to eq_time(original_bumped_at)endit "should be able to post with topic bumping" do@@ -1335,7 +1337,7 @@ describe PostsController do}expect(response.status).to eq(200)- expect(topic.reload.bumped_at).to eq(topic.posts.last.created_at)+ expect(topic.reload.bumped_at).to eq_time(topic.posts.last.created_at)endenddiff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex bb570a8674b..481de344e4b 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -577,7 +577,11 @@ RSpec.describe TopicsController doenddescribe 'changing timestamps' do- before { sign_in(moderator) }+ before do+ freeze_time+ sign_in(moderator)+ end+let(:old_timestamp) { Time.zone.now }let(:new_timestamp) { old_timestamp - 1.day }let!(:topic) { Fabricate(:topic, created_at: old_timestamp) }@@ -594,9 +598,9 @@ RSpec.describe TopicsController do}expect(response.status).to eq(200)- expect(topic.reload.created_at).to be_within_one_second_of(new_timestamp)- expect(p1.reload.created_at).to be_within_one_second_of(new_timestamp)- expect(p2.reload.created_at).to be_within_one_second_of(old_timestamp)+ expect(topic.reload.created_at).to eq_time(new_timestamp)+ expect(p1.reload.created_at).to eq_time(new_timestamp)+ expect(p2.reload.created_at).to eq_time(old_timestamp)endit 'should create a staff log entry' do@@ -713,7 +717,6 @@ RSpec.describe TopicsController doendcontext 'for last post only' do-it 'should allow you to retain topic timing but remove last post only' dofreeze_time@@ -777,9 +780,7 @@ RSpec.describe TopicsController doexpect(PostTiming.where(topic: topic, user: user, post_number: 1).exists?).to eq(false)expect(TopicUser.where(topic: topic, user: user, last_read_post_number: nil, highest_seen_post_number: nil).exists?).to eq(true)-end-endcontext 'when logged in' do@@ -1694,7 +1695,7 @@ RSpec.describe TopicsController dosign_in(user)get "/t/#{topic.slug}/#{topic.id}"topic_user = TopicUser.where(user: user, topic: topic).first- expect(topic_user.last_visited_at).to eq(topic_user.first_visited_at)+ expect(topic_user.last_visited_at).to eq_time(topic_user.first_visited_at)endcontext 'consider for a promotion' do@@ -2072,6 +2073,10 @@ RSpec.describe TopicsController dolet(:post) { Fabricate(:post) }let(:topic) { post.topic }+ after do+ Discourse.redis.flushall+ end+it 'returns first post of the topic' do# we need one for suggestedcreate_post@@ -2594,6 +2599,7 @@ RSpec.describe TopicsController docontext 'when logged in as an admin' dobefore do+ freeze_timesign_in(admin)end@@ -2608,14 +2614,12 @@ RSpec.describe TopicsController dotopic_status_update = TopicTimer.lastexpect(topic_status_update.topic).to eq(topic)-- expect(topic_status_update.execute_at)- .to be_within(1.second).of(24.hours.from_now)+ expect(topic_status_update.execute_at).to eq_time(24.hours.from_now)json = JSON.parse(response.body)expect(DateTime.parse(json['execute_at']))- .to be_within(1.seconds).of(DateTime.parse(topic_status_update.execute_at.to_s))+ .to eq_time(DateTime.parse(topic_status_update.execute_at.to_s))expect(json['duration']).to eq(topic_status_update.duration)expect(json['closed']).to eq(topic.reload.closed)@@ -2652,10 +2656,7 @@ RSpec.describe TopicsController dotopic_status_update = TopicTimer.lastexpect(topic_status_update.topic).to eq(topic)-- expect(topic_status_update.execute_at)- .to be_within(1.second).of(24.hours.from_now)-+ expect(topic_status_update.execute_at).to eq_time(24.hours.from_now)expect(topic_status_update.status_type).to eq(TopicTimer.types[:publish_to_category])@@ -3134,7 +3135,7 @@ RSpec.describe TopicsController doput "/t/#{topic.id}/reset-bump-date.json"expect(response.status).to eq(200)- expect(topic.reload.bumped_at).to be_within_one_second_of(timestamp)+ expect(topic.reload.bumped_at).to eq_time(timestamp)endendenddiff --git a/spec/services/badge_granter_spec.rb b/spec/services/badge_granter_spec.rbindex 6bfd968e4ca..362e03dff3b 100644--- a/spec/services/badge_granter_spec.rb+++ b/spec/services/badge_granter_spec.rb@@ -119,21 +119,19 @@ describe BadgeGranter dodescribe 'grant' doit 'allows overriding of granted_at does not notify old bronze' do+ freeze_timebadge = Badge.create!(name: 'a badge', badge_type_id: BadgeType::Bronze)+ user_badge = BadgeGranter.grant(badge, user, created_at: 1.year.ago)- time = 1.year.ago-- user_badge = BadgeGranter.grant(badge, user, created_at: time)-- expect(user_badge.granted_at).to eq(time)+ expect(user_badge.granted_at).to eq_time(1.year.ago)expect(Notification.where(user_id: user.id).count).to eq(0)endit "doesn't grant disabled badges" do+ freeze_timebadge = Fabricate(:badge, badge_type_id: BadgeType::Bronze, enabled: false)- time = 1.year.ago- user_badge = BadgeGranter.grant(badge, user, created_at: time)+ user_badge = BadgeGranter.grant(badge, user, created_at: 1.year.ago)expect(user_badge).to eq(nil)end@@ -147,11 +145,10 @@ describe BadgeGranter doendit 'sets granted_at' do- time = 1.day.ago- freeze_time time-+ day_ago = freeze_time 1.day.agouser_badge = BadgeGranter.grant(badge, user)- expect(user_badge.granted_at).to be_within(1.second).of(time)++ expect(user_badge.granted_at).to eq_time(day_ago)endit 'sets granted_by if the option is present' do@@ -228,7 +225,6 @@ describe BadgeGranter dodescribe 'revoke_all' doit 'deletes every user_badge record associated with that badge' dodescribed_class.grant(badge, user)-described_class.revoke_all(badge)expect(UserBadge.exists?(badge: badge, user: user)).to eq(false)diff --git a/spec/services/post_owner_changer_spec.rb b/spec/services/post_owner_changer_spec.rbindex b32a0ed0b06..1cee8eeae94 100644--- a/spec/services/post_owner_changer_spec.rb+++ b/spec/services/post_owner_changer_spec.rb@@ -23,16 +23,17 @@ describe PostOwnerChanger doendit "changes the user" do- bumped_at = topic.bumped_at+ bumped_at = freeze_time topic.bumped_atold_user = p1.userPostActionCreator.like(user_a, p1)p1.reloadexpect(p1.topic.like_count).to eq(1)+PostOwnerChanger.new(post_ids: [p1.id], topic_id: topic.id, new_owner: user_a, acting_user: editor).change_owner!p1.reloadexpect(p1.topic.like_count).to eq(0)- expect(p1.topic.bumped_at).to be_within(1.second).of (bumped_at)+ expect(p1.topic.bumped_at).to eq_time(bumped_at)expect(p1.topic.last_post_user_id).to eq(user_a.id)expect(old_user).not_to eq(p1.user)expect(p1.user).to eq(user_a)diff --git a/spec/services/topic_timestamp_changer_spec.rb b/spec/services/topic_timestamp_changer_spec.rbindex 887aa71bfe0..c94cecfb921 100644--- a/spec/services/topic_timestamp_changer_spec.rb+++ b/spec/services/topic_timestamp_changer_spec.rb@@ -26,39 +26,32 @@ describe TopicTimestampChanger doTopicTimestampChanger.new(topic: topic, timestamp: new_timestamp.to_f).change!topic.reload- [:created_at, :updated_at, :bumped_at].each do |column|- expect(topic.public_send(column)).to be_within(1.second).of(new_timestamp)- end+ expect(topic.created_at).to eq_time(new_timestamp)+ expect(topic.updated_at).to eq_time(new_timestamp)+ expect(topic.bumped_at).to eq_time(new_timestamp)p1.reload- [:created_at, :updated_at].each do |column|- expect(p1.public_send(column)).to be_within(1.second).of(new_timestamp)- end+ expect(p1.created_at).to eq_time(new_timestamp)+ expect(p1.updated_at).to eq_time(new_timestamp)p2.reload- [:created_at, :updated_at].each do |column|- expect(p2.public_send(column)).to be_within(1.second).of(new_timestamp + 1.day)- end+ expect(p2.created_at).to eq_time(new_timestamp + 1.day)+ expect(p2.updated_at).to eq_time(new_timestamp + 1.day)- expect(topic.last_posted_at).to be_within(1.second).of(p2.reload.created_at)+ expect(topic.last_posted_at).to eq_time(p2.reload.created_at)enddescribe 'when posts have timestamps in the future' do- let(:new_timestamp) { Time.zone.now }- let(:p3) { Fabricate(:post, topic: topic, created_at: new_timestamp + 3.day) }-it 'should set the new timestamp as the default timestamp' do- freeze_time-- p3+ new_timestamp = freeze_time+ p3 = Fabricate(:post, topic: topic, created_at: new_timestamp + 3.days)TopicTimestampChanger.new(topic: topic, timestamp: new_timestamp.to_f).change!p3.reload- [:created_at, :updated_at].each do |column|- expect(p3.public_send(column)).to be_within(1.second).of(new_timestamp)- end+ expect(p3.created_at).to eq_time(new_timestamp)+ expect(p3.updated_at).to eq_time(new_timestamp)endendenddiff --git a/spec/services/user_activator_spec.rb b/spec/services/user_activator_spec.rbindex 9678fb57030..5172843319f 100644--- a/spec/services/user_activator_spec.rb+++ b/spec/services/user_activator_spec.rb@@ -16,6 +16,8 @@ describe UserActivator doendit 'creates and send new email token if the existing token expired' do+ now = freeze_time+SiteSetting.email_token_valid_hours = 24user = Fabricate(:user)email_token = user.email_tokens.first@@ -27,7 +29,7 @@ describe UserActivator doactivator.activateuser.reload- expect(user.email_tokens.last.created_at).to be_within_one_second_of(Time.zone.now)+ expect(user.email_tokens.last.created_at).to eq_time(now)endend