From fa9ea057d1252a578f8e056defef41b93853bc8b Mon Sep 17 00:00:00 2001 From: Jeff Dean Date: Fri, 14 Nov 2008 03:14:09 -0500 Subject: Plugin guide: updated to start working with GemPlugin --- railties/doc/guides/html/creating_plugins.html | 10 +++++----- railties/doc/guides/source/creating_plugins/core_ext.txt | 5 ++--- railties/doc/guides/source/creating_plugins/gem.txt | 1 + railties/doc/guides/source/creating_plugins/test_setup.txt | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 railties/doc/guides/source/creating_plugins/gem.txt diff --git a/railties/doc/guides/html/creating_plugins.html b/railties/doc/guides/html/creating_plugins.html index 023a4ddbab..375d216b4a 100644 --- a/railties/doc/guides/html/creating_plugins.html +++ b/railties/doc/guides/html/creating_plugins.html @@ -447,6 +447,7 @@ create vendor/plugins/yaffle/generators/yaffle/templates create vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb create vendor/plugins/yaffle/generators/yaffle/USAGE +

To begin just change one thing - move init.rb to rails/init.rb.

1.3. Setup the plugin for testing

If your plugin interacts with a database, you'll need to setup a database connection. In this guide you will learn how to test your plugin against multiple different database adapters using Active Record. This guide will not cover how to use fixtures in plugin tests.

To setup your plugin to allow for easy testing you'll need to add 3 files:

@@ -553,7 +554,7 @@ ENV['RAILS_ROOT ActiveRecord::Base.establish_connection(config[db_adapter]) load(File.dirname(__FILE__) + "/schema.rb") - require File.dirname(__FILE__) + '/../init.rb' + require File.dirname(__FILE__) + '/../rails/init.rb' end

Now whenever you write a test that requires the database, you can call load_schema.

@@ -668,14 +669,13 @@ NoMethodError: undefined method `to_squawk' for "Hello World":String

A common pattern in rails plugins is to set up the file structure like this:

-
|-- init.rb
-|-- lib
+
|-- lib
 |   |-- yaffle
 |   |   `-- core_ext.rb
 |   `-- yaffle.rb
-

The first thing we need to to is to require our lib/yaffle.rb file from init.rb:

-

vendor/plugins/yaffle/init.rb

+

The first thing we need to to is to require our lib/yaffle.rb file from rails/init.rb:

+

vendor/plugins/yaffle/rails/init.rb