From dc0a758ec6d180dca4ce43d57f5942a893e7b7fc Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 30 Apr 2014 14:21:43 -0400 Subject: [PATCH] FIX: quote whole post button was broken --- app/serializers/post_serializer.rb | 2 +- spec/serializers/post_serializer_spec.rb | 44 ++++++++++++++++-------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb index 35b3951ef..452835ae0 100644 --- a/app/serializers/post_serializer.rb +++ b/app/serializers/post_serializer.rb @@ -181,7 +181,7 @@ class PostSerializer < BasicPostSerializer end def include_raw? - @add_raw.present? && (scope.user.try(:staff?) || yours) + @add_raw.present? && (!object.hidden || scope.user.try(:staff?) || yours) end def include_link_counts? diff --git a/spec/serializers/post_serializer_spec.rb b/spec/serializers/post_serializer_spec.rb index c61ed48b7..773dd0bcd 100644 --- a/spec/serializers/post_serializer_spec.rb +++ b/spec/serializers/post_serializer_spec.rb @@ -77,8 +77,7 @@ describe PostSerializer do context "a hidden post with add_raw enabled" do let(:user) { Fabricate.build(:user) } - let(:raw) { "Offensive stuff here!" } - let(:post) { Fabricate.build(:post, raw: raw, user: user, hidden: true, hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached]) } + let(:raw) { "Raw contents of the post." } def serialized_post_for_user(u) s = PostSerializer.new(post, scope: Guardian.new(u), root: false) @@ -86,22 +85,37 @@ describe PostSerializer do s.as_json end - it "shows the raw post only if authorized to see it" do - serialized_post_for_user(user)[:raw].should == raw - serialized_post_for_user(nil)[:raw].should be_nil - serialized_post_for_user(Fabricate(:user))[:raw].should be_nil - serialized_post_for_user(Fabricate(:moderator))[:raw].should == raw - serialized_post_for_user(Fabricate(:admin))[:raw].should == raw + context "a public post" do + let(:post) { Fabricate.build(:post, raw: raw, user: user) } + + it "includes the raw post for everyone" do + serialized_post_for_user(user)[:raw].should == raw + serialized_post_for_user(nil)[:raw].should == raw + serialized_post_for_user(Fabricate(:user))[:raw].should == raw + serialized_post_for_user(Fabricate(:moderator))[:raw].should == raw + serialized_post_for_user(Fabricate(:admin))[:raw].should == raw + end end - it "can view edit history only if authorized" do - serialized_post_for_user(user)[:can_view_edit_history].should == true - serialized_post_for_user(nil)[:can_view_edit_history].should == false - serialized_post_for_user(Fabricate(:user))[:can_view_edit_history].should == false - serialized_post_for_user(Fabricate(:moderator))[:can_view_edit_history].should == true - serialized_post_for_user(Fabricate(:admin))[:can_view_edit_history].should == true - end + context "a hidden post" do + let(:post) { Fabricate.build(:post, raw: raw, user: user, hidden: true, hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached]) } + it "shows the raw post only if authorized to see it" do + serialized_post_for_user(user)[:raw].should == raw + serialized_post_for_user(nil)[:raw].should be_nil + serialized_post_for_user(Fabricate(:user))[:raw].should be_nil + serialized_post_for_user(Fabricate(:moderator))[:raw].should == raw + serialized_post_for_user(Fabricate(:admin))[:raw].should == raw + end + + it "can view edit history only if authorized" do + serialized_post_for_user(user)[:can_view_edit_history].should == true + serialized_post_for_user(nil)[:can_view_edit_history].should == false + serialized_post_for_user(Fabricate(:user))[:can_view_edit_history].should == false + serialized_post_for_user(Fabricate(:moderator))[:can_view_edit_history].should == true + serialized_post_for_user(Fabricate(:admin))[:can_view_edit_history].should == true + end + end end end