plugin_test_helper 0.1.6 → 0.2.0
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.rdoc +4 -0
- data/Rakefile +1 -1
- data/generators/plugin_test_controller/plugin_test_controller_generator.rb +1 -1
- data/generators/plugin_test_migration/plugin_test_migration_generator.rb +1 -1
- data/generators/plugin_test_model/plugin_test_model_generator.rb +1 -1
- data/generators/plugin_test_structure/templates/app_root/config/environment.rb +1 -1
- data/lib/plugin_test_helper/extensions/initializer.rb +84 -86
- data/lib/plugin_test_helper/generator.rb +19 -21
- data/lib/plugin_test_helper/plugin_locator.rb +6 -8
- data/test/app_roots/with_custom_config/vendor/plugins/acts_as_foo/lib/acts_as_foo.rb +1 -3
- data/test/functional/plugin_test_helper_test.rb +1 -1
- data/test/unit/plugin_locator_test.rb +1 -1
- metadata +3 -2
data/CHANGELOG.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rake/contrib/sshpublisher'
|
|
5
5
|
|
6
6
|
spec = Gem::Specification.new do |s|
|
7
7
|
s.name = 'plugin_test_helper'
|
8
|
-
s.version = '0.
|
8
|
+
s.version = '0.2.0'
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.summary = 'Simplifies plugin testing by creating an isolated Rails environment that simulates its usage in a real application.'
|
11
11
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Generates the class and view for a controller in a plugin's test application
|
2
|
-
class PluginTestControllerGenerator <
|
2
|
+
class PluginTestControllerGenerator < PluginTestHelper::Generator
|
3
3
|
def manifest #:nodoc:
|
4
4
|
record do |m|
|
5
5
|
# Check for class naming collisions
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Generates migrations for a plugin's test application
|
2
|
-
class PluginTestMigrationGenerator <
|
2
|
+
class PluginTestMigrationGenerator < PluginTestHelper::Generator
|
3
3
|
def manifest #:nodoc:
|
4
4
|
record do |m|
|
5
5
|
m.migration_template 'migration.rb', "#{plugin_app_root}/db/migrate"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Generates the class, fixtures, and migration for a model in a plugin's test application
|
2
|
-
class PluginTestModelGenerator <
|
2
|
+
class PluginTestModelGenerator < PluginTestHelper::Generator
|
3
3
|
default_options :skip_migration => false
|
4
4
|
|
5
5
|
def manifest #:nodoc:
|
@@ -1,108 +1,106 @@
|
|
1
1
|
require 'plugin_test_helper/plugin_locator'
|
2
2
|
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
alias_method :require_frameworks, :require_frameworks_with_test_helper
|
13
|
-
end
|
3
|
+
module PluginTestHelper
|
4
|
+
module Extensions #:nodoc:
|
5
|
+
# Adds in hooks for extending other parts of the Rails framework *after*
|
6
|
+
# Rails has loaded those frameworks
|
7
|
+
module Initializer
|
8
|
+
def self.included(base)
|
9
|
+
base.class_eval do
|
10
|
+
alias_method :require_frameworks_without_test_helper, :require_frameworks
|
11
|
+
alias_method :require_frameworks, :require_frameworks_with_test_helper
|
14
12
|
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Load the needed frameworks and then our extensions to them
|
16
|
+
def require_frameworks_with_test_helper
|
17
|
+
require_frameworks_without_test_helper
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
require 'plugin_test_helper/generator'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Overrides some of the default values in the Rails configuration so that
|
24
|
+
# files can be reused from this test helper or overridden by the plugin
|
25
|
+
# using the helper
|
26
|
+
module Configuration
|
27
|
+
def self.included(base) #:nodoc:
|
28
|
+
alias_method_chain base, :environment_path, :test_helper
|
29
|
+
alias_method_chain base, :default_load_paths, :test_helper
|
30
|
+
alias_method_chain base, :default_database_configuration_file, :test_helper
|
31
|
+
alias_method_chain base, :default_routes_configuration_file, :test_helper
|
32
|
+
alias_method_chain base, :default_controller_paths, :test_helper
|
33
|
+
alias_method_chain base, :default_plugin_locators, :test_helper
|
34
|
+
alias_method_chain base, :default_plugin_paths, :test_helper
|
35
|
+
end
|
36
|
+
|
37
|
+
# Defines a "lite" version of ActiveSupport's alias chaining extensions.
|
38
|
+
# This is defined here and acts on a particular class so as to not conflict
|
39
|
+
# with other classes that we have no control over
|
40
|
+
def self.alias_method_chain(klass, target, feature)
|
41
|
+
with_method, without_method = "#{target}_with_#{feature}", "#{target}_without_#{feature}"
|
42
|
+
klass.class_eval do
|
43
|
+
alias_method without_method, target
|
44
|
+
alias_method target, with_method
|
21
45
|
end
|
22
46
|
end
|
23
47
|
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
48
|
+
# Load the environment file from the plugin or the helper
|
49
|
+
def environment_path_with_test_helper
|
50
|
+
environment_path = environment_path_without_test_helper
|
51
|
+
File.exists?(environment_path) ? environment_path : "#{HELPER_RAILS_ROOT}/config/environments/#{environment}.rb"
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
# Add the helper's load paths
|
56
|
+
def default_load_paths_with_test_helper
|
57
|
+
paths = default_load_paths_without_test_helper
|
58
|
+
paths.concat %w(
|
59
|
+
app
|
60
|
+
app/controllers
|
61
|
+
config
|
62
|
+
lib
|
63
|
+
vendor
|
64
|
+
).map {|dir| "#{HELPER_RAILS_ROOT}/#{dir}"}
|
36
65
|
end
|
37
66
|
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
with_method, without_method = "#{target}_with_#{feature}", "#{target}_without_#{feature}"
|
43
|
-
klass.class_eval do
|
44
|
-
alias_method without_method, target
|
45
|
-
alias_method target, with_method
|
46
|
-
end
|
67
|
+
# Load the database configuration from the plugin or the helper
|
68
|
+
def default_database_configuration_file_with_test_helper
|
69
|
+
database_file = default_database_configuration_file_without_test_helper
|
70
|
+
File.exists?(database_file) ? database_file : File.join(HELPER_RAILS_ROOT, 'config/database.yml')
|
47
71
|
end
|
48
72
|
|
49
|
-
# Load the
|
50
|
-
def
|
51
|
-
|
52
|
-
File.exists?(
|
73
|
+
# Load the routes configuration file from the plugin or the helper
|
74
|
+
def default_routes_configuration_file_with_test_helper
|
75
|
+
routes_file = default_routes_configuration_file_without_test_helper
|
76
|
+
File.exists?(routes_file) ? routes_file : File.join(HELPER_RAILS_ROOT, 'config/routes.rb')
|
53
77
|
end
|
54
78
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
# Load the routes configuration file from the plugin or the helper
|
75
|
-
def default_routes_configuration_file_with_test_helper
|
76
|
-
routes_file = default_routes_configuration_file_without_test_helper
|
77
|
-
File.exists?(routes_file) ? routes_file : File.join(HELPER_RAILS_ROOT, 'config/routes.rb')
|
78
|
-
end
|
79
|
-
|
80
|
-
# Add the helper's controllers path
|
81
|
-
def default_controller_paths_with_test_helper
|
82
|
-
paths = default_controller_paths_without_test_helper
|
83
|
-
paths << File.join(HELPER_RAILS_ROOT, 'app/controllers')
|
84
|
-
end
|
85
|
-
|
86
|
-
# Adds a custom plugin locator for loading the plugin being tested
|
87
|
-
def default_plugin_locators_with_test_helper
|
88
|
-
locators = default_plugin_locators_without_test_helper
|
89
|
-
locators.unshift(PluginAWeek::PluginTestHelper::PluginLocator)
|
90
|
-
end
|
91
|
-
|
92
|
-
# Add the helper's vendor/plugins path
|
93
|
-
def default_plugin_paths_with_test_helper
|
94
|
-
paths = default_plugin_paths_without_test_helper
|
95
|
-
paths << File.join(HELPER_RAILS_ROOT, 'vendor/plugins')
|
96
|
-
end
|
97
|
-
end
|
79
|
+
# Add the helper's controllers path
|
80
|
+
def default_controller_paths_with_test_helper
|
81
|
+
paths = default_controller_paths_without_test_helper
|
82
|
+
paths << File.join(HELPER_RAILS_ROOT, 'app/controllers')
|
83
|
+
end
|
84
|
+
|
85
|
+
# Adds a custom plugin locator for loading the plugin being tested
|
86
|
+
def default_plugin_locators_with_test_helper
|
87
|
+
locators = default_plugin_locators_without_test_helper
|
88
|
+
locators.unshift(PluginTestHelper::PluginLocator)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Add the helper's vendor/plugins path
|
92
|
+
def default_plugin_paths_with_test_helper
|
93
|
+
paths = default_plugin_paths_without_test_helper
|
94
|
+
paths << File.join(HELPER_RAILS_ROOT, 'vendor/plugins')
|
95
|
+
end
|
98
96
|
end
|
99
97
|
end
|
100
98
|
end
|
101
99
|
|
102
100
|
Rails::Initializer.class_eval do
|
103
|
-
include
|
101
|
+
include PluginTestHelper::Extensions::Initializer
|
104
102
|
end
|
105
103
|
|
106
104
|
Rails::Configuration.class_eval do
|
107
|
-
include
|
105
|
+
include PluginTestHelper::Extensions::Configuration
|
108
106
|
end
|
@@ -1,27 +1,25 @@
|
|
1
1
|
require 'rails_generator'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
module PluginTestHelper
|
4
|
+
# The base generator for creating parts of the test application. The first
|
5
|
+
# argument of the generator is always the name of the plugin.
|
6
|
+
class Generator < Rails::Generator::NamedBase
|
7
|
+
attr_accessor :plugin_name
|
8
|
+
|
9
|
+
def initialize(*runtime_args) #:nodoc:
|
10
|
+
@plugin_name = runtime_args.first.shift if runtime_args.first.is_a?(Array)
|
11
|
+
super(*runtime_args)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
# The root path of the plugin's test directory
|
16
|
+
def plugin_test_root
|
17
|
+
"vendor/plugins/#{plugin_name}/test"
|
13
18
|
end
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
# The root path of the plugin's test app
|
22
|
-
def plugin_app_root
|
23
|
-
"#{plugin_test_root}/app_root"
|
24
|
-
end
|
25
|
-
end
|
20
|
+
# The root path of the plugin's test app
|
21
|
+
def plugin_app_root
|
22
|
+
"#{plugin_test_root}/app_root"
|
23
|
+
end
|
26
24
|
end
|
27
25
|
end
|
@@ -1,11 +1,9 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
[Rails::Plugin.new(File.expand_path('.'))]
|
8
|
-
end
|
1
|
+
module PluginTestHelper
|
2
|
+
# Assists in the initialization process by locating the plugin being tested
|
3
|
+
# so that it is tested as if the plugin were loaded in a regular app
|
4
|
+
class PluginLocator < Rails::Plugin::Locator
|
5
|
+
def plugins
|
6
|
+
[Rails::Plugin.new(File.expand_path('.'))]
|
9
7
|
end
|
10
8
|
end
|
11
9
|
end
|
@@ -7,7 +7,7 @@ class PluginLocatorTest < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_should_locate_plugin_being_tested
|
10
|
-
locator =
|
10
|
+
locator = PluginTestHelper::PluginLocator.new(nil)
|
11
11
|
assert_equal ['plugin_test_helper'], locator.plugins.map(&:name)
|
12
12
|
end
|
13
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plugin_test_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-14 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- test/app_roots/with_migration/app/models/person.rb
|
136
136
|
- test/unit
|
137
137
|
- test/unit/plugin_locator_test.rb
|
138
|
+
- test/app_root
|
138
139
|
- CHANGELOG.rdoc
|
139
140
|
- init.rb
|
140
141
|
- LICENSE
|