From 7efdccdbc55f4166278fc8ad181ceafc509b0241 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Tue, 26 Jun 2018 16:59:33 +0530 Subject: [PATCH] FIX: allow staff to remove tags from queued topics --- app/controllers/queued_posts_controller.rb | 4 ++-- spec/requests/queued_posts_controller_spec.rb | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/controllers/queued_posts_controller.rb b/app/controllers/queued_posts_controller.rb index 7db439e929b..6b31c14d5ae 100644 --- a/app/controllers/queued_posts_controller.rb +++ b/app/controllers/queued_posts_controller.rb @@ -25,10 +25,10 @@ class QueuedPostsController < ApplicationController update_params = params[:queued_post] qp.raw = update_params[:raw] if update_params[:raw].present? - unless qp.topic_id + if qp.topic_id.blank? && params[:queued_post][:state].blank? qp.post_options['title'] = update_params[:title] if update_params[:title].present? qp.post_options['category'] = update_params[:category_id].to_i if update_params[:category_id].present? - qp.post_options['tags'] = update_params[:tags] if update_params[:tags].present? + qp.post_options['tags'] = update_params[:tags] end qp.save(validate: false) diff --git a/spec/requests/queued_posts_controller_spec.rb b/spec/requests/queued_posts_controller_spec.rb index d8911e52e10..d17d2c4367c 100644 --- a/spec/requests/queued_posts_controller_spec.rb +++ b/spec/requests/queued_posts_controller_spec.rb @@ -100,6 +100,23 @@ describe QueuedPostsController do expect(queued_topic.post_options['category']).to eq(changes[:category_id]) expect(queued_topic.post_options['tags']).to eq(changes[:tags]) end + + it 'removes tags if not present' do + queued_topic.post_options[:tags] = ['another-tag'] + queued_topic.save! + + put "/queued_posts/#{queued_topic.id}.json", params: { + queued_post: changes.except(:tags) + } + + expect(response.status).to eq(200) + queued_topic.reload + + expect(queued_topic.raw).to eq(changes[:raw]) + expect(queued_topic.post_options['title']).to eq(changes[:title]) + expect(queued_topic.post_options['category']).to eq(changes[:category_id]) + expect(queued_topic.post_options['tags']).to be_nil + end end context 'when it is a reply' do