From 8c58206e63507c9152b91b2e431a9a44e01080ce Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Fri, 26 Aug 2016 21:04:57 +0200 Subject: [PATCH] Fix links of more-button on mobile streams Fixes #6999 closes #7036 --- Changelog.md | 1 + app/helpers/stream_helper.rb | 28 ++++++++++++++++-------- spec/helpers/stream_helper_spec.rb | 34 ++++++++++++++++++++++-------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/Changelog.md b/Changelog.md index 388087832..da66cf97c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,6 +11,7 @@ * Post comments no longer get collapsed when interacting with a post [#7040](https://github.com/diaspora/diaspora/pull/7040) * Closed accounts will no longer show up in the account search [#7042](https://github.com/diaspora/diaspora/pull/7042) * Code blocks in conversations no longer overflow the content [#7055](https://github.com/diaspora/diaspora/pull/7055) +* More buttons in mobile streams are fixed [#7036](https://github.com/diaspora/diaspora/pull/7036) ## Features * Deleted comments will be removed when loading more comments [#7045](https://github.com/diaspora/diaspora/pull/7045) diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index f3eb25415..73e23d25c 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -8,16 +8,8 @@ module StreamHelper tag_path(:name => @stream.tag_name, :max_time => time_for_scroll(@stream)) elsif controller.instance_of?(PeopleController) local_or_remote_person_path(@person, :max_time => time_for_scroll(@stream)) - elsif controller.instance_of?(PostsController) - public_stream_path(:max_time => time_for_scroll(@stream)) elsif controller.instance_of?(StreamsController) - if current_page?(:stream) - stream_path(:max_time => time_for_scroll(@stream)) - elsif current_page?(:aspects_stream) - aspects_stream_path(:max_time => time_for_scroll(@stream), :a_ids => session[:a_ids]) - else - activity_stream_path(:max_time => time_for_scroll(@stream)) - end + next_stream_path else raise 'in order to use pagination for this new controller, update next_page_path in stream helper' end @@ -29,6 +21,24 @@ module StreamHelper private + def next_stream_path + if current_page?(:stream) + stream_path(max_time: time_for_scroll(@stream)) + elsif current_page?(:activity_stream) + activity_stream_path(max_time: time_for_scroll(@stream)) + elsif current_page?(:aspects_stream) + aspects_stream_path(max_time: time_for_scroll(@stream), a_ids: session[:a_ids]) + elsif current_page?(:public_stream) + public_stream_path(max_time: time_for_scroll(@stream)) + elsif current_page?(:mentioned_stream) + mentioned_stream_path(max_time: time_for_scroll(@stream)) + elsif current_page?(:followed_tags_stream) + followed_tags_stream_path(max_time: time_for_scroll(@stream)) + else + raise "in order to use pagination for this new stream, update next_stream_path in stream helper" + end + end + def time_for_scroll(stream) if stream.stream_posts.empty? (Time.now() + 1).to_i diff --git a/spec/helpers/stream_helper_spec.rb b/spec/helpers/stream_helper_spec.rb index b7c39ce10..7705409b3 100644 --- a/spec/helpers/stream_helper_spec.rb +++ b/spec/helpers/stream_helper_spec.rb @@ -2,9 +2,9 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -require 'spec_helper' +require "spec_helper" -describe StreamHelper, :type => :helper do +describe StreamHelper, type: :helper do describe "next_page_path" do def build_controller controller_class controller_class.new.tap {|c| c.request = controller.request } @@ -13,30 +13,46 @@ describe StreamHelper, :type => :helper do @stream = Stream::Base.new(alice, :max_time => Time.now) end - it 'works for public page' do - allow(helper).to receive(:controller).and_return(build_controller(PostsController)) - expect(helper.next_page_path).to include '/public' + it "works for public page when current page is public stream" do + allow(helper).to receive(:current_page?).and_return(false) + expect(helper).to receive(:current_page?).with(:public_stream).and_return(true) + allow(helper).to receive(:controller).and_return(build_controller(StreamsController)) + expect(helper.next_page_path).to include "/public" end - it 'works for stream page when current page is stream' do + it "works for stream page when current page is stream" do allow(helper).to receive(:current_page?).and_return(false) expect(helper).to receive(:current_page?).with(:stream).and_return(true) allow(helper).to receive(:controller).and_return(build_controller(StreamsController)) expect(helper.next_page_path).to include stream_path end - it 'works for aspects page when current page is aspects' do + it "works for aspects page when current page is aspects" do allow(helper).to receive(:current_page?).and_return(false) expect(helper).to receive(:current_page?).with(:aspects_stream).and_return(true) allow(helper).to receive(:controller).and_return(build_controller(StreamsController)) expect(helper.next_page_path).to include aspects_stream_path end - it 'works for activity page when current page is not stream or aspects' do + it "works for activity page when current page is activity stream" do allow(helper).to receive(:current_page?).and_return(false) + expect(helper).to receive(:current_page?).with(:activity_stream).and_return(true) allow(helper).to receive(:controller).and_return(build_controller(StreamsController)) - # binding.pry expect(helper.next_page_path).to include activity_stream_path end + + it "works for mentioned page when current page is mentioned stream" do + allow(helper).to receive(:current_page?).and_return(false) + expect(helper).to receive(:current_page?).with(:mentioned_stream).and_return(true) + allow(helper).to receive(:controller).and_return(build_controller(StreamsController)) + expect(helper.next_page_path).to include mentioned_stream_path + end + + it "works for followed tags page when current page is followed tags stream" do + allow(helper).to receive(:current_page?).and_return(false) + expect(helper).to receive(:current_page?).with(:followed_tags_stream).and_return(true) + allow(helper).to receive(:controller).and_return(build_controller(StreamsController)) + expect(helper.next_page_path).to include followed_tags_stream_path + end end end