From 5e1de292e909fe35595d8e7fc86ae2f8637046da Mon Sep 17 00:00:00 2001 From: Sidharth Date: Wed, 31 Jan 2018 22:44:40 +0530 Subject: [PATCH] Maps and Question Tests --- app/controllers/tag_controller.rb | 37 ++++++++++------ app/views/tag/show.html.erb | 3 +- test/fixtures/node_tags.yml | 6 +++ test/fixtures/nodes.yml | 12 ++++++ test/functional/tag_controller_test.rb | 59 +++++++++++++++++++++++++- 5 files changed, 100 insertions(+), 17 deletions(-) diff --git a/app/controllers/tag_controller.rb b/app/controllers/tag_controller.rb index 0dc599f972b..fd564b59f36 100644 --- a/app/controllers/tag_controller.rb +++ b/app/controllers/tag_controller.rb @@ -138,15 +138,10 @@ def show end def show_for_author + # try for a matching /wiki/_TAGNAME_ or /_TAGNAME_ @wiki = Node.where(path: "/wiki/#{params[:id]}").try(:first) || Node.where(path: "/#{params[:id]}").try(:first) @wiki = Node.find(@wiki.power_tag('redirect')) if @wiki&.has_power_tag('redirect') - if params[:id][-1..-1] == '*' # wildcard tags - @wildcard = true - @tags = Tag.where('name LIKE (?)', params[:id][0..-2] + '%') - else - @tags = Tag.where(name: params[:id]) - end - @tagname = params[:id] + default_type = if params[:id].match('question:') 'questions' else @@ -156,21 +151,35 @@ def show_for_author # params[:node_type] - this is an optional param # if params[:node_type] is nil - use @default_type @node_type = params[:node_type] || default_type - @user = User.find_by(name: params[:author]) - @title = "'" + @tagname.to_s + "' by " + params[:author] + node_type = 'note' if @node_type == 'questions' || @node_type == 'note' + node_type = 'page' if @node_type == 'wiki' + node_type = 'map' if @node_type == 'maps' qids = Node.questions.where(status: 1).collect(&:nid) + + if params[:id][-1..-1] == '*' # wildcard tags + @wildcard = true + @tags = Tag.where('name LIKE (?)', params[:id][0..-2] + '%') + else + @tags = Tag.where(name: params[:id]) + end + @tagname = params[:id] + @user = User.find_by(name: params[:author]) + nodes = Tag.tagged_nodes_by_author(@tagname, @user) - .paginate(page: params[:page], per_page: 24) + .where(status: 1, type: node_type) + .paginate(page: params[:page], per_page: 24) + + # breaks the parameter + # sets everything to an empty array + set_sidebar :tags, [params[:id]] @notes = nodes.where('node.nid NOT IN (?)', qids) if @node_type == 'note' - @unpaginated = true - node_type = 'note' if @node_type == 'questions' || @node_type == 'note' - node_type = 'page' if @node_type == 'wiki' - node_type = 'map' if @node_type == 'maps' @questions = nodes.where('node.nid IN (?)', qids) if @node_type == 'questions' @wikis = nodes if @node_type == 'wiki' @nodes = nodes if @node_type == 'maps' + @title = "'" + @tagname.to_s + "' by " + params[:author] + @unpaginated = true # the following could be refactored into a Tag.contributor_count method: notes = Node.where(status: 1, type: 'note') .select('node.nid, node.type, node.uid, node.status, term_data.*, community_tags.*') diff --git a/app/views/tag/show.html.erb b/app/views/tag/show.html.erb index 65931a6cf4b..d2d9628f4f7 100644 --- a/app/views/tag/show.html.erb +++ b/app/views/tag/show.html.erb @@ -63,13 +63,14 @@ <% unless @wildcard %>

<%= raw t('tag.show.ask_question', :tag => params[:id].gsub('question:', '')) %> <%= raw t('tag.show.or_subscribe_to_answer', :url1 => "/subscribe/tag/question:"+params[:id].gsub('question:', '')) %>

<% end %>