Skip to content
This repository was archived by the owner on Mar 20, 2019. It is now read-only.

Commit b56a5bb

Browse files
committed
Moved some convoluted logic to determine which protip search results into a helper and created a placeholder spec
1 parent afa070d commit b56a5bb

File tree

3 files changed

+34
-36
lines changed

3 files changed

+34
-36
lines changed

app/helpers/protips_helper.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
require 'cfm'
2+
23
module ProtipsHelper
34

5+
def protip_search_results_to_render(protips)
6+
(protips.results if protips.respond_to?(:results)) || protips.try(:all)
7+
end
8+
49
def protip_summary
510
"A protip by #{@protip.user.username} about #{@protip.topics.to_sentence}."
611
end
@@ -296,12 +301,12 @@ def protip_stat_class(protip)
296301

297302
def formatted_best_stat_value(protip)
298303
value =
299-
case best_stat_name(protip).to_sym
300-
when :views
301-
views_stat_value(protip)
302-
else
303-
best_stat_value(protip)
304-
end
304+
case best_stat_name(protip).to_sym
305+
when :views
306+
views_stat_value(protip)
307+
else
308+
best_stat_value(protip)
309+
end
305310
number_to_human(value, units: {unit: "", thousand: "k"})
306311
end
307312

app/views/protips/topic.html.haml

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
1-
-#-content_for :javascript do
2-
-# -if @topic_user
3-
-# %script="logUsage('viewed', 'users protips');"
4-
-# -else
5-
-# %script="logUsage('viewed', 'topics protips');"
6-
7-
= render :partial => "head", :locals => {:topic => @topic}
1+
= render(partial: 'head', locals: { topic: @topic })
82

93
.secondary-notice
104
%p
11-
-if @topic_user
12-
-if @topic_user && signed_in? && @topic_user == current_user
5+
- if @topic_user
6+
- if @topic_user && signed_in? && @topic_user == current_user
137
These are your links, code snippets, posts and other pro tips you have created or upvoted. Have a quick pro tip to
14-
=link_to('share?', new_protip_path, 'data-action' => 'create protip', 'data-from' => 'own protips page')
8+
= link_to('share?', new_protip_path, 'data-action' => 'create protip', 'data-from' => 'own protips page')
159
or
16-
=link_to('learn more', faq_path, :class => 'track', 'data-action' => 'view faq', 'data-from' => 'own protips page')
10+
= link_to('learn more', faq_path, class: 'track', 'data-action' => 'view faq', 'data-from' => 'own protips page')
1711
- if @topic_user.protips.reject(&:created_automagically?).count == 0
1812
%br Pro tips you currently see here are created automagically from repos you follow/consider useful or slideshares you've created
19-
-else
20-
==These are the links, code snippets, posts, and other pro tips #{@topic_user.display_name} has created. Have your own to
21-
=link_to('share?', new_protip_path, 'data-action' => 'create protip', 'data-from' => 'user protips page')
13+
- else
14+
== These are the links, code snippets, posts, and other pro tips #{@topic_user.display_name} has created. Have your own to
15+
= link_to('share?', new_protip_path, 'data-action' => 'create protip', 'data-from' => 'user protips page')
2216
or
23-
=link_to('learn more', faq_path, :class => 'track', 'data-action' => 'view faq', 'data-from' => 'user protips page')
24-
-elsif signed_in?
25-
%p
26-
=link_to('Share', new_protip_path(:topics => @topic), 'data-action' => 'create protip', 'data-from' => 'user protips page') + " a link, code snippet, post or other pro tip about #{@topic}"
27-
-else
28-
=link_to('Sign in', root_path)
29-
==to start sharing your #{@topic} pro tips or
30-
=link_to('learn more', faq_path, :class => 'track', 'data-action' => 'view faq', 'data-from' => 'user protips page')
17+
= link_to('learn more', faq_path, class: 'track', 'data-action' => 'view faq', 'data-from' => 'user protips page')
18+
- elsif signed_in?
19+
%p= link_to('Share', new_protip_path(topics: @topic), 'data-action' => 'create protip', 'data-from' => 'user protips page') + " a link, code snippet, post or other pro tip about #{@topic}"
20+
- else
21+
= link_to('Sign in', root_path)
22+
== to start sharing your #{@topic} pro tips or
23+
= link_to('learn more', faq_path, class: 'track', 'data-action' => 'view faq', 'data-from' => 'user protips page')
3124

32-
#browse-results
33-
= render :partial => "grid", :locals => {:protips => (@protips.results if @protips.respond_to?(:results)) || @protips.try(:all), :collection => @protips, :url => :tagged_protips_path, :hide_more => false, :mode => 'popup'}
25+
#browse-results= render(partial: 'grid', locals: { protips: protip_search_results_to_render(@protips), collection: @protips, url: :tagged_protips_path, hide_more: false, mode: 'popup' })

spec/helpers/protips_helper_spec.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
require 'spec_helper'
2-
3-
RSpec.describe ProtipsHelper, :type => :helper do
4-
5-
6-
end
1+
RSpec.describe ProtipsHelper, type: :helper do
2+
describe ".protip_search_results_to_render" do
3+
it 'has no protips to render' do
4+
expect(helper.protip_search_results_to_render(nil)).to be_nil
5+
end
6+
end
7+
end

0 commit comments

Comments
 (0)