diff options
Diffstat (limited to 'railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt')
-rw-r--r-- | railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt b/railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt index 12d40deb18..06878543e4 100644 --- a/railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt +++ b/railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt @@ -4,10 +4,10 @@ A common pattern in plugins is to add a method called `acts_as_something` to mod To keep things clean, create a new test file called 'acts_as_yaffle_test.rb' in your plugin's test directory and require your test helper. +*vendor/plugins/yaffle/test/acts_as_yaffle_test.rb* + [source, ruby] ------------------------------------------------------ -# File: vendor/plugins/yaffle/test/acts_as_yaffle_test.rb - require File.dirname(__FILE__) + '/test_helper.rb' class Hickwall < ActiveRecord::Base @@ -18,16 +18,18 @@ class ActsAsYaffleTest < Test::Unit::TestCase end ------------------------------------------------------ +*vendor/plugins/lib/acts_as_yaffle.rb* + [source, ruby] ------------------------------------------------------ -# File: vendor/plugins/lib/acts_as_yaffle.rb - module Yaffle end ------------------------------------------------------ One of the most common plugin patterns for `acts_as_yaffle` plugins is to structure your file like so: +*vendor/plugins/lib/acts_as_yaffle.rb* + [source, ruby] ------------------------------------------------------ module Yaffle @@ -65,10 +67,10 @@ end Now that test should pass. Since your plugin is going to work with field names, you need to allow people to define the field names, in case there is a naming conflict. You can write a few simple tests for this: +*vendor/plugins/yaffle/test/acts_as_yaffle_test.rb* + [source, ruby] ------------------------------------------------------ -# File: vendor/plugins/yaffle/test/acts_as_yaffle_test.rb - require File.dirname(__FILE__) + '/test_helper.rb' class ActsAsYaffleTest < Test::Unit::TestCase @@ -92,10 +94,10 @@ end To make these tests pass, you could modify your `acts_as_yaffle` file like so: +*vendor/plugins/yaffle/lib/acts_as_yaffle.rb* + [source, ruby] ------------------------------------------------------ -# File: vendor/plugins/yaffle/lib/acts_as_yaffle.rb - module Yaffle def self.included(base) base.send :extend, ClassMethods @@ -117,10 +119,10 @@ end Now you can add tests for the instance methods, and the instance method itself: +*vendor/plugins/yaffle/test/acts_as_yaffle_test.rb* + [source, ruby] ------------------------------------------------------ -# File: vendor/plugins/yaffle/test/acts_as_yaffle_test.rb - require File.dirname(__FILE__) + '/test_helper.rb' class ActsAsYaffleTest < Test::Unit::TestCase @@ -163,10 +165,10 @@ class ActsAsYaffleTest < Test::Unit::TestCase end ------------------------------------------------------ +*vendor/plugins/yaffle/lib/acts_as_yaffle.rb* + [source, ruby] ------------------------------------------------------ -# File: vendor/plugins/yaffle/lib/acts_as_yaffle.rb - module Yaffle def self.included(base) base.send :extend, ClassMethods @@ -190,4 +192,5 @@ module Yaffle end ------------------------------------------------------ -Note the use of `write_attribute` to write to the field in model. +.Editor's note: +NOTE: The use of `write_attribute` to write to the field in model is just one example of how a plugin can interact with the model, and will not always be the right method to use. For example, you could also use `send("#{self.class.yaffle_text_field}=", string.to_squawk)`. |