3 This section describes how to add a controller named 'woodpeckers' to your plugin that will behave the same as a controller in your main app. This is very similar to adding a model.
5 You can test your plugin's controller as you would test any other controller:
7 *vendor/plugins/yaffle/yaffle/woodpeckers_controller_test.rb:*
10 ----------------------------------------------
11 require File.dirname(__FILE__) + '/test_helper.rb'
12 require 'woodpeckers_controller'
13 require 'action_controller/test_process'
15 class WoodpeckersController; def rescue_action(e) raise e end; end
17 class WoodpeckersControllerTest < Test::Unit::TestCase
19 @controller = WoodpeckersController.new
20 @request = ActionController::TestRequest.new
21 @response = ActionController::TestResponse.new
26 assert_response :success
29 ----------------------------------------------
31 This is just a simple test to make sure the controller is being loaded correctly. After watching it fail with `rake`, you can make it pass like so:
33 *vendor/plugins/yaffle/lib/yaffle.rb:*
36 ----------------------------------------------
37 %w{ models controllers }.each do |dir|
38 path = File.join(File.dirname(__FILE__), 'app', dir)
40 ActiveSupport::Dependencies.load_paths << path
41 ActiveSupport::Dependencies.load_once_paths.delete(path)
43 ----------------------------------------------
46 *vendor/plugins/yaffle/lib/app/controllers/woodpeckers_controller.rb:*
49 ----------------------------------------------
50 class WoodpeckersController < ActionController::Base
53 render :text => "Squawk!"
57 ----------------------------------------------
59 Now your test should be passing, and you should be able to use the Woodpeckers controller in your app. If you add a route for the woodpeckers controller you can start up your server and go to http://localhost:3000/woodpeckers to see your controller in action.