From 127bb4523e111bca6b7bb1d2d0125d069a1f6b78 Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Mon, 13 Oct 2008 15:23:48 +0000 Subject: [PATCH] Fixed problems with the relations functional tests. --- app/controllers/relation_controller.rb | 2 +- app/models/old_relation.rb | 6 +++ app/models/relation.rb | 2 +- test/fixtures/current_relations.yml | 3 ++ test/functional/relation_controller_test.rb | 49 ++++++++++++++------- 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/app/controllers/relation_controller.rb b/app/controllers/relation_controller.rb index b77d41ead..09c878325 100644 --- a/app/controllers/relation_controller.rb +++ b/app/controllers/relation_controller.rb @@ -71,7 +71,7 @@ class RelationController < ApplicationController new_relation = Relation.from_xml(request.raw_post) if new_relation and new_relation.id == relation.id relation.delete_with_history(new_relation, @user) - render :nothing => true, :status => :success + render :nothing => true else render :nothing => true, :status => :bad_request end diff --git a/app/models/old_relation.rb b/app/models/old_relation.rb index 3a7cc29b2..b7e7248d9 100644 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@ -88,6 +88,12 @@ class OldRelation < ActiveRecord::Base OldRelationTag.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version]) end + def to_xml + doc = OSM::API.new.get_xml_doc + doc.root << to_xml_node() + return doc + end + def to_xml_node el1 = XML::Node.new 'relation' el1['id'] = self.id.to_s diff --git a/app/models/relation.rb b/app/models/relation.rb index 081c44b25..dd2d1c7d5 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -77,7 +77,7 @@ class Relation < ActiveRecord::Base if user_display_name_cache and user_display_name_cache.key?(self.changeset.user_id) # use the cache if available - elsif self.user.data_public? + elsif self.changeset.user.data_public? user_display_name_cache[self.changeset.user_id] = self.changeset.user.display_name else user_display_name_cache[self.changeset.user_id] = nil diff --git a/test/fixtures/current_relations.yml b/test/fixtures/current_relations.yml index 510df492c..e4c3b18fa 100644 --- a/test/fixtures/current_relations.yml +++ b/test/fixtures/current_relations.yml @@ -3,15 +3,18 @@ visible_relation: changeset_id: 1 timestamp: 2007-01-01 00:00:00 visible: 1 + version: 1 invisible_relation: id: 2 changeset_id: 1 timestamp: 2007-01-01 00:00:00 visible: 0 + version: 1 used_relation: id: 3 changeset_id: 1 timestamp: 2007-01-01 00:00:00 visible: 1 + version: 1 diff --git a/test/functional/relation_controller_test.rb b/test/functional/relation_controller_test.rb index 3c7025235..b45c80874 100644 --- a/test/functional/relation_controller_test.rb +++ b/test/functional/relation_controller_test.rb @@ -6,9 +6,6 @@ class RelationController; def rescue_action(e) raise e end; end class RelationControllerTest < Test::Unit::TestCase api_fixtures - fixtures :relations, :current_relations, :relation_members, :current_relation_members, :relation_tags, :current_relation_tags - set_fixture_class :current_relations => :Relation - set_fixture_class :relations => :OldRelation def setup @controller = RelationController.new @@ -21,7 +18,7 @@ class RelationControllerTest < Test::Unit::TestCase end def content(c) - @request.env["RAW_POST_DATA"] = c + @request.env["RAW_POST_DATA"] = c.to_s end # ------------------------------------- @@ -84,10 +81,11 @@ class RelationControllerTest < Test::Unit::TestCase def test_create basic_authorization "test@openstreetmap.org", "test" - # FIXME create a new changeset and use the id that is returned for the next step + # put the relation in a dummy fixture changset + changeset_id = changesets(:normal_user_first_change).id # create an relation without members - content "" + content "" put :create # hope for success assert_response :success, @@ -102,6 +100,8 @@ class RelationControllerTest < Test::Unit::TestCase "saved relation contains members but should not" assert_equal checkrelation.tags.length, 1, "saved relation does not contain exactly one tag" + assert_equal changeset_id, checkrelation.changeset.id, + "saved relation does not belong in the changeset it was assigned to" assert_equal users(:normal_user).id, checkrelation.changeset.user_id, "saved relation does not belong to user that created it" assert_equal true, checkrelation.visible, @@ -113,8 +113,9 @@ class RelationControllerTest < Test::Unit::TestCase # create an relation with a node as member nid = current_nodes(:used_node_1).id - content "" + - "" + content "" + + "" + + "" put :create # hope for success assert_response :success, @@ -129,7 +130,9 @@ class RelationControllerTest < Test::Unit::TestCase "saved relation does not contain exactly one member" assert_equal checkrelation.tags.length, 1, "saved relation does not contain exactly one tag" - assert_equal users(:normal_user).id, checkrelation.user_id, + assert_equal changeset_id, checkrelation.changeset.id, + "saved relation does not belong in the changeset it was assigned to" + assert_equal users(:normal_user).id, checkrelation.changeset.user_id, "saved relation does not belong to user that created it" assert_equal true, checkrelation.visible, "saved relation is not visible" @@ -141,9 +144,10 @@ class RelationControllerTest < Test::Unit::TestCase # create an relation with a way and a node as members nid = current_nodes(:used_node_1).id wid = current_ways(:used_way).id - content "" + - "" + - "" + content "" + + "" + + "" + + "" put :create # hope for success assert_response :success, @@ -158,7 +162,9 @@ class RelationControllerTest < Test::Unit::TestCase "saved relation does not have exactly two members" assert_equal checkrelation.tags.length, 1, "saved relation does not contain exactly one tag" - assert_equal users(:normal_user).id, checkrelation.user_id, + assert_equal changeset_id, checkrelation.changeset.id, + "saved relation does not belong in the changeset it was assigned to" + assert_equal users(:normal_user).id, checkrelation.changeset.user_id, "saved relation does not belong to user that created it" assert_equal true, checkrelation.visible, "saved relation is not visible" @@ -175,8 +181,13 @@ class RelationControllerTest < Test::Unit::TestCase def test_create_invalid basic_authorization "test@openstreetmap.org", "test" + # put the relation in a dummy fixture changset + changeset_id = changesets(:normal_user_first_change).id + # create a relation with non-existing node as member - content "" + content "" + + "" + + "" put :create # expect failure assert_response :precondition_failed, @@ -188,8 +199,6 @@ class RelationControllerTest < Test::Unit::TestCase # ------------------------------------- def test_delete - return true - # first try to delete relation without auth delete :delete, :id => current_relations(:visible_relation).id assert_response :unauthorized @@ -197,11 +206,17 @@ class RelationControllerTest < Test::Unit::TestCase # now set auth basic_authorization("test@openstreetmap.org", "test"); - # this should work + # this shouldn't work, as we should need the payload... + delete :delete, :id => current_relations(:visible_relation).id + assert_response :bad_request + + # this should work when we provide the appropriate payload... + content(relations(:visible_relation).to_xml) delete :delete, :id => current_relations(:visible_relation).id assert_response :success # this won't work since the relation is already deleted + content(relations(:invisible_relation).to_xml) delete :delete, :id => current_relations(:invisible_relation).id assert_response :gone -- 2.43.2