3 class OldWaysControllerTest < ActionDispatch::IntegrationTest
6 { :path => "/way/1/history", :method => :get },
7 { :controller => "old_ways", :action => "index", :id => "1" }
10 { :path => "/way/1/history/2", :method => :get },
11 { :controller => "old_ways", :action => "show", :id => "1", :version => "2" }
16 way = create(:way, :with_history)
17 sidebar_browse_check :way_history_path, way.id, "browse/history"
18 assert_select "h4", /^Version/ do
19 assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1
23 def test_history_of_redacted
24 way = create(:way, :with_history, :version => 4)
25 way_v1 = way.old_ways.find_by(:version => 1)
26 way_v1.redact!(create(:redaction))
27 way_v3 = way.old_ways.find_by(:version => 3)
28 way_v3.redact!(create(:redaction))
30 get way_history_path(:id => way)
31 assert_response :success
32 assert_template "browse/history"
34 # there are 4 revisions of the redacted way, but only 2
35 # should be showing details here.
36 assert_select ".browse-section", 4
37 assert_select ".browse-section.browse-redacted", 2
38 assert_select ".browse-section.browse-way", 2
41 def test_unredacted_history_of_redacted
42 session_for(create(:moderator_user))
43 way = create(:way, :with_history, :version => 4)
44 way_v1 = way.old_ways.find_by(:version => 1)
45 way_v1.redact!(create(:redaction))
46 way_v3 = way.old_ways.find_by(:version => 3)
47 way_v3.redact!(create(:redaction))
49 get way_history_path(:id => way, :params => { :show_redactions => true })
50 assert_response :success
51 assert_template "browse/history"
53 assert_select ".browse-section", 4
54 assert_select ".browse-section.browse-redacted", 0
55 assert_select ".browse-section.browse-way", 4
58 def test_visible_with_one_version
59 way = create(:way, :with_history)
60 get old_way_path(way, 1)
61 assert_response :success
62 assert_template "old_ways/show"
63 assert_template :layout => "map"
64 assert_select "h4", /^Version/ do
65 assert_select "a[href='#{old_way_path way, 1}']", :count => 0
67 assert_select ".secondary-actions a[href='#{api_old_way_path way, 1}']", :count => 1
68 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
69 assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0
70 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
73 def test_visible_with_two_versions
74 way = create(:way, :with_history, :version => 2)
75 get old_way_path(way, 1)
76 assert_response :success
77 assert_template "old_ways/show"
78 assert_template :layout => "map"
79 assert_select "h4", /^Version/ do
80 assert_select "a[href='#{old_way_path way, 1}']", :count => 0
82 assert_select ".secondary-actions a[href='#{api_old_way_path way, 1}']", :count => 1
83 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
84 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
85 assert_select ".secondary-actions a[href='#{old_way_path way, 2}']", :count => 1
87 get old_way_path(way, 2)
88 assert_response :success
89 assert_template "old_ways/show"
90 assert_template :layout => "map"
91 assert_select "h4", /^Version/ do
92 assert_select "a[href='#{old_way_path way, 2}']", :count => 0
94 assert_select ".secondary-actions a[href='#{api_old_way_path way, 2}']", :count => 1
95 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
96 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
97 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 1
100 def test_visible_with_shared_nodes
101 node = create(:node, :with_history)
102 way = create(:way, :with_history)
103 create(:way_node, :way => way, :node => node)
104 create(:old_way_node, :old_way => way.old_ways.first, :node => node)
105 sharing_way = create(:way, :with_history)
106 create(:way_node, :way => sharing_way, :node => node)
107 create(:old_way_node, :old_way => sharing_way.old_ways.first, :node => node)
108 get old_way_path(way, 1)
109 assert_response :success
110 assert_template "old_ways/show"
111 assert_template :layout => "map"
114 test "show unrevealed redacted versions to anonymous users" do
115 way = create_redacted_way
116 get old_way_path(way, 1)
117 assert_response :success
118 assert_template "old_ways/show"
119 assert_template :layout => "map"
120 assert_select "td", :text => "TOP SECRET", :count => 0
121 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
122 assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0
123 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0
124 assert_select ".secondary-actions a[href='#{api_old_way_path way, 1}']", :count => 0
127 test "show unrevealed redacted versions to regular users" do
128 session_for(create(:user))
129 way = create_redacted_way
130 get old_way_path(way, 1)
131 assert_response :success
132 assert_template "old_ways/show"
133 assert_template :layout => "map"
134 assert_select "td", :text => "TOP SECRET", :count => 0
135 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
136 assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0
137 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0
138 assert_select ".secondary-actions a[href='#{api_old_way_path way, 1}']", :count => 0
141 test "show unrevealed redacted versions to moderators" do
142 session_for(create(:moderator_user))
143 way = create_redacted_way
144 get old_way_path(way, 1)
145 assert_response :success
146 assert_template "old_ways/show"
147 assert_template :layout => "map"
148 assert_select "td", :text => "TOP SECRET", :count => 0
149 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
150 assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 1
151 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0
152 assert_select ".secondary-actions a[href='#{api_old_way_path way, 1}']", :count => 0
155 test "don't reveal redacted versions to anonymous users" do
156 way = create_redacted_way
157 get old_way_path(way, 1, :params => { :show_redactions => true })
158 assert_response :redirect
161 test "don't reveal redacted versions to regular users" do
162 session_for(create(:user))
163 way = create_redacted_way
164 get old_way_path(way, 1, :params => { :show_redactions => true })
165 assert_response :redirect
168 test "reveal redacted versions to moderators" do
169 session_for(create(:moderator_user))
170 way = create_redacted_way
171 get old_way_path(way, 1, :params => { :show_redactions => true })
172 assert_response :success
173 assert_select "td", :text => "TOP SECRET", :count => 1
174 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 1
178 get old_way_path(0, 0)
179 assert_response :not_found
180 assert_template "old_ways/not_found"
181 assert_template :layout => "map"
182 assert_select "#sidebar_content", /way #0 version 0 could not be found/
185 def test_show_timeout
186 way = create(:way, :with_history)
187 with_settings(:web_timeout => -1) do
188 get old_way_path(way, 1)
190 assert_response :error
191 assert_template :layout => "map"
192 assert_dom "h2", "Timeout Error"
193 assert_dom "p", /#{Regexp.quote("the way with the id #{way.id}")}/
198 def create_redacted_way
199 create(:way, :with_history, :version => 2) do |way|
200 way_v1 = way.old_ways.find_by(:version => 1)
201 create(:old_way_tag, :old_way => way_v1, :k => "name", :v => "TOP SECRET")
202 way_v1.redact!(create(:redaction))