pager-engines 2.0.20080513

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/CHANGELOG +267 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +83 -0
  4. data/Rakefile +188 -0
  5. data/about.yml +7 -0
  6. data/boot.rb +19 -0
  7. data/generators/plugin_migration/USAGE +45 -0
  8. data/generators/plugin_migration/plugin_migration_generator.rb +79 -0
  9. data/generators/plugin_migration/templates/plugin_migration.erb +13 -0
  10. data/init.rb +5 -0
  11. data/lib/engines.rb +174 -0
  12. data/lib/engines/assets.rb +38 -0
  13. data/lib/engines/plugin.rb +142 -0
  14. data/lib/engines/plugin/list.rb +30 -0
  15. data/lib/engines/plugin/loader.rb +18 -0
  16. data/lib/engines/plugin/locator.rb +37 -0
  17. data/lib/engines/plugin/migrator.rb +73 -0
  18. data/lib/engines/rails_extensions/action_mailer.rb +85 -0
  19. data/lib/engines/rails_extensions/asset_helpers.rb +119 -0
  20. data/lib/engines/rails_extensions/dependencies.rb +145 -0
  21. data/lib/engines/rails_extensions/migrations.rb +161 -0
  22. data/lib/engines/rails_extensions/rails.rb +11 -0
  23. data/lib/engines/rails_extensions/routing.rb +84 -0
  24. data/lib/engines/testing.rb +87 -0
  25. data/lib/engines_initializer.rb +5 -0
  26. data/rails/init.rb +5 -0
  27. data/tasks/engines.rake +179 -0
  28. data/test/app/controllers/app_and_plugin_controller.rb +5 -0
  29. data/test/app/controllers/application.rb +18 -0
  30. data/test/app/controllers/namespace/app_and_plugin_controller.rb +5 -0
  31. data/test/app/helpers/mail_helper.rb +5 -0
  32. data/test/app/models/app_and_plugin_model.rb +3 -0
  33. data/test/app/models/notify_mail.rb +26 -0
  34. data/test/app/things/thing.rb +3 -0
  35. data/test/app/views/app_and_plugin/a_view.html.erb +1 -0
  36. data/test/app/views/namespace/app_and_plugin/a_view.html.erb +1 -0
  37. data/test/app/views/notify_mail/implicit_multipart.text.html.erb +1 -0
  38. data/test/app/views/notify_mail/implicit_multipart.text.plain.erb +1 -0
  39. data/test/app/views/notify_mail/multipart_html.html.erb +1 -0
  40. data/test/app/views/notify_mail/multipart_plain.html.erb +1 -0
  41. data/test/app/views/notify_mail/signup.text.plain.erb +5 -0
  42. data/test/app/views/plugin_mail/mail_from_plugin_with_application_template.text.plain.erb +1 -0
  43. data/test/app/views/plugin_mail/multipart_from_plugin_with_application_template_plain.html.erb +1 -0
  44. data/test/functional/controller_loading_test.rb +51 -0
  45. data/test/functional/routes_test.rb +33 -0
  46. data/test/functional/view_helpers_test.rb +32 -0
  47. data/test/functional/view_loading_test.rb +60 -0
  48. data/test/lib/app_and_plugin_lib_model.rb +3 -0
  49. data/test/lib/engines_test_helper.rb +36 -0
  50. data/test/plugins/alpha_plugin/app/controllers/alpha_plugin_controller.rb +8 -0
  51. data/test/plugins/alpha_plugin/app/controllers/app_and_plugin_controller.rb +5 -0
  52. data/test/plugins/alpha_plugin/app/controllers/namespace/alpha_plugin_controller.rb +5 -0
  53. data/test/plugins/alpha_plugin/app/controllers/namespace/app_and_plugin_controller.rb +5 -0
  54. data/test/plugins/alpha_plugin/app/controllers/namespace/shared_plugin_controller.rb +5 -0
  55. data/test/plugins/alpha_plugin/app/controllers/shared_plugin_controller.rb +5 -0
  56. data/test/plugins/alpha_plugin/app/models/alpha_plugin_model.rb +3 -0
  57. data/test/plugins/alpha_plugin/app/models/app_and_plugin_model.rb +7 -0
  58. data/test/plugins/alpha_plugin/app/models/shared_plugin_model.rb +3 -0
  59. data/test/plugins/alpha_plugin/app/views/alpha_plugin/a_view.html.erb +1 -0
  60. data/test/plugins/alpha_plugin/app/views/app_and_plugin/a_view.html.erb +1 -0
  61. data/test/plugins/alpha_plugin/app/views/layouts/plugin_layout.erb +1 -0
  62. data/test/plugins/alpha_plugin/app/views/namespace/alpha_plugin/a_view.html.erb +1 -0
  63. data/test/plugins/alpha_plugin/app/views/namespace/app_and_plugin/a_view.html.erb +1 -0
  64. data/test/plugins/alpha_plugin/app/views/namespace/shared_plugin/a_view.html.erb +1 -0
  65. data/test/plugins/alpha_plugin/app/views/shared_plugin/a_view.html.erb +1 -0
  66. data/test/plugins/alpha_plugin/lib/alpha_plugin_lib_model.rb +3 -0
  67. data/test/plugins/alpha_plugin/lib/app_and_plugin_lib_model.rb +7 -0
  68. data/test/plugins/beta_plugin/app/controllers/app_and_plugin_controller.rb +5 -0
  69. data/test/plugins/beta_plugin/app/controllers/namespace/shared_plugin_controller.rb +5 -0
  70. data/test/plugins/beta_plugin/app/controllers/shared_plugin_controller.rb +5 -0
  71. data/test/plugins/beta_plugin/app/models/shared_plugin_model.rb +3 -0
  72. data/test/plugins/beta_plugin/app/views/namespace/shared_plugin/a_view.html.erb +1 -0
  73. data/test/plugins/beta_plugin/app/views/shared_plugin/a_view.html.erb +1 -0
  74. data/test/plugins/beta_plugin/init.rb +1 -0
  75. data/test/plugins/not_a_plugin/public/should_not_be_copied.txt +0 -0
  76. data/test/plugins/test_assets/app/controllers/assets_controller.rb +2 -0
  77. data/test/plugins/test_assets/app/views/assets/index.html.erb +3 -0
  78. data/test/plugins/test_assets/app/views/layouts/assets.html.erb +3 -0
  79. data/test/plugins/test_assets/init.rb +0 -0
  80. data/test/plugins/test_assets/public/file.txt +0 -0
  81. data/test/plugins/test_assets/public/subfolder/file_in_subfolder.txt +0 -0
  82. data/test/plugins/test_assets_with_assets_directory/assets/file.txt +0 -0
  83. data/test/plugins/test_assets_with_assets_directory/assets/subfolder/file_in_subfolder.txt +0 -0
  84. data/test/plugins/test_assets_with_assets_directory/init.rb +0 -0
  85. data/test/plugins/test_assets_with_no_subdirectory/assets/file.txt +0 -0
  86. data/test/plugins/test_assets_with_no_subdirectory/init.rb +0 -0
  87. data/test/plugins/test_code_mixing/app/things/thing.rb +3 -0
  88. data/test/plugins/test_code_mixing/init.rb +1 -0
  89. data/test/plugins/test_load_path/init.rb +0 -0
  90. data/test/plugins/test_migration/db/migrate/001_create_tests.rb +11 -0
  91. data/test/plugins/test_migration/db/migrate/002_create_others.rb +11 -0
  92. data/test/plugins/test_migration/init.rb +0 -0
  93. data/test/plugins/test_plugin_mailing/app/models/plugin_mail.rb +26 -0
  94. data/test/plugins/test_plugin_mailing/app/views/plugin_mail/mail_from_plugin.text.plain.erb +1 -0
  95. data/test/plugins/test_plugin_mailing/app/views/plugin_mail/multipart_from_plugin_html.html.erb +1 -0
  96. data/test/plugins/test_plugin_mailing/app/views/plugin_mail/multipart_from_plugin_plain.html.erb +1 -0
  97. data/test/plugins/test_plugin_mailing/app/views/plugin_mail/multipart_from_plugin_with_application_template_html.html.erb +1 -0
  98. data/test/plugins/test_plugin_mailing/app/views/plugin_mail/multipart_from_plugin_with_application_template_plain.html.erb +1 -0
  99. data/test/plugins/test_plugin_mailing/init.rb +0 -0
  100. data/test/plugins/test_routing/app/controllers/namespace/test_routing_controller.rb +5 -0
  101. data/test/plugins/test_routing/app/controllers/test_routing_controller.rb +9 -0
  102. data/test/plugins/test_routing/init.rb +0 -0
  103. data/test/plugins/test_routing/routes.rb +2 -0
  104. data/test/plugins/test_testing/init.rb +0 -0
  105. data/test/plugins/test_testing/test/fixtures/testing_fixtures.yml +0 -0
  106. data/test/unit/action_mailer_test.rb +54 -0
  107. data/test/unit/arbitrary_code_mixing_test.rb +41 -0
  108. data/test/unit/assets_test.rb +48 -0
  109. data/test/unit/backwards_compat_test.rb +8 -0
  110. data/test/unit/load_path_test.rb +58 -0
  111. data/test/unit/migration_test.rb +43 -0
  112. data/test/unit/model_and_lib_test.rb +37 -0
  113. data/test/unit/plugins_test.rb +11 -0
  114. data/test/unit/testing_test.rb +18 -0
  115. metadata +255 -0
@@ -0,0 +1,267 @@
1
+ = EDGE
2
+
3
+ * Refactored the view loading to work with changes in Edge Rails
4
+
5
+ * Fixed integration of plugin migrations with the new, default timestamped migrations in Edge Rails
6
+
7
+ * Refactored tests into the plugin itself - the plugin can now generate its own test_app harness and run tests within it.
8
+
9
+
10
+ = 2.0.0 - (ANOTHER) MASSIVE INTERNAL REFACTORING
11
+
12
+ * Engines now conforms to the new plugin loading mechanism, delegating plugin load order and lots of other things to Rails itself.
13
+
14
+
15
+
16
+ = 1.2.2
17
+
18
+ * Added the ability to code mix different types of files, cleaning up the existing code-mixing implementation slightly (Ticket #271)
19
+
20
+
21
+ = 1.2.1
22
+
23
+ * Added documentation to clarify some of the issues with Rails unloading classes that aren't required using "require_dependency" (Ticket #266)
24
+
25
+ * Fixed a bug where test_help was being loaded when it wasn't needed, and was actually causing problems (Ticket #265)
26
+
27
+
28
+ = 1.2.0 - MASSIVE INTERNAL REFACTORING
29
+
30
+ * !!!Support for Rails < 1.2 has been dropped!!!; if you are using Rails =< 1.1.6, please use Engines 1.1.6, available from http://svn.rails-engines.org/engines/tags/rel_1.1.6
31
+
32
+ * Engines are dead! Long live plugins! There is now no meaningful notion of an engine - all plugins can take advantage of the more powerful features that the engines plugin provides by including app directories, etc.
33
+
34
+ * Init_engine.rb is no longer used; please use the plugin-standard init.rb instead.
35
+
36
+ * Engines.start is no longer required; please use the config.plugins array provided by Rails instead
37
+
38
+ * To get the most benefit from Engines, set config.plugins to ["engines", "*"] to load the engines plugin first, and then all other plugins in their normal order after.
39
+
40
+ * Access all loaded plugins via the new Rails.plugins array, and by name using Rails.plugins[:plugin_name].
41
+
42
+ * Access plugin metadata loaded automatically from about.yml: Rails.plugins[:name].about. Plugin#version is provided directly, for easy access.
43
+
44
+ * Module.config is has been removed - use mattr_accessor instead, and initialize your default values via the init.rb mechanism.
45
+
46
+ * Public asset helpers have been rewritten; instead of engine_stylesheet, now use stylesheet_link_tag :name, :plugin => "plugin_name"
47
+
48
+ * Plugin migrations have been reworked to integrate into the main migration stream. Please run script/generate plugin_migration to create plugin migrations in your main application.
49
+
50
+ * The fixture method for loading fixtures against any class has been removed; instead, engines will now provide a mechanism for loading fixtures from all plugins, by mirroring fixtures into a common location.
51
+
52
+ * All references to engines have been removed; For example, any rake tasks which applied to engines now apply to all plugins. The default Rails rake tasks for plugins are overridden where necessary.
53
+
54
+ * Layouts can now be shared via plugins - inspiration gratefully taken from PluginAWeek's plugin_routing :)
55
+
56
+ * Actual routing from plugins is now possible, by including routes.rb in your plugin directory and using the from_plugin method in config/routes.rb (Ticket #182)
57
+
58
+ * Controllers are no longer loaded twice if they're not present in the normal app/ directory (Ticket #177)
59
+
60
+ * The preferred location for javascripts/stylesheets/etc is now 'assets' rather than 'public'
61
+
62
+ * Ensure that plugins started before routing have their controllers appropriately added to config.controller_paths (Ticket #258)
63
+
64
+ * Removed Engines.version - it's not longer relevant, now we're loading version information from about.yml files.
65
+
66
+ * Added a huge amount of documentation to all new modules.
67
+
68
+ * Added new warning message if installation of engines 1.2.x is attempted in a Rails 1.1.x application
69
+
70
+ * Added details of the removal of the config method to UPGRADING
71
+
72
+ * Removed the plugins:info rake task in favour of adding information to script/about via the Rails::Info module (Ticket #261)
73
+
74
+ * Improved handling of testing and documentation tasks for plugins
75
+
76
+
77
+
78
+ = 1.1.4
79
+
80
+ * Fixed creation of multipart emails (Ticket #190)
81
+
82
+ * Added a temporary fix to the code-mixing issue. In your engine's test/test_helper.rb, please add the following lines:
83
+
84
+ # Ensure that the code mixing and view loading from the application is disabled
85
+ Engines.disable_app_views_loading = true
86
+ Engines.disable_app_code_mixing = true
87
+
88
+ which will prevent code mixing for controllers and helpers, and loading views from the application. One thing to remember is to load any controllers/helpers using 'require_or_load' in your tests, to ensure that the engine behaviour is respected (Ticket #135)
89
+
90
+ * Added tasks to easily test engines individually (Ticket #120)
91
+
92
+ * Fixture extensions will now fail with an exception if the corresponding class cannot be loaded (Ticket #138)
93
+
94
+ * Patch for new routing/controller loading in Rails 1.1.6. The routing code is now replaced with the contents of config.controller_paths, along with controller paths from any started engines (Ticket #196)
95
+
96
+ * Rails' Configuration instance is now stored, and available from all engines and plugins.
97
+
98
+
99
+
100
+ = 1.1.3
101
+
102
+ * Fixed README to show 'models' rather than 'model' class (Ticket #167)
103
+ * Fixed dependency loading to work with Rails 1.1.4 (Ticket #180)
104
+
105
+
106
+
107
+ = 1.1.2
108
+
109
+ * Added better fix to version checking (Ticket #130, jdell@gbdev.com).
110
+
111
+ * Fixed generated init_engine.rb so that VERSION module doesn't cause probems (Ticket #131, japgolly@gmail.com)
112
+
113
+ * Fixed error with Rails 1.0 when trying to ignore the engine_schema_info table (Ticket #132, snowblink@gmail.com)
114
+
115
+ * Re-added old style rake tasks (Ticket #133)
116
+
117
+ * No longer adding all subdirectories of <engine>/app or <engine>/lib, as this can cause issues when files are grouped in modules (Ticket #149, kasatani@gmail.com)
118
+
119
+ * Fixed engine precidence ordering for Rails 1.1 (Ticket #146)
120
+
121
+ * Added new Engines.each method to assist in processing the engines in the desired order (Ticket #146)
122
+
123
+ * Fixed annoying error message at appears when starting the console in development mode (Ticket #134)
124
+
125
+ * Engines is now super-careful about loading the correct version of Rails from vendor (Ticket #154)
126
+
127
+
128
+
129
+ = 1.1.1
130
+
131
+ * Fixed migration rake task failing when given a specific version (Ticket #115)
132
+
133
+ * Added new rake task "test:engines" which will test engines (and other plugins) but ensure that the test database is cloned from development beforehand (Ticket #125)
134
+
135
+ * Fixed issue where 'engine_schema_info' table was included in schema dumps (Ticket #87)
136
+
137
+ * Fixed multi-part emails (Ticket #121)
138
+
139
+ * Added an 'install.rb' file to new engines created by the bundled generator, which installs the engines plugin automatically if it doesn't already exist (Ticket #122)
140
+
141
+ * Added a default VERSION module to generated engines (Ticket #123)
142
+
143
+ * Refactored copying of engine's public files to a method of an Engine instance. You can now call Engines.get(:engine_name).copy_public_files (Ticket #108)
144
+
145
+ * Changed engine generator templates from .rb files to .erb files (Ticket #106)
146
+
147
+ * Fixed the test_helper.erb file to use the correct testing extensions and not load any schema - the schema will be cloned automatically via rake test:engines
148
+
149
+ * Fixed problem when running with Rails 1.1.1 where version wasn't determined correctly (Ticket #129)
150
+
151
+ * Fixed bug preventing engines from loading when both Rails 1.1.0 and 1.1.1 gems are installed and in use.
152
+
153
+ * Updated version (d'oh!)
154
+
155
+
156
+
157
+ = 1.1.0
158
+
159
+ * Improved regexp matching for Rails 1.0 engines with peculiar paths
160
+
161
+ * Engine instance objects can be accessed via Engines[:name], an alias for Engines.get(:name) (Ticket #99)
162
+
163
+ * init_engine.rb is now processed as the final step in the Engine.start process, so it can access files within the lib directory, which is now in the $LOAD_PATH at that point. (Ticket #99)
164
+
165
+ * Clarified MIT license (Ticket #98)
166
+
167
+ * Updated Rake tasks to integrate smoothly with Rails 1.1 namespaces
168
+
169
+ * Changed the version to "1.1.0 (svn)"
170
+
171
+ * Added more information about using the plugin with Edge Rails to the README
172
+
173
+ * moved extensions into lib/engines/ directory to enable use of Engines module in extension code.
174
+
175
+ * Added conditional require_or_load method which attempts to detect the current Rails version. To use the Edge Rails version of the loading mechanism, add the line:
176
+
177
+ * Engines.config :edge, true
178
+
179
+ * to your environment.rb file.
180
+
181
+ * Merged changes from /branches/edge and /branches/rb_1.0 into /trunk
182
+
183
+ * engine_schema_info now respects the prefix/suffixes set for ActiveRecord::Base (Ticket #67)
184
+
185
+ * added ActiveRecord::Base.wrapped_table_name(name) method to assist in determining the correct table name
186
+
187
+
188
+
189
+ = 1.0.6
190
+
191
+ * Added ability to determine version information for engines: rake engine_info
192
+
193
+ * Added a custom logger for the Engines module, to stop pollution of the Rails logs.
194
+
195
+ * Added some more tests (in particular, see rails_engines/applications/engines_test).
196
+
197
+ * Another attempt at solving Ticket #53 - controllers and helpers should now be loadable from modules, and if a full path (including RAILS_ROOT/ENGINES_ROOT) is given, it should be safely stripped from the require filename such that corresponding files can be located in any active engines. In other words, controller/helper overloading should now completely work, even if the controllers/helpers are in modules.
198
+
199
+ * Added (finally) patch from Ticket #22 - ActionMailer helpers should now load
200
+
201
+ * Removed support for Engines.start :engine, :engine_name => 'whatever'. It was pointless.
202
+
203
+ * Fixed engine name referencing; engine_stylesheet/engine_javascript can now happily use shorthand engine names (i.e. :test == :test_engine) (Ticket #45)
204
+
205
+ * Fixed minor documentation error ('Engine.start' ==> 'Engines.start') (Ticket #57)
206
+
207
+ * Fixed double inclusion of RAILS_ROOT in engine_migrate rake task (Ticket #61)
208
+
209
+ * Added ability to force config values even if given as a hash (Ticket #62)
210
+
211
+
212
+
213
+ = 1.0.5
214
+
215
+ * Fixed bug stopping fixtures from loading with PostgreSQL
216
+
217
+
218
+
219
+ = 1.0.4
220
+
221
+ * Another attempt at loading controllers within modules (Ticket #56)
222
+
223
+
224
+
225
+ = 1.0.3
226
+
227
+ * Fixed serious dependency bug stopping controllers being loaded (Ticket #56)
228
+
229
+
230
+
231
+ = 1.0.2
232
+
233
+ * Fixed bug with overloading controllers in modules from /app directory
234
+
235
+ * Fixed exception thrown when public files couldn't be created; exception is now logged (Ticket #52)
236
+
237
+ * Fixed problem with generated test_helper.rb file via File.expand_path (Ticket #50)
238
+
239
+
240
+
241
+ = 1.0.1
242
+
243
+ * Added engine generator for creation of new engines
244
+
245
+ * Fixed 'Engine' typo in README
246
+
247
+ * Fixed bug in fixtures extensions
248
+
249
+ * Fixed /lib path management bug
250
+
251
+ * Added method to determine public directory location from Engine object
252
+
253
+ * Fixed bug in the error message in get_engine_dir()
254
+
255
+ * Added proper component loading
256
+
257
+ * Added preliminary tests for the config() methods module
258
+
259
+
260
+
261
+ = pre-v170
262
+
263
+ * Fixed copyright notices to point to DHH, rather than me.
264
+
265
+ * Moved extension require statements into lib/engines.rb, so the will be loaded if another module/file calls require 'engines
266
+
267
+ * Added a CHANGELOG file (this file)
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2008 James Adam
2
+
3
+ The MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,83 @@
1
+ The engines plugin enhances Rails' own plugin framework, making it simple to share controllers, helpers, models, public assets, routes and migrations in plugins.
2
+
3
+ For more information, see http://rails-engines.org
4
+
5
+ = Using the plugin
6
+
7
+ Once you've installed the engines plugin, you'll need to add a single line to the top of config/environment.rb:
8
+
9
+ require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')
10
+
11
+ You should add this line just below the require for Rails' own boot.rb file. This will enabled the enhanced plugin loading mechanism automatically for you (i.e. you don't need to set config.plugin_loader manually).
12
+
13
+ With that aside, you're now ready to start using more powerful plugins in your application. Read on to find out more about what the engines plugin enables.
14
+
15
+
16
+ == Better plugins
17
+
18
+ In addition to the regular set of plugin-supported files (lib, init.rb, tasks, generators, tests), plugins can carry the following when the engines plugin is also installed.
19
+
20
+
21
+ === Controllers, Helpers, and Views
22
+
23
+ Include these files in an <tt>app</tt> directory just like you would in a normal Rails application. If you need to override a method, view or partial, create the corresponding file in your main <tt>app</tt> directory and it will be used instead.
24
+
25
+ * Controllers & Helpers: See Engines::RailsExtensions::Dependencies for more information.
26
+ * Views: See Engines::RailsExtensions::Templates for more information.
27
+
28
+ === Models
29
+
30
+ Model code can similarly be placed in an <tt>app/models/</tt> directory. Unfortunately, it's not possible to automatically override methods within a model; if your application needs to change the way a model behaves, consider creating a subclass, or replacing the model entirely within your application's <tt>app/models/</tt> directory. See Engines::RailsExtensions::Dependencies for more information.
31
+
32
+ IMPORTANT NOTE: when you load code from within plugins, it is typically not handled well by Rails in terms of unloading and reloading changes. Look here for more information - http://rails-engines.org/development/common-issues-when-overloading-code-from-plugins/
33
+
34
+ === Routes
35
+
36
+ Include your route declarations in a <tt>routes.rb</tt> file at the root of your plugins, e.g.:
37
+
38
+ connect "/my/url", :controller => "some_controller"
39
+ my_named_route "do_stuff", :controller => "blah", :action => "stuff"
40
+ # etc.
41
+
42
+ You can then load these files into your application by declaring their inclusion in the application's <tt>config/routes.rb</tt>:
43
+
44
+ map.from_plugin :plugin_name
45
+
46
+ See Engines::RailsExtensions::Routing for more information.
47
+
48
+ === Migrations
49
+
50
+ Migrations record the changes in your database as your application evolves. With engines 1.2, migrations from plugins can also join in this evolution as first-class entities. To add migrations to a plugin, include a <tt>db/migrate/</tt> folder and add migrations there as normal. These migrations can then be integrated into the main flow of database evolution by running the plugin_migration generator:
51
+
52
+ script/generate plugin_migration
53
+
54
+ This will produce a migration in your application. Running this migration (via <tt>rake db:migrate</tt>, as normal) will migrate the database according to the latest migrations in each plugin. See Engines::RailsExtensions::Migrations for more information.
55
+
56
+
57
+ === More powerful Rake tasks
58
+
59
+ The engines plugin enhances and adds to the suite of default rake tasks for working with plugins. The <tt>doc:plugins</tt> task now includes controllers, helpers and models under <tt>app</tt>, and anything other code found under the plugin's <tt>code_paths</tt> attribute. New testing tasks have been added to run unit, functional and integration tests from plugins, whilst making it easier to load fixtures from plugins. See Engines::Testing for more details about testing, and run
60
+
61
+ rake -T
62
+
63
+ to see the set of rake tasks available.
64
+
65
+ = Testing the engines plugin itself
66
+
67
+ Because of the way the engines plugin modifies Rails, the simplest way to consistently test it against multiple versions is by generating a test harness application - a full Rails application that includes tests to verify the engines plugin behaviour in a real, running environment.
68
+
69
+ Run the tests like this:
70
+
71
+ $ cd engines
72
+ $ rake test
73
+
74
+ This will generate a test_app directory within the engines plugin (using the default 'rails' command), import tests and code into that application and then run the test suite.
75
+
76
+ If you wish to test against a specific version of Rails, run the tests with the RAILS environment variable set to the local directory containing your Rails checkout
77
+
78
+ $ rake test RAILS=/Users/james/Code/rails_edge_checkout
79
+
80
+ Alternatively, you can clone the latest version of Rails ('edge rails') from github like so:
81
+
82
+ $ rake test RAILS=edge
83
+
@@ -0,0 +1,188 @@
1
+ require 'rake'
2
+ require 'rake/rdoctask'
3
+ require 'tmpdir'
4
+
5
+ task :default => :doc
6
+
7
+ desc 'Generate documentation for the engines plugin.'
8
+ Rake::RDocTask.new(:doc) do |doc|
9
+ doc.rdoc_dir = 'doc'
10
+ doc.title = 'Engines'
11
+ doc.main = "README"
12
+ doc.rdoc_files.include("README", "CHANGELOG", "MIT-LICENSE")
13
+ doc.rdoc_files.include('lib/**/*.rb')
14
+ doc.options << '--line-numbers' << '--inline-source'
15
+ end
16
+
17
+ desc 'Run the engine plugin tests within their test harness'
18
+ task :cruise do
19
+ # checkout the project into a temporary directory
20
+ version = "rails_2.0"
21
+ test_dir = "#{Dir.tmpdir}/engines_plugin_#{version}_test"
22
+ puts "Checking out test harness for #{version} into #{test_dir}"
23
+ `svn co http://svn.rails-engines.org/test/engines/#{version} #{test_dir}`
24
+
25
+ # run all the tests in this project
26
+ Dir.chdir(test_dir)
27
+ load 'Rakefile'
28
+ puts "Running all tests in test harness"
29
+ ['db:migrate', 'test', 'test:plugins'].each do |t|
30
+ Rake::Task[t].invoke
31
+ end
32
+ end
33
+
34
+ task :clean => [:clobber_doc, "test:clean"]
35
+
36
+ namespace :test do
37
+
38
+ # Yields a block with STDOUT and STDERR silenced. If you *really* want
39
+ # to output something, the block is yielded with the original output
40
+ # streams, i.e.
41
+ #
42
+ # silence do |o, e|
43
+ # puts 'hello!' # no output produced
44
+ # o.puts 'hello!' # output on STDOUT
45
+ # end
46
+ #
47
+ # (based on silence_stream in ActiveSupport.)
48
+ def silence
49
+ yield(STDOUT, STDERR) if ENV['VERBOSE']
50
+ streams = [STDOUT, STDERR]
51
+ actual_stdout = STDOUT.dup
52
+ actual_stderr = STDERR.dup
53
+ streams.each do |s|
54
+ s.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
55
+ s.sync = true
56
+ end
57
+ yield actual_stdout, actual_stderr
58
+ ensure
59
+ STDOUT.reopen(actual_stdout)
60
+ STDERR.reopen(actual_stderr)
61
+ end
62
+
63
+ def test_app_dir
64
+ File.join(File.dirname(__FILE__), 'test_app')
65
+ end
66
+
67
+ def run(cmd)
68
+ system(cmd) || raise("failed running '#{cmd}'")
69
+ end
70
+
71
+ desc 'Remove the test application'
72
+ task :clean do
73
+ FileUtils.rm_r(test_app_dir) if File.exist?(test_app_dir)
74
+ end
75
+
76
+ desc 'Build the test rails application (use RAILS=[edge,<directory>] to test against specific version)'
77
+ task :generate_app do
78
+ silence do |out, err|
79
+
80
+ out.puts "> Creating test application at #{test_app_dir}"
81
+
82
+ if ENV['RAILS']
83
+ vendor_dir = File.join(test_app_dir, 'vendor')
84
+ FileUtils.mkdir_p vendor_dir
85
+
86
+ if ENV['RAILS'] == 'edge'
87
+ out.puts " Cloning rails from GitHub"
88
+ run "cd #{vendor_dir} && git clone --depth 1 git://github.com/rails/rails.git"
89
+ elsif File.exist?(ENV['RAILS'])
90
+ out.puts " Linking rails from #{ENV['RAILS']}"
91
+ run "cd #{vendor_dir} && ln -s #{ENV['RAILS']} rails"
92
+ else
93
+ raise "Couldn't build test application from '#{ENV['RAILS']}'"
94
+ end
95
+
96
+ out.puts " generating rails default directory structure"
97
+ run "ruby #{File.join(vendor_dir, 'rails', 'railties', 'bin', 'rails')} #{test_app_dir}"
98
+ else
99
+ version = `rails --version`.chomp.split.last
100
+ out.puts " building rails using the 'rails' command (rails version: #{version})"
101
+ run "rails #{test_app_dir}"
102
+ end
103
+
104
+ # get the database config and schema in place
105
+ out.puts " writing database.yml"
106
+ require 'yaml'
107
+ File.open(File.join(test_app_dir, 'config', 'database.yml'), 'w') do |f|
108
+ f.write(%w(development test).inject({}) do |h, env|
109
+ h[env] = {"adapter" => "sqlite3", "database" => "engines_#{env}.sqlite3"} ; h
110
+ end.to_yaml)
111
+ end
112
+ end
113
+ end
114
+
115
+ # We can't link the plugin, as it needs to be present for script/generate to find
116
+ # the plugin generator.
117
+ # TODO: find and +1/create issue for loading generators from symlinked plugins
118
+ desc 'Mirror the engines plugin into the test application'
119
+ task :copy_engines_plugin do
120
+ puts "> Copying engines plugin into test application"
121
+ engines_plugin = File.join(test_app_dir, "vendor", "plugins", "engines")
122
+ FileUtils.rm_r(engines_plugin) if File.exist?(engines_plugin)
123
+ FileUtils.mkdir_p(engines_plugin)
124
+ FileList["*"].exclude("test_app").each do |file|
125
+ FileUtils.cp_r(file, engines_plugin)
126
+ end
127
+ end
128
+
129
+ def insert_line(line, options)
130
+ line = line + "\n"
131
+ target_file = File.join(test_app_dir, options[:into])
132
+ lines = File.readlines(target_file)
133
+ return if lines.include?(line)
134
+
135
+ if options[:after]
136
+ if options[:after].is_a?(String)
137
+ after_line = options[:after] + "\n"
138
+ else
139
+ after_line = lines.find { |l| l =~ options[:after] }
140
+ raise "couldn't find a line matching #{options[:after].inspect} in #{target_file}" unless after_line
141
+ end
142
+ index = lines.index(after_line)
143
+ raise "couldn't find line '#{after_line}' in #{target_file}" unless index
144
+ lines.insert(index + 1, line)
145
+ else
146
+ lines << line
147
+ end
148
+ File.open(target_file, 'w') { |f| f.write lines.join }
149
+ end
150
+
151
+ def mirror_test_files(src, dest=nil)
152
+ destination_dir = File.join(*([test_app_dir, dest].compact))
153
+ FileUtils.cp_r(File.join(File.dirname(__FILE__), 'test', src), destination_dir)
154
+ end
155
+
156
+ desc 'Update the plugin and tests files in the test application from the plugin'
157
+ task :mirror_engine_files => [:test_app, :copy_engines_plugin] do
158
+ puts "> Modifying default config files to load engines plugin"
159
+ insert_line("require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')",
160
+ :into => 'config/environment.rb',
161
+ :after => "require File.join(File.dirname(__FILE__), 'boot')")
162
+
163
+ insert_line('map.from_plugin :test_routing', :into => 'config/routes.rb',
164
+ :after => /\AActionController::Routing::Routes/)
165
+
166
+ insert_line("require 'engines_test_helper'", :into => 'test/test_helper.rb')
167
+
168
+ puts "> Mirroring test application files into #{test_app_dir}"
169
+ mirror_test_files('app')
170
+ mirror_test_files('lib')
171
+ mirror_test_files('plugins', 'vendor')
172
+ mirror_test_files('unit', 'test')
173
+ mirror_test_files('functional', 'test')
174
+ end
175
+
176
+ desc 'Prepare the engines test environment'
177
+ file :test_app do
178
+ puts "> Recreating test application"
179
+ Rake::Task["test:clean"].invoke
180
+ Rake::Task["test:generate_app"].invoke
181
+ end
182
+ end
183
+
184
+ task :test => "test:mirror_engine_files" do
185
+ puts "> Loading the test application environment and running tests"
186
+ # We use exec here to replace the current running rake process
187
+ exec("cd #{test_app_dir} && rake")
188
+ end