mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 22:05:48 +08:00
c9dab6fd08
It's very easy to forget to add `require 'rails_helper'` at the top of every core/plugin spec file, and omissions can cause some very confusing/sporadic errors. By setting this flag in `.rspec`, we can remove the need for `require 'rails_helper'` entirely.
43 lines
1.4 KiB
Ruby
43 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe UserExport do
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
describe '.remove_old_exports' do
|
|
it 'should remove the right records' do
|
|
csv_file_1 = Fabricate(:upload, created_at: 3.days.ago)
|
|
topic_1 = Fabricate(:topic, created_at: 3.days.ago)
|
|
post_1 = Fabricate(:post, topic: topic_1)
|
|
export = UserExport.create!(
|
|
file_name: "test",
|
|
user: user,
|
|
upload_id: csv_file_1.id,
|
|
topic_id: topic_1.id,
|
|
created_at: 3.days.ago
|
|
)
|
|
|
|
csv_file_2 = Fabricate(:upload, created_at: 1.day.ago)
|
|
topic_2 = Fabricate(:topic, created_at: 1.day.ago)
|
|
export2 = UserExport.create!(
|
|
file_name: "test2",
|
|
user: user,
|
|
upload_id: csv_file_2.id,
|
|
topic_id: topic_2.id,
|
|
created_at: 1.day.ago
|
|
)
|
|
|
|
expect do
|
|
UserExport.remove_old_exports
|
|
end.to change { UserExport.count }.by(-1)
|
|
|
|
expect(UserExport.exists?(id: export.id)).to eq(false)
|
|
expect(Upload.exists?(id: csv_file_1.id)).to eq(false)
|
|
expect(Topic.with_deleted.exists?(id: topic_1.id)).to eq(false)
|
|
expect(Post.with_deleted.exists?(id: post_1.id)).to eq(false)
|
|
expect(UserExport.exists?(id: export2.id)).to eq(true)
|
|
expect(Upload.exists?(id: csv_file_2.id)).to eq(true)
|
|
expect(Topic.exists?(id: topic_2.id)).to eq(true)
|
|
end
|
|
end
|
|
end
|