2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-04 20:41:40 -05:00
|
|
|
RSpec.describe UserExport do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:user)
|
2018-06-04 20:41:40 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe ".remove_old_exports" do
|
|
|
|
it "should remove the right records" do
|
2019-04-03 03:01:19 -05:00
|
|
|
csv_file_1 = Fabricate(:upload, created_at: 3.days.ago)
|
2019-05-28 06:08:41 -05:00
|
|
|
topic_1 = Fabricate(:topic, created_at: 3.days.ago)
|
|
|
|
post_1 = Fabricate(:post, topic: topic_1)
|
2023-01-09 05:18:21 -06:00
|
|
|
export =
|
|
|
|
UserExport.create!(
|
|
|
|
file_name: "test",
|
|
|
|
user: user,
|
|
|
|
upload_id: csv_file_1.id,
|
|
|
|
topic_id: topic_1.id,
|
|
|
|
created_at: 3.days.ago,
|
|
|
|
)
|
2018-06-04 20:41:40 -05:00
|
|
|
|
2019-04-03 03:01:19 -05:00
|
|
|
csv_file_2 = Fabricate(:upload, created_at: 1.day.ago)
|
2019-05-28 06:08:41 -05:00
|
|
|
topic_2 = Fabricate(:topic, created_at: 1.day.ago)
|
2023-01-09 05:18:21 -06:00
|
|
|
export2 =
|
|
|
|
UserExport.create!(
|
|
|
|
file_name: "test2",
|
|
|
|
user: user,
|
|
|
|
upload_id: csv_file_2.id,
|
|
|
|
topic_id: topic_2.id,
|
|
|
|
created_at: 1.day.ago,
|
|
|
|
)
|
2018-06-04 20:41:40 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
expect do UserExport.remove_old_exports end.to change { UserExport.count }.by(-1)
|
2018-06-04 20:41:40 -05:00
|
|
|
|
|
|
|
expect(UserExport.exists?(id: export.id)).to eq(false)
|
2019-04-03 03:01:19 -05:00
|
|
|
expect(Upload.exists?(id: csv_file_1.id)).to eq(false)
|
2019-05-28 06:08:41 -05:00
|
|
|
expect(Topic.with_deleted.exists?(id: topic_1.id)).to eq(false)
|
|
|
|
expect(Post.with_deleted.exists?(id: post_1.id)).to eq(false)
|
2018-06-04 20:41:40 -05:00
|
|
|
expect(UserExport.exists?(id: export2.id)).to eq(true)
|
2019-04-03 03:01:19 -05:00
|
|
|
expect(Upload.exists?(id: csv_file_2.id)).to eq(true)
|
2019-05-28 06:08:41 -05:00
|
|
|
expect(Topic.exists?(id: topic_2.id)).to eq(true)
|
2018-06-04 20:41:40 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|