1816 |
1816 |
distance_of_time_in_words(Time.now, child_page.updated_on)))
|
1817 |
1817 |
end
|
1818 |
1818 |
|
1819 |
|
def test_render_page_hierarchy_when_action_is_export
|
|
1819 |
def test_render_page_hierarchy_when_action_is_export_and_format_html
|
1820 |
1820 |
parent_page = WikiPage.find(1)
|
1821 |
1821 |
child_page = WikiPage.find_by(parent_id: parent_page.id)
|
1822 |
1822 |
pages_by_parent_id = {nil => [parent_page], parent_page.id => [child_page]}
|
1823 |
1823 |
|
1824 |
|
# Change controller and action using stub
|
1825 |
|
controller.stubs(:controller_name).returns('wiki')
|
|
1824 |
# Change action and format using stub
|
|
1825 |
controller.stubs(:params).returns({ format: 'html' })
|
1826 |
1826 |
controller.stubs(:action_name).returns("export")
|
1827 |
1827 |
|
1828 |
1828 |
result = render_page_hierarchy(pages_by_parent_id, nil)
|
... | ... | |
1830 |
1830 |
assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', "##{child_page.title}"
|
1831 |
1831 |
end
|
1832 |
1832 |
|
|
1833 |
def test_render_page_hierarchy_links_when_format_is_html
|
|
1834 |
parent_page = WikiPage.find(1)
|
|
1835 |
child_page = WikiPage.find_by(parent_id: parent_page.id)
|
|
1836 |
pages_by_parent_id = {nil => [parent_page], parent_page.id => [child_page]}
|
|
1837 |
|
|
1838 |
# Change format using stub
|
|
1839 |
controller.stubs(:params).returns({ format: 'html' })
|
|
1840 |
|
|
1841 |
result = render_page_hierarchy(pages_by_parent_id, nil)
|
|
1842 |
assert_select_in result, 'ul.pages-hierarchy li a[href=?]', "#{h(parent_page.pretty_title)}.html"
|
|
1843 |
assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', "#{h(child_page.pretty_title)}.html"
|
|
1844 |
end
|
|
1845 |
|
|
1846 |
def test_render_page_hierarchy_links_when_format_is_pdf
|
|
1847 |
parent_page = WikiPage.find(1)
|
|
1848 |
child_page = WikiPage.find_by(parent_id: parent_page.id)
|
|
1849 |
pages_by_parent_id = {nil => [parent_page], parent_page.id => [child_page]}
|
|
1850 |
|
|
1851 |
# Change request format using stub
|
|
1852 |
format = mock('format')
|
|
1853 |
format.stubs(:pdf?).returns(true)
|
|
1854 |
|
|
1855 |
# Stub the controller's request.format to return the mocked format object
|
|
1856 |
controller.request.stubs(:format).returns(format)
|
|
1857 |
|
|
1858 |
result = render_page_hierarchy(pages_by_parent_id, nil)
|
|
1859 |
parent_page_url = project_wiki_page_url(project_id: parent_page.project, id: parent_page.title, version: nil)
|
|
1860 |
child_page_url = project_wiki_page_url(project_id: child_page.project, id: child_page.title, version: nil)
|
|
1861 |
|
|
1862 |
assert_select_in result, 'ul.pages-hierarchy li a[href=?]', parent_page_url
|
|
1863 |
assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', child_page_url
|
|
1864 |
|
|
1865 |
# Make sure that the pdf? method returns the expected value
|
|
1866 |
assert_equal true, controller.request.format.pdf?
|
|
1867 |
end
|
|
1868 |
|
1833 |
1869 |
def test_link_to_user
|
1834 |
1870 |
user = User.find(2)
|
1835 |
1871 |
result = link_to("John Smith", "/users/2", :class => "user active")
|