discourse/spec/import_export/topic_exporter_spec.rb
Daniel Waterworth 6e161d3e75
DEV: Allow fab! without block (#24314)
The most common thing that we do with fab! is:

    fab!(:thing) { Fabricate(:thing) }

This commit adds a shorthand for this which is just simply:

    fab!(:thing)

i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
2023-11-09 16:47:59 -06:00

34 lines
1.0 KiB
Ruby

# frozen_string_literal: true
require "import_export"
RSpec.describe ImportExport::TopicExporter do
before { STDOUT.stubs(:write) }
fab!(:user)
fab!(:topic) { Fabricate(:topic, user: user) }
fab!(:post) { Fabricate(:post, topic: topic, user: user) }
describe ".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