A platform for community discussion. Free, open, simple.
shorter method name and better specs
OsamaSayegh69450750d1e9
diff --git a/app/models/post_mover.rb b/app/models/post_mover.rbindex ec4cb3f02f0..535ffe50d09 100644--- a/app/models/post_mover.rb+++ b/app/models/post_mover.rb@@ -34,7 +34,7 @@ class PostMover)DiscourseTagging.tag_topic_by_names(new_topic, Guardian.new(user), tags)move_posts_to new_topic- force_user_to_watch_new_topic+ watch_new_topicnew_topicendend@@ -226,7 +226,7 @@ class PostMoverendend- def force_user_to_watch_new_topic+ def watch_new_topicTopicUser.change(destination_topic.user,destination_topic.id,diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rbindex 9f8e49778e1..83d6a68d511 100644--- a/spec/models/post_mover_spec.rb+++ b/spec/models/post_mover_spec.rb@@ -264,6 +264,19 @@ describe PostMover domoderator_post = topic.posts.lastexpect(moderator_post.raw).to include("2 posts were split")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)+ endendcontext "to an existing topic" dodiff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex b57c190756a..e98a2ab94ae 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -58,12 +58,9 @@ RSpec.describe TopicsController dodescribe 'moving to a new topic' dolet(:user) { Fabricate(:user) }- let(:user2) { Fabricate(:user) }let(:moderator) { Fabricate(:moderator) }let(:p1) { Fabricate(:post, user: user, post_number: 1) }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 }it "raises an error without post_ids" do@@ -119,30 +116,6 @@ RSpec.describe TopicsController doexpect(Tag.all.pluck(:name)).to contain_exactly("tag1", "tag2")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' doit 'should still be able to move posts' doPostDestroyer.new(Fabricate(:admin), topic.first_post).destroy