0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-24 10:20:28 +01:00
discourse-custom-wizard/spec/extensions/guardian_extension_spec.rb

47 Zeilen
1,6 KiB
Ruby

2021-10-19 05:35:55 +02:00
# frozen_string_literal: true
2022-01-31 08:20:20 +01:00
2021-10-19 05:35:55 +02:00
describe ::Guardian do
2024-10-16 13:52:03 +02:00
fab!(:user) { Fabricate(:user, name: "Angus", username: "angus", email: "angus@email.com") }
fab!(:category) { Fabricate(:category, name: "cat1", slug: "cat-slug") }
let(:wizard_template) do
2021-10-19 05:35:55 +02:00
JSON.parse(
2024-10-16 13:52:03 +02:00
File.open("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json").read,
2021-10-19 05:35:55 +02:00
)
2024-10-16 13:52:03 +02:00
end
2021-10-19 05:35:55 +02:00
2022-01-31 08:20:20 +01:00
def create_topic_by_wizard(wizard)
wizard.create_updater(
wizard.steps.first.id,
step_1_field_1: "Topic Title",
2024-10-16 13:52:03 +02:00
step_1_field_2: "topic body",
2022-01-31 08:20:20 +01:00
).update
wizard.create_updater(wizard.steps.second.id, {}).update
2024-10-16 13:52:03 +02:00
wizard.create_updater(wizard.steps.last.id, step_3_field_3: category.id).update
2022-01-31 08:20:20 +01:00
2024-10-16 13:52:03 +02:00
topic = Topic.where(title: "Topic Title", category_id: category.id).first
2022-01-31 08:20:20 +01:00
topic
end
2021-10-19 05:35:55 +02:00
before do
CustomWizard::Template.save(wizard_template, skip_jobs: true)
2024-10-16 13:52:03 +02:00
@template = CustomWizard::Template.find("super_mega_fun_wizard")
2021-10-19 05:35:55 +02:00
end
2022-01-31 08:20:20 +01:00
context "topic created by user using wizard" do
2021-10-19 05:35:55 +02:00
it "allows editing the topic first post" do
wizard = CustomWizard::Builder.new(@template[:id], user).build
2022-01-31 08:20:20 +01:00
topic = create_topic_by_wizard(wizard)
expect(user.guardian.wizard_can_edit_topic?(topic)).to be_truthy
2021-10-19 05:35:55 +02:00
end
end
2021-10-30 12:33:30 +02:00
2022-01-31 08:20:20 +01:00
context "topic created by user without wizard" do
2021-10-30 12:33:30 +02:00
it "restricts editing the topic first post" do
2024-10-16 13:52:03 +02:00
topic_params = { title: "Topic Title", raw: "Topic body", skip_validations: true }
2022-01-31 08:20:20 +01:00
post = PostCreator.new(user, topic_params).create
expect(user.guardian.wizard_can_edit_topic?(post.topic)).to be_falsey
2021-10-30 12:33:30 +02:00
end
end
2021-10-19 05:35:55 +02:00
end