From: Anton Khorev Date: Tue, 8 Apr 2025 08:04:19 +0000 (+0300) Subject: Add transient bbox attribute to changesets factory X-Git-Tag: live~51^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/3c00c2032afe8112734fc59255aa002b6fb1051e?ds=inline Add transient bbox attribute to changesets factory --- diff --git a/test/controllers/api/changesets_controller_test.rb b/test/controllers/api/changesets_controller_test.rb index 4b72e432e..c20b9bddc 100644 --- a/test/controllers/api/changesets_controller_test.rb +++ b/test/controllers/api/changesets_controller_test.rb @@ -53,8 +53,8 @@ module Api user = create(:user) changeset = create(:changeset, :user => user) closed_changeset = create(:changeset, :closed, :user => user, :created_at => Time.utc(2008, 1, 1, 0, 0, 0), :closed_at => Time.utc(2008, 1, 2, 0, 0, 0)) - changeset2 = create(:changeset, :min_lat => (5 * GeoRecord::SCALE).round, :min_lon => (5 * GeoRecord::SCALE).round, :max_lat => (15 * GeoRecord::SCALE).round, :max_lon => (15 * GeoRecord::SCALE).round) - changeset3 = create(:changeset, :min_lat => (4.5 * GeoRecord::SCALE).round, :min_lon => (4.5 * GeoRecord::SCALE).round, :max_lat => (5 * GeoRecord::SCALE).round, :max_lon => (5 * GeoRecord::SCALE).round) + changeset2 = create(:changeset, :bbox => [5, 5, 15, 15]) + changeset3 = create(:changeset, :bbox => [4.5, 4.5, 5, 5]) get api_changesets_path(:bbox => "-10,-10, 10, 10") assert_response :success, "can't get changesets in bbox" @@ -627,9 +627,7 @@ module Api end def test_show_bbox_json - # test bbox attribute - changeset = create(:changeset, :min_lat => (-5 * GeoRecord::SCALE).round, :min_lon => (5 * GeoRecord::SCALE).round, - :max_lat => (15 * GeoRecord::SCALE).round, :max_lon => (12 * GeoRecord::SCALE).round) + changeset = create(:changeset, :bbox => [5, -5, 12, 15]) get api_changeset_path(changeset, :format => "json") assert_response :success, "cannot get first changeset" @@ -2092,9 +2090,7 @@ module Api create(:changeset, :user => user, :created_at => Time.now.utc - 7.days) # create a changeset that puts us near the initial size limit - changeset = create(:changeset, :user => user, - :min_lat => (-0.5 * GeoRecord::SCALE).round, :min_lon => (0.5 * GeoRecord::SCALE).round, - :max_lat => (0.5 * GeoRecord::SCALE).round, :max_lon => (2.5 * GeoRecord::SCALE).round) + changeset = create(:changeset, :user => user, :bbox => [0.5, -0.5, 2.5, 0.5]) # create authentication header auth_header = bearer_authorization_header user diff --git a/test/controllers/changesets_controller_test.rb b/test/controllers/changesets_controller_test.rb index 7cc329ec8..914f7f651 100644 --- a/test/controllers/changesets_controller_test.rb +++ b/test/controllers/changesets_controller_test.rb @@ -91,8 +91,8 @@ class ChangesetsControllerTest < ActionDispatch::IntegrationTest ## # This should display the last 20 changesets closed in a specific area def test_index_bbox - changesets = create_list(:changeset, 10, :num_changes => 1, :min_lat => 50000000, :max_lat => 50000001, :min_lon => 50000000, :max_lon => 50000001) - other_changesets = create_list(:changeset, 10, :num_changes => 1, :min_lat => 0, :max_lat => 1, :min_lon => 0, :max_lon => 1) + changesets = create_list(:changeset, 10, :num_changes => 1, :bbox => [5, 5, 5, 5]) + other_changesets = create_list(:changeset, 10, :num_changes => 1, :bbox => [0, 0, 1, 1]) # First check they all show up without a bbox parameter get history_path(:format => "html", :list => "1"), :xhr => true @@ -389,12 +389,12 @@ class ChangesetsControllerTest < ActionDispatch::IntegrationTest ## # This should display the last 20 changesets closed in a specific area def test_feed_bbox - changeset = create(:changeset, :num_changes => 1, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE) + changeset = create(:changeset, :num_changes => 1, :bbox => [5, 5, 5, 5]) create(:changeset_tag, :changeset => changeset) create(:changeset_tag, :changeset => changeset, :k => "website", :v => "http://example.com/") - closed_changeset = create(:changeset, :closed, :num_changes => 1, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE) - _elsewhere_changeset = create(:changeset, :num_changes => 1, :min_lat => -5 * GeoRecord::SCALE, :min_lon => -5 * GeoRecord::SCALE, :max_lat => -5 * GeoRecord::SCALE, :max_lon => -5 * GeoRecord::SCALE) - _empty_changeset = create(:changeset, :num_changes => 0, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE) + closed_changeset = create(:changeset, :closed, :num_changes => 1, :bbox => [5, 5, 5, 5]) + _elsewhere_changeset = create(:changeset, :num_changes => 1, :bbox => [-5, -5, -5, -5]) + _empty_changeset = create(:changeset, :num_changes => 0, :bbox => [5, 5, 5, 5]) get history_feed_path(:format => :atom, :bbox => "4.5,4.5,5.5,5.5") assert_response :success diff --git a/test/factories/changesets.rb b/test/factories/changesets.rb index d4ebdcee1..6a89a7d37 100644 --- a/test/factories/changesets.rb +++ b/test/factories/changesets.rb @@ -1,7 +1,15 @@ FactoryBot.define do factory :changeset do + transient do + bbox { nil } + end + created_at { Time.now.utc } closed_at { Time.now.utc + 1.day } + min_lon { (bbox[0] * GeoRecord::SCALE).round if bbox } + min_lat { (bbox[1] * GeoRecord::SCALE).round if bbox } + max_lon { (bbox[2] * GeoRecord::SCALE).round if bbox } + max_lat { (bbox[3] * GeoRecord::SCALE).round if bbox } user diff --git a/test/system/browse_comment_links_test.rb b/test/system/browse_comment_links_test.rb index 6c81a928f..c690551c7 100644 --- a/test/system/browse_comment_links_test.rb +++ b/test/system/browse_comment_links_test.rb @@ -2,8 +2,7 @@ require "application_system_test_case" class BrowseCommentLinksTest < ApplicationSystemTestCase test "visiting changeset comment link should pan to changeset" do - changeset = create(:changeset, :min_lat => 60 * GeoRecord::SCALE, :min_lon => 30 * GeoRecord::SCALE, - :max_lat => 60 * GeoRecord::SCALE, :max_lon => 30 * GeoRecord::SCALE) + changeset = create(:changeset, :bbox => [30, 60, 30, 60]) comment = create(:changeset_comment, :changeset => changeset, :body => "Linked changeset comment") visit changeset_path(changeset, :anchor => "c#{comment.id}") diff --git a/test/system/history_test.rb b/test/system/history_test.rb index 5c66144c1..50215abc5 100644 --- a/test/system/history_test.rb +++ b/test/system/history_test.rb @@ -110,9 +110,9 @@ class HistoryTest < ApplicationSystemTestCase end test "update sidebar when before param is included and map is moved" do - changeset1 = create(:changeset, :num_changes => 1, :min_lat => 50000000, :max_lat => 50000001, :min_lon => 50000000, :max_lon => 50000001) + changeset1 = create(:changeset, :num_changes => 1, :bbox => [5, 5, 5, 5]) create(:changeset_tag, :changeset => changeset1, :k => "comment", :v => "changeset-at-fives") - changeset2 = create(:changeset, :num_changes => 1, :min_lat => 50100000, :max_lat => 50100001, :min_lon => 50100000, :max_lon => 50100001) + changeset2 = create(:changeset, :num_changes => 1, :bbox => [5.01, 5.01, 5.01, 5.01]) create(:changeset_tag, :changeset => changeset2, :k => "comment", :v => "changeset-close-to-fives") changeset3 = create(:changeset) @@ -136,9 +136,7 @@ class HistoryTest < ApplicationSystemTestCase test "all changesets are listed when fully zoomed out" do user = create(:user) [-177, -90, 0, 90, 177].each do |lon| - create(:changeset, :user => user, :num_changes => 1, - :min_lat => 0 * GeoRecord::SCALE, :min_lon => (lon - 1) * GeoRecord::SCALE, - :max_lat => 1 * GeoRecord::SCALE, :max_lon => (lon + 1) * GeoRecord::SCALE) do |changeset| + create(:changeset, :user => user, :num_changes => 1, :bbox => [lon - 1, 0, lon + 1, 1]) do |changeset| create(:changeset_tag, :changeset => changeset, :k => "comment", :v => "changeset-at-lon(#{lon})") end end