Skip to content

Commit

Permalink
[ifmeorg#1713] Test for resources_url_tags filter
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Warmenhoven committed Apr 24, 2020
1 parent e2d4112 commit ccd18fe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/moments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions app/helpers/moments_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
10 changes: 10 additions & 0 deletions spec/helpers/moments_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ccd18fe

Please sign in to comment.