A platform for community discussion. Free, open, simple.
Prefabricate users in post_revisor_spec.rb
Daniel Waterworth6f5fb020d273
diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rbindex cdc23952eaf..7f18ac2421b 100644--- a/spec/components/post_revisor_spec.rb+++ b/spec/components/post_revisor_spec.rb@@ -7,6 +7,9 @@ describe PostRevisor dofab!(:topic) { Fabricate(:topic) }fab!(:newuser) { Fabricate(:newuser) }+ fab!(:user) { Fabricate(:user) }+ fab!(:admin) { Fabricate(:admin) }+ fab!(:moderator) { Fabricate(:moderator) }let(:post_args) { { user: newuser, topic: topic } }context 'TopicChanges' do@@ -466,8 +469,6 @@ describe PostRevisor doendcontext "logging staff edits" do- fab!(:moderator) { Fabricate(:moderator) }-it "doesn't log when a regular user revises a post" dosubject.revise!(post.user,@@ -513,8 +514,6 @@ describe PostRevisor docontext "staff_edit_locks_post" docontext "disabled" do- fab!(:moderator) { Fabricate(:moderator) }-before doSiteSetting.staff_edit_locks_post = falseend@@ -532,7 +531,6 @@ describe PostRevisor doendcontext "enabled" do- fab!(:moderator) { Fabricate(:moderator) }before doSiteSetting.staff_edit_locks_post = true@@ -572,7 +570,7 @@ describe PostRevisor doit "doesn't lock the post when revised by a regular user" doresult = subject.revise!(- Fabricate(:user),+ user,raw: "lets totally update the body")expect(result).to eq(true)@@ -615,7 +613,7 @@ describe PostRevisor doit "generates a notification for a mention" doexpect {- subject.revise!(Fabricate(:user), raw: "Random user is mentioning @#{mentioned_user.username_lower}")+ subject.revise!(user, raw: "Random user is mentioning @#{mentioned_user.username_lower}")}.to change { Notification.where(notification_type: Notification.types[:mentioned]).count }end@@ -634,7 +632,7 @@ describe PostRevisor doendit "doesn't add the tags" do- result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: ['totally', 'update'])+ result = subject.revise!(user, raw: "lets totally update the body", tags: ['totally', 'update'])expect(result).to eq(true)post.reloadexpect(post.topic.tags.size).to eq(0)@@ -654,7 +652,7 @@ describe PostRevisor doit "can create all tags if none exist" doexpect {- @result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: ['totally', 'update'])+ @result = subject.revise!(user, raw: "lets totally update the body", tags: ['totally', 'update'])}.to change { Tag.count }.by(2)expect(@result).to eq(true)post.reload@@ -664,7 +662,7 @@ describe PostRevisor doit "creates missing tags if some exist" doFabricate(:tag, name: 'totally')expect {- @result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: ['totally', 'update'])+ @result = subject.revise!(user, raw: "lets totally update the body", tags: ['totally', 'update'])}.to change { Tag.count }.by(1)expect(@result).to eq(true)post.reload@@ -673,7 +671,7 @@ describe PostRevisor doit "can remove all tags" dotopic.tags = [Fabricate(:tag, name: "super"), Fabricate(:tag, name: "stuff")]- result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: [])+ result = subject.revise!(user, raw: "lets totally update the body", tags: [])expect(result).to eq(true)post.reloadexpect(post.topic.tags.size).to eq(0)@@ -681,7 +679,7 @@ describe PostRevisor doit "can remove all tags using tags_empty_array" dotopic.tags = [Fabricate(:tag, name: "stuff")]- result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags_empty_array: "true")+ result = subject.revise!(user, raw: "lets totally update the body", tags_empty_array: "true")expect(result).to eq(true)post.reloadexpect(post.topic.tags.size).to eq(0)@@ -689,14 +687,14 @@ describe PostRevisor doit "can't add staff-only tags" docreate_staff_tags(['important'])- result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: ['important', 'stuff'])+ result = subject.revise!(user, raw: "lets totally update the body", tags: ['important', 'stuff'])expect(result).to eq(false)expect(post.topic.errors.present?).to eq(true)endit "staff can add staff-only tags" docreate_staff_tags(['important'])- result = subject.revise!(Fabricate(:admin), raw: "lets totally update the body", tags: ['important', 'stuff'])+ result = subject.revise!(admin, raw: "lets totally update the body", tags: ['important', 'stuff'])expect(result).to eq(true)post.reloadexpect(post.topic.tags.map(&:name).sort).to eq(['important', 'stuff'])@@ -710,7 +708,7 @@ describe PostRevisor doendit "staff-only tags can't be removed" do- result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: ['stuff'])+ result = subject.revise!(user, raw: "lets totally update the body", tags: ['stuff'])expect(result).to eq(false)expect(post.topic.errors.present?).to eq(true)post.reload@@ -718,7 +716,7 @@ describe PostRevisor doendit "can't remove all tags if some are staff-only" do- result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: [])+ result = subject.revise!(user, raw: "lets totally update the body", tags: [])expect(result).to eq(false)expect(post.topic.errors.present?).to eq(true)post.reload@@ -726,14 +724,14 @@ describe PostRevisor doendit "staff-only tags can be removed by staff" do- result = subject.revise!(Fabricate(:admin), raw: "lets totally update the body", tags: ['stuff'])+ result = subject.revise!(admin, raw: "lets totally update the body", tags: ['stuff'])expect(result).to eq(true)post.reloadexpect(post.topic.tags.map(&:name)).to eq(['stuff'])endit "staff can remove all tags" do- result = subject.revise!(Fabricate(:admin), raw: "lets totally update the body", tags: [])+ result = subject.revise!(admin, raw: "lets totally update the body", tags: [])expect(result).to eq(true)post.reloadexpect(post.topic.tags.size).to eq(0)@@ -782,7 +780,7 @@ describe PostRevisor doit "only uses existing tags" doFabricate(:tag, name: 'totally')expect {- @result = subject.revise!(Fabricate(:user), raw: "lets totally update the body", tags: ['totally', 'update'])+ @result = subject.revise!(user, raw: "lets totally update the body", tags: ['totally', 'update'])}.to_not change { Tag.count }expect(@result).to eq(true)post.reload