Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-09 20:02:54 +01:00
35021eb176
I've tweaked the subscription client gem so we can just use the gem's models and tables in this plugin's rspec, which makes duplicating and stubbing them unnecessary. See further https://github.com/paviliondev/discourse_subscription_client
59 Zeilen
1,6 KiB
Ruby
59 Zeilen
1,6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe ::Guardian do
|
|
fab!(:user) {
|
|
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
|
|
)
|
|
}
|
|
|
|
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
|
|
|
|
before do
|
|
CustomWizard::Template.save(wizard_template, skip_jobs: true)
|
|
@template = CustomWizard::Template.find('super_mega_fun_wizard')
|
|
end
|
|
|
|
context "topic created by user using wizard" do
|
|
it "allows editing the topic first post" do
|
|
wizard = CustomWizard::Builder.new(@template[:id], user).build
|
|
topic = create_topic_by_wizard(wizard)
|
|
expect(user.guardian.wizard_can_edit_topic?(topic)).to be_truthy
|
|
end
|
|
end
|
|
|
|
context "topic created by user without wizard" do
|
|
it "restricts editing the topic first post" do
|
|
topic_params = {
|
|
title: "Topic Title",
|
|
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
|
|
end
|
|
end
|
|
end
|