Skip to content

Commit

Permalink
[#785] Fix Tag Links on Document Pages
Browse files Browse the repository at this point in the history
Fix broken links on the various Document pages for Tags with spaces in
their titles.

Closes #785
  • Loading branch information
prikhi committed Mar 24, 2016
1 parent 00ee5f8 commit 1840d3e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
4 changes: 2 additions & 2 deletions fec/documents/templates/documents/document_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ <h5>Shared by
<!-- Tags -->
{% keywords_for document as keywords %}
{% if keywords %}
<h5>
<h5 class="document-keywords">
Tags:
{% for keyword in keywords %}<a
href="{% url "document_tag_list" tag=keyword.title %}">{{ keyword.title }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}
href="{% url "document_tag_list" tag=keyword.slug %}">{{ keyword.title }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}
</h5>
<br />
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
{# Tags #}
{% keywords_for document as keywords %}
{% if keywords and show_tags %}
<small>
<small class='document-keywords'>
({% for keyword in keywords %}<a
href="{% url "document_tag_list" tag=keyword.title %}">{{ keyword.title }}</a>{% if not forloop.last %}, {% endif %}{% endfor %})
href="{% url "document_tag_list" tag=keyword.slug %}">{{ keyword.title }}</a>{% if not forloop.last %}, {% endif %}{% endfor %})
</small>
{% endif %}
</li>
Expand Down
33 changes: 33 additions & 0 deletions fec/functional_tests/document_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This module contains functional tests that validate Community Pages."""
from django.core.urlresolvers import reverse
from mezzanine.generic.models import Keyword, AssignedKeyword

from communities.models import Community
from fec.utils import SeleniumTestCase
Expand Down Expand Up @@ -125,6 +126,17 @@ def test_page_contains_childrens_documents(self):
self.assertIn(self.doc_one.title, docs[0].text)
self.assertIn(self.doc_two.title, docs[1].text)

def test_tag_link_is_valid(self):
"""Entries with a Tag should have a valid link to a Tag page.
The link should use the Tag's slug, in case there are spaces in the
Tag's title. See issue #785.
"""
self.tag, _ = Keyword.objects.get_or_create(title='Tag With Spaces')
self.doc_one.keywords.add(AssignedKeyword(keyword=self.tag))
self.selenium.refresh()
tag_link_is_valid(self)


class DocumentDetailPageTests(SeleniumTestCase):
"""Test Expectations for the Document Detail Pages."""
Expand All @@ -138,6 +150,7 @@ def setUp(self):
self.document = Document.objects.create(
title="Darmok & Jalad", category=self.category,
community=self.community, contents="Treaty of Algeron, 2311.")

self.selenium.get(self.live_server_url +
self.document.get_absolute_url())

Expand Down Expand Up @@ -167,3 +180,23 @@ def test_page_contains_document_contents(self):
contents = self.selenium.find_element_by_css_selector(
"#document-contents")
self.assertEqual(self.document.contents, contents.text)

def test_tag_link_is_valid(self):
"""Entries with a Tag should have a valid link to a Tag page.
The link should use the Tag's slug, in case there are spaces in the
Tag's title. See issue #785.
"""
self.tag, _ = Keyword.objects.get_or_create(title='Tag With Spaces')
self.document.keywords.add(AssignedKeyword(keyword=self.tag))
self.selenium.refresh()
tag_link_is_valid(self)


def tag_link_is_valid(obj):
"""A generic test that ensures a Document's Tag link returns a 200."""
tag_link = obj.selenium.find_element_by_css_selector(
".document-keywords a")
response = obj.client.get(tag_link.get_attribute('href'))

obj.assertEqual(response.status_code, 200)

0 comments on commit 1840d3e

Please sign in to comment.