2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-04 21:41:40 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe UserExport do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
2018-06-04 21:41:40 -04:00
|
|
|
|
|
|
|
describe '.remove_old_exports' do
|
|
|
|
it 'should remove the right records' do
|
2019-04-03 04:01:19 -04:00
|
|
|
csv_file_1 = Fabricate(:upload, created_at: 3.days.ago)
|
2018-06-04 21:41:40 -04:00
|
|
|
export = UserExport.create!(
|
|
|
|
file_name: "test",
|
|
|
|
user: user,
|
2019-04-03 04:01:19 -04:00
|
|
|
upload_id: csv_file_1.id,
|
2018-06-04 21:41:40 -04:00
|
|
|
created_at: 3.days.ago
|
|
|
|
)
|
|
|
|
|
2019-04-03 04:01:19 -04:00
|
|
|
csv_file_2 = Fabricate(:upload, created_at: 1.day.ago)
|
2018-06-04 21:41:40 -04:00
|
|
|
export2 = UserExport.create!(
|
|
|
|
file_name: "test2",
|
|
|
|
user: user,
|
2019-04-03 04:01:19 -04:00
|
|
|
upload_id: csv_file_2.id,
|
2018-06-04 21:41:40 -04:00
|
|
|
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)
|
2019-04-03 04:01:19 -04:00
|
|
|
expect(Upload.exists?(id: csv_file_1.id)).to eq(false)
|
2018-06-04 21:41:40 -04:00
|
|
|
expect(UserExport.exists?(id: export2.id)).to eq(true)
|
2019-04-03 04:01:19 -04:00
|
|
|
expect(Upload.exists?(id: csv_file_2.id)).to eq(true)
|
2018-06-04 21:41:40 -04:00
|
|
|
end
|
|
|
|
end
|
2019-05-21 04:02:36 -04:00
|
|
|
|
|
|
|
describe '#destroy!' do
|
|
|
|
it 'should create post custom field for ignored missing uploads' do
|
|
|
|
upload = Fabricate(:upload, created_at: 3.days.ago)
|
|
|
|
export = UserExport.create!(
|
|
|
|
file_name: "test",
|
|
|
|
user: user,
|
|
|
|
upload_id: upload.id,
|
|
|
|
created_at: 3.days.ago
|
|
|
|
)
|
|
|
|
post = Fabricate(:post, raw: "![#{upload.original_filename}](#{upload.short_url})")
|
|
|
|
post.link_post_uploads
|
|
|
|
|
|
|
|
export.destroy!
|
|
|
|
|
|
|
|
expect(PostCustomField.exists?(post_id: post.id, name: Post::MISSING_UPLOADS_IGNORED)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
2018-06-04 21:41:40 -04:00
|
|
|
end
|