From 427becc1db048c05576887e74b26c4118fa32d77 Mon Sep 17 00:00:00 2001 From: Shaun McDonald Date: Tue, 28 Oct 2008 12:27:10 +0000 Subject: [PATCH] Moving all the functional tests to the Rails 2 way, which uses less code by having an additional sub-class to take care of the duplicate code in every test. There is a bug in rails 2.0.2, which means that super doesn't get called in the setup method in the functional tests. This is fixed in Rails 2.1.2, thus a version bump should really be done. --- test/functional/api_controller_test.rb | 9 ++------- test/functional/browse_controller_test.rb | 13 +------------ test/functional/changeset_controller_test.rb | 13 +------------ test/functional/geocoder_controller_test.rb | 10 +--------- test/functional/message_controller_test.rb | 10 +--------- test/functional/node_controller_test.rb | 11 +---------- test/functional/old_node_controller_test.rb | 11 +---------- test/functional/old_relation_controller_test.rb | 12 +----------- test/functional/old_way_controller_test.rb | 11 +---------- test/functional/relation_controller_test.rb | 11 +---------- test/functional/way_controller_test.rb | 11 +---------- test/test_helper.rb | 2 +- 12 files changed, 13 insertions(+), 111 deletions(-) diff --git a/test/functional/api_controller_test.rb b/test/functional/api_controller_test.rb index 0ee49517f..b6bd2bf1d 100644 --- a/test/functional/api_controller_test.rb +++ b/test/functional/api_controller_test.rb @@ -1,16 +1,11 @@ require File.dirname(__FILE__) + '/../test_helper' require 'api_controller' -# Re-raise errors caught by the controller. -class ApiController; def rescue_action(e) raise e end; end - -class ApiControllerTest < Test::Unit::TestCase +class ApiControllerTest < ActionController::TestCase api_fixtures def setup - @controller = ApiController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + super @badbigbbox = %w{ -0.1,-0.1,1.1,1.1 10,10,11,11 } @badmalformedbbox = %w{ -0.1 hello 10N2W10.1N2.1W } diff --git a/test/functional/browse_controller_test.rb b/test/functional/browse_controller_test.rb index 81dbede57..65e851011 100644 --- a/test/functional/browse_controller_test.rb +++ b/test/functional/browse_controller_test.rb @@ -1,19 +1,8 @@ require File.dirname(__FILE__) + '/../test_helper' require 'browse_controller' -# Re-raise errors caught by the controller. -class BrowseController; def rescue_action(e) raise e end; end - - class BrowseControllerTest < Test::Unit::TestCase +class BrowseControllerTest < ActionController::TestCase api_fixtures - - - - def setup - @controller = BrowseController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end def basic_authorization(user, pass) @request.env["HTTP_AUTHORIZATION"] = "Basic %s" % Base64.encode64("#{user}:#{pass}") diff --git a/test/functional/changeset_controller_test.rb b/test/functional/changeset_controller_test.rb index 848b6d5f5..5e26c2071 100644 --- a/test/functional/changeset_controller_test.rb +++ b/test/functional/changeset_controller_test.rb @@ -1,19 +1,8 @@ require File.dirname(__FILE__) + '/../test_helper' require 'changeset_controller' -# Re-raise errors caught by the controller. -class ChangesetController; def rescue_action(e) raise e end; end - - class ChangesetControllerTest < Test::Unit::TestCase +class ChangesetControllerTest < ActionController::TestCase api_fixtures - - - - def setup - @controller = ChangesetController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end def basic_authorization(user, pass) @request.env["HTTP_AUTHORIZATION"] = "Basic %s" % Base64.encode64("#{user}:#{pass}") diff --git a/test/functional/geocoder_controller_test.rb b/test/functional/geocoder_controller_test.rb index 3faadc740..f63fe518d 100644 --- a/test/functional/geocoder_controller_test.rb +++ b/test/functional/geocoder_controller_test.rb @@ -1,15 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' require 'geocoder_controller' -# Re-raise errors caught by the controller. -class GeocoderController; def rescue_action(e) raise e end; end - -class GeocoderControllerTest < Test::Unit::TestCase - def setup - @controller = GeocoderController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end +class GeocoderControllerTest < ActionController::TestCase # Replace this with your real tests. def test_truth diff --git a/test/functional/message_controller_test.rb b/test/functional/message_controller_test.rb index 54c8a18d1..96f509cb0 100644 --- a/test/functional/message_controller_test.rb +++ b/test/functional/message_controller_test.rb @@ -1,15 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' require 'message_controller' -# Re-raise errors caught by the controller. -class MessageController; def rescue_action(e) raise e end; end - -class MessageControllerTest < Test::Unit::TestCase - def setup - @controller = MessageController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end +class MessageControllerTest < ActionController::TestCase # Replace this with your real tests. def test_truth diff --git a/test/functional/node_controller_test.rb b/test/functional/node_controller_test.rb index dbc00cbb2..9e5621f8b 100644 --- a/test/functional/node_controller_test.rb +++ b/test/functional/node_controller_test.rb @@ -1,18 +1,9 @@ require File.dirname(__FILE__) + '/../test_helper' require 'node_controller' -# Re-raise errors caught by the controller. -class NodeController; def rescue_action(e) raise e end; end - -class NodeControllerTest < Test::Unit::TestCase +class NodeControllerTest < ActionController::TestCase api_fixtures - def setup - @controller = NodeController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end - def test_create # cannot read password from fixture as it is stored as MD5 digest basic_authorization(users(:normal_user).email, "test"); diff --git a/test/functional/old_node_controller_test.rb b/test/functional/old_node_controller_test.rb index cdacca52b..f1328e650 100644 --- a/test/functional/old_node_controller_test.rb +++ b/test/functional/old_node_controller_test.rb @@ -1,18 +1,9 @@ require File.dirname(__FILE__) + '/../test_helper' require 'old_node_controller' -# Re-raise errors caught by the controller. -class OldNodeController; def rescue_action(e) raise e end; end - -class OldNodeControllerTest < Test::Unit::TestCase +class OldNodeControllerTest < ActionController::TestCase api_fixtures - def setup - @controller = OldNodeController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end - # # TODO: test history # diff --git a/test/functional/old_relation_controller_test.rb b/test/functional/old_relation_controller_test.rb index b8bf464b6..a52211e2e 100644 --- a/test/functional/old_relation_controller_test.rb +++ b/test/functional/old_relation_controller_test.rb @@ -1,22 +1,12 @@ 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 +class OldRelationControllerTest < ActionController::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 diff --git a/test/functional/old_way_controller_test.rb b/test/functional/old_way_controller_test.rb index c47b45dfc..31da1d2c7 100644 --- a/test/functional/old_way_controller_test.rb +++ b/test/functional/old_way_controller_test.rb @@ -1,18 +1,9 @@ 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 +class OldWayControllerTest < ActionController::TestCase api_fixtures - def setup - @controller = OldWayController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end - # ------------------------------------- # Test reading old ways. # ------------------------------------- diff --git a/test/functional/relation_controller_test.rb b/test/functional/relation_controller_test.rb index 1c6439a96..812b35fb1 100644 --- a/test/functional/relation_controller_test.rb +++ b/test/functional/relation_controller_test.rb @@ -1,18 +1,9 @@ require File.dirname(__FILE__) + '/../test_helper' require 'relation_controller' -# Re-raise errors caught by the controller. -class RelationController; def rescue_action(e) raise e end; end - -class RelationControllerTest < Test::Unit::TestCase +class RelationControllerTest < ActionController::TestCase api_fixtures - def setup - @controller = RelationController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end - def basic_authorization(user, pass) @request.env["HTTP_AUTHORIZATION"] = "Basic %s" % Base64.encode64("#{user}:#{pass}") end diff --git a/test/functional/way_controller_test.rb b/test/functional/way_controller_test.rb index 895e7532f..19b7fd54c 100644 --- a/test/functional/way_controller_test.rb +++ b/test/functional/way_controller_test.rb @@ -1,18 +1,9 @@ require File.dirname(__FILE__) + '/../test_helper' require 'way_controller' -# Re-raise errors caught by the controller. -class WayController; def rescue_action(e) raise e end; end - -class WayControllerTest < Test::Unit::TestCase +class WayControllerTest < ActionController::TestCase api_fixtures - def setup - @controller = WayController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end - def basic_authorization(user, pass) @request.env["HTTP_AUTHORIZATION"] = "Basic %s" % Base64.encode64("#{user}:#{pass}") end diff --git a/test/test_helper.rb b/test/test_helper.rb index a170aed4f..c01c31fca 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -27,7 +27,7 @@ class Test::Unit::TestCase # Load standard fixtures needed to test API methods def self.api_fixtures - print "setting up the api_fixtures" + #print "setting up the api_fixtures" fixtures :users, :changesets fixtures :current_nodes, :nodes -- 2.39.5