Rename a number of methods in the map_bugs controller

This commit is contained in:
Tom Hughes 2011-05-18 00:23:39 +01:00
parent bb2c0c76ae
commit f4928d0e95
8 changed files with 45 additions and 46 deletions

View file

@ -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"] })

View file

@ -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

View file

@ -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