Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/2917' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Oct 28, 2020
2 parents b704f59 + c04d056 commit 048ab33
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require:
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 370
Max: 250

# Offense count: 36
# Configuration parameters: AllowSafeAssignment.
Expand Down
26 changes: 22 additions & 4 deletions test/controllers/api/map_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,17 @@ def test_map
end
assert_response :success, "Expected scucess with the map call"
assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
assert_select "bounds[minlon='#{format('%<lon>.7f', :lon => minlon)}'][minlat='#{format('%<lat>.7f', :lat => minlat)}'][maxlon='#{format('%<lon>.7f', :lon => maxlon)}'][maxlat='#{format('%<lat>.7f', :lat => maxlat)}']", :count => 1
assert_select "node[id='#{node.id}'][lat='#{format('%<lat>.7f', :lat => node.lat)}'][lon='#{format('%<lon>.7f', :lon => node.lon)}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
assert_select "bounds[minlon='#{format('%<lon>.7f', :lon => minlon)}']" \
"[minlat='#{format('%<lat>.7f', :lat => minlat)}']" \
"[maxlon='#{format('%<lon>.7f', :lon => maxlon)}']" \
"[maxlat='#{format('%<lat>.7f', :lat => maxlat)}']", :count => 1
assert_select "node[id='#{node.id}']" \
"[lat='#{format('%<lat>.7f', :lat => node.lat)}']" \
"[lon='#{format('%<lon>.7f', :lon => node.lon)}']" \
"[version='#{node.version}']" \
"[changeset='#{node.changeset_id}']" \
"[visible='#{node.visible}']" \
"[timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
# This should really be more generic
assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
end
Expand Down Expand Up @@ -205,8 +214,17 @@ def test_map_inclusive
get map_path(:bbox => bbox)
assert_response :success, "The map call should have succeeded"
assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1
assert_select "node[id='#{node.id}'][lat='#{format('%<lat>.7f', :lat => node.lat)}'][lon='#{format('%<lon>.7f', :lon => node.lon)}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
assert_select "bounds[minlon='#{node.lon}']" \
"[minlat='#{node.lat}']" \
"[maxlon='#{node.lon}']" \
"[maxlat='#{node.lat}']", :count => 1
assert_select "node[id='#{node.id}']" \
"[lat='#{format('%<lat>.7f', :lat => node.lat)}']" \
"[lon='#{format('%<lon>.7f', :lon => node.lon)}']" \
"[version='#{node.version}']" \
"[changeset='#{node.changeset_id}']" \
"[visible='#{node.visible}']" \
"[timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
# This should really be more generic
assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
end
Expand Down
21 changes: 14 additions & 7 deletions test/controllers/api/old_nodes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,15 @@ def test_history_redacted

get api_node_history_path(:id => node_v1.node_id)
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 0, "redacted node #{node_v1.node_id} version #{node_v1.version} shouldn't be present in the history."
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 0,
"redacted node #{node_v1.node_id} version #{node_v1.version} shouldn't be present in the history."

# not even to a logged-in user
auth_header = basic_authorization_header create(:user).email, "test"
get api_node_history_path(:id => node_v1.node_id), :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 0, "redacted node #{node_v1.node_id} version #{node_v1.version} shouldn't be present in the history, even when logged in."
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 0,
"redacted node #{node_v1.node_id} version #{node_v1.version} shouldn't be present in the history, even when logged in."
end

##
Expand All @@ -292,10 +294,12 @@ def test_redact_node_moderator
# and when accessed via history
get api_node_history_path(:id => node_v3.node_id)
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0, "node #{node_v3.node_id} version #{node_v3.version} should not be present in the history for moderators when not passing flag."
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0,
"node #{node_v3.node_id} version #{node_v3.version} should not be present in the history for moderators when not passing flag."
get api_node_history_path(:id => node_v3.node_id), :params => { :show_redactions => "true" }, :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 1, "node #{node_v3.node_id} version #{node_v3.version} should still be present in the history for moderators when passing flag."
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 1,
"node #{node_v3.node_id} version #{node_v3.version} should still be present in the history for moderators when passing flag."
end

# testing that if the moderator drops auth, he can't see the
Expand All @@ -318,7 +322,8 @@ def test_redact_node_is_redacted
# and when accessed via history
get api_node_history_path(:id => node_v3.node_id), :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0, "redacted node #{node_v3.node_id} version #{node_v3.version} shouldn't be present in the history."
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0,
"redacted node #{node_v3.node_id} version #{node_v3.version} shouldn't be present in the history."
end

##
Expand Down Expand Up @@ -370,7 +375,8 @@ def test_unredact_node_moderator
# and when accessed via history
get api_node_history_path(:id => node_v1.node_id)
assert_response :success, "Unredaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1, "node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for moderators without passing flag."
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1,
"node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for moderators without passing flag."

auth_header = basic_authorization_header create(:user).email, "test"

Expand All @@ -381,7 +387,8 @@ def test_unredact_node_moderator
# and when accessed via history
get api_node_history_path(:id => node_v1.node_id)
assert_response :success, "Unredaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1, "node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for normal users without passing flag."
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1,
"node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for normal users without passing flag."
end

private
Expand Down
21 changes: 14 additions & 7 deletions test/controllers/api/old_relations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ def test_history_redacted

get api_relation_history_path(:id => relation_v1.relation_id)
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 0, "redacted relation #{relation_v1.relation_id} version #{relation_v1.version} shouldn't be present in the history."
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 0,
"redacted relation #{relation_v1.relation_id} version #{relation_v1.version} shouldn't be present in the history."

# not even to a logged-in user
auth_header = basic_authorization_header create(:user).email, "test"
get relation_version_path(:id => relation_v1.relation_id, :version => relation_v1.version), :headers => auth_header
get api_relation_history_path(:id => relation_v1.relation_id), :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 0, "redacted relation #{relation_v1.relation_id} version #{relation_v1.version} shouldn't be present in the history, even when logged in."
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 0,
"redacted relation #{relation_v1.relation_id} version #{relation_v1.version} shouldn't be present in the history, even when logged in."
end

##
Expand All @@ -135,10 +137,12 @@ def test_redact_relation_moderator
# and when accessed via history
get api_relation_history_path(:id => relation_v3.relation_id), :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0, "relation #{relation_v3.relation_id} version #{relation_v3.version} should not be present in the history for moderators when not passing flag."
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0,
"relation #{relation_v3.relation_id} version #{relation_v3.version} should not be present in the history for moderators when not passing flag."
get api_relation_history_path(:id => relation_v3.relation_id), :params => { :show_redactions => "true" }, :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 1, "relation #{relation_v3.relation_id} version #{relation_v3.version} should still be present in the history for moderators when passing flag."
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 1,
"relation #{relation_v3.relation_id} version #{relation_v3.version} should still be present in the history for moderators when passing flag."
end

# testing that if the moderator drops auth, he can't see the
Expand All @@ -162,7 +166,8 @@ def test_redact_relation_is_redacted
# and when accessed via history
get api_relation_history_path(:id => relation_v3.relation_id), :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0, "redacted relation #{relation_v3.relation_id} version #{relation_v3.version} shouldn't be present in the history."
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0,
"redacted relation #{relation_v3.relation_id} version #{relation_v3.version} shouldn't be present in the history."
end

##
Expand Down Expand Up @@ -212,7 +217,8 @@ def test_unredact_relation_moderator
# and when accessed via history
get api_relation_history_path(:id => relation_v1.relation_id), :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 1, "relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for moderators."
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 1,
"relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for moderators."

auth_header = basic_authorization_header create(:user).email, "test"

Expand All @@ -223,7 +229,8 @@ def test_unredact_relation_moderator
# and when accessed via history
get api_relation_history_path(:id => relation_v1.relation_id), :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 1, "relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for normal users."
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 1,
"relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for normal users."
end

private
Expand Down
21 changes: 14 additions & 7 deletions test/controllers/api/old_ways_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,16 @@ def test_history_redacted

get api_way_history_path(:id => way_v1.way_id)
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 0, "redacted way #{way_v1.way_id} version #{way_v1.version} shouldn't be present in the history."
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 0,
"redacted way #{way_v1.way_id} version #{way_v1.version} shouldn't be present in the history."

# not even to a logged-in user
auth_header = basic_authorization_header create(:user).email, "test"
get way_version_path(:id => way_v1.way_id, :version => way_v1.version), :headers => auth_header
get api_way_history_path(:id => way_v1.way_id), :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 0, "redacted node #{way_v1.way_id} version #{way_v1.version} shouldn't be present in the history, even when logged in."
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 0,
"redacted node #{way_v1.way_id} version #{way_v1.version} shouldn't be present in the history, even when logged in."
end

##
Expand All @@ -175,10 +177,12 @@ def test_redact_way_moderator
# and when accessed via history
get api_way_history_path(:id => way_v3.way_id), :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0, "way #{way_v3.way_id} version #{way_v3.version} should not be present in the history for moderators when not passing flag."
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0,
"way #{way_v3.way_id} version #{way_v3.version} should not be present in the history for moderators when not passing flag."
get api_way_history_path(:id => way_v3.way_id), :params => { :show_redactions => "true" }, :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 1, "way #{way_v3.way_id} version #{way_v3.version} should still be present in the history for moderators when passing flag."
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 1,
"way #{way_v3.way_id} version #{way_v3.version} should still be present in the history for moderators when passing flag."
end

# testing that if the moderator drops auth, he can't see the
Expand All @@ -201,7 +205,8 @@ def test_redact_way_is_redacted
# and when accessed via history
get api_way_history_path(:id => way_v3.way_id), :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0, "redacted way #{way_v3.way_id} version #{way_v3.version} shouldn't be present in the history."
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0,
"redacted way #{way_v3.way_id} version #{way_v3.version} shouldn't be present in the history."
end

##
Expand Down Expand Up @@ -252,7 +257,8 @@ def test_unredact_way_moderator
# and when accessed via history
get api_way_history_path(:id => way_v1.way_id), :headers => auth_header
assert_response :success, "Unredaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1, "way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for moderators."
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1,
"way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for moderators."

auth_header = basic_authorization_header create(:user).email, "test"

Expand All @@ -263,7 +269,8 @@ def test_unredact_way_moderator
# and when accessed via history
get api_way_history_path(:id => way_v1.way_id), :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1, "way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for normal users."
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1,
"way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for normal users."
end

private
Expand Down
3 changes: 2 additions & 1 deletion test/helpers/browse_tags_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def test_format_value
assert_dom_equal "<a title=\"The Q42 item on Wikidata\" href=\"//www.wikidata.org/entity/Q42?uselang=en\">Q42</a>", html

html = format_value("operator:wikidata", "Q12;Q98")
assert_dom_equal "<a title=\"The Q12 item on Wikidata\" href=\"//www.wikidata.org/entity/Q12?uselang=en\">Q12</a>;<a title=\"The Q98 item on Wikidata\" href=\"//www.wikidata.org/entity/Q98?uselang=en\">Q98</a>", html
assert_dom_equal "<a title=\"The Q12 item on Wikidata\" href=\"//www.wikidata.org/entity/Q12?uselang=en\">Q12</a>;" \
"<a title=\"The Q98 item on Wikidata\" href=\"//www.wikidata.org/entity/Q98?uselang=en\">Q98</a>", html

html = format_value("name:etymology:wikidata", "Q123")
assert_dom_equal "<a title=\"The Q123 item on Wikidata\" href=\"//www.wikidata.org/entity/Q123?uselang=en\">Q123</a>", html
Expand Down
Loading

0 comments on commit 048ab33

Please sign in to comment.