From ccd18fe8630c6ef8f0c3fb7eacdb033901a86bb3 Mon Sep 17 00:00:00 2001 From: stephanie-warmenhoven Date: Thu, 23 Apr 2020 20:42:11 -0700 Subject: [PATCH] [#1713] Test for resources_url_tags filter --- app/controllers/moments_controller.rb | 2 +- app/helpers/moments_helper.rb | 15 ++++++++------- spec/helpers/moments_helper_spec.rb | 10 ++++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/controllers/moments_controller.rb b/app/controllers/moments_controller.rb index 267dabe5d8..58464a9715 100644 --- a/app/controllers/moments_controller.rb +++ b/app/controllers/moments_controller.rb @@ -26,7 +26,7 @@ def index def show show_with_comments(@moment) @resources = ResourceRecommendations.new(@moment).call - @resources_tags = resources_url_tags + @resources_tags = resources_url_tags(@moment) end # GET /moments/new diff --git a/app/helpers/moments_helper.rb b/app/helpers/moments_helper.rb index bcdd56d6d8..71433018b7 100644 --- a/app/helpers/moments_helper.rb +++ b/app/helpers/moments_helper.rb @@ -61,6 +61,14 @@ def present_moment_or_strategy(element) storyType: present_object[:story_type] } end + def resources_url_tags(moment) + matched_tags = ResourceRecommendations.new(moment).matched_tags + filter_tags = matched_tags.uniq.map do |t| + "filter[]=#{t}&" + end + URI::encode(filter_tags.join) + end + private def moment_or_strategy_actions(element, present_object) @@ -108,11 +116,4 @@ def get_present_object(element) } end - def resources_url_tags - matched_tags = ResourceRecommendations.new(@moment).matched_tags - filter_tags = matched_tags.uniq.map do |t| - "filter[]=#{t}&" - end - filter_tags.join - end end diff --git a/spec/helpers/moments_helper_spec.rb b/spec/helpers/moments_helper_spec.rb index 6750d5995d..ad197ddb9f 100644 --- a/spec/helpers/moments_helper_spec.rb +++ b/spec/helpers/moments_helper_spec.rb @@ -45,4 +45,14 @@ end end end + + describe '#resources_url_tags' do + let(:user) { create(:user1) } + let(:moment) { create(:moment, name: 'tech industry', user: user) } + output = 'filter[]=tech%20industry&' + subject { controller.resources_url_tags(moment) } + it 'returns a filtered tag of matched resources' do + expect(subject).to eq(output) + end + end end