Skip to content

Commit

Permalink
Add time ranges in tag_controller#show (#2618)
Browse files Browse the repository at this point in the history
* Add time ranges in tag_controller#show

* Add functional test for range in tag#show.
  • Loading branch information
rishabhptr authored and jywarren committed Apr 24, 2018
1 parent 291cb33 commit b56de9d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def show
# params[:node_type] - this is an optional param
# if params[:node_type] is nil - use @default_type
@node_type = params[:node_type] || default_type
@start = Time.parse(params[:start]) if params[:start]
@end = Time.parse(params[:end]) if params[:end]

node_type = 'note' if @node_type == 'questions' || @node_type == 'note'
node_type = 'page' if @node_type == 'wiki'
Expand All @@ -97,6 +99,7 @@ def show
.paginate(page: params[:page], per_page: 24)
.order('node_revisions.timestamp DESC')
end
nodes = nodes.where(created: @start.to_i..@end.to_i) if @start && @end

# breaks the parameter
# sets everything to an empty array
Expand Down
4 changes: 3 additions & 1 deletion app/views/tag/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script src="/assets/wikis.js" type="text/javascript"></script>

<div class="col-md-12">

<% if @wiki %>
<div id="wiki-content">
<% if @wiki.main_image %>
Expand Down Expand Up @@ -40,6 +39,9 @@
<% else %>
<h3> Notes on <%= params[:id] %> by <%= link_to(@user.name,"/profile/#{@user.name}") %> </h3>
<% end %>
<% if @start && @end %>
<p>From <%= @start.to_formatted_s(:long) %> to <%= @end.to_formatted_s(:long) %></p>
<% end %>

<h3><% unless @tags.try(:first).try(:parent).nil? %><small>parent: <%= @tags.first.parent %></small><% end %></h3>
<%= render :partial => "notes/format_toggle" if @node_type == "note" %>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

# these need precedence for tag listings
get 'feed/tag/:tagname' => 'tag#rss'
get ':node_type/tag(/:id)' => 'tag#show'
get ':node_type/tag(/:id)(/:start)(/:end)' => 'tag#show'
get 'feed/tag/:tagname/author/:authorname' => 'tag#rss_for_tagged_with_author'
get 'wiki/raw/:id' => 'wiki#raw'
get 'wiki/revisions/:id' => 'wiki#revisions'
Expand Down
21 changes: 15 additions & 6 deletions test/functional/tag_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ def setup
assert_select '#wiki-content', 1
end

test 'tag show range' do
get :show, id: tags(:spectrometer).name,
start: (Time.now - 1.day).strftime('%d-%m-%Y'),
end: Time.now.strftime('%d-%m-%Y')

assert :success
assert_not_nil :tags
end

test 'tag show JSON' do
get :show, id: tags(:spectrometer).name, format: 'json'

Expand Down Expand Up @@ -180,16 +189,16 @@ def setup

test 'wildcard tag should list answered questions' do
get :show, id: 'question:*'

assert_not_nil assigns(:answered_questions)
end

test 'wildcard tag should have a active asked and an inactive answered tab for question' do
get :show, id: 'question:*'

selector = css_select '#asked-tab.active'
assert_equal selector.size, 1
assert_select '#answered-tab', 1
assert_equal selector.size, 1
assert_select '#answered-tab', 1
end

test "wildcard tag show wiki pages with author" do
Expand Down Expand Up @@ -493,7 +502,7 @@ def setup
get :show_for_author, id: tag.name, author: 'jeff'
selector = css_select "ul>li>a[href = '/questions/tag/question:spectrometer/author/jeff']"
assert_equal selector.size, 1
selector = css_select '#questions.active'
selector = css_select '#questions.active'
assert_equal selector.size, 1
end

Expand All @@ -504,14 +513,14 @@ def setup

selector = css_select '#asked-tab.active'
assert_equal selector.size, 1
assert_select '#answered-tab', 1
assert_select '#answered-tab', 1
end

test 'should list answered questions' do
tag = tags(:question)

get :show_for_author, id: tag.name, author: 'jeff'

assert_not_nil assigns(:answered_questions)
end

Expand Down

0 comments on commit b56de9d

Please sign in to comment.