From f492a1b709b74f0bb36821864090657f6026f9f2 Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Sat, 28 Mar 2009 20:18:26 +0000 Subject: [PATCH] Fixed unit tests and fixture loading for postgres. The foreign keys were playing havoc with the tests when only some fixtures were loaded. --- test/functional/changeset_controller_test.rb | 14 +++++ test/test_helper.rb | 63 +++++++++++--------- test/unit/changeset_tag_test.rb | 2 +- test/unit/changeset_test.rb | 3 +- test/unit/diary_comment_test.rb | 2 +- test/unit/diary_entry_test.rb | 2 +- test/unit/friend_test.rb | 4 +- test/unit/message_test.rb | 3 +- test/unit/node_tag_test.rb | 4 +- test/unit/node_test.rb | 8 +-- test/unit/old_node_tag_test.rb | 6 +- test/unit/old_node_test.rb | 8 +-- test/unit/old_relation_tag_test.rb | 3 +- test/unit/old_way_tag_test.rb | 3 +- test/unit/relation_member_test.rb | 3 +- test/unit/relation_tag_test.rb | 3 +- test/unit/relation_test.rb | 3 +- test/unit/trace_test.rb | 3 +- test/unit/tracepoint_test.rb | 3 +- test/unit/tracetag_test.rb | 3 +- test/unit/user_preference_test.rb | 3 +- test/unit/user_test.rb | 5 +- test/unit/user_token_test.rb | 5 +- test/unit/way_node_test.rb | 4 +- test/unit/way_tag_test.rb | 3 +- test/unit/way_test.rb | 1 - 26 files changed, 83 insertions(+), 81 deletions(-) diff --git a/test/functional/changeset_controller_test.rb b/test/functional/changeset_controller_test.rb index 4c98fb36d..7faa56028 100644 --- a/test/functional/changeset_controller_test.rb +++ b/test/functional/changeset_controller_test.rb @@ -240,6 +240,20 @@ EOF assert_equal false, Node.find(node.id).visible end + def test_repeated_changeset_create + 30.times do + basic_authorization "test@openstreetmap.org", "test" + + # create a temporary changeset + content "" + + "" + + "" + put :create + assert_response :success + changeset_id = @response.body.to_i + end + end + ## # test that deleting stuff in a transaction doesn't bypass the checks # to ensure that used elements are not deleted. diff --git a/test/test_helper.rb b/test/test_helper.rb index 88a6fbe4a..8c270c682 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -25,43 +25,52 @@ class Test::Unit::TestCase # then set this back to true. self.use_instantiated_fixtures = false + # Load standard fixtures needed to test API methods def self.api_fixtures #print "setting up the api_fixtures" fixtures :users, :changesets, :changeset_tags fixtures :current_nodes, :nodes - set_fixture_class :current_nodes => Node - set_fixture_class :nodes => OldNode + set_fixture_class :current_nodes => 'Node' + set_fixture_class :nodes => 'OldNode' fixtures :current_node_tags,:node_tags - set_fixture_class :current_node_tags => NodeTag - set_fixture_class :node_tags => OldNodeTag - - fixtures :current_ways, :current_way_nodes, :current_way_tags - set_fixture_class :current_ways => Way - set_fixture_class :current_way_nodes => WayNode - set_fixture_class :current_way_tags => WayTag - - fixtures :ways, :way_nodes, :way_tags - 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 + set_fixture_class :current_node_tags => 'NodeTag' + set_fixture_class :node_tags => 'OldNodeTag' + + fixtures :current_ways + set_fixture_class :current_ways => 'Way' + + fixtures :current_way_nodes, :current_way_tags + set_fixture_class :current_way_nodes => 'WayNode' + set_fixture_class :current_way_tags => 'WayTag' + + fixtures :ways + set_fixture_class :ways => 'OldWay' + + fixtures :way_nodes, :way_tags + set_fixture_class :way_nodes => 'OldWayNode' + set_fixture_class :way_tags => 'OldWayTag' + + fixtures :current_relations + set_fixture_class :current_relations => 'Relation' + + fixtures :current_relation_members, :current_relation_tags + set_fixture_class :current_relation_members => 'RelationMember' + set_fixture_class :current_relation_tags => 'RelationTag' + + fixtures :relations + set_fixture_class :relations => 'OldRelation' + + fixtures :relation_members, :relation_tags + set_fixture_class :relation_members => 'OldRelationMember' + set_fixture_class :relation_tags => 'OldRelationTag' fixtures :gpx_files, :gps_points, :gpx_file_tags - set_fixture_class :gpx_files => Trace - set_fixture_class :gps_points => Tracepoint - set_fixture_class :gpx_file_tags => Tracetag + set_fixture_class :gpx_files => 'Trace' + set_fixture_class :gps_points => 'Tracepoint' + set_fixture_class :gpx_file_tags => 'Tracetag' end ## diff --git a/test/unit/changeset_tag_test.rb b/test/unit/changeset_tag_test.rb index e0201d538..c89f426cc 100644 --- a/test/unit/changeset_tag_test.rb +++ b/test/unit/changeset_tag_test.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class ChangesetTagTest < Test::Unit::TestCase - fixtures :changeset_tags + api_fixtures def test_changeset_tag_count assert_equal 1, ChangesetTag.count diff --git a/test/unit/changeset_test.rb b/test/unit/changeset_test.rb index 4550ffba5..448289aaf 100644 --- a/test/unit/changeset_test.rb +++ b/test/unit/changeset_test.rb @@ -1,8 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class ChangesetTest < Test::Unit::TestCase - fixtures :changesets - + api_fixtures def test_changeset_count assert_equal 6, Changeset.count diff --git a/test/unit/diary_comment_test.rb b/test/unit/diary_comment_test.rb index d7f30a69c..8e2bbf32c 100644 --- a/test/unit/diary_comment_test.rb +++ b/test/unit/diary_comment_test.rb @@ -1,9 +1,9 @@ require File.dirname(__FILE__) + '/../test_helper' class DiaryCommentTest < Test::Unit::TestCase + api_fixtures fixtures :diary_comments - def test_diary_comment_count assert_equal 1, DiaryComment.count end diff --git a/test/unit/diary_entry_test.rb b/test/unit/diary_entry_test.rb index 6b2800d18..e28e03a10 100644 --- a/test/unit/diary_entry_test.rb +++ b/test/unit/diary_entry_test.rb @@ -1,9 +1,9 @@ require File.dirname(__FILE__) + '/../test_helper' class DiaryEntryTest < Test::Unit::TestCase + api_fixtures fixtures :diary_entries - def test_diary_entry_count assert_equal 2, DiaryEntry.count end diff --git a/test/unit/friend_test.rb b/test/unit/friend_test.rb index fd8b5033f..8c93146ae 100644 --- a/test/unit/friend_test.rb +++ b/test/unit/friend_test.rb @@ -1,9 +1,9 @@ require File.dirname(__FILE__) + '/../test_helper' class FriendTest < Test::Unit::TestCase + api_fixtures fixtures :friends - - + def test_friend_count assert_equal 1, Friend.count end diff --git a/test/unit/message_test.rb b/test/unit/message_test.rb index 3b83bf95a..a732aa586 100644 --- a/test/unit/message_test.rb +++ b/test/unit/message_test.rb @@ -1,7 +1,8 @@ require File.dirname(__FILE__) + '/../test_helper' class MessageTest < Test::Unit::TestCase - fixtures :messages, :users + api_fixtures + fixtures :messages EURO = "\xe2\x82\xac" #euro symbol diff --git a/test/unit/node_tag_test.rb b/test/unit/node_tag_test.rb index 2ff9f9f00..bd7d9f6e3 100644 --- a/test/unit/node_tag_test.rb +++ b/test/unit/node_tag_test.rb @@ -1,9 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class NodeTagTest < Test::Unit::TestCase - fixtures :current_node_tags, :current_nodes - set_fixture_class :current_nodes => Node - set_fixture_class :current_node_tags => NodeTag + api_fixtures def test_tag_count assert_equal 6, NodeTag.count diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index 13dea88da..51cf82d12 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb @@ -1,12 +1,8 @@ require File.dirname(__FILE__) + '/../test_helper' class NodeTest < Test::Unit::TestCase - fixtures :changesets, :current_nodes, :users, :current_node_tags, :nodes, :node_tags - set_fixture_class :current_nodes => Node - set_fixture_class :nodes => OldNode - set_fixture_class :node_tags => OldNodeTag - set_fixture_class :current_node_tags => NodeTag - + api_fixtures + def test_node_too_far_north invalid_node_test(:node_too_far_north) end diff --git a/test/unit/old_node_tag_test.rb b/test/unit/old_node_tag_test.rb index 497184348..969677653 100644 --- a/test/unit/old_node_tag_test.rb +++ b/test/unit/old_node_tag_test.rb @@ -1,10 +1,8 @@ require File.dirname(__FILE__) + '/../test_helper' class OldNodeTest < Test::Unit::TestCase - set_fixture_class :nodes => OldNode - set_fixture_class :node_tags => OldNodeTag - fixtures :users, :nodes, :node_tags - + api_fixtures + def test_old_node_tag_count assert_equal 8, OldNodeTag.count, "Unexpected number of fixtures loaded." end diff --git a/test/unit/old_node_test.rb b/test/unit/old_node_test.rb index bdd685388..4915e40b6 100644 --- a/test/unit/old_node_test.rb +++ b/test/unit/old_node_test.rb @@ -1,12 +1,8 @@ require File.dirname(__FILE__) + '/../test_helper' class OldNodeTest < Test::Unit::TestCase - set_fixture_class :current_nodes => Node - set_fixture_class :nodes => OldNode - set_fixture_class :node_tags => OldNodeTag - set_fixture_class :current_node_tags => NodeTag - fixtures :current_nodes, :users, :current_node_tags, :nodes, :node_tags - + api_fixtures + def test_node_too_far_north invalid_node_test(:node_too_far_north) end diff --git a/test/unit/old_relation_tag_test.rb b/test/unit/old_relation_tag_test.rb index d651810c0..aee2901cd 100644 --- a/test/unit/old_relation_tag_test.rb +++ b/test/unit/old_relation_tag_test.rb @@ -1,8 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class OldRelationTagTest < Test::Unit::TestCase - fixtures :relation_tags - set_fixture_class :relation_tags => OldRelationTag + api_fixtures def test_tag_count assert_equal 3, OldRelationTag.count diff --git a/test/unit/old_way_tag_test.rb b/test/unit/old_way_tag_test.rb index 8210ef0c4..b2724cb01 100644 --- a/test/unit/old_way_tag_test.rb +++ b/test/unit/old_way_tag_test.rb @@ -1,8 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class WayTagTest < Test::Unit::TestCase - fixtures :way_tags - set_fixture_class :way_tags => OldWayTag + api_fixtures def test_tag_count assert_equal 3, OldWayTag.count diff --git a/test/unit/relation_member_test.rb b/test/unit/relation_member_test.rb index d67ac3462..f0590ef71 100644 --- a/test/unit/relation_member_test.rb +++ b/test/unit/relation_member_test.rb @@ -1,8 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class RelationMemberTest < Test::Unit::TestCase - fixtures :current_relation_members - set_fixture_class :current_relation_members => RelationMember + api_fixtures def test_relation_member_count assert_equal 5, RelationMember.count diff --git a/test/unit/relation_tag_test.rb b/test/unit/relation_tag_test.rb index f93e689ca..5c008fc34 100644 --- a/test/unit/relation_tag_test.rb +++ b/test/unit/relation_tag_test.rb @@ -1,8 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class RelationTagTest < Test::Unit::TestCase - fixtures :current_relation_tags - set_fixture_class :current_relation_tags => RelationTag + api_fixtures def test_relation_tag_count assert_equal 3, RelationTag.count diff --git a/test/unit/relation_test.rb b/test/unit/relation_test.rb index b5b6391ab..36aad7c25 100644 --- a/test/unit/relation_test.rb +++ b/test/unit/relation_test.rb @@ -1,8 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class RelationTest < Test::Unit::TestCase - fixtures :current_relations - set_fixture_class :current_relations => Relation + api_fixtures def test_relation_count assert_equal 3, Relation.count diff --git a/test/unit/trace_test.rb b/test/unit/trace_test.rb index 706455aa2..638003962 100644 --- a/test/unit/trace_test.rb +++ b/test/unit/trace_test.rb @@ -1,8 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class TraceTest < Test::Unit::TestCase - fixtures :gpx_files - set_fixture_class :gpx_files => Trace + api_fixtures def test_trace_count assert_equal 1, Trace.count diff --git a/test/unit/tracepoint_test.rb b/test/unit/tracepoint_test.rb index 5d4100530..80534c2cb 100644 --- a/test/unit/tracepoint_test.rb +++ b/test/unit/tracepoint_test.rb @@ -1,8 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class TracepointTest < Test::Unit::TestCase - fixtures :gps_points - set_fixture_class :gps_points => Tracepoint + api_fixtures def test_tracepoint_count assert_equal 1, Tracepoint.count diff --git a/test/unit/tracetag_test.rb b/test/unit/tracetag_test.rb index 4eaf41ed8..c61913ff0 100644 --- a/test/unit/tracetag_test.rb +++ b/test/unit/tracetag_test.rb @@ -1,8 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class TracetagTest < Test::Unit::TestCase - fixtures :gpx_file_tags - set_fixture_class :gpx_file_tags => Tracetag + api_fixtures def test_tracetag_count assert_equal 1, Tracetag.count diff --git a/test/unit/user_preference_test.rb b/test/unit/user_preference_test.rb index 2118fcd39..df9e1e9b2 100644 --- a/test/unit/user_preference_test.rb +++ b/test/unit/user_preference_test.rb @@ -1,7 +1,8 @@ require File.dirname(__FILE__) + '/../test_helper' class UserPreferenceTest < ActiveSupport::TestCase - fixtures :users, :user_preferences + api_fixtures + fixtures :user_preferences # This checks to make sure that there are two user preferences # stored in the test database. diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index c0df4b716..f87b5b6fc 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -1,8 +1,9 @@ require File.dirname(__FILE__) + '/../test_helper' class UserTest < Test::Unit::TestCase - fixtures :users - + api_fixtures + fixtures :friends + def test_invalid_with_empty_attributes user = User.new assert !user.valid? diff --git a/test/unit/user_token_test.rb b/test/unit/user_token_test.rb index 2bc1a2dce..83a36f8d9 100644 --- a/test/unit/user_token_test.rb +++ b/test/unit/user_token_test.rb @@ -1,8 +1,9 @@ require File.dirname(__FILE__) + '/../test_helper' class UserTokenTest < Test::Unit::TestCase - fixtures :users - + api_fixtures + fixtures :user_tokens + def test_user_token_count assert_equal 0, UserToken.count end diff --git a/test/unit/way_node_test.rb b/test/unit/way_node_test.rb index 1871eae9d..acc62d330 100644 --- a/test/unit/way_node_test.rb +++ b/test/unit/way_node_test.rb @@ -1,9 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class WayNodeTest < Test::Unit::TestCase - fixtures :way_nodes, :current_way_nodes - set_fixture_class :way_nodes=>OldWayNode - set_fixture_class :current_way_nodes=>WayNode + api_fixtures def test_way_nodes_count assert_equal 4, WayNode.count diff --git a/test/unit/way_tag_test.rb b/test/unit/way_tag_test.rb index b1a7d2256..018263da1 100644 --- a/test/unit/way_tag_test.rb +++ b/test/unit/way_tag_test.rb @@ -1,8 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class WayTagTest < Test::Unit::TestCase - fixtures :current_way_tags - set_fixture_class :current_way_tags => WayTag + api_fixtures def test_way_tag_count assert_equal 3, WayTag.count diff --git a/test/unit/way_test.rb b/test/unit/way_test.rb index 584a30daa..55ab092ea 100644 --- a/test/unit/way_test.rb +++ b/test/unit/way_test.rb @@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/../test_helper' class WayTest < Test::Unit::TestCase api_fixtures - # Check that we have the correct number of currnet ways in the db # This will need to updated whenever the current_ways.yml is updated def test_db_count -- 2.39.5