Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add a test for create_post in import scripts (#18893)

Harry Woodbdf8815b7198
diff --git a/spec/script/import_scripts/base_spec.rb b/spec/script/import_scripts/base_spec.rb
index 3f637f4d8b1..86a9ba42df2 100644
--- a/spec/script/import_scripts/base_spec.rb
+++ b/spec/script/import_scripts/base_spec.rb
@@ -54,4 +54,34 @@ RSpec.describe ImportScripts::Base do
MockSpecImporter.new(import_data).perform
expect(SiteSetting.purge_unactivated_users_grace_period_days).to eq(0)
end
+
+ describe "#create_post" do
+ let(:importer) { described_class.new }
+ fab!(:user) { Fabricate(:user) }
+ let(:post_params) {
+ {
+ user_id: user.id,
+ raw: "Test post [b]content[/b]",
+ title: "Test topic for post"
+ }
+ }
+
+ it "creates a Post" do
+ expect {
+ importer.create_post(post_params, 123)
+ }.to change { Post.count }.by(1)
+ end
+
+ if ENV["IMPORT"] == "1"
+ it "uses the ruby-bbcode-to-md gem (conditional Gemfile option)" do
+ expect(String.method_defined?(:bbcode_to_md)).to be true
+ end
+
+ it "converts bbcode to markdown when specified" do
+ importer.instance_variable_set(:@bbcode_to_md, true)
+ importer.create_post(post_params, 123)
+ expect(Post.first.raw).to eq "Test post **content**"
+ end
+ end
+ end
end