From: Frederik Ramm Date: Sun, 16 Mar 2008 23:16:18 +0000 (+0000) Subject: - add old_relation_controller and stuff so that relation history works. fixes #557. X-Git-Tag: live~7846 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/d0aa199e92a110c93791bcc9eeb2c691d004e87a - add old_relation_controller and stuff so that relation history works. fixes #557. - minor testing fixes. --- diff --git a/app/controllers/old_relation_controller.rb b/app/controllers/old_relation_controller.rb new file mode 100644 index 000000000..0b5aa89be --- /dev/null +++ b/app/controllers/old_relation_controller.rb @@ -0,0 +1,23 @@ +class OldRelationController < ApplicationController + require 'xml/libxml' + + session :off + after_filter :compress_output + + def history + begin + relation = Relation.find(params[:id]) + doc = OSM::API.new.get_xml_doc + + relation.old_relations.each do |old_relation| + doc.root << old_relation.to_xml_node + end + + render :text => doc.to_s, :content_type => "text/xml" + rescue ActiveRecord::RecordNotFound + render :nothing => true, :status => :not_found + rescue + render :nothing => true, :status => :internal_server_error + end + end +end diff --git a/app/controllers/old_relation_member_controller.rb b/app/controllers/old_relation_member_controller.rb new file mode 100644 index 000000000..d7023ab46 --- /dev/null +++ b/app/controllers/old_relation_member_controller.rb @@ -0,0 +1,3 @@ +class OldRelationMemberController < ApplicationController + +end diff --git a/app/controllers/old_relation_tag_controller.rb b/app/controllers/old_relation_tag_controller.rb new file mode 100644 index 000000000..fba59a043 --- /dev/null +++ b/app/controllers/old_relation_tag_controller.rb @@ -0,0 +1,3 @@ +class OldRelationTagController < ApplicationController + +end diff --git a/test/functional/node_controller_test.rb b/test/functional/node_controller_test.rb index bd1be9e69..a380eeb20 100644 --- a/test/functional/node_controller_test.rb +++ b/test/functional/node_controller_test.rb @@ -28,8 +28,8 @@ class NodeControllerTest < Test::Unit::TestCase checknode = Node.find(nodeid) assert_not_nil checknode, "uploaded node not found in data base after upload" # compare values - assert_in_delta lat, checknode.latitude, 1E-8, "saved node does not match requested latitude" - assert_in_delta lon, checknode.longitude, 1E-8, "saved node does not match requested longitude" + assert_in_delta lat * 10000000, checknode.latitude, 1, "saved node does not match requested latitude" + assert_in_delta lon * 10000000, checknode.longitude, 1, "saved node does not match requested longitude" assert_equal users(:normal_user).id, checknode.user_id, "saved node does not belong to user that created it" assert_equal true, checknode.visible, "saved node is not visible" end diff --git a/test/functional/old_relation_controller_test.rb b/test/functional/old_relation_controller_test.rb new file mode 100644 index 000000000..b8bf464b6 --- /dev/null +++ b/test/functional/old_relation_controller_test.rb @@ -0,0 +1,31 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'old_relation_controller' + +# Re-raise errors caught by the controller. +#class OldRelationController; def rescue_action(e) raise e end; end + +class OldRelationControllerTest < Test::Unit::TestCase + api_fixtures + + def setup + @controller = OldRelationController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + # ------------------------------------- + # Test reading old relations. + # ------------------------------------- + + def test_history + # check that a visible relations is returned properly + get :history, :id => relations(:visible_relation).id + assert_response :success + + # check chat a non-existent relations is not returned + get :history, :id => 0 + assert_response :not_found + + end + +end diff --git a/test/functional/old_way_controller_test.rb b/test/functional/old_way_controller_test.rb new file mode 100644 index 000000000..374ea7dc2 --- /dev/null +++ b/test/functional/old_way_controller_test.rb @@ -0,0 +1,31 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'old_way_controller' + +# Re-raise errors caught by the controller. +class OldWayController; def rescue_action(e) raise e end; end + +class OldWayControllerTest < Test::Unit::TestCase + api_fixtures + + def setup + @controller = OldWayController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + # ------------------------------------- + # Test reading old ways. + # ------------------------------------- + + def test_history + # check that a visible way is returned properly + get :history, :id => ways(:visible_way).id + assert_response :success + + # check chat a non-existent way is not returned + get :history, :id => 0 + assert_response :not_found + + end + +end diff --git a/test/functional/relation_controller_test.rb b/test/functional/relation_controller_test.rb index 8f8b72770..202a015a8 100644 --- a/test/functional/relation_controller_test.rb +++ b/test/functional/relation_controller_test.rb @@ -57,7 +57,6 @@ class RelationControllerTest < Test::Unit::TestCase print @response.body end - # check the "relations for relation" mode get :relations_for_relation, :id => current_relations(:used_relation).id assert_response :success diff --git a/test/test_helper.rb b/test/test_helper.rb index f3baf4ff2..b1d7a8fcc 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -41,6 +41,16 @@ class Test::Unit::TestCase set_fixture_class :ways => :OldWay set_fixture_class :way_nodes => :OldWayNode set_fixture_class :way_tags => :OldWayTag + + fixtures :current_relations, :current_relation_members, :current_relation_tags + set_fixture_class :current_relations => :Relation + set_fixture_class :current_relation_members => :RelationMember + set_fixture_class :current_relation_tags => :RelationTag + + fixtures :relations, :relation_members, :relation_tags + set_fixture_class :relations => :OldRelation + set_fixture_class :relation_members => :OldRelationMember + set_fixture_class :relation_tags => :OldRelationTag end # Add more helper methods to be used by all tests here...