Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time ranges in tag_controller#show #2618

Merged
merged 2 commits into from
Apr 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -143,6 +143,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 @@ -181,16 +190,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 @@ -494,7 +503,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 @@ -505,14 +514,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