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

62 Zeilen
1,7 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
require_relative '../plugin_helper'
describe ::Guardian do
2021-10-30 12:33:30 +02:00
fab!(:user) {
2021-10-19 05:35:55 +02:00
Fabricate(:user, name: "Angus", username: 'angus', email: "angus@email.com")
}
fab!(:category) { Fabricate(:category, name: 'cat1', slug: 'cat-slug') }
let(:wizard_template) {
JSON.parse(
File.open(
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json"
).read
)
}
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",
step_1_field_2: "topic body"
).update
wizard.create_updater(wizard.steps.second.id, {}).update
wizard.create_updater(wizard.steps.last.id,
step_3_field_3: category.id
).update
topic = Topic.where(
title: "Topic Title",
category_id: category.id
).first
topic
end
2021-10-19 05:35:55 +02:00
before do
CustomWizard::Template.save(wizard_template, skip_jobs: true)
@template = CustomWizard::Template.find('super_mega_fun_wizard')
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
2022-01-31 08:20:20 +01:00
topic_params = {
2021-10-30 12:33:30 +02:00
title: "Topic Title",
2022-01-31 08:20:20 +01:00
raw: "Topic body",
skip_validations: true
}
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