From a8a0be0b34921c3571b7301ca7d8c7d7c6a520c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 12 Nov 2014 16:34:30 +0100 Subject: [PATCH] FIX: change the unlisted/invisible topic state only when unhiding the first post --- app/models/post.rb | 2 +- spec/models/post_spec.rb | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index d67dc4cd2ef..b4b64f9696b 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -299,7 +299,7 @@ class Post < ActiveRecord::Base def unhide! self.update_attributes(hidden: false, hidden_at: nil, hidden_reason_id: nil) - self.topic.update_attributes(visible: true) + self.topic.update_attributes(visible: true) if post_number == 1 save(validate: false) publish_change_to_clients!(:acted) end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 6b21e685240..d7d714a1a12 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -828,8 +828,10 @@ describe Post do describe ".unhide!" do before { SiteSetting.stubs(:unique_posts_mins).returns(5) } - it "will unhide the post" do - post = create_post(user: Fabricate(:newuser)) + it "will unhide the first post & make the topic visible" do + hidden_topic = Fabricate(:topic, visible: false) + + post = create_post(topic: hidden_topic) post.update_columns(hidden: true, hidden_at: Time.now, hidden_reason_id: 1) post.reload @@ -838,10 +840,30 @@ describe Post do post.expects(:publish_change_to_clients!).with(:acted) post.unhide! + post.reload + hidden_topic.reload post.hidden.should == false + hidden_topic.visible.should == true end end + it "will unhide the post but will keep the topic invisible/unlisted" do + hidden_topic = Fabricate(:topic, visible: false) + first_post = create_post(topic: hidden_topic) + second_post = create_post(topic: hidden_topic) + + second_post.update_columns(hidden: true, hidden_at: Time.now, hidden_reason_id: 1) + second_post.expects(:publish_change_to_clients!).with(:acted) + + second_post.unhide! + + second_post.reload + hidden_topic.reload + + second_post.hidden.should == false + hidden_topic.visible.should == false + end + end