mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 01:24:03 +08:00
3e50313fdc
Since rspec-rails 3, the default installation creates two helper files: * `spec_helper.rb` * `rails_helper.rb` `spec_helper.rb` is intended as a way of running specs that do not require Rails, whereas `rails_helper.rb` loads Rails (as Discourse's current `spec_helper.rb` does). For more information: https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files In this commit, I've simply replaced all instances of `spec_helper` with `rails_helper`, and renamed the original `spec_helper.rb`. This brings the Discourse project closer to the standard usage of RSpec in a Rails app. At present, every spec relies on loading Rails, but there are likely many that don't need to. In a future pull request, I hope to introduce a separate, minimal `spec_helper.rb` which can be used in tests which don't rely on Rails.
58 lines
1.9 KiB
Ruby
58 lines
1.9 KiB
Ruby
require 'rails_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
|
|
|
|
expect(topic.last_posted_at).to be_within_one_second_of(p2.reload.created_at)
|
|
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
|