shorter method name and better specs
This commit is contained in:
parent
547b571d84
commit
69450750d1
|
@ -34,7 +34,7 @@ class PostMover
|
||||||
)
|
)
|
||||||
DiscourseTagging.tag_topic_by_names(new_topic, Guardian.new(user), tags)
|
DiscourseTagging.tag_topic_by_names(new_topic, Guardian.new(user), tags)
|
||||||
move_posts_to new_topic
|
move_posts_to new_topic
|
||||||
force_user_to_watch_new_topic
|
watch_new_topic
|
||||||
new_topic
|
new_topic
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -226,7 +226,7 @@ class PostMover
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def force_user_to_watch_new_topic
|
def watch_new_topic
|
||||||
TopicUser.change(
|
TopicUser.change(
|
||||||
destination_topic.user,
|
destination_topic.user,
|
||||||
destination_topic.id,
|
destination_topic.id,
|
||||||
|
|
|
@ -264,6 +264,19 @@ describe PostMover do
|
||||||
moderator_post = topic.posts.last
|
moderator_post = topic.posts.last
|
||||||
expect(moderator_post.raw).to include("2 posts were split")
|
expect(moderator_post.raw).to include("2 posts were split")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "forces resulting topic owner to watch the new topic" do
|
||||||
|
new_topic = topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name", category_id: category.id)
|
||||||
|
|
||||||
|
expect(new_topic.posts_count).to eq(2)
|
||||||
|
|
||||||
|
expect(TopicUser.exists?(
|
||||||
|
user_id: another_user,
|
||||||
|
topic_id: new_topic.id,
|
||||||
|
notification_level: TopicUser.notification_levels[:watching],
|
||||||
|
notifications_reason_id: TopicUser.notification_reasons[:created_topic]
|
||||||
|
)).to eq(true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "to an existing topic" do
|
context "to an existing topic" do
|
||||||
|
|
|
@ -58,12 +58,9 @@ RSpec.describe TopicsController do
|
||||||
|
|
||||||
describe 'moving to a new topic' do
|
describe 'moving to a new topic' do
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
let(:user2) { Fabricate(:user) }
|
|
||||||
let(:moderator) { Fabricate(:moderator) }
|
let(:moderator) { Fabricate(:moderator) }
|
||||||
let(:p1) { Fabricate(:post, user: user, post_number: 1) }
|
let(:p1) { Fabricate(:post, user: user, post_number: 1) }
|
||||||
let(:p2) { Fabricate(:post, user: user, post_number: 2, topic: p1.topic) }
|
let(:p2) { Fabricate(:post, user: user, post_number: 2, topic: p1.topic) }
|
||||||
let(:p3) { Fabricate(:post, user: user2, post_number: 3, topic: p1.topic) }
|
|
||||||
let(:p4) { Fabricate(:post, user: user2, post_number: 4, topic: p1.topic) }
|
|
||||||
let!(:topic) { p1.topic }
|
let!(:topic) { p1.topic }
|
||||||
|
|
||||||
it "raises an error without post_ids" do
|
it "raises an error without post_ids" do
|
||||||
|
@ -119,30 +116,6 @@ RSpec.describe TopicsController do
|
||||||
expect(Tag.all.pluck(:name)).to contain_exactly("tag1", "tag2")
|
expect(Tag.all.pluck(:name)).to contain_exactly("tag1", "tag2")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "forces resulting topic owner to watch the new topic" do
|
|
||||||
expect do
|
|
||||||
post "/t/#{topic.id}/move-posts.json", params: {
|
|
||||||
title: 'Logan is a good movie',
|
|
||||||
post_ids: [p3.id, p4.id],
|
|
||||||
}
|
|
||||||
end.to change { Topic.count }.by(1)
|
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
|
|
||||||
result = ::JSON.parse(response.body)
|
|
||||||
|
|
||||||
expect(result['success']).to eq(true)
|
|
||||||
new_topic = p3.reload.topic
|
|
||||||
expect(result['url']).to eq(new_topic.relative_url)
|
|
||||||
|
|
||||||
expect(TopicUser.exists?(
|
|
||||||
user_id: user2.id,
|
|
||||||
topic_id: new_topic.id,
|
|
||||||
notification_level: TopicUser.notification_levels[:watching],
|
|
||||||
notifications_reason_id: TopicUser.notification_reasons[:created_topic]
|
|
||||||
)).to eq(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'when topic has been deleted' do
|
describe 'when topic has been deleted' do
|
||||||
it 'should still be able to move posts' do
|
it 'should still be able to move posts' do
|
||||||
PostDestroyer.new(Fabricate(:admin), topic.first_post).destroy
|
PostDestroyer.new(Fabricate(:admin), topic.first_post).destroy
|
||||||
|
|
Loading…
Reference in New Issue