]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/2175'
authorTom Hughes <tom@compton.nu>
Tue, 26 Mar 2019 19:14:04 +0000 (19:14 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 26 Mar 2019 19:14:04 +0000 (19:14 +0000)
1  2 
.travis.yml
INSTALL.md
app/controllers/geocoder_controller.rb
test/controllers/api/changesets_controller_test.rb

diff --combined .travis.yml
index 0b528b46958ae30757c28f8a3eff56811c3ded21,9438622cda03b43284816b7cc50779a30804266f..1b99a514375447cc93ad5b9606f3d0063a67c593
@@@ -1,7 -1,7 +1,7 @@@
  sudo: false
  language: ruby
  rvm:
-   - 2.3.3
+   - 2.5.1
  cache: bundler
  addons:
    postgresql: 9.5
@@@ -14,6 -14,7 +14,6 @@@ env
    global:
      - OSM_MEMCACHE_SERVERS="127.0.0.1"
  before_script:
 -  - cp config/example.application.yml config/application.yml
    - psql -U postgres -c "CREATE DATABASE openstreetmap"
    - psql -U postgres -c "CREATE EXTENSION btree_gist" openstreetmap
    - make -C db/functions libpgosm.so
@@@ -22,7 -23,6 +22,7 @@@
    - psql -U postgres -c "CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '/tmp/libpgosm', 'tile_for_point' LANGUAGE C STRICT" openstreetmap
    - psql -U postgres -c "CREATE FUNCTION xid_to_int4(xid) RETURNS int4 AS '/tmp/libpgosm', 'xid_to_int4' LANGUAGE C STRICT" openstreetmap
    - cp config/travis.database.yml config/database.yml
 +  - touch config/settings.local.yml
    - bundle exec rake db:migrate
    - bundle exec rake i18n:js:export
  script:
diff --combined INSTALL.md
index f069521eb80feacc08a52b4d12614483dcea4247,b1fb1eafb822ab0a3a8a453c616d276da76e2e39..5b2652c3e0cc4dc114b5bd692f01f375c7e6eac3
@@@ -5,7 -5,7 +5,7 @@@ If you want to deploy the software for 
  
  You can install the software directly on your machine, which is the traditional and probably best-supported approach. However, there is an alternative which may be easier: Vagrant. This installs the software into a virtual machine, which makes it easier to get a consistent development environment and may avoid installation difficulties. For Vagrant instructions, see [VAGRANT.md](VAGRANT.md).
  
- These instructions are based on Ubuntu 16.04 LTS, which is the platform used by the OSMF servers.
+ These instructions are based on Ubuntu 18.04 LTS, which is the platform used by the OSMF servers.
  The instructions also work, with only minor amendments, for all other current Ubuntu releases, Fedora and MacOSX
  
  We don't recommend attempting to develop or deploy this software on Windows. If you need to use Windows, then try developing this software using Ubuntu in a virtual machine, or use [Vagrant](VAGRANT.md).
@@@ -18,8 -18,7 +18,7 @@@ of packages required before you can ge
  
  ## Minimum requirements
  
- * Ruby 2.3
- * RubyGems 1.3.1+
+ * Ruby 2.5+
  * PostgreSQL 9.1+
  * ImageMagick
  * Bundler
  These can be installed on Ubuntu 16.04 or later with:
  
  ```
- sudo apt-get install ruby2.3 libruby2.3 ruby2.3-dev \
+ sudo apt-get install ruby2.5 libruby2.5 ruby2.5-dev \
                       libmagickwand-dev libxml2-dev libxslt1-dev nodejs \
                       apache2 apache2-dev build-essential git-core \
                       postgresql postgresql-contrib libpq-dev postgresql-server-dev-all \
                       libsasl2-dev imagemagick libffi-dev
- sudo gem2.3 install bundler
+ sudo gem2.5 install bundler
  ```
  
  ### Alternative platforms
@@@ -115,6 -114,16 +114,6 @@@ cd openstreetmap-websit
  bundle install
  ```
  
 -## Application setup
 -
 -We need to create the `config/application.yml` file from the example template. This contains various configuration options.
 -
 -```
 -cp config/example.application.yml config/application.yml
 -```
 -
 -You can customize your installation of The Rails Port by changing the values in `config/application.yml`
 -
  ## Database setup
  
  The Rails Port uses three databases -  one for development, one for testing, and one for production. The database-specific configuration
index a877fc0926d575c56c9d6bed892447bd8f324602,d9b56147f46a6a1a2f82e3154fbdf04d278836e3..4a8f7765065ab11c7f6db3caa668f37826f2fc4e
@@@ -15,18 -15,18 +15,18 @@@ class GeocoderController < ApplicationC
      if @params[:lat] && @params[:lon]
        @sources.push "latlon"
        @sources.push "osm_nominatim_reverse"
 -      @sources.push "geonames_reverse" if defined?(GEONAMES_USERNAME)
 +      @sources.push "geonames_reverse" if Settings.key?(:geonames_username)
      elsif @params[:query]
-       if @params[:query] =~ /^\d{5}(-\d{4})?$/
+       if @params[:query].match?(/^\d{5}(-\d{4})?$/)
          @sources.push "osm_nominatim"
-       elsif @params[:query] =~ /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i
+       elsif @params[:query].match?(/^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i)
          @sources.push "osm_nominatim"
-       elsif @params[:query] =~ /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i
+       elsif @params[:query].match?(/^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i)
          @sources.push "ca_postcode"
          @sources.push "osm_nominatim"
        else
          @sources.push "osm_nominatim"
 -        @sources.push "geonames" if defined?(GEONAMES_USERNAME)
 +        @sources.push "geonames" if Settings.key?(:geonames_username)
        end
      end
  
@@@ -93,7 -93,7 +93,7 @@@
      if response.get_elements("geodata/error").empty?
        @results.push(:lat => response.text("geodata/latt"),
                      :lon => response.text("geodata/longt"),
 -                    :zoom => POSTCODE_ZOOM,
 +                    :zoom => Settings.postcode_zoom,
                      :name => query.upcase)
      end
  
      exclude = "&exclude_place_ids=#{params[:exclude]}" if params[:exclude]
  
      # ask nominatim
 -    response = fetch_xml("#{NOMINATIM_URL}search?format=xml&extratags=1&q=#{escape_query(query)}#{viewbox}#{exclude}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}")
 +    response = fetch_xml("#{Settings.nominatim_url}search?format=xml&extratags=1&q=#{escape_query(query)}#{viewbox}#{exclude}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}")
  
      # extract the results from the response
      results =  response.elements["searchresults"]
      @results = []
  
      # ask geonames.org
 -    response = fetch_xml("http://api.geonames.org/search?q=#{escape_query(query)}&lang=#{lang}&maxRows=20&username=#{GEONAMES_USERNAME}")
 +    response = fetch_xml("http://api.geonames.org/search?q=#{escape_query(query)}&lang=#{lang}&maxRows=20&username=#{Settings.geonames_username}")
  
      # parse the response
      response.elements.each("geonames/geoname") do |geoname|
        country = geoname.text("countryName")
  
        @results.push(:lat => lat, :lon => lon,
 -                    :zoom => GEONAMES_ZOOM,
 +                    :zoom => Settings.geonames_zoom,
                      :name => name,
                      :suffix => ", #{country}")
      end
      @results = []
  
      # ask nominatim
 -    response = fetch_xml("#{NOMINATIM_URL}reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}")
 +    response = fetch_xml("#{Settings.nominatim_url}reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}")
  
      # parse the response
      response.elements.each("reversegeocode/result") do |result|
      @results = []
  
      # ask geonames.org
 -    response = fetch_xml("http://api.geonames.org/countrySubdivision?lat=#{lat}&lng=#{lon}&lang=#{lang}&username=#{GEONAMES_USERNAME}")
 +    response = fetch_xml("http://api.geonames.org/countrySubdivision?lat=#{lat}&lng=#{lon}&lang=#{lang}&username=#{Settings.geonames_username}")
  
      # parse the response
      response.elements.each("geonames/countrySubdivision") do |geoname|
        country = geoname.text("countryName")
  
        @results.push(:lat => lat, :lon => lon,
 -                    :zoom => GEONAMES_ZOOM,
 +                    :zoom => Settings.geonames_zoom,
                      :name => name,
                      :suffix => ", #{country}")
      end
index be4875630caece982a086a8f0d68630cbc6b4ffc,daf062154913559b267465be7beb1718f710ff0c..e9132764c12b3a77ad1b8e96da0e561bf5a5cb7a
@@@ -137,14 -137,14 +137,14 @@@ module Ap
        get :show, :params => { :id => changeset_id }
        assert_response :success, "cannot get first changeset"
  
 -      assert_select "osm[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
 +      assert_select "osm[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1
        assert_select "osm>changeset[id='#{changeset_id}']", 1
        assert_select "osm>changeset>discussion", 0
  
        get :show, :params => { :id => changeset_id, :include_discussion => true }
        assert_response :success, "cannot get first changeset with comments"
  
 -      assert_select "osm[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
 +      assert_select "osm[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1
        assert_select "osm>changeset[id='#{changeset_id}']", 1
        assert_select "osm>changeset>discussion", 1
        assert_select "osm>changeset>discussion>comment", 0
        get :show, :params => { :id => changeset_id, :include_discussion => true }
        assert_response :success, "cannot get closed changeset with comments"
  
 -      assert_select "osm[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
 +      assert_select "osm[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1
        assert_select "osm>changeset[id='#{changeset_id}']", 1
        assert_select "osm>changeset>discussion", 1
        assert_select "osm>changeset>discussion>comment", 3
      # check that a changeset that doesn't exist returns an appropriate message
      def test_show_not_found
        [0, -32, 233455644, "afg", "213"].each do |id|
-         begin
-           get :show, :params => { :id => id }
-           assert_response :not_found, "should get a not found"
-         rescue ActionController::UrlGenerationError => ex
-           assert_match(/No route matches/, ex.to_s)
-         end
+         get :show, :params => { :id => id }
+         assert_response :not_found, "should get a not found"
+       rescue ActionController::UrlGenerationError => ex
+         assert_match(/No route matches/, ex.to_s)
        end
      end
  
  
        # First try to do it with no auth
        cs_ids.each do |id|
-         begin
-           put :close, :params => { :id => id }
-           assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized"
-         rescue ActionController::UrlGenerationError => ex
-           assert_match(/No route matches/, ex.to_s)
-         end
+         put :close, :params => { :id => id }
+         assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized"
+       rescue ActionController::UrlGenerationError => ex
+         assert_match(/No route matches/, ex.to_s)
        end
  
        # Now try with auth
        basic_authorization create(:user).email, "test"
        cs_ids.each do |id|
-         begin
-           put :close, :params => { :id => id }
-           assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed"
-         rescue ActionController::UrlGenerationError => ex
-           assert_match(/No route matches/, ex.to_s)
-         end
+         put :close, :params => { :id => id }
+         assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed"
+       rescue ActionController::UrlGenerationError => ex
+         assert_match(/No route matches/, ex.to_s)
        end
      end
  
@@@ -409,7 -403,7 +403,7 @@@ CHANGESE
                        "can't upload a simple valid creation to changeset: #{@response.body}"
  
        # check the returned payload
 -      assert_select "diffResult[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
 +      assert_select "diffResult[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1
        assert_select "diffResult>node", 1
        assert_select "diffResult>way", 1
        assert_select "diffResult>relation", 1
@@@ -647,7 -641,7 +641,7 @@@ CHANGESE
                        "can't do a conditional delete of in use objects: #{@response.body}"
  
        # check the returned payload
 -      assert_select "diffResult[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
 +      assert_select "diffResult[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1
        assert_select "diffResult>node", 1
        assert_select "diffResult>way", 1
        assert_select "diffResult>relation", 1
@@@ -742,7 -736,7 +736,7 @@@ CHANGESE
                        "can't upload a complex diff to changeset: #{@response.body}"
  
        # check the returned payload
 -      assert_select "diffResult[version='#{API_VERSION}'][generator='#{GENERATOR}']", 1
 +      assert_select "diffResult[version='#{Settings.api_version}'][generator='#{Settings.generator}']", 1
        assert_select "diffResult>node", 1
        assert_select "diffResult>way", 1
        assert_select "diffResult>relation", 1
@@@ -1234,7 -1228,7 +1228,7 @@@ CHANGESE
                        "failed to return error in XML format"
  
        # check the returned payload
 -      assert_select "osmError[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
 +      assert_select "osmError[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1
        assert_select "osmError>status", 1
        assert_select "osmError>message", 1
      end
@@@ -1428,7 -1422,7 +1422,7 @@@ CHANGESE
        assert_template nil
        # print @response.body
        # FIXME: needs more assert_select tests
 -      assert_select "osmChange[version='#{API_VERSION}'][generator='#{GENERATOR}']" do
 +      assert_select "osmChange[version='#{Settings.api_version}'][generator='#{Settings.generator}']" do
          assert_select "create", :count => 5
          assert_select "create>node[id='#{node.id}'][visible='#{node.visible?}'][version='#{node.version}']" do
            assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
        changeset = create(:changeset, :user => user)
  
        ## First try with a non-public user
 -      new_changeset = private_changeset.to_xml
 +      new_changeset = create_changeset_xml(:user => private_user)
        new_tag = XML::Node.new "tag"
        new_tag["k"] = "tagtesting"
        new_tag["v"] = "valuetesting"
        assert_require_public_data "user with their data non-public, shouldn't be able to edit their changeset"
  
        ## Now try with the public user
 -      create(:changeset_tag, :changeset => changeset)
 -      new_changeset = changeset.to_xml
 +      new_changeset = create_changeset_xml(:id => 1)
        new_tag = XML::Node.new "tag"
        new_tag["k"] = "tagtesting"
        new_tag["v"] = "valuetesting"
        assert_response :success
  
        assert_select "osm>changeset[id='#{changeset.id}']", 1
 -      assert_select "osm>changeset>tag", 2
 +      assert_select "osm>changeset>tag", 1
        assert_select "osm>changeset>tag[k='tagtesting'][v='valuetesting']", 1
      end
  
        basic_authorization create(:user).email, "test"
  
        changeset = create(:changeset)
 -      new_changeset = changeset.to_xml
 +      new_changeset = create_changeset_xml(:user => changeset.user, :id => changeset.id)
        new_tag = XML::Node.new "tag"
        new_tag["k"] = "testing"
        new_tag["v"] = "testing"
        xml.find("//osm/way").first[name] = value.to_s
        xml
      end
 +
 +    ##
 +    # build XML for changesets
 +    def create_changeset_xml(user: nil, id: nil)
 +      root = XML::Document.new
 +      root.root = XML::Node.new "osm"
 +      cs = XML::Node.new "changeset"
 +      if user
 +        cs["user"] = user.display_name
 +        cs["uid"] = user.id.to_s
 +      end
 +      cs["id"] = id.to_s if id
 +      root.root << cs
 +      root
 +    end
    end
  end