mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 12:13:58 -06:00
4ea21fa2d0
This change both speeds up specs (less strings to allocate) and helps catch cases where methods in Discourse are mutating inputs. Overall we will be migrating everything to use #frozen_string_literal: true it will take a while, but this is the first and safest move in this direction
39 lines
1.1 KiB
Ruby
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
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
let(:topic) { Fabricate(:topic, user: user) }
|
|
let!(: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
|