pager-engines 2.0.20080513
Sign up to get free protection for your applications and to get access to all the features.
- 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,18 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
def render_class_and_action(note = nil, options={})
|
6
|
+
text = "rendered in #{self.class.name}##{params[:action]}"
|
7
|
+
text += " (#{note})" unless note.nil?
|
8
|
+
render options.update(:text => text)
|
9
|
+
end
|
10
|
+
|
11
|
+
def rescue_action(e) raise e end;
|
12
|
+
|
13
|
+
helper :all # include all helpers, all the time
|
14
|
+
|
15
|
+
# See ActionController::RequestForgeryProtection for details
|
16
|
+
# Uncomment the :secret if you're not using the cookie session store
|
17
|
+
protect_from_forgery # :secret => 'b955354e438fc4ba070083505af94518'
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class NotifyMail < ActionMailer::Base
|
2
|
+
|
3
|
+
helper :mail
|
4
|
+
|
5
|
+
def signup(txt)
|
6
|
+
body(:name => txt)
|
7
|
+
end
|
8
|
+
|
9
|
+
def multipart
|
10
|
+
recipients 'some_address@email.com'
|
11
|
+
subject 'multi part email'
|
12
|
+
from "another_user@email.com"
|
13
|
+
content_type 'multipart/alternative'
|
14
|
+
|
15
|
+
part :content_type => "text/html", :body => render_message("multipart_html", {})
|
16
|
+
part "text/plain" do |p|
|
17
|
+
p.body = render_message("multipart_plain", {})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def implicit_multipart
|
22
|
+
recipients 'some_address@email.com'
|
23
|
+
subject 'multi part email'
|
24
|
+
from "another_user@email.com"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= self.first_render %> (from app)
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= self.first_render %> (from app)
|
@@ -0,0 +1 @@
|
|
1
|
+
the implicit html part of the email <%= do_something_helpful("semaj") %>
|
@@ -0,0 +1 @@
|
|
1
|
+
the implicit plaintext part of the email
|
@@ -0,0 +1 @@
|
|
1
|
+
the html part of the email <%= do_something_helpful("semaj") %>
|
@@ -0,0 +1 @@
|
|
1
|
+
the plaintext part of the email
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @note %> (from application)
|
data/test/app/views/plugin_mail/multipart_from_plugin_with_application_template_plain.html.erb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
plugin mail template loaded from application
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Tests in this file ensure that:
|
2
|
+
#
|
3
|
+
# * plugin controller actions are found
|
4
|
+
# * actions defined in application controllers take precedence over those in plugins
|
5
|
+
# * actions in controllers in subsequently loaded plugins take precendence over those in previously loaded plugins
|
6
|
+
# * this works for actions in namespaced controllers accordingly
|
7
|
+
|
8
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
9
|
+
|
10
|
+
class ControllerLoadingTest < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@response = ActionController::TestResponse.new
|
14
|
+
end
|
15
|
+
|
16
|
+
# plugin controller actions should be found
|
17
|
+
|
18
|
+
def test_WITH_an_action_defined_only_in_a_plugin_IT_should_use_this_action
|
19
|
+
get_action_on_controller :an_action, :alpha_plugin
|
20
|
+
assert_response_body 'rendered in AlphaPluginController#an_action'
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_WITH_an_action_defined_only_in_a_namespaced_plugin_controller_IT_should_use_this_action
|
24
|
+
get_action_on_controller :an_action, :alpha_plugin, :namespace
|
25
|
+
assert_response_body 'rendered in Namespace::AlphaPluginController#an_action'
|
26
|
+
end
|
27
|
+
|
28
|
+
# app takes precedence over plugins
|
29
|
+
|
30
|
+
def test_WITH_an_action_defined_in_both_app_and_plugin_IT_should_use_the_one_in_app
|
31
|
+
get_action_on_controller :an_action, :app_and_plugin
|
32
|
+
assert_response_body 'rendered in AppAndPluginController#an_action (from app)'
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_WITH_an_action_defined_in_namespaced_controllers_in_both_app_and_plugin_IT_should_use_the_one_in_app
|
36
|
+
get_action_on_controller :an_action, :app_and_plugin, :namespace
|
37
|
+
assert_response_body 'rendered in Namespace::AppAndPluginController#an_action (from app)'
|
38
|
+
end
|
39
|
+
|
40
|
+
# subsequently loaded plugins take precendence over previously loaded plugins
|
41
|
+
|
42
|
+
def test_WITH_an_action_defined_in_two_plugin_controllers_IT_should_use_the_latter_of_both
|
43
|
+
get_action_on_controller :an_action, :shared_plugin
|
44
|
+
assert_response_body 'rendered in SharedPluginController#an_action (from beta_plugin)'
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_WITH_an_action_defined_in_two_namespaced_plugin_controllers_IT_should_use_the_latter_of_both
|
48
|
+
get_action_on_controller :an_action, :shared_plugin, :namespace
|
49
|
+
assert_response_body 'rendered in Namespace::SharedPluginController#an_action (from beta_plugin)'
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Tests in this file ensure that:
|
2
|
+
#
|
3
|
+
# * Routes from plugins can be routed to
|
4
|
+
# * Named routes can be defined within a plugin
|
5
|
+
|
6
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
7
|
+
|
8
|
+
class RoutesTest < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
@controller = TestRoutingController.new
|
11
|
+
@request = ActionController::TestRequest.new
|
12
|
+
@response = ActionController::TestResponse.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_WITH_a_route_defined_in_a_plugin_IT_should_route_it
|
16
|
+
path = '/routes/an_action'
|
17
|
+
opts = {:controller => 'test_routing', :action => 'an_action'}
|
18
|
+
assert_routing path, opts
|
19
|
+
assert_recognizes opts, path # not sure what exactly the difference is, but it won't hurt either
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_WITH_a_route_for_a_namespaced_controller_defined_in_a_plugin_IT_should_route_it
|
23
|
+
path = 'somespace/routes/an_action'
|
24
|
+
opts = {:controller => 'namespace/test_routing', :action => 'an_action'}
|
25
|
+
assert_routing path, opts
|
26
|
+
assert_recognizes opts, path
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_properly_generate_named_routes
|
30
|
+
get :test_named_routes_from_plugin
|
31
|
+
assert_response_body '/somespace/routes'
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class ViewHelpersTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@controller = AssetsController.new
|
6
|
+
@request = ActionController::TestRequest.new
|
7
|
+
@response = ActionController::TestResponse.new
|
8
|
+
get :index
|
9
|
+
end
|
10
|
+
|
11
|
+
# TODO: refactor this to use assert_select
|
12
|
+
def test_plugin_javascript_helpers
|
13
|
+
attrs = { :type => "text/javascript" }
|
14
|
+
assert_tag :script, :attributes => attrs.update(:src => "/plugin_assets/test_assets/javascripts/file.1.js")
|
15
|
+
assert_tag :script, :attributes => attrs.update(:src => "/plugin_assets/test_assets/javascripts/file2.js")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_plugin_stylesheet_helpers
|
19
|
+
attrs = { :media => "screen", :rel => "stylesheet", :type => "text/css" }
|
20
|
+
assert_tag :link, :attributes => attrs.update(:href => "/plugin_assets/test_assets/stylesheets/file.1.css")
|
21
|
+
assert_tag :link, :attributes => attrs.update(:href => "/plugin_assets/test_assets/stylesheets/file2.css")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_plugin_image_helpers
|
25
|
+
assert_tag :img, :attributes => { :src => "/plugin_assets/test_assets/images/image.png", :alt => "Image" }
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_plugin_layouts
|
29
|
+
get :index
|
30
|
+
assert_tag :div, :attributes => { :id => "assets_layout" }
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Tests in this file ensure that:
|
2
|
+
#
|
3
|
+
# * plugin views are found
|
4
|
+
# * views in the application take precedence over those in plugins
|
5
|
+
# * views in subsequently loaded plugins take precendence over those in previously loaded plugins
|
6
|
+
# * this works for namespaced views accordingly
|
7
|
+
|
8
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
9
|
+
|
10
|
+
class ViewLoadingTest < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@response = ActionController::TestResponse.new
|
14
|
+
end
|
15
|
+
|
16
|
+
# plugin views should be found
|
17
|
+
|
18
|
+
def test_WITH_a_view_defined_only_in_a_plugin_IT_should_find_the_view
|
19
|
+
get_action_on_controller :a_view, :alpha_plugin
|
20
|
+
assert_response_body 'alpha_plugin/a_view'
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_WITH_a_namespaced_view_defined_only_in_a_plugin_IT_should_find_the_view
|
24
|
+
get_action_on_controller :a_view, :alpha_plugin, :namespace
|
25
|
+
assert_response_body 'namespace/alpha_plugin/a_view'
|
26
|
+
end
|
27
|
+
|
28
|
+
# app takes precedence over plugins
|
29
|
+
|
30
|
+
def test_WITH_a_view_defined_in_both_app_and_plugin_IT_should_find_the_one_in_app
|
31
|
+
get_action_on_controller :a_view, :app_and_plugin
|
32
|
+
assert_response_body 'app_and_plugin/a_view (from app)'
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_WITH_a_namespaced_view_defined_in_both_app_and_plugin_IT_should_find_the_one_in_app
|
36
|
+
get_action_on_controller :a_view, :app_and_plugin, :namespace
|
37
|
+
assert_response_body 'namespace/app_and_plugin/a_view (from app)'
|
38
|
+
end
|
39
|
+
|
40
|
+
# subsequently loaded plugins take precendence over previously loaded plugins
|
41
|
+
|
42
|
+
def test_WITH_a_view_defined_in_two_plugins_IT_should_find_the_latter_of_both
|
43
|
+
get_action_on_controller :a_view, :shared_plugin
|
44
|
+
assert_response_body 'shared_plugin/a_view (from beta_plugin)'
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_WITH_a_namespaced_view_defined_in_two_plugins_IT_should_find_the_latter_of_both
|
48
|
+
get_action_on_controller :a_view, :shared_plugin, :namespace
|
49
|
+
assert_response_body 'namespace/shared_plugin/a_view (from beta_plugin)'
|
50
|
+
end
|
51
|
+
|
52
|
+
# layouts loaded from plugins
|
53
|
+
|
54
|
+
def test_should_be_able_to_load_a_layout_from_a_plugin
|
55
|
+
get_action_on_controller :action_with_layout, :alpha_plugin
|
56
|
+
assert_response_body 'rendered in AlphaPluginController#action_with_layout (with plugin layout)'
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module TestHelper
|
2
|
+
def self.report_location(path)
|
3
|
+
[RAILS_ROOT + '/', 'vendor/plugins/'].each { |part| path.sub! part, ''}
|
4
|
+
path = path.split('/')
|
5
|
+
location, subject = path.first, path.last
|
6
|
+
if subject.sub! '.rb', ''
|
7
|
+
subject = subject.classify
|
8
|
+
else
|
9
|
+
subject.sub! '.html.erb', ''
|
10
|
+
end
|
11
|
+
"#{subject} (from #{location})"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Test::Unit::TestCase
|
16
|
+
# Add more helper methods to be used by all tests here...
|
17
|
+
def get_action_on_controller(*args)
|
18
|
+
action = args.shift
|
19
|
+
with_controller *args
|
20
|
+
get action
|
21
|
+
end
|
22
|
+
|
23
|
+
def with_controller(controller, namespace = nil)
|
24
|
+
classname = controller.to_s.classify + 'Controller'
|
25
|
+
classname = namespace.to_s.classify + '::' + classname unless namespace.nil?
|
26
|
+
@controller = classname.constantize.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def assert_response_body(expected)
|
30
|
+
assert_equal expected, @response.body
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Because we're testing this behaviour, we actually want these features on!
|
35
|
+
Engines.disable_application_view_loading = false
|
36
|
+
Engines.disable_application_code_loading = false
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= self.first_render %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= self.first_render %> (from a_view)
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %> (with plugin layout)
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= self.first_render %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= self.first_render %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= self.first_render %> (from alpha_plugin)
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= self.first_render %> (from alpha_plugin)
|