From f226e4efc0ab4a0ed2de497d3d8db808caa44b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 2 Dec 2014 02:16:30 +0100 Subject: [PATCH] FIX: don't error out when updating a topic with no changes --- app/controllers/topics_controller.rb | 4 ++-- spec/controllers/topics_controller_spec.rb | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 8e8d226d3..9e976f212 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -123,8 +123,8 @@ class TopicsController < ApplicationController guardian.ensure_can_edit!(topic) changes = {} - changes[:title] = params[:title] if params[:title] - changes[:category_id] = params[:category_id] if params[:category_id] + changes[:title] = params[:title] if params[:title] && topic.title != params[:title] + changes[:category_id] = params[:category_id] if params[:category_id] && topic.category_id != params[:category_id].to_i success = true diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index d8500e82d..c8a05095d 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -783,6 +783,12 @@ describe TopicsController do expect(response).not_to be_success end + it "doesn't call the PostRevisor when there is no changes" do + PostRevisor.any_instance.expects(:revise!).never + xhr :put, :update, topic_id: @topic.id, slug: @topic.title, title: @topic.title, category_id: @topic.category_id + expect(response).to be_success + end + context "allow_uncategorized_topics is false" do before do SiteSetting.stubs(:allow_uncategorized_topics).returns(false)