<commit_before>require 'spec_helper'

describe PostTimestampChanger do
  describe "change!" do
    let(:old_timestamp) { Time.zone.now }
    let(:new_timestamp) { old_timestamp + 1.day }
    let!(:topic) { Fabricate(:topic, created_at: old_timestamp) }
    let!(:p1) { Fabricate(:post, topic: topic, created_at: old_timestamp) }
    let!(:p2) { Fabricate(:post, topic: topic, created_at: old_timestamp + 1.day) }
    let(:params) { { topic_id: topic.id, timestamp: new_timestamp.to_f } }

    it 'changes the timestamp of the topic and opening post' do
      PostTimestampChanger.new(params).change!

      topic.reload
      [:created_at, :updated_at, :bumped_at].each do |column|
        expect(topic.public_send(column).to_s).to eq(new_timestamp.to_s)
      end

      p1.reload
      [:created_at, :updated_at].each do |column|
        expect(p1.public_send(column).to_s).to eq(new_timestamp.to_s)
      end
    end

    describe 'predated timestamp' do
      it 'updates the timestamp of posts in the topic with the time difference applied' do
        PostTimestampChanger.new(params).change!

        p2.reload
        [:created_at, :updated_at].each do |column|
          expect(p2.public_send(column).to_s).to eq((old_timestamp + 2.day).to_s)
        end
      end
    end

    describe 'backdated timestamp' do
      let(:new_timestamp) { old_timestamp - 1.day }

      it 'updates the timestamp of posts in the topic with the time difference applied' do
        PostTimestampChanger.new(params).change!

        p2.reload
        [:created_at, :updated_at].each do |column|
          expect(p2.public_send(column).to_s).to eq((old_timestamp).to_s)
        end
      end
    end

    it 'deletes the stats cache' do
      $redis.expects(:del).twice
      PostTimestampChanger.new(params).change!
    end
  end
end
<commit_msg>Fix timestamp comparison in tests.<commit_after>require 'spec_helper'

describe PostTimestampChanger do
  describe "change!" do
    let(:old_timestamp) { Time.zone.now }
    let(:new_timestamp) { old_timestamp + 1.day }
    let!(:topic) { Fabricate(:topic, created_at: old_timestamp) }
    let!(:p1) { Fabricate(:post, topic: topic, created_at: old_timestamp) }
    let!(:p2) { Fabricate(:post, topic: topic, created_at: old_timestamp + 1.day) }
    let(:params) { { topic_id: topic.id, timestamp: new_timestamp.to_f } }

    it 'changes the timestamp of the topic and opening post' do
      PostTimestampChanger.new(params).change!

      topic.reload
      [:created_at, :updated_at, :bumped_at].each do |column|
        expect(topic.public_send(column)).to be_within_one_second_of(new_timestamp)
      end

      p1.reload
      [:created_at, :updated_at].each do |column|
        expect(p1.public_send(column)).to be_within_one_second_of(new_timestamp)
      end
    end

    describe 'predated timestamp' do
      it 'updates the timestamp of posts in the topic with the time difference applied' do
        PostTimestampChanger.new(params).change!

        p2.reload
        [:created_at, :updated_at].each do |column|
          expect(p2.public_send(column)).to be_within_one_second_of(old_timestamp + 2.day)
        end
      end
    end

    describe 'backdated timestamp' do
      let(:new_timestamp) { old_timestamp - 1.day }

      it 'updates the timestamp of posts in the topic with the time difference applied' do
        PostTimestampChanger.new(params).change!

        p2.reload
        [:created_at, :updated_at].each do |column|
          expect(p2.public_send(column)).to be_within_one_second_of(old_timestamp)
        end
      end
    end

    it 'deletes the stats cache' do
      $redis.expects(:del).twice
      PostTimestampChanger.new(params).change!
    end
  end
end

{'fraction_non_alphanumeric': 0.10533369069954436, 'fraction_numerical': 0.006432591798445457, 'mean_word_length': 3.0921052631578947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6072046', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1174, 'n_words': 284}