From 1d793fcc490f2c44f845049d74979cd1791edfbf Mon Sep 17 00:00:00 2001 From: CSammy Date: Mon, 15 Aug 2016 04:35:46 +0200 Subject: [PATCH 1/3] Reused tag stream query for tag pages. --- lib/stream/tag.rb | 20 ++++++++++---------- spec/lib/stream/tag_spec.rb | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/stream/tag.rb b/lib/stream/tag.rb index d8f3ba06b..53372ba57 100644 --- a/lib/stream/tag.rb +++ b/lib/stream/tag.rb @@ -29,7 +29,16 @@ class Stream::Tag < Stream::Base end def posts - @posts ||= construct_post_query + @posts ||= if user + StatusMessage.user_tag_stream(user, tag.id) + else + StatusMessage.public_tag_stream(tag.id) + end + end + + def stream_posts + return [] unless tag + super end def tag_name=(tag_name) @@ -42,13 +51,4 @@ class Stream::Tag < Stream::Base def publisher_opts {:open => true} end - - def construct_post_query - posts = if user.present? - StatusMessage.owned_or_visible_by_user(user) - else - StatusMessage.all_public - end - posts.tagged_with(tag_name, :any => true) - end end diff --git a/spec/lib/stream/tag_spec.rb b/spec/lib/stream/tag_spec.rb index 5e1205c83..7bcbf559a 100644 --- a/spec/lib/stream/tag_spec.rb +++ b/spec/lib/stream/tag_spec.rb @@ -80,7 +80,7 @@ describe Stream::Tag do describe 'shared behaviors' do before do - @stream = Stream::Tag.new(FactoryGirl.create(:user), "test") + @stream = Stream::Tag.new(FactoryGirl.create(:user), FactoryGirl.create(:tag).name) end it_should_behave_like 'it is a stream' end From adc9492bf0e32ab44595c06550eda20bf4ea1638 Mon Sep 17 00:00:00 2001 From: CSammy Date: Mon, 15 Aug 2016 04:36:18 +0200 Subject: [PATCH 2/3] Added tests for various result cardinalities of tag pages. --- spec/lib/stream/tag_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/lib/stream/tag_spec.rb b/spec/lib/stream/tag_spec.rb index 7bcbf559a..75952680a 100644 --- a/spec/lib/stream/tag_spec.rb +++ b/spec/lib/stream/tag_spec.rb @@ -85,6 +85,25 @@ describe Stream::Tag do it_should_behave_like 'it is a stream' end + describe '#stream_posts' do + it "returns an empty array if the tag does not exist" do + stream = Stream::Tag.new(FactoryGirl.create(:user), "test") + expect(stream.stream_posts).to eq([]) + end + + it "returns an empty array if there are no visible posts for the tag" do + alice.post(:status_message, text: "#what", public: false, to: "all") + stream = Stream::Tag.new(nil, "what") + expect(stream.stream_posts).to eq([]) + end + + it "returns the post containing the tag" do + post = alice.post(:status_message, text: "#what", public: true) + stream = Stream::Tag.new(FactoryGirl.create(:user), "what") + expect(stream.stream_posts).to eq([post]) + end + end + describe '#tag_name=' do it 'downcases the tag' do stream = Stream::Tag.new(nil, "WHAT") From 8491df162590d437fa20cb879990d1461a4a030d Mon Sep 17 00:00:00 2001 From: CSammy Date: Mon, 15 Aug 2016 04:59:54 +0200 Subject: [PATCH 3/3] Added test for loading of previous posts on a tag page. --- spec/controllers/tags_controller_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb index ebcf401ff..663251a10 100644 --- a/spec/controllers/tags_controller_spec.rb +++ b/spec/controllers/tags_controller_spec.rb @@ -107,6 +107,18 @@ describe TagsController, :type => :controller do get :show, :name => 'foo', :format => :mobile expect(response).to be_success end + + it "returns the post with the correct age" do + post2 = eve.post( + :status_message, + text: "#what #yes #hellyes #foo tagged second post", + public: true, + created_at: @post.created_at - 1.day + ) + get :show, name: "what", max_time: @post.created_at, format: :json + expect(JSON.parse(response.body).size).to be(1) + expect(JSON.parse(response.body).first["guid"]).to eq(post2.guid) + end end end end