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 @@
|
|
|
1
|
+
<%= self.first_render %> (from beta_plugin)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= self.first_render %> (from beta_plugin)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# just here so that Rails recognizes this as a plugin
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# just here so that Rails recognizes this as a plugin
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class PluginMail < ActionMailer::Base
|
|
2
|
+
def mail_from_plugin(note=nil)
|
|
3
|
+
body(:note => note)
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def mail_from_plugin_with_application_template(note=nil)
|
|
7
|
+
body(:note => note)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def multipart_from_plugin
|
|
11
|
+
content_type 'multipart/alternative'
|
|
12
|
+
part :content_type => "text/html", :body => render_message("multipart_from_plugin_html", {})
|
|
13
|
+
part "text/plain" do |p|
|
|
14
|
+
p.body = render_message("multipart_from_plugin_plain", {})
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def multipart_from_plugin_with_application_template
|
|
19
|
+
content_type 'multipart/alternative'
|
|
20
|
+
part :content_type => "text/html", :body => render_message("multipart_from_plugin_with_application_template_html", {})
|
|
21
|
+
part "text/plain" do |p|
|
|
22
|
+
p.body = render_message("multipart_from_plugin_with_application_template_plain", {})
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= @note %>
|
data/test/plugins/test_plugin_mailing/app/views/plugin_mail/multipart_from_plugin_html.html.erb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
html template
|
data/test/plugins/test_plugin_mailing/app/views/plugin_mail/multipart_from_plugin_plain.html.erb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
plain template
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
template from plugin
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
template from plugin
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
|
2
|
+
|
|
3
|
+
class ActionMailerWithinApplicationTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def test_normal_implicit_template
|
|
6
|
+
m = NotifyMail.create_signup("hello")
|
|
7
|
+
assert m.body =~ /^Signup template from application/
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_action_mailer_can_get_helper
|
|
11
|
+
m = NotifyMail.create_signup('James')
|
|
12
|
+
assert m.body =~ /James/
|
|
13
|
+
assert m.body =~ /semaJ/ # from the helper
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_multipart_mails_with_explicit_templates
|
|
17
|
+
m = NotifyMail.create_multipart
|
|
18
|
+
assert_equal 2, m.parts.length
|
|
19
|
+
assert_equal 'the html part of the email james', m.parts[0].body
|
|
20
|
+
assert_equal 'the plaintext part of the email', m.parts[1].body
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_multipart_mails_with_implicit_templates
|
|
24
|
+
m = NotifyMail.create_implicit_multipart
|
|
25
|
+
assert_equal 2, m.parts.length
|
|
26
|
+
assert_equal 'the implicit plaintext part of the email', m.parts[0].body
|
|
27
|
+
assert_equal 'the implicit html part of the email james', m.parts[1].body
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ActionMailerWithinPluginsTest < Test::Unit::TestCase
|
|
33
|
+
def test_should_be_able_to_create_mails_from_plugin
|
|
34
|
+
m = PluginMail.create_mail_from_plugin("from_plugin")
|
|
35
|
+
assert_equal "from_plugin", m.body
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_should_be_able_to_overload_views_within_the_application
|
|
39
|
+
m = PluginMail.create_mail_from_plugin_with_application_template("from_plugin")
|
|
40
|
+
assert_equal "from_plugin (from application)", m.body
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_should_be_able_to_create_a_multipart_mail_from_within_plugin
|
|
44
|
+
m = PluginMail.create_multipart_from_plugin
|
|
45
|
+
assert_equal 2, m.parts.length
|
|
46
|
+
assert_equal 'html template', m.parts[0].body
|
|
47
|
+
assert_equal 'plain template', m.parts[1].body
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_plugin_mailer_template_overriding
|
|
51
|
+
m = PluginMail.create_multipart_from_plugin_with_application_template
|
|
52
|
+
assert_equal 'plugin mail template loaded from application', m.parts[1].body
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
|
2
|
+
|
|
3
|
+
class ArbitraryCodeMixingTest < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
Engines.code_mixing_file_types = %w(controller helper)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_should_allow_setting_of_different_code_mixing_file_types
|
|
9
|
+
assert_nothing_raised {
|
|
10
|
+
Engines.mix_code_from :things
|
|
11
|
+
}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_should_add_new_types_to_existing_code_mixing_file_types
|
|
15
|
+
Engines.mix_code_from :things
|
|
16
|
+
assert_equal ["controller", "helper", "thing"], Engines.code_mixing_file_types
|
|
17
|
+
Engines.mix_code_from :other
|
|
18
|
+
assert_equal ["controller", "helper", "thing", "other"], Engines.code_mixing_file_types
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_should_allow_setting_of_multiple_types_at_once
|
|
22
|
+
Engines.mix_code_from :things, :other
|
|
23
|
+
assert_equal ["controller", "helper", "thing", "other"], Engines.code_mixing_file_types
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_should_singularize_elements_to_be_mixed
|
|
27
|
+
# this is the only test using mocha, so let's try to work around it
|
|
28
|
+
# also, this seems to be already tested with the :things in the tests above
|
|
29
|
+
# arg = stub(:to_s => stub(:singularize => "element"))
|
|
30
|
+
Engines.mix_code_from :elements
|
|
31
|
+
assert Engines.code_mixing_file_types.include?("element")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# TODO doesn't seem to work as expected?
|
|
35
|
+
|
|
36
|
+
# def test_should_successfully_mix_custom_types
|
|
37
|
+
# Engines.mix_code_from :things
|
|
38
|
+
# assert_equal 'Thing (from app)', Thing.from_app
|
|
39
|
+
# assert_equal 'Thing (from test_code_mixing)', Thing.from_plugin
|
|
40
|
+
# end
|
|
41
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
|
2
|
+
|
|
3
|
+
class AssetsTest < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
Engines::Assets.mirror_files_for Engines.plugins[:test_assets]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def teardown
|
|
9
|
+
FileUtils.rm_r(Engines.public_directory) if File.exist?(Engines.public_directory)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_engines_has_created_base_public_file
|
|
13
|
+
assert File.exist?(Engines.public_directory)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_engines_has_created_README_in_public_directory
|
|
17
|
+
assert File.exist?(File.join(Engines.public_directory, 'README'))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_public_files_have_been_copied_from_test_assets_plugin
|
|
21
|
+
assert File.exist?(File.join(Engines.public_directory, 'test_assets'))
|
|
22
|
+
assert File.exist?(File.join(Engines.public_directory, 'test_assets', 'file.txt'))
|
|
23
|
+
assert File.exist?(File.join(Engines.public_directory, 'test_assets', 'subfolder'))
|
|
24
|
+
assert File.exist?(File.join(Engines.public_directory, 'test_assets', 'subfolder', 'file_in_subfolder.txt'))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_public_files_have_been_copied_from_test_assets_with_assets_dir_plugin
|
|
28
|
+
Engines::Assets.mirror_files_for Engines.plugins[:test_assets_with_assets_directory]
|
|
29
|
+
|
|
30
|
+
assert File.exist?(File.join(Engines.public_directory, 'test_assets_with_assets_directory'))
|
|
31
|
+
assert File.exist?(File.join(Engines.public_directory, 'test_assets_with_assets_directory', 'file.txt'))
|
|
32
|
+
assert File.exist?(File.join(Engines.public_directory, 'test_assets_with_assets_directory', 'subfolder'))
|
|
33
|
+
assert File.exist?(File.join(Engines.public_directory, 'test_assets_with_assets_directory', 'subfolder', 'file_in_subfolder.txt'))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_public_files_have_been_copied_from_test_assets_with_no_subdirectory_plugin
|
|
37
|
+
Engines::Assets.mirror_files_for Engines.plugins[:test_assets_with_no_subdirectory]
|
|
38
|
+
|
|
39
|
+
assert File.exist?(File.join(Engines.public_directory, 'test_assets_with_no_subdirectory'))
|
|
40
|
+
assert File.exist?(File.join(Engines.public_directory, 'test_assets_with_no_subdirectory', 'file.txt'))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_public_files_have_NOT_been_copied_from_plugins_without_public_or_asset_directories
|
|
44
|
+
Engines::Assets.mirror_files_for Engines.plugins[:alpha_plugin]
|
|
45
|
+
|
|
46
|
+
assert !File.exist?(File.join(Engines.public_directory, 'alpha_plugin'))
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
|
2
|
+
|
|
3
|
+
class BackwardsCompatibilityTest < Test::Unit::TestCase
|
|
4
|
+
def test_rails_module_plugin_method_should_delegate_to_engines_plugins
|
|
5
|
+
assert_nothing_raised { Rails.plugins }
|
|
6
|
+
assert_equal Engines.plugins, Rails.plugins
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Tests in this file ensure that:
|
|
2
|
+
#
|
|
3
|
+
# * the application /app/[controllers|helpers|models] and /lib
|
|
4
|
+
# paths preceed the corresponding plugin paths
|
|
5
|
+
# * the plugin paths are added to $LOAD_PATH in the order in which plugins are
|
|
6
|
+
# loaded
|
|
7
|
+
|
|
8
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
|
9
|
+
|
|
10
|
+
class LoadPathTest < Test::Unit::TestCase
|
|
11
|
+
def setup
|
|
12
|
+
@load_path = expand_paths($LOAD_PATH)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Not sure if these test actually make sense as this now essentially tests
|
|
16
|
+
# Rails core functionality. On the other hand Engines relies on this to some
|
|
17
|
+
# extend so this will choke if something important changes in Rails.
|
|
18
|
+
|
|
19
|
+
# the application app/... and lib/ directories should appear
|
|
20
|
+
# before any plugin directories
|
|
21
|
+
|
|
22
|
+
def test_application_app_libs_should_precede_all_plugin_app_libs
|
|
23
|
+
types = %w(app/controllers app/helpers app/models lib)
|
|
24
|
+
types.each do |t|
|
|
25
|
+
app_index = load_path_index(File.join(RAILS_ROOT, t))
|
|
26
|
+
assert_not_nil app_index, "#{t} is missing in $LOAD_PATH"
|
|
27
|
+
Engines.plugins.each do |plugin|
|
|
28
|
+
first_plugin_index = load_path_index(File.join(plugin.directory, t))
|
|
29
|
+
assert(app_index < first_plugin_index) unless first_plugin_index.nil?
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# the engine directories should appear in the proper order based on
|
|
35
|
+
# the order they were started
|
|
36
|
+
|
|
37
|
+
def test_plugin_dirs_should_appear_in_reverse_plugin_loading_order
|
|
38
|
+
app_paths = %w(app/controllers/ app app/models app/helpers config lib)
|
|
39
|
+
app_paths.map { |p| File.join(RAILS_ROOT, p)}
|
|
40
|
+
plugin_paths = Engines.plugins.reverse.collect { |plugin| plugin.load_paths.reverse }.flatten
|
|
41
|
+
|
|
42
|
+
expected_paths = expand_paths(app_paths + plugin_paths)
|
|
43
|
+
# only look at those paths that are also present in expected_paths so
|
|
44
|
+
# the only difference would be in the order of the paths
|
|
45
|
+
actual_paths = @load_path & expected_paths
|
|
46
|
+
|
|
47
|
+
assert_equal expected_paths, actual_paths
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
protected
|
|
51
|
+
def expand_paths(paths)
|
|
52
|
+
paths.collect { |p| File.expand_path(p) }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def load_path_index(dir)
|
|
56
|
+
@load_path.index(File.expand_path(dir))
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
|
2
|
+
require 'rails_generator'
|
|
3
|
+
require 'rails_generator/scripts/generate'
|
|
4
|
+
|
|
5
|
+
class MigrationsTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
@@migration_dir = "#{RAILS_ROOT}/db/migrate"
|
|
8
|
+
|
|
9
|
+
def setup
|
|
10
|
+
ActiveRecord::Migration.verbose = false
|
|
11
|
+
Engines.plugins[:test_migration].migrate(0)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def teardown
|
|
15
|
+
FileUtils.rm_r(@@migration_dir) if File.exist?(@@migration_dir)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_engine_migrations_can_run_down
|
|
19
|
+
assert !table_exists?('tests'), ActiveRecord::Base.connection.tables.inspect
|
|
20
|
+
assert !table_exists?('others'), ActiveRecord::Base.connection.tables.inspect
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_engine_migrations_can_run_up
|
|
24
|
+
Engines.plugins[:test_migration].migrate(2)
|
|
25
|
+
assert table_exists?('tests')
|
|
26
|
+
assert table_exists?('others')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_generator_creates_plugin_migration_file
|
|
30
|
+
Rails::Generator::Scripts::Generate.new.run(['plugin_migration', 'test_migration'], :quiet => true)
|
|
31
|
+
assert migration_file, "migration file is missing"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def table_exists?(table)
|
|
37
|
+
ActiveRecord::Base.connection.tables.include?(table)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def migration_file
|
|
41
|
+
Dir["#{@@migration_dir}/*test_migration_to_version_2.rb"][0]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
|
2
|
+
|
|
3
|
+
class ModelAndLibTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def test_WITH_a_model_defined_only_in_a_plugin_IT_should_load_the_model
|
|
6
|
+
assert_equal 'AlphaPluginModel (from alpha_plugin)', AlphaPluginModel.report_location
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def test_WITH_a_model_defined_only_in_a_plugin_lib_dir_IT_should_load_the_model
|
|
10
|
+
assert_equal 'AlphaPluginLibModel (from alpha_plugin)', AlphaPluginLibModel.report_location
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# app takes precedence over plugins
|
|
14
|
+
|
|
15
|
+
def test_WITH_a_model_defined_in_both_app_and_plugin_IT_should_load_the_one_in_app
|
|
16
|
+
assert_equal 'AppAndPluginModel (from app)', AppAndPluginModel.report_location
|
|
17
|
+
assert_raises(NoMethodError) { AppAndPluginLibModel.defined_only_in_alpha_engine_version }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_WITH_a_model_defined_in_both_app_and_plugin_lib_dirs_IT_should_load_the_one_in_app
|
|
21
|
+
assert_equal 'AppAndPluginLibModel (from lib)', AppAndPluginLibModel.report_location
|
|
22
|
+
assert_raises(NoMethodError) { AppAndPluginLibModel.defined_only_in_alpha_engine_version }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# subsequently loaded plugins take precendence over previously loaded plugins
|
|
26
|
+
|
|
27
|
+
# TODO
|
|
28
|
+
#
|
|
29
|
+
# this does work when we rely on $LOAD_PATH while it won't work when we use
|
|
30
|
+
# Dependency constant autoloading. This somewhat confusing difference has
|
|
31
|
+
# been there since at least Rails 1.2.x. See http://www.ruby-forum.com/topic/134529
|
|
32
|
+
|
|
33
|
+
def test_WITH_a_model_defined_in_two_plugins_IT_should_load_the_latter_of_both
|
|
34
|
+
require 'shared_plugin_model'
|
|
35
|
+
assert_equal SharedPluginModel.report_location, 'SharedPluginModel (from beta_plugin)'
|
|
36
|
+
end
|
|
37
|
+
end
|