3 class BrowseHelperTest < ActionView::TestCase
5 include ApplicationHelper
15 def test_printable_name
16 node = create(:node, :with_history, :version => 2)
17 node_v1 = node.old_nodes.find_by(:version => 1)
18 node_v2 = node.old_nodes.find_by(:version => 2)
19 node_v1.redact!(create(:redaction))
21 add_tags_selection(node)
22 add_old_tags_selection(node_v2)
23 add_old_tags_selection(node_v1)
25 node_with_ref_without_name = create(:node)
26 create(:node_tag, :node => node_with_ref_without_name, :k => "ref", :v => "3.1415926")
28 deleted_node = create(:node, :deleted)
30 assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
31 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
32 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
33 assert_dom_equal node.id.to_s, printable_name(node_v1)
34 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, true)
35 assert_dom_equal "#{node.id}, v1", printable_name(node_v1, true)
36 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
40 assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
41 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
42 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
43 assert_dom_equal node.id.to_s, printable_name(node_v1)
44 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, true)
45 assert_dom_equal "#{node.id}, v1", printable_name(node_v1, true)
46 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
50 assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
51 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
52 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
53 assert_dom_equal node.id.to_s, printable_name(node_v1)
54 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, true)
55 assert_dom_equal "#{node.id}, v1", printable_name(node_v1, true)
56 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
60 assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
61 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
62 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
63 assert_dom_equal node.id.to_s, printable_name(node_v1)
64 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, true)
65 assert_dom_equal "#{node.id}, v1", printable_name(node_v1, true)
66 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
70 node = create(:node, :with_history, :version => 2)
71 node_v1 = node.old_nodes.find_by(:version => 1)
72 node_v2 = node.old_nodes.find_by(:version => 2)
73 node_v1.redact!(create(:redaction))
75 add_tags_selection(node)
76 add_old_tags_selection(node_v2)
77 add_old_tags_selection(node_v1)
79 assert_equal "node", link_class("node", create(:node))
80 assert_equal "node deleted", link_class("node", create(:node, :deleted))
82 assert_equal "node building yes shop gift tourism museum", link_class("node", node)
83 assert_equal "node building yes shop gift tourism museum", link_class("node", node_v2)
84 assert_equal "node deleted", link_class("node", node_v1)
88 node = create(:node, :with_history, :version => 2)
89 node_v1 = node.old_nodes.find_by(:version => 1)
90 node_v2 = node.old_nodes.find_by(:version => 2)
91 node_v1.redact!(create(:redaction))
93 add_tags_selection(node)
94 add_old_tags_selection(node_v2)
95 add_old_tags_selection(node_v1)
97 assert_equal "", link_title(create(:node))
98 assert_equal "", link_title(create(:node, :deleted))
100 assert_equal "building=yes, shop=gift, and tourism=museum", link_title(node)
101 assert_equal "building=yes, shop=gift, and tourism=museum", link_title(node_v2)
102 assert_equal "", link_title(node_v1)
106 node = create(:node, :with_history, :version => 2)
107 node_v1 = node.old_nodes.find_by(:version => 1)
108 node_v2 = node.old_nodes.find_by(:version => 2)
109 node_v1.redact!(create(:redaction))
111 add_tags_selection(node)
113 tags = icon_tags(node)
114 assert_equal 3, tags.count
115 assert_includes tags, %w[building yes]
116 assert_includes tags, %w[tourism museum]
117 assert_includes tags, %w[shop gift]
119 add_old_tags_selection(node_v2)
120 add_old_tags_selection(node_v1)
122 tags = icon_tags(node_v2)
123 assert_equal 3, tags.count
124 assert_includes tags, %w[building yes]
125 assert_includes tags, %w[tourism museum]
126 assert_includes tags, %w[shop gift]
128 tags = icon_tags(node_v1)
129 assert_equal 3, tags.count
130 assert_includes tags, %w[building yes]
131 assert_includes tags, %w[tourism museum]
132 assert_includes tags, %w[shop gift]
135 def add_old_tags_selection(old_node)
136 { "building" => "yes",
138 "tourism" => "museum",
139 "name" => "Test Node",
140 "name:pt" => "Nó teste" }.each do |key, value|
141 create(:old_node_tag, :old_node => old_node, :k => key, :v => value)
145 def add_tags_selection(node)
146 { "building" => "yes",
148 "tourism" => "museum",
149 "name" => "Test Node",
150 "name:pt" => "Nó teste" }.each do |key, value|
151 create(:node_tag, :node => node, :k => key, :v => value)
157 def preferred_languages
158 Locale.list(I18n.locale)