discourse/spec/import_export/topic_exporter_spec.rb
Daniel Waterworth e219588142 DEV: Prefabrication (test optimization) (#7414)
* Introduced fab!, a helper that creates database state for a group

It's almost identical to let_it_be, except:

 1. It creates a new object for each test by default,
 2. You can disable it using PREFABRICATION=0
2019-05-07 13:12:20 +10:00

39 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require "rails_helper"
require "import_export/topic_exporter"
describe ImportExport::TopicExporter do
before do
STDOUT.stubs(:write)
end
fab!(:user) { Fabricate(:user) }
fab!(:topic) { Fabricate(:topic, user: user) }
fab!(:post) { Fabricate(:post, topic: topic, user: user) }
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)
post2 = Fabricate(:post, user: user, topic: topic2)
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)
expect(data[:users].map { |u| u[:id] }).to match_array([user.id])
end
end
end