]> git.openstreetmap.org Git - rails.git/commitdiff
Replace geocoder with search resource
authorAnton Khorev <tony29@yandex.ru>
Mon, 31 Mar 2025 02:51:07 +0000 (05:51 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sun, 20 Apr 2025 13:07:52 +0000 (16:07 +0300)
.rubocop.yml
app/abilities/ability.rb
app/controllers/searches/queries_controller.rb
app/controllers/searches_controller.rb [moved from app/controllers/geocoder_controller.rb with 97% similarity]
app/views/searches/show.html.erb [moved from app/views/geocoder/search.html.erb with 100% similarity]
config/locales/en.yml
config/routes.rb
test/abilities/abilities_test.rb
test/controllers/searches_controller_test.rb [moved from test/controllers/geocoder_controller_test.rb with 97% similarity]
test/controllers/site_controller_test.rb

index d084946e3058b6aa6c708e24d7a5cf33e44706fc..aa75d2d89601512538936dc739fcb363fde69cd6 100644 (file)
@@ -145,7 +145,6 @@ Rails/SpecificActionNames:
     - 'app/controllers/directions_controller.rb'
     - 'app/controllers/errors_controller.rb'
     - 'app/controllers/export_controller.rb'
-    - 'app/controllers/geocoder_controller.rb'
     - 'app/controllers/issues_controller.rb'
     - 'app/controllers/site_controller.rb'
     - 'app/controllers/traces_controller.rb'
index 5de3d6b5e81d49b6fee4ff71e93bf3c9aab8f9e9..b1c943812856168eab6ffa8376ae04171435b2ad 100644 (file)
@@ -10,7 +10,7 @@ class Ability
     can :search, :direction
     can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :id], :site
     can [:finish, :embed], :export
-    can [:create, :search], :geocoder
+    can [:create, :read], :search
 
     if Settings.status != "database_offline"
       can [:read, :feed], Changeset
index 9c130f10d9015668e08c111ac1f9696216396ffa..82745082ce68acbd0f64bed26467ccc38f69f70a 100644 (file)
@@ -2,7 +2,7 @@ module Searches
   class QueriesController < ApplicationController
     before_action :authorize_web
     before_action :set_locale
-    authorize_resource :class => :geocoder
+    authorize_resource :class => :search
 
     private
 
similarity index 97%
rename from app/controllers/geocoder_controller.rb
rename to app/controllers/searches_controller.rb
index 1ff7ed2f963ec285c11558a5722adac7833b9e4f..0381d542dd10003fd7ce007de8623e76715eefab 100644 (file)
@@ -1,4 +1,4 @@
-class GeocoderController < ApplicationController
+class SearchesController < ApplicationController
   include NominatimMethods
 
   before_action :authorize_web
@@ -9,7 +9,7 @@ class GeocoderController < ApplicationController
 
   before_action :normalize_params
 
-  def search
+  def show
     @sources = []
 
     if params[:lat] && params[:lon]
index 7c9c19d461a8a25f7e707e7457efbe22199b6baf..d1eaa6b9ad9f64b98928440d31bb23913b7c5a85 100644 (file)
@@ -709,11 +709,6 @@ en:
       success: "You successfully unfollowed %{name}."
       not_followed: "You are not following %{name}."
   geocoder:
-    search:
-      title:
-        latlon: Internal
-        osm_nominatim: OpenStreetMap Nominatim
-        osm_nominatim_reverse: OpenStreetMap Nominatim
     search_osm_nominatim:
       prefix_format: "%{name}"
       prefix:
@@ -1537,6 +1532,11 @@ en:
         township: "Township Boundary"
         village: "Village Boundary"
   searches:
+    show:
+      title:
+        latlon: Internal
+        osm_nominatim: OpenStreetMap Nominatim
+        osm_nominatim_reverse: OpenStreetMap Nominatim
     queries:
       create:
         no_results: "No results found"
index f4d6c826f2895ba0a56b68cd9df3ac51f88c07e8..93aa2f9fdbc9808d6c6caf78611ee513d576f6ca 100644 (file)
@@ -333,8 +333,7 @@ OpenStreetMap::Application.routes.draw do
   end
 
   # geocoder
-  get "/search" => "geocoder#search"
-  resource :search, :only => [] do
+  resource :search, :only => :show do
     scope :module => :searches do
       resource :latlon_query, :only => :create
       resource :nominatim_query, :only => :create
index 4219b41c06357ce62f5372c41b7e099a33911499..a72e4d792044c6a9950b7734a399244441fde4f0 100644 (file)
@@ -6,11 +6,11 @@ class AbilityTest < ActiveSupport::TestCase
 end
 
 class GuestAbilityTest < AbilityTest
-  test "geocoder permission for a guest" do
+  test "search permissions for a guest" do
     ability = Ability.new nil
 
-    [:create, :search].each do |action|
-      assert ability.can?(action, :geocoder), "should be able to #{action} geocoder"
+    [:create, :show].each do |action|
+      assert ability.can?(action, :search), "should be able to #{action} searches"
     end
   end
 
similarity index 97%
rename from test/controllers/geocoder_controller_test.rb
rename to test/controllers/searches_controller_test.rb
index 134101eba62867dc3c85085f19072bc124d458fb..51022bb4b2a4ed3f031127d5b708f8950628a488 100644 (file)
@@ -1,12 +1,12 @@
 require "test_helper"
 
-class GeocoderControllerTest < ActionDispatch::IntegrationTest
+class SearchesControllerTest < ActionDispatch::IntegrationTest
   ##
   # test all routes which lead to this controller
   def test_routes
     assert_routing(
       { :path => "/search", :method => :get },
-      { :controller => "geocoder", :action => "search" }
+      { :controller => "searches", :action => "show" }
     )
   end
 
@@ -243,7 +243,7 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest
     ].each do |code|
       get search_path(:query => code)
       assert_response :success
-      assert_template :search
+      assert_template :show
       assert_template :layout => "map"
       assert_equal %w[osm_nominatim], assigns(:sources).pluck(:name)
     end
@@ -316,7 +316,7 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest
   def latlon_check(query, lat, lon)
     get search_path(:query => query)
     assert_response :success
-    assert_template :search
+    assert_template :show
     assert_template :layout => "map"
     assert_equal %w[latlon osm_nominatim_reverse], assigns(:sources).pluck(:name)
     assert_nil @controller.params[:query]
@@ -327,7 +327,7 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest
 
     get search_path(:query => query), :xhr => true
     assert_response :success
-    assert_template :search
+    assert_template :show
     assert_template :layout => "xhr"
     assert_equal %w[latlon osm_nominatim_reverse], assigns(:sources).pluck(:name)
     assert_nil @controller.params[:query]
@@ -340,13 +340,13 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest
   def search_check(query, sources)
     get search_path(:query => query)
     assert_response :success
-    assert_template :search
+    assert_template :show
     assert_template :layout => "map"
     assert_equal sources, assigns(:sources).pluck(:name)
 
     get search_path(:query => query), :xhr => true
     assert_response :success
-    assert_template :search
+    assert_template :show
     assert_template :layout => "xhr"
     assert_equal sources, assigns(:sources).pluck(:name)
   end
index 9246dcc1b0076f3d025e5e71ae5f4ed3597072a2..1a8af5275c7d6af2f32ed1f1574bf44c5bfd9bd9 100644 (file)
@@ -97,7 +97,7 @@ class SiteControllerTest < ActionDispatch::IntegrationTest
     assert_redirected_to :controller => :notes, :action => :show, :id => 123
 
     get root_path(:query => "test")
-    assert_redirected_to :controller => :geocoder, :action => :search, :query => "test"
+    assert_redirected_to search_path(:query => "test")
 
     get root_path(:lat => 4, :lon => 5)
     assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"