From: Tom Hughes Date: Tue, 17 May 2011 23:23:39 +0000 (+0100) Subject: Rename a number of methods in the map_bugs controller X-Git-Tag: live~5616^2~153 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/f4928d0e952ddbde662517d781367dd97eab86a7 Rename a number of methods in the map_bugs controller --- diff --git a/app/controllers/map_bugs_controller.rb b/app/controllers/map_bugs_controller.rb index bd91c1281..28d22c3f3 100644 --- a/app/controllers/map_bugs_controller.rb +++ b/app/controllers/map_bugs_controller.rb @@ -1,20 +1,19 @@ class MapBugsController < ApplicationController - layout 'site', :only => [:my_bugs] + layout 'site', :only => [:mine] before_filter :check_api_readable - before_filter :authorize_web, :only => [:add_bug, :close_bug, :edit_bug, :delete, :my_bugs] - before_filter :check_api_writable, :only => [:add_bug, :close_bug, :edit_bug, :delete] + before_filter :authorize_web, :only => [:create, :close, :update, :delete, :mine] + before_filter :check_api_writable, :only => [:create, :close, :update, :delete] before_filter :require_moderator, :only => [:delete] - before_filter :set_locale, :only => [:my_bugs] + before_filter :set_locale, :only => [:mine] after_filter :compress_output around_filter :api_call_handle_error, :api_call_timeout # Help methods for checking boundary sanity and area size include MapBoundary - def get_bugs - + def list # Figure out the bbox bbox = params['bbox'] @@ -42,16 +41,16 @@ class MapBugsController < ApplicationController @bugs = MapBug.find_by_area(@min_lat, @min_lon, @max_lat, @max_lon, :include => :comments, :order => "updated_at DESC", :limit => limit, :conditions => conditions) respond_to do |format| - format.html {render :template => 'map_bugs/get_bugs.rjs', :content_type => "text/javascript"} - format.rss {render :template => 'map_bugs/get_bugs.rss'} + format.html {render :template => 'map_bugs/list.rjs', :content_type => "text/javascript"} + format.rss {render :template => 'map_bugs/list.rss'} format.js - format.xml {render :template => 'map_bugs/get_bugs.xml'} + format.xml {render :template => 'map_bugs/list.xml'} format.json { render :json => @bugs.to_json(:methods => [:lat, :lon], :only => [:id, :status, :created_at], :include => { :comments => { :only => [:author_name, :created_at, :body]}}) } - format.gpx {render :template => 'map_bugs/get_bugs.gpx'} + format.gpx {render :template => 'map_bugs/list.gpx'} end end - def add_bug + def create raise OSM::APIBadUserInput.new("No lat was given") unless params['lat'] raise OSM::APIBadUserInput.new("No lon was given") unless params['lon'] raise OSM::APIBadUserInput.new("No text was given") unless params['text'] @@ -89,7 +88,7 @@ class MapBugsController < ApplicationController render_ok end - def edit_bug + def update raise OSM::APIBadUserInput.new("No id was given") unless params['id'] raise OSM::APIBadUserInput.new("No text was given") unless params['text'] @@ -109,7 +108,7 @@ class MapBugsController < ApplicationController render_ok end - def close_bug + def close raise OSM::APIBadUserInput.new("No id was given") unless params['id'] id = params['id'].to_i @@ -187,16 +186,16 @@ class MapBugsController < ApplicationController :conditions => conditions) @bugs = bugs2.uniq respond_to do |format| - format.html {render :template => 'map_bugs/get_bugs.rjs', :content_type => "text/javascript"} - format.rss {render :template => 'map_bugs/get_bugs.rss'} + format.html {render :template => 'map_bugs/list.rjs', :content_type => "text/javascript"} + format.rss {render :template => 'map_bugs/list.rss'} format.js - format.xml {render :template => 'map_bugs/get_bugs.xml'} + format.xml {render :template => 'map_bugs/list.xml'} format.json { render :json => @bugs.to_json(:methods => [:lat, :lon], :only => [:id, :status, :created_at], :include => { :comments => { :only => [:author_name, :created_at, :body]}}) } - format.gpx {render :template => 'map_bugs/get_bugs.gpx'} + format.gpx {render :template => 'map_bugs/list.gpx'} end end - def my_bugs + def mine if params[:display_name] @user2 = User.find_by_display_name(params[:display_name], :conditions => { :status => ["active", "confirmed"] }) diff --git a/app/views/map_bugs/get_bugs.gpx.builder b/app/views/map_bugs/list.gpx.builder similarity index 100% rename from app/views/map_bugs/get_bugs.gpx.builder rename to app/views/map_bugs/list.gpx.builder diff --git a/app/views/map_bugs/get_bugs.rjs b/app/views/map_bugs/list.rjs similarity index 100% rename from app/views/map_bugs/get_bugs.rjs rename to app/views/map_bugs/list.rjs diff --git a/app/views/map_bugs/get_bugs.rss.builder b/app/views/map_bugs/list.rss.builder similarity index 100% rename from app/views/map_bugs/get_bugs.rss.builder rename to app/views/map_bugs/list.rss.builder diff --git a/app/views/map_bugs/get_bugs.xml.builder b/app/views/map_bugs/list.xml.builder similarity index 100% rename from app/views/map_bugs/get_bugs.xml.builder rename to app/views/map_bugs/list.xml.builder diff --git a/app/views/map_bugs/my_bugs.html.erb b/app/views/map_bugs/mine.html.erb similarity index 100% rename from app/views/map_bugs/my_bugs.html.erb rename to app/views/map_bugs/mine.html.erb diff --git a/config/routes.rb b/config/routes.rb index ce60d17a6..e4ace79b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -76,19 +76,19 @@ ActionController::Routing::Routes.draw do |map| map.connect "api/#{API_VERSION}/swf/trackpoints", :controller =>'swf', :action =>'trackpoints' # Map Bugs API - map.connect "api/#{API_VERSION}/bugs", :controller => 'map_bugs', :action => 'get_bugs' + map.connect "api/#{API_VERSION}/bugs", :controller => 'map_bugs', :action => 'list' map.connect "api/#{API_VERSION}/bugs/search", :controller => 'map_bugs', :action => 'search' map.connect "api/#{API_VERSION}/bugs/rss", :controller =>'map_bugs', :action => 'rss' - map.connect "api/#{API_VERSION}/bug/create", :controller => 'map_bugs', :action => 'add_bug' - map.connect "api/#{API_VERSION}/bug/:id/comment", :controller => 'map_bugs', :action => 'edit_bug', :id => /\d+/ - map.connect "api/#{API_VERSION}/bug/:id/close", :controller => 'map_bugs', :action => 'close_bug', :id => /\d+/ + map.connect "api/#{API_VERSION}/bug/create", :controller => 'map_bugs', :action => 'create' + map.connect "api/#{API_VERSION}/bug/:id/comment", :controller => 'map_bugs', :action => 'update', :id => /\d+/ + map.connect "api/#{API_VERSION}/bug/:id/close", :controller => 'map_bugs', :action => 'close', :id => /\d+/ map.connect "api/#{API_VERSION}/bug/:id", :controller => 'map_bugs', :action => 'read', :id => /\d+/, :conditions => { :method => :get } map.connect "api/#{API_VERSION}/bug/:id", :controller => 'map_bugs', :action => 'delete', :id => /\d+/, :conditions => { :method => :delete } - map.connect "api/#{API_VERSION}/bugs/getBugs", :controller => 'map_bugs', :action => 'get_bugs' - map.connect "api/#{API_VERSION}/bugs/addPOIexec", :controller => 'map_bugs', :action => 'add_bug' - map.connect "api/#{API_VERSION}/bugs/closePOIexec", :controller => 'map_bugs', :action => 'close_bug' - map.connect "api/#{API_VERSION}/bugs/editPOIexec", :controller => 'map_bugs', :action => 'edit_bug' - map.connect "api/#{API_VERSION}/bugs/getGPX", :controller => 'map_bugs', :action => 'get_bugs', :format => :gpx + map.connect "api/#{API_VERSION}/bugs/getBugs", :controller => 'map_bugs', :action => 'list' + map.connect "api/#{API_VERSION}/bugs/addPOIexec", :controller => 'map_bugs', :action => 'create' + map.connect "api/#{API_VERSION}/bugs/closePOIexec", :controller => 'map_bugs', :action => 'close' + map.connect "api/#{API_VERSION}/bugs/editPOIexec", :controller => 'map_bugs', :action => 'update' + map.connect "api/#{API_VERSION}/bugs/getGPX", :controller => 'map_bugs', :action => 'list', :format => :gpx map.connect "api/#{API_VERSION}/bugs/getRSSfeed", :controller => 'map_bugs', :action => 'rss' # Data browsing @@ -105,7 +105,7 @@ ActionController::Routing::Routes.draw do |map| map.connect '/browse/changesets/feed', :controller => 'changeset', :action => 'list', :format => :atom map.connect '/browse/changesets', :controller => 'changeset', :action => 'list' map.connect '/browse/bug/:id', :controller => 'browse', :action => 'bug', :id => /\d+/ - map.connect '/user/:display_name/bugs', :controller => 'map_bugs', :action => 'my_bugs' + map.connect '/user/:display_name/bugs', :controller => 'map_bugs', :action => 'mine' map.connect '/browse', :controller => 'changeset', :action => 'list' # web site diff --git a/test/functional/map_bugs_controller_test.rb b/test/functional/map_bugs_controller_test.rb index 19c38834e..b88f2608a 100644 --- a/test/functional/map_bugs_controller_test.rb +++ b/test/functional/map_bugs_controller_test.rb @@ -6,7 +6,7 @@ class MapBugsControllerTest < ActionController::TestCase def test_map_bug_create_success assert_difference('MapBug.count') do assert_difference('MapBugComment.count') do - post :add_bug, {:lat => -1.0, :lon => -1.0, :name => "new_tester", :text => "This is a comment"} + post :create, {:lat => -1.0, :lon => -1.0, :name => "new_tester", :text => "This is a comment"} end end assert_response :success @@ -21,7 +21,7 @@ class MapBugsControllerTest < ActionController::TestCase def test_map_bug_comment_create_success assert_difference('MapBugComment.count') do - post :edit_bug, {:id => 2, :name => "new_tester2", :text => "This is an additional comment"} + post :update, {:id => 2, :name => "new_tester2", :text => "This is an additional comment"} end assert_response :success @@ -52,7 +52,7 @@ class MapBugsControllerTest < ActionController::TestCase end def test_map_bug_close_success - post :close_bug, {:id => 2} + post :close, {:id => 2} assert_response :success get :read, {:id => 2, :format => 'json'} @@ -62,44 +62,44 @@ class MapBugsControllerTest < ActionController::TestCase end def test_get_bugs_success - get :get_bugs, {:bbox=>'1,1,1.2,1.2'} + get :list, {:bbox=>'1,1,1.2,1.2'} assert_response :success - get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'rss'} + get :list, {:bbox=>'1,1,1.2,1.2', :format => 'rss'} assert_response :success - get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'json'} + get :list, {:bbox=>'1,1,1.2,1.2', :format => 'json'} assert_response :success - get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'xml'} + get :list, {:bbox=>'1,1,1.2,1.2', :format => 'xml'} assert_response :success - get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'gpx'} + get :list, {:bbox=>'1,1,1.2,1.2', :format => 'gpx'} assert_response :success end def test_get_bugs_large_area_success - get :get_bugs, {:bbox=>'-2.5,-2.5,2.5,2.5'} + get :list, {:bbox=>'-2.5,-2.5,2.5,2.5'} assert_response :success end def test_get_bugs_large_area_bad_request - get :get_bugs, {:bbox=>'-10,-10,12,12'} + get :list, {:bbox=>'-10,-10,12,12'} assert_response :bad_request end def test_get_bugs_closed_7_success - get :get_bugs, {:bbox=>'1,1,1.2,1.2', :closed => '7'} + get :list, {:bbox=>'1,1,1.2,1.2', :closed => '7'} assert_response :success end def test_get_bugs_closed_0_success - get :get_bugs, {:bbox=>'1,1,1.2,1.2', :closed => '0'} + get :list, {:bbox=>'1,1,1.2,1.2', :closed => '0'} assert_response :success end def test_get_bugs_closed_n1_success - get :get_bugs, {:bbox=>'1,1,1.2,1.2', :closed => '-1'} + get :list, {:bbox=>'1,1,1.2,1.2', :closed => '-1'} assert_response :success end @@ -130,25 +130,25 @@ class MapBugsControllerTest < ActionController::TestCase end def test_user_bugs_success - get :my_bugs, {:display_name=>'test'} + get :mine, {:display_name=>'test'} assert_response :success - get :my_bugs, {:display_name=>'pulibc_test2'} + get :mine, {:display_name=>'pulibc_test2'} assert_response :success - get :my_bugs, {:display_name=>'non-existent'} + get :mine, {:display_name=>'non-existent'} assert_response :not_found end def test_map_bug_comment_create_not_found assert_no_difference('MapBugComment.count') do - post :edit_bug, {:id => 12345, :name => "new_tester", :text => "This is an additional comment"} + post :update, {:id => 12345, :name => "new_tester", :text => "This is an additional comment"} end assert_response :not_found end def test_map_bug_close_not_found - post :close_bug, {:id => 12345} + post :close, {:id => 12345} assert_response :not_found end