2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-10-02 00:50:54 -04:00
|
|
|
require "import_export"
|
2017-10-26 16:29:36 -04:00
|
|
|
|
|
|
|
describe ImportExport::TopicExporter do
|
|
|
|
|
2017-11-02 05:33:36 -04:00
|
|
|
before do
|
|
|
|
STDOUT.stubs(:write)
|
|
|
|
end
|
|
|
|
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
fab!(:topic) { Fabricate(:topic, user: user) }
|
|
|
|
fab!(:post) { Fabricate(:post, topic: topic, user: user) }
|
2017-10-26 16:29:36 -04:00
|
|
|
|
|
|
|
context '.perform' do
|
|
|
|
it 'export a single topic' do
|
|
|
|
data = ImportExport::TopicExporter.new([topic.id]).perform.export_data
|
|
|
|
|
|
|
|
expect(data[:categories].blank?).to eq(true)
|
|
|
|
expect(data[:groups].blank?).to eq(true)
|
|
|
|
expect(data[:topics].count).to eq(1)
|
|
|
|
expect(data[:users].count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'export multiple topics' do
|
|
|
|
topic2 = Fabricate(:topic, user: user)
|
2019-10-02 00:50:54 -04:00
|
|
|
_post2 = Fabricate(:post, user: user, topic: topic2)
|
2017-10-26 16:29:36 -04:00
|
|
|
data = ImportExport::TopicExporter.new([topic.id, topic2.id]).perform.export_data
|
|
|
|
|
|
|
|
expect(data[:categories].blank?).to eq(true)
|
|
|
|
expect(data[:groups].blank?).to eq(true)
|
|
|
|
expect(data[:topics].count).to eq(2)
|
2018-01-16 12:51:37 -05:00
|
|
|
expect(data[:users].map { |u| u[:id] }).to match_array([user.id])
|
2017-10-26 16:29:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|