|
1 | 1 | # frozen_string_literal: true |
| 2 | + |
2 | 3 | require_relative '../plugin_helper' |
3 | 4 |
|
4 | 5 | describe ::Guardian do |
|
14 | 15 | ) |
15 | 16 | } |
16 | 17 |
|
| 18 | + def create_topic_by_wizard(wizard) |
| 19 | + wizard.create_updater( |
| 20 | + wizard.steps.first.id, |
| 21 | + step_1_field_1: "Topic Title", |
| 22 | + step_1_field_2: "topic body" |
| 23 | + ).update |
| 24 | + wizard.create_updater(wizard.steps.second.id, {}).update |
| 25 | + wizard.create_updater(wizard.steps.last.id, |
| 26 | + step_3_field_3: category.id |
| 27 | + ).update |
| 28 | + |
| 29 | + topic = Topic.where( |
| 30 | + title: "Topic Title", |
| 31 | + category_id: category.id |
| 32 | + ).first |
| 33 | + |
| 34 | + topic |
| 35 | + end |
| 36 | + |
17 | 37 | before do |
18 | 38 | CustomWizard::Template.save(wizard_template, skip_jobs: true) |
19 | 39 | @template = CustomWizard::Template.find('super_mega_fun_wizard') |
20 | 40 | end |
21 | 41 |
|
22 | | - context "the user has access to creating wizard" do |
| 42 | + context "topic created by user using wizard" do |
23 | 43 | it "allows editing the topic first post" do |
24 | 44 | wizard = CustomWizard::Builder.new(@template[:id], user).build |
25 | | - |
26 | | - wizard.create_updater( |
27 | | - wizard.steps.first.id, |
28 | | - step_1_field_1: "Topic Title", |
29 | | - step_1_field_2: "topic body" |
30 | | - ).update |
31 | | - wizard.create_updater(wizard.steps.second.id, {}).update |
32 | | - wizard.create_updater(wizard.steps.last.id, |
33 | | - step_3_field_3: category.id |
34 | | - ).update |
35 | | - |
36 | | - topic = Topic.where( |
37 | | - title: "Topic Title", |
38 | | - category_id: category.id |
39 | | - ).first |
40 | | - |
41 | | - expect(user.guardian.send(:wizard_user_can_create_topic_on_category?, topic)).to be_truthy |
42 | | - end |
43 | | - end |
44 | | - |
45 | | - context "the user doesn't have access to creating wizard" do |
46 | | - it "restricts editing the topic first post" do |
47 | | - wizard = CustomWizard::Builder.new(@template[:id], user).build |
48 | | - CustomWizard::Wizard.any_instance.stubs(:permitted?).returns(false) |
49 | | - |
50 | | - wizard.create_updater( |
51 | | - wizard.steps.first.id, |
52 | | - step_1_field_1: "Topic Title", |
53 | | - step_1_field_2: "topic body" |
54 | | - ).update |
55 | | - wizard.create_updater(wizard.steps.second.id, {}).update |
56 | | - wizard.create_updater(wizard.steps.last.id, |
57 | | - step_3_field_3: category.id |
58 | | - ).update |
59 | | - |
60 | | - topic = Topic.where( |
61 | | - title: "Topic Title", |
62 | | - category_id: category.id |
63 | | - ).first |
64 | | - |
65 | | - expect(user.guardian.send(:wizard_user_can_create_topic_on_category?, topic)).to be_falsey |
| 45 | + topic = create_topic_by_wizard(wizard) |
| 46 | + expect(user.guardian.wizard_can_edit_topic?(topic)).to be_truthy |
66 | 47 | end |
67 | 48 | end |
68 | 49 |
|
69 | | - context "the wizard can't create a topic in the category" do |
| 50 | + context "topic created by user without wizard" do |
70 | 51 | it "restricts editing the topic first post" do |
71 | | - wizard = CustomWizard::Builder.new(@template[:id], user).build |
72 | | - wizard.create_updater( |
73 | | - wizard.steps.first.id, |
74 | | - step_1_field_1: "Topic Title", |
75 | | - step_1_field_2: "topic body" |
76 | | - ).update |
77 | | - wizard.create_updater(wizard.steps.second.id, {}).update |
78 | | - wizard.create_updater(wizard.steps.last.id, |
79 | | - step_3_field_3: category.id |
80 | | - ).update |
81 | | - |
82 | | - topic = Topic.where( |
| 52 | + topic_params = { |
83 | 53 | title: "Topic Title", |
84 | | - category_id: category.id |
85 | | - ).first |
86 | | - |
87 | | - new_category = Fabricate(:category) |
88 | | - topic.category_id = new_category.id |
89 | | - topic.save |
90 | | - topic.reload |
91 | | - |
92 | | - expect(user.guardian.send(:wizard_user_can_create_topic_on_category?, topic)).to be_falsey |
| 54 | + raw: "Topic body", |
| 55 | + skip_validations: true |
| 56 | + } |
| 57 | + post = PostCreator.new(user, topic_params).create |
| 58 | + expect(user.guardian.wizard_can_edit_topic?(post.topic)).to be_falsey |
93 | 59 | end |
94 | 60 | end |
95 | 61 | end |
0 commit comments