3 class OldWaysControllerTest < ActionDispatch::IntegrationTest
6 { :path => "/way/1/history/2", :method => :get },
7 { :controller => "old_ways", :action => "show", :id => "1", :version => "2" }
11 def test_visible_with_one_version
12 way = create(:way, :with_history)
13 get old_way_path(way, 1)
14 assert_response :success
15 assert_template "old_ways/show"
16 assert_template :layout => "map"
17 assert_select "h4", /^Version/ do
18 assert_select "a[href='#{old_way_path way, 1}']", :count => 0
20 assert_select ".secondary-actions a[href='#{way_version_path way, 1}']", :count => 1
21 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
22 assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0
23 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
26 def test_visible_with_two_versions
27 way = create(:way, :with_history, :version => 2)
28 get old_way_path(way, 1)
29 assert_response :success
30 assert_template "old_ways/show"
31 assert_template :layout => "map"
32 assert_select "h4", /^Version/ do
33 assert_select "a[href='#{old_way_path way, 1}']", :count => 0
35 assert_select ".secondary-actions a[href='#{way_version_path way, 1}']", :count => 1
36 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
37 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
38 assert_select ".secondary-actions a[href='#{old_way_path way, 2}']", :count => 1
40 get old_way_path(way, 2)
41 assert_response :success
42 assert_template "old_ways/show"
43 assert_template :layout => "map"
44 assert_select "h4", /^Version/ do
45 assert_select "a[href='#{old_way_path way, 2}']", :count => 0
47 assert_select ".secondary-actions a[href='#{way_version_path way, 2}']", :count => 1
48 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
49 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
50 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 1
53 def test_visible_with_shared_nodes
54 node = create(:node, :with_history)
55 way = create(:way, :with_history)
56 create(:way_node, :way => way, :node => node)
57 create(:old_way_node, :old_way => way.old_ways.first, :node => node)
58 sharing_way = create(:way, :with_history)
59 create(:way_node, :way => sharing_way, :node => node)
60 create(:old_way_node, :old_way => sharing_way.old_ways.first, :node => node)
61 get old_way_path(way, 1)
62 assert_response :success
63 assert_template "old_ways/show"
64 assert_template :layout => "map"
67 test "show unrevealed redacted versions to anonymous users" do
68 way = create_redacted_way
69 get old_way_path(way, 1)
70 assert_response :success
71 assert_template "old_ways/show"
72 assert_template :layout => "map"
73 assert_select "td", :text => "TOP SECRET", :count => 0
74 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
75 assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0
76 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0
77 assert_select ".secondary-actions a[href='#{way_version_path way, 1}']", :count => 0
80 test "show unrevealed redacted versions to regular users" do
81 session_for(create(:user))
82 way = create_redacted_way
83 get old_way_path(way, 1)
84 assert_response :success
85 assert_template "old_ways/show"
86 assert_template :layout => "map"
87 assert_select "td", :text => "TOP SECRET", :count => 0
88 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
89 assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0
90 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0
91 assert_select ".secondary-actions a[href='#{way_version_path way, 1}']", :count => 0
94 test "show unrevealed redacted versions to moderators" do
95 session_for(create(:moderator_user))
96 way = create_redacted_way
97 get old_way_path(way, 1)
98 assert_response :success
99 assert_template "old_ways/show"
100 assert_template :layout => "map"
101 assert_select "td", :text => "TOP SECRET", :count => 0
102 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
103 assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 1
104 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0
105 assert_select ".secondary-actions a[href='#{way_version_path way, 1}']", :count => 0
108 test "don't reveal redacted versions to anonymous users" do
109 way = create_redacted_way
110 get old_way_path(way, 1, :params => { :show_redactions => true })
111 assert_response :redirect
114 test "don't reveal redacted versions to regular users" do
115 session_for(create(:user))
116 way = create_redacted_way
117 get old_way_path(way, 1, :params => { :show_redactions => true })
118 assert_response :redirect
121 test "reveal redacted versions to moderators" do
122 session_for(create(:moderator_user))
123 way = create_redacted_way
124 get old_way_path(way, 1, :params => { :show_redactions => true })
125 assert_response :success
126 assert_select "td", :text => "TOP SECRET", :count => 1
127 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 1
131 get old_way_path(0, 0)
132 assert_response :not_found
133 assert_template "old_ways/not_found"
134 assert_template :layout => "map"
135 assert_select "#sidebar_content", /way #0 version 0 could not be found/
140 def create_redacted_way
141 create(:way, :with_history, :version => 2) do |way|
142 way_v1 = way.old_ways.find_by(:version => 1)
143 create(:old_way_tag, :old_way => way_v1, :k => "name", :v => "TOP SECRET")
144 way_v1.redact!(create(:redaction))