pager-engines 2.0.20080513
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +267 -0
- data/MIT-LICENSE +21 -0
- data/README +83 -0
- data/Rakefile +188 -0
- data/about.yml +7 -0
- data/boot.rb +19 -0
- data/generators/plugin_migration/USAGE +45 -0
- data/generators/plugin_migration/plugin_migration_generator.rb +79 -0
- data/generators/plugin_migration/templates/plugin_migration.erb +13 -0
- data/init.rb +5 -0
- data/lib/engines.rb +174 -0
- data/lib/engines/assets.rb +38 -0
- data/lib/engines/plugin.rb +142 -0
- data/lib/engines/plugin/list.rb +30 -0
- data/lib/engines/plugin/loader.rb +18 -0
- data/lib/engines/plugin/locator.rb +37 -0
- data/lib/engines/plugin/migrator.rb +73 -0
- data/lib/engines/rails_extensions/action_mailer.rb +85 -0
- data/lib/engines/rails_extensions/asset_helpers.rb +119 -0
- data/lib/engines/rails_extensions/dependencies.rb +145 -0
- data/lib/engines/rails_extensions/migrations.rb +161 -0
- data/lib/engines/rails_extensions/rails.rb +11 -0
- data/lib/engines/rails_extensions/routing.rb +84 -0
- data/lib/engines/testing.rb +87 -0
- data/lib/engines_initializer.rb +5 -0
- data/rails/init.rb +5 -0
- data/tasks/engines.rake +179 -0
- data/test/app/controllers/app_and_plugin_controller.rb +5 -0
- data/test/app/controllers/application.rb +18 -0
- data/test/app/controllers/namespace/app_and_plugin_controller.rb +5 -0
- data/test/app/helpers/mail_helper.rb +5 -0
- data/test/app/models/app_and_plugin_model.rb +3 -0
- data/test/app/models/notify_mail.rb +26 -0
- data/test/app/things/thing.rb +3 -0
- data/test/app/views/app_and_plugin/a_view.html.erb +1 -0
- data/test/app/views/namespace/app_and_plugin/a_view.html.erb +1 -0
- data/test/app/views/notify_mail/implicit_multipart.text.html.erb +1 -0
- data/test/app/views/notify_mail/implicit_multipart.text.plain.erb +1 -0
- data/test/app/views/notify_mail/multipart_html.html.erb +1 -0
- data/test/app/views/notify_mail/multipart_plain.html.erb +1 -0
- data/test/app/views/notify_mail/signup.text.plain.erb +5 -0
- data/test/app/views/plugin_mail/mail_from_plugin_with_application_template.text.plain.erb +1 -0
- data/test/app/views/plugin_mail/multipart_from_plugin_with_application_template_plain.html.erb +1 -0
- data/test/functional/controller_loading_test.rb +51 -0
- data/test/functional/routes_test.rb +33 -0
- data/test/functional/view_helpers_test.rb +32 -0
- data/test/functional/view_loading_test.rb +60 -0
- data/test/lib/app_and_plugin_lib_model.rb +3 -0
- data/test/lib/engines_test_helper.rb +36 -0
- data/test/plugins/alpha_plugin/app/controllers/alpha_plugin_controller.rb +8 -0
- data/test/plugins/alpha_plugin/app/controllers/app_and_plugin_controller.rb +5 -0
- data/test/plugins/alpha_plugin/app/controllers/namespace/alpha_plugin_controller.rb +5 -0
- data/test/plugins/alpha_plugin/app/controllers/namespace/app_and_plugin_controller.rb +5 -0
- data/test/plugins/alpha_plugin/app/controllers/namespace/shared_plugin_controller.rb +5 -0
- data/test/plugins/alpha_plugin/app/controllers/shared_plugin_controller.rb +5 -0
- data/test/plugins/alpha_plugin/app/models/alpha_plugin_model.rb +3 -0
- data/test/plugins/alpha_plugin/app/models/app_and_plugin_model.rb +7 -0
- data/test/plugins/alpha_plugin/app/models/shared_plugin_model.rb +3 -0
- data/test/plugins/alpha_plugin/app/views/alpha_plugin/a_view.html.erb +1 -0
- data/test/plugins/alpha_plugin/app/views/app_and_plugin/a_view.html.erb +1 -0
- data/test/plugins/alpha_plugin/app/views/layouts/plugin_layout.erb +1 -0
- data/test/plugins/alpha_plugin/app/views/namespace/alpha_plugin/a_view.html.erb +1 -0
- data/test/plugins/alpha_plugin/app/views/namespace/app_and_plugin/a_view.html.erb +1 -0
- data/test/plugins/alpha_plugin/app/views/namespace/shared_plugin/a_view.html.erb +1 -0
- data/test/plugins/alpha_plugin/app/views/shared_plugin/a_view.html.erb +1 -0
- data/test/plugins/alpha_plugin/lib/alpha_plugin_lib_model.rb +3 -0
- data/test/plugins/alpha_plugin/lib/app_and_plugin_lib_model.rb +7 -0
- data/test/plugins/beta_plugin/app/controllers/app_and_plugin_controller.rb +5 -0
- data/test/plugins/beta_plugin/app/controllers/namespace/shared_plugin_controller.rb +5 -0
- data/test/plugins/beta_plugin/app/controllers/shared_plugin_controller.rb +5 -0
- data/test/plugins/beta_plugin/app/models/shared_plugin_model.rb +3 -0
- data/test/plugins/beta_plugin/app/views/namespace/shared_plugin/a_view.html.erb +1 -0
- data/test/plugins/beta_plugin/app/views/shared_plugin/a_view.html.erb +1 -0
- data/test/plugins/beta_plugin/init.rb +1 -0
- data/test/plugins/not_a_plugin/public/should_not_be_copied.txt +0 -0
- data/test/plugins/test_assets/app/controllers/assets_controller.rb +2 -0
- data/test/plugins/test_assets/app/views/assets/index.html.erb +3 -0
- data/test/plugins/test_assets/app/views/layouts/assets.html.erb +3 -0
- data/test/plugins/test_assets/init.rb +0 -0
- data/test/plugins/test_assets/public/file.txt +0 -0
- data/test/plugins/test_assets/public/subfolder/file_in_subfolder.txt +0 -0
- data/test/plugins/test_assets_with_assets_directory/assets/file.txt +0 -0
- data/test/plugins/test_assets_with_assets_directory/assets/subfolder/file_in_subfolder.txt +0 -0
- data/test/plugins/test_assets_with_assets_directory/init.rb +0 -0
- data/test/plugins/test_assets_with_no_subdirectory/assets/file.txt +0 -0
- data/test/plugins/test_assets_with_no_subdirectory/init.rb +0 -0
- data/test/plugins/test_code_mixing/app/things/thing.rb +3 -0
- data/test/plugins/test_code_mixing/init.rb +1 -0
- data/test/plugins/test_load_path/init.rb +0 -0
- data/test/plugins/test_migration/db/migrate/001_create_tests.rb +11 -0
- data/test/plugins/test_migration/db/migrate/002_create_others.rb +11 -0
- data/test/plugins/test_migration/init.rb +0 -0
- data/test/plugins/test_plugin_mailing/app/models/plugin_mail.rb +26 -0
- data/test/plugins/test_plugin_mailing/app/views/plugin_mail/mail_from_plugin.text.plain.erb +1 -0
- data/test/plugins/test_plugin_mailing/app/views/plugin_mail/multipart_from_plugin_html.html.erb +1 -0
- data/test/plugins/test_plugin_mailing/app/views/plugin_mail/multipart_from_plugin_plain.html.erb +1 -0
- data/test/plugins/test_plugin_mailing/app/views/plugin_mail/multipart_from_plugin_with_application_template_html.html.erb +1 -0
- data/test/plugins/test_plugin_mailing/app/views/plugin_mail/multipart_from_plugin_with_application_template_plain.html.erb +1 -0
- data/test/plugins/test_plugin_mailing/init.rb +0 -0
- data/test/plugins/test_routing/app/controllers/namespace/test_routing_controller.rb +5 -0
- data/test/plugins/test_routing/app/controllers/test_routing_controller.rb +9 -0
- data/test/plugins/test_routing/init.rb +0 -0
- data/test/plugins/test_routing/routes.rb +2 -0
- data/test/plugins/test_testing/init.rb +0 -0
- data/test/plugins/test_testing/test/fixtures/testing_fixtures.yml +0 -0
- data/test/unit/action_mailer_test.rb +54 -0
- data/test/unit/arbitrary_code_mixing_test.rb +41 -0
- data/test/unit/assets_test.rb +48 -0
- data/test/unit/backwards_compat_test.rb +8 -0
- data/test/unit/load_path_test.rb +58 -0
- data/test/unit/migration_test.rb +43 -0
- data/test/unit/model_and_lib_test.rb +37 -0
- data/test/unit/plugins_test.rb +11 -0
- data/test/unit/testing_test.rb +18 -0
- metadata +255 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Contains the enhancements to Rails' migrations system to support the
|
|
2
|
+
# Engines::Plugin::Migrator. See Engines::RailsExtensions::Migrations for more
|
|
3
|
+
# information.
|
|
4
|
+
|
|
5
|
+
require "engines/plugin/migrator"
|
|
6
|
+
|
|
7
|
+
# = Plugins and Migrations: Background
|
|
8
|
+
#
|
|
9
|
+
# Rails uses migrations to describe changes to the databases as your application
|
|
10
|
+
# evolves. Each change to your application - adding and removing models, most
|
|
11
|
+
# commonly - might require tweaks to your schema in the form of new tables, or new
|
|
12
|
+
# columns on existing tables, or possibly the removal of tables or columns. Migrations
|
|
13
|
+
# can even include arbitrary code to *transform* data as the underlying schema
|
|
14
|
+
# changes.
|
|
15
|
+
#
|
|
16
|
+
# The point is that at any particular stage in your application's development,
|
|
17
|
+
# migrations serve to transform the database into a state where it is compatible
|
|
18
|
+
# and appropriate at that time.
|
|
19
|
+
#
|
|
20
|
+
# == What about plugins?
|
|
21
|
+
#
|
|
22
|
+
# If you want to share models using plugins, chances are that you might also
|
|
23
|
+
# want to include the corresponding migrations to create tables for those models.
|
|
24
|
+
# With the engines plugin installed, plugins can carry migration data easily:
|
|
25
|
+
#
|
|
26
|
+
# vendor/
|
|
27
|
+
# |
|
|
28
|
+
# plugins/
|
|
29
|
+
# |
|
|
30
|
+
# my_plugin/
|
|
31
|
+
# |- init.rb
|
|
32
|
+
# |- lib/
|
|
33
|
+
# |- db/
|
|
34
|
+
# |-migrate/
|
|
35
|
+
# |- 001_do_something.rb
|
|
36
|
+
# |- 002_and_something_else.rb
|
|
37
|
+
# |- ...
|
|
38
|
+
#
|
|
39
|
+
# When you install a plugin which contains migrations, you are undertaking a
|
|
40
|
+
# further step in the development of your application, the same as the addition
|
|
41
|
+
# of any other code. With this in mind, you may want to 'roll back' the
|
|
42
|
+
# installation of this plugin at some point, and the database should be able
|
|
43
|
+
# to migrate back to the point without this plugin in it too.
|
|
44
|
+
#
|
|
45
|
+
# == An example
|
|
46
|
+
#
|
|
47
|
+
# For example, our current application is at version 14 (according to the
|
|
48
|
+
# +schema_info+ table), when we decide that we want to add a tagging plugin. The
|
|
49
|
+
# tagging plugin chosen includes migrations to create the tables it requires
|
|
50
|
+
# (say, _tags_ and _taggings_, for instance), along with the models and helpers
|
|
51
|
+
# one might expect.
|
|
52
|
+
#
|
|
53
|
+
# After installing this plugin, these tables should be created in our database.
|
|
54
|
+
# Rather than running the migrations directly from the plugin, they should be
|
|
55
|
+
# integrated into our main migration stream in order to accurately reflect the
|
|
56
|
+
# state of our application's database *at this moment in time*.
|
|
57
|
+
#
|
|
58
|
+
# $ script/generate plugin_migration
|
|
59
|
+
# exists db/migrate
|
|
60
|
+
# create db/migrate/015_migrate_tagging_plugin_to_version_3.rb
|
|
61
|
+
#
|
|
62
|
+
# This migration will take our application to version 15, and contains the following,
|
|
63
|
+
# typical migration code:
|
|
64
|
+
#
|
|
65
|
+
# class MigrateTaggingPluginToVersion3 < ActiveRecord::Migration
|
|
66
|
+
# def self.up
|
|
67
|
+
# Engines.plugins[:tagging].migrate(3)
|
|
68
|
+
# end
|
|
69
|
+
# def self.down
|
|
70
|
+
# Engines.plugins[:tagging].migrate(0)
|
|
71
|
+
# end
|
|
72
|
+
# end
|
|
73
|
+
#
|
|
74
|
+
# When we migrate our application up, using <tt>rake db:migrate</tt> as normal,
|
|
75
|
+
# the plugin will be migrated up to its latest version (3 in this example). If we
|
|
76
|
+
# ever decide to migrate the application back to the state it was in at version 14,
|
|
77
|
+
# the plugin migrations will be taken back down to version 0 (which, typically,
|
|
78
|
+
# would remove all tables the plugin migrations define).
|
|
79
|
+
#
|
|
80
|
+
# == Upgrading plugins
|
|
81
|
+
#
|
|
82
|
+
# It might happen that later in an application's life, we update to a new version of
|
|
83
|
+
# the tagging plugin which requires some changes to our database. The tagging plugin
|
|
84
|
+
# provides these changes in the form of its own migrations.
|
|
85
|
+
#
|
|
86
|
+
# In this case, we just need to re-run the plugin_migration generator to create a
|
|
87
|
+
# new migration from the current revision to the newest one:
|
|
88
|
+
#
|
|
89
|
+
# $ script/generate plugin_migration
|
|
90
|
+
# exists db/migrate
|
|
91
|
+
# create db/migrate/023_migrate_tagging_plugin_to_version_5.rb
|
|
92
|
+
#
|
|
93
|
+
# The contents of this migration are:
|
|
94
|
+
#
|
|
95
|
+
# class MigrateTaggingPluginToVersion3 < ActiveRecord::Migration
|
|
96
|
+
# def self.up
|
|
97
|
+
# Engines.plugins[:tagging].migrate(5)
|
|
98
|
+
# end
|
|
99
|
+
# def self.down
|
|
100
|
+
# Engines.plugins[:tagging].migrate(3)
|
|
101
|
+
# end
|
|
102
|
+
# end
|
|
103
|
+
#
|
|
104
|
+
# Notice that if we were to migrate down to revision 22 or lower, the tagging plugin
|
|
105
|
+
# will be migrated back down to version 3 - the version we were previously at.
|
|
106
|
+
#
|
|
107
|
+
#
|
|
108
|
+
# = Creating migrations in plugins
|
|
109
|
+
#
|
|
110
|
+
# In order to use the plugin migration functionality that engines provides, a plugin
|
|
111
|
+
# only needs to provide regular migrations in a <tt>db/migrate</tt> folder within it.
|
|
112
|
+
#
|
|
113
|
+
# = Explicitly migrating plugins
|
|
114
|
+
#
|
|
115
|
+
# It's possible to migrate plugins within your own migrations, or any other code.
|
|
116
|
+
# Simply get the Plugin instance, and its Plugin#migrate method with the version
|
|
117
|
+
# you wish to end up at:
|
|
118
|
+
#
|
|
119
|
+
# Engines.plugins[:whatever].migrate(version)
|
|
120
|
+
#
|
|
121
|
+
# ---
|
|
122
|
+
#
|
|
123
|
+
# The Engines::RailsExtensions::Migrations module defines extensions for Rails'
|
|
124
|
+
# migration systems. Specifically:
|
|
125
|
+
#
|
|
126
|
+
# * Adding a hook to initialize_schema_migrations_table to create the plugin schema
|
|
127
|
+
# info table.
|
|
128
|
+
#
|
|
129
|
+
module Engines::RailsExtensions::Migrations
|
|
130
|
+
def self.included(base) # :nodoc:
|
|
131
|
+
base.class_eval { alias_method_chain :initialize_schema_migrations_table, :engine_additions }
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Create the schema tables, and ensure that the plugin schema table
|
|
135
|
+
# is also initialized. The plugin schema info table is defined by
|
|
136
|
+
# Engines::Plugin::Migrator.schema_info_table_name.
|
|
137
|
+
def initialize_schema_migrations_table_with_engine_additions
|
|
138
|
+
initialize_schema_migrations_table_without_engine_additions
|
|
139
|
+
|
|
140
|
+
# create the plugin schema stuff.
|
|
141
|
+
begin
|
|
142
|
+
execute <<-ESQL
|
|
143
|
+
CREATE TABLE #{Engines::Plugin::Migrator.schema_info_table_name}
|
|
144
|
+
(plugin_name #{type_to_sql(:string)}, version #{type_to_sql(:integer)})
|
|
145
|
+
ESQL
|
|
146
|
+
rescue ActiveRecord::StatementInvalid
|
|
147
|
+
# Schema has been initialized
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
module ::ActiveRecord #:nodoc:
|
|
153
|
+
module ConnectionAdapters #:nodoc:
|
|
154
|
+
module SchemaStatements #:nodoc:
|
|
155
|
+
include Engines::RailsExtensions::Migrations
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Set ActiveRecord to ignore the plugin schema table by default
|
|
161
|
+
::ActiveRecord::SchemaDumper.ignore_tables << Engines.schema_info_table
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# This is only here to allow for backwards compability with Engines that
|
|
2
|
+
# have been implemented based on Engines for Rails 1.2. It is preferred that
|
|
3
|
+
# the plugin list be accessed via Engines.plugins.
|
|
4
|
+
|
|
5
|
+
module Rails
|
|
6
|
+
# Returns the Engines::Plugin::List from Engines.plugins. It is preferable to
|
|
7
|
+
# access Engines.plugins directly.
|
|
8
|
+
def self.plugins
|
|
9
|
+
Engines.plugins
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Effective use of Rails' routes can help create a tidy and elegant set of URLs,
|
|
2
|
+
# and is a significant part of creating an external API for your web application.
|
|
3
|
+
#
|
|
4
|
+
# When developing plugins which contain controllers, it seems obvious that including
|
|
5
|
+
# the corresponding routes would be extremely useful. This is particularly true
|
|
6
|
+
# when exposing RESTful resources using the new REST-ian features of Rails.
|
|
7
|
+
#
|
|
8
|
+
# == Including routes in your plugin
|
|
9
|
+
#
|
|
10
|
+
# The engines plugin makes it possible to include a set of routes within your plugin
|
|
11
|
+
# very simply, as it turns out. In your plugin, you simply include a <tt>routes.rb</tt>
|
|
12
|
+
# file like the one below at the root of your plugin:
|
|
13
|
+
#
|
|
14
|
+
# connect "/login", :controller => "my_plugin/account", :action => "login"
|
|
15
|
+
#
|
|
16
|
+
# # add a named route
|
|
17
|
+
# logout "/logout", :controller => "my_plugin/account", :action => "logout"
|
|
18
|
+
#
|
|
19
|
+
# # some restful stuff
|
|
20
|
+
# resources :things do |t|
|
|
21
|
+
# t.resources :other_things
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# Everywhere in a normal <tt>RAILS_ROOT/config/routes.rb</tt> file
|
|
25
|
+
# where you might have <tt>map.connect</tt>, you just use <tt>connect</tt> in your
|
|
26
|
+
# plugin's <tt>routes.rb</tt>.
|
|
27
|
+
#
|
|
28
|
+
# === Hooking it up in your application
|
|
29
|
+
#
|
|
30
|
+
# While it would be possible to have each plugin's routes automagically included into
|
|
31
|
+
# the application's route set, to do so would actually be a stunningly bad idea. Route
|
|
32
|
+
# priority is the key issue here. You, the application developer, needs to be in complete
|
|
33
|
+
# control when it comes to specifying the priority of routes in your application, since
|
|
34
|
+
# the ordering of your routes directly affects how Rails will interpret incoming requests.
|
|
35
|
+
#
|
|
36
|
+
# To add plugin routes into your application's <tt>routes.rb</tt> file, you need to explicitly
|
|
37
|
+
# map them in using the Engines::RailsExtensions::Routing#from_plugin method:
|
|
38
|
+
#
|
|
39
|
+
# ApplicationController::Routing::Routes.draw do |map|
|
|
40
|
+
#
|
|
41
|
+
# map.connect "/app_stuff", :controller => "application_thing" # etc...
|
|
42
|
+
#
|
|
43
|
+
# # This line includes the routes from the given plugin at this point, giving you
|
|
44
|
+
# # control over the priority of your application routes
|
|
45
|
+
# map.from_plugin :your_plugin
|
|
46
|
+
#
|
|
47
|
+
# map.connect ":controller/:action/:id"
|
|
48
|
+
# end
|
|
49
|
+
#
|
|
50
|
+
# By including routes in plugins which have controllers, you can now share in a simple way
|
|
51
|
+
# a compact and elegant URL scheme which corresponds to those controllers.
|
|
52
|
+
#
|
|
53
|
+
# ---
|
|
54
|
+
#
|
|
55
|
+
# The Engines::RailsExtensions::Routing module defines extensions to Rails'
|
|
56
|
+
# routing (ActionController::Routing) mechanism such that routes can be loaded
|
|
57
|
+
# from a given plugin.
|
|
58
|
+
#
|
|
59
|
+
# The key method is Engines::RailsExtensions::Routing#from_plugin, which can be called
|
|
60
|
+
# within your application's <tt>config/routes.rb</tt> file to load plugin routes at that point.
|
|
61
|
+
#
|
|
62
|
+
module Engines::RailsExtensions::Routing
|
|
63
|
+
# Loads the set of routes from within a plugin and evaluates them at this
|
|
64
|
+
# point within an application's main <tt>routes.rb</tt> file.
|
|
65
|
+
#
|
|
66
|
+
# Plugin routes are loaded from <tt><plugin_root>/routes.rb</tt>.
|
|
67
|
+
def from_plugin(name)
|
|
68
|
+
map = self # to make 'map' available within the plugin route file
|
|
69
|
+
routes_path = Engines.plugins[name].routes_path
|
|
70
|
+
Engines.logger.debug "loading routes from #{routes_path}"
|
|
71
|
+
eval(IO.read(routes_path), binding, routes_path) if File.file?(routes_path)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
module ::ActionController #:nodoc:
|
|
77
|
+
module Routing #:nodoc:
|
|
78
|
+
class RouteSet #:nodoc:
|
|
79
|
+
class Mapper #:nodoc:
|
|
80
|
+
include Engines::RailsExtensions::Routing
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Contains the enhancements to assist in testing plugins. See Engines::Testing
|
|
2
|
+
# for more details.
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
|
|
6
|
+
require 'tmpdir'
|
|
7
|
+
require 'fileutils'
|
|
8
|
+
|
|
9
|
+
# In most cases, Rails' own plugin testing mechanisms are sufficient. However, there
|
|
10
|
+
# are cases where plugins can be given a helping hand in the testing arena. This module
|
|
11
|
+
# contains some methods to assist when testing plugins that contain fixtures.
|
|
12
|
+
#
|
|
13
|
+
# == Fixtures and plugins
|
|
14
|
+
#
|
|
15
|
+
# Since Rails' own fixtures method is fairly strict about where files can be loaded from,
|
|
16
|
+
# the simplest approach when running plugin tests with fixtures is to simply copy all
|
|
17
|
+
# fixtures into a single temporary location and inform the standard Rails mechanism to
|
|
18
|
+
# use this directory, rather than RAILS_ROOT/test/fixtures.
|
|
19
|
+
#
|
|
20
|
+
# The Engines::Testing#setup_plugin_fixtures method does this, copying all plugin fixtures
|
|
21
|
+
# into the temporary location before and tests are performed. This behaviour is invoked
|
|
22
|
+
# the the rake tasks provided by the Engines plugin, in the "test:plugins" namespace. If
|
|
23
|
+
# necessary, you can invoke the task manually.
|
|
24
|
+
#
|
|
25
|
+
# If you wish to take advantage of this, add a call to the Engines::Testing.set_fixture_path
|
|
26
|
+
# method somewhere before your tests (in a test_helper file, or above the TestCase itself).
|
|
27
|
+
#
|
|
28
|
+
# = Testing plugins
|
|
29
|
+
#
|
|
30
|
+
# Normally testing a plugin will require that Rails is loaded, unless you are including
|
|
31
|
+
# a skeleton Rails environment or set of mocks within your plugin tests. If you require
|
|
32
|
+
# the Rails environment to be started, you must ensure that this actually happens; while
|
|
33
|
+
# it's not obvious, your tests do not automatically run with Rails loaded.
|
|
34
|
+
#
|
|
35
|
+
# The simplest way to setup plugin tests is to include a test helper with the following
|
|
36
|
+
# contents:
|
|
37
|
+
#
|
|
38
|
+
# # Load the normal Rails helper. This ensures the environment is loaded
|
|
39
|
+
# require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper')
|
|
40
|
+
# # Ensure that we are using the temporary fixture path
|
|
41
|
+
# Engines::Testing.set_fixture_path
|
|
42
|
+
#
|
|
43
|
+
# Then run tests using the provided tasks (<tt>test:plugins</tt>, or the tasks that the engines
|
|
44
|
+
# plugin provides - <tt>test:plugins:units</tt>, etc.).
|
|
45
|
+
#
|
|
46
|
+
# Alternatively, you can explicitly load the environment by adpating the contents of the
|
|
47
|
+
# default <tt>test_helper</tt>:
|
|
48
|
+
#
|
|
49
|
+
# ENV["RAILS_ENV"] = "test"
|
|
50
|
+
# # Note that we are requiring config/environment from the root of the enclosing application.
|
|
51
|
+
# require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
|
|
52
|
+
# require 'test_help'
|
|
53
|
+
#
|
|
54
|
+
module Engines::Testing
|
|
55
|
+
mattr_accessor :temporary_fixtures_directory
|
|
56
|
+
self.temporary_fixtures_directory = FileUtils.mkdir_p(File.join(Dir.tmpdir, "rails_fixtures"))
|
|
57
|
+
|
|
58
|
+
# Copies fixtures from plugins and the application into a temporary directory
|
|
59
|
+
# (Engines::Testing.temporary_fixtures_directory).
|
|
60
|
+
#
|
|
61
|
+
# If a set of plugins is not given, fixtures are copied from all plugins in order
|
|
62
|
+
# of precedence, meaning that plugins can 'overwrite' the fixtures of others if they are
|
|
63
|
+
# loaded later; the application's fixtures are copied last, allowing any custom fixtures
|
|
64
|
+
# to override those in the plugins. If no argument is given, plugins are loaded via
|
|
65
|
+
# PluginList#by_precedence.
|
|
66
|
+
#
|
|
67
|
+
# This method is called by the engines-supplied plugin testing rake tasks
|
|
68
|
+
def self.setup_plugin_fixtures(plugins = Engines.plugins.by_precedence)
|
|
69
|
+
|
|
70
|
+
# Copy all plugin fixtures, and then the application fixtures, into this directory
|
|
71
|
+
plugins.each do |plugin|
|
|
72
|
+
plugin_fixtures_directory = File.join(plugin.directory, "test", "fixtures")
|
|
73
|
+
if File.directory?(plugin_fixtures_directory)
|
|
74
|
+
Engines.mirror_files_from(plugin_fixtures_directory, self.temporary_fixtures_directory)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
Engines.mirror_files_from(File.join(RAILS_ROOT, "test", "fixtures"),
|
|
78
|
+
self.temporary_fixtures_directory)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Sets the fixture path used by Test::Unit::TestCase to the temporary
|
|
82
|
+
# directory which contains all plugin fixtures.
|
|
83
|
+
def self.set_fixture_path
|
|
84
|
+
Test::Unit::TestCase.fixture_path = self.temporary_fixtures_directory
|
|
85
|
+
$LOAD_PATH.unshift self.temporary_fixtures_directory
|
|
86
|
+
end
|
|
87
|
+
end
|
data/rails/init.rb
ADDED
data/tasks/engines.rake
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# This code lets us redefine existing Rake tasks, which is extremely
|
|
2
|
+
# handy for modifying existing Rails rake tasks.
|
|
3
|
+
# Credit for the original snippet of code goes to Jeremy Kemper
|
|
4
|
+
# http://pastie.caboo.se/9620
|
|
5
|
+
unless Rake::TaskManager.methods.include?(:redefine_task)
|
|
6
|
+
module Rake
|
|
7
|
+
module TaskManager
|
|
8
|
+
|
|
9
|
+
def redefine_task(task_class, args, &block)
|
|
10
|
+
task_name, deps = resolve_args([args])
|
|
11
|
+
task_name = task_class.scope_name(@scope, task_name)
|
|
12
|
+
deps = [deps] unless deps.respond_to?(:to_ary)
|
|
13
|
+
deps = deps.collect {|d| d.to_s }
|
|
14
|
+
task = @tasks[task_name.to_s] = task_class.new(task_name, self)
|
|
15
|
+
task.application = self
|
|
16
|
+
task.add_description(@last_description)
|
|
17
|
+
@last_description = nil
|
|
18
|
+
task.enhance(deps, &block)
|
|
19
|
+
task
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
class Task
|
|
24
|
+
class << self
|
|
25
|
+
def redefine_task(args, &block)
|
|
26
|
+
Rake.application.redefine_task(self, [args], &block)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
namespace :db do
|
|
34
|
+
namespace :migrate do
|
|
35
|
+
desc 'Migrate database and plugins to current status.'
|
|
36
|
+
task :all => [ 'db:migrate', 'db:migrate:plugins' ]
|
|
37
|
+
|
|
38
|
+
desc 'Migrate plugins to current status.'
|
|
39
|
+
task :plugins => :environment do
|
|
40
|
+
Engines.plugins.each do |plugin|
|
|
41
|
+
next unless File.exists? plugin.migration_directory
|
|
42
|
+
puts "Migrating plugin #{plugin.name} ..."
|
|
43
|
+
plugin.migrate
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
desc 'Migrate a specified plugin.'
|
|
48
|
+
task({:plugin => :environment}, :name, :version) do |task, args|
|
|
49
|
+
name = args[:name] || ENV['NAME']
|
|
50
|
+
if plugin = Engines.plugins[name]
|
|
51
|
+
version = args[:version] || ENV['VERSION']
|
|
52
|
+
puts "Migrating #{plugin.name} to " + (version ? "version #{version}" : 'latest version') + " ..."
|
|
53
|
+
plugin.migrate(version ? version.to_i : nil)
|
|
54
|
+
else
|
|
55
|
+
puts "Plugin #{name} does not exist."
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
namespace :db do
|
|
63
|
+
namespace :fixtures do
|
|
64
|
+
namespace :plugins do
|
|
65
|
+
|
|
66
|
+
desc "Load plugin fixtures into the current environment's database."
|
|
67
|
+
task :load => :environment do
|
|
68
|
+
require 'active_record/fixtures'
|
|
69
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
|
70
|
+
Dir.glob(File.join(RAILS_ROOT, 'vendor', 'plugins', ENV['PLUGIN'] || '**',
|
|
71
|
+
'test', 'fixtures', '*.yml')).each do |fixture_file|
|
|
72
|
+
Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# this is just a modification of the original task in railties/lib/tasks/documentation.rake,
|
|
81
|
+
# because the default task doesn't support subdirectories like <plugin>/app or
|
|
82
|
+
# <plugin>/component. These tasks now include every file under a plugin's code paths (see
|
|
83
|
+
# Plugin#code_paths).
|
|
84
|
+
namespace :doc do
|
|
85
|
+
|
|
86
|
+
plugins = FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) }
|
|
87
|
+
|
|
88
|
+
namespace :plugins do
|
|
89
|
+
|
|
90
|
+
# Define doc tasks for each plugin
|
|
91
|
+
plugins.each do |plugin|
|
|
92
|
+
desc "Create plugin documentation for '#{plugin}'"
|
|
93
|
+
Rake::Task.redefine_task(plugin => :environment) do
|
|
94
|
+
plugin_base = RAILS_ROOT + "/vendor/plugins/#{plugin}"
|
|
95
|
+
options = []
|
|
96
|
+
files = Rake::FileList.new
|
|
97
|
+
options << "-o doc/plugins/#{plugin}"
|
|
98
|
+
options << "--title '#{plugin.titlecase} Plugin Documentation'"
|
|
99
|
+
options << '--line-numbers' << '--inline-source'
|
|
100
|
+
options << '-T html'
|
|
101
|
+
|
|
102
|
+
# Include every file in the plugin's code_paths (see Plugin#code_paths)
|
|
103
|
+
if Engines.plugins[plugin]
|
|
104
|
+
files.include("#{plugin_base}/{#{Engines.plugins[plugin].code_paths.join(",")}}/**/*.rb")
|
|
105
|
+
end
|
|
106
|
+
if File.exists?("#{plugin_base}/README")
|
|
107
|
+
files.include("#{plugin_base}/README")
|
|
108
|
+
options << "--main '#{plugin_base}/README'"
|
|
109
|
+
end
|
|
110
|
+
files.include("#{plugin_base}/CHANGELOG") if File.exists?("#{plugin_base}/CHANGELOG")
|
|
111
|
+
|
|
112
|
+
if files.empty?
|
|
113
|
+
puts "No source files found in #{plugin_base}. No documentation will be generated."
|
|
114
|
+
else
|
|
115
|
+
options << files.to_s
|
|
116
|
+
sh %(rdoc #{options * ' '})
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
namespace :test do
|
|
126
|
+
task :warn_about_multiple_plugin_testing_with_engines do
|
|
127
|
+
puts %{-~============== A Moste Polite Warninge ===========================~-
|
|
128
|
+
|
|
129
|
+
You may experience issues testing multiple plugins at once when using
|
|
130
|
+
the code-mixing features that the engines plugin provides. If you do
|
|
131
|
+
experience any problems, please test plugins individually, i.e.
|
|
132
|
+
|
|
133
|
+
$ rake test:plugins PLUGIN=my_plugin
|
|
134
|
+
|
|
135
|
+
or use the per-type plugin test tasks:
|
|
136
|
+
|
|
137
|
+
$ rake test:plugins:units
|
|
138
|
+
$ rake test:plugins:functionals
|
|
139
|
+
$ rake test:plugins:integration
|
|
140
|
+
$ rake test:plugins:all
|
|
141
|
+
|
|
142
|
+
Report any issues on http://dev.rails-engines.org. Thanks!
|
|
143
|
+
|
|
144
|
+
-~===============( ... as you were ... )============================~-}
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
namespace :plugins do
|
|
148
|
+
|
|
149
|
+
desc "Run the plugin tests in vendor/plugins/**/test (or specify with PLUGIN=name)"
|
|
150
|
+
task :all => [:warn_about_multiple_plugin_testing_with_engines,
|
|
151
|
+
:units, :functionals, :integration]
|
|
152
|
+
|
|
153
|
+
desc "Run all plugin unit tests"
|
|
154
|
+
Rake::TestTask.new(:units => :setup_plugin_fixtures) do |t|
|
|
155
|
+
t.pattern = "vendor/plugins/#{ENV['PLUGIN'] || "**"}/test/unit/**/*_test.rb"
|
|
156
|
+
t.verbose = true
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
desc "Run all plugin functional tests"
|
|
160
|
+
Rake::TestTask.new(:functionals => :setup_plugin_fixtures) do |t|
|
|
161
|
+
t.pattern = "vendor/plugins/#{ENV['PLUGIN'] || "**"}/test/functional/**/*_test.rb"
|
|
162
|
+
t.verbose = true
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
desc "Integration test engines"
|
|
166
|
+
Rake::TestTask.new(:integration => :setup_plugin_fixtures) do |t|
|
|
167
|
+
t.pattern = "vendor/plugins/#{ENV['PLUGIN'] || "**"}/test/integration/**/*_test.rb"
|
|
168
|
+
t.verbose = true
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
desc "Mirrors plugin fixtures into a single location to help plugin tests"
|
|
172
|
+
task :setup_plugin_fixtures => :environment do
|
|
173
|
+
Engines::Testing.setup_plugin_fixtures
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Patch the default plugin testing task to have setup_plugin_fixtures as a prerequisite
|
|
177
|
+
Rake::Task["test:plugins"].prerequisites << "test:plugins:setup_plugin_fixtures"
|
|
178
|
+
end
|
|
179
|
+
end
|