plugin_test_helper 0.0.2 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +19 -0
- data/README +57 -49
- data/Rakefile +3 -3
- data/generators/plugin_test_console/plugin_test_console_generator.rb +14 -0
- data/generators/plugin_test_console/templates/console +7 -0
- data/generators/plugin_test_controller/plugin_test_controller_generator.rb +1 -1
- data/generators/plugin_test_helper/plugin_test_helper_generator.rb +1 -1
- data/generators/plugin_test_helper/templates/test_helper.rb +8 -8
- data/generators/plugin_test_migration/plugin_test_migration_generator.rb +1 -1
- data/generators/plugin_test_model/plugin_test_model_generator.rb +4 -4
- data/generators/plugin_test_structure/plugin_test_structure_generator.rb +28 -28
- data/generators/plugin_test_structure/templates/app_root/config/boot.rb +6 -2
- data/lib/plugin_test_helper.rb +9 -7
- data/lib/plugin_test_helper/console_with_fixtures.rb +3 -0
- data/lib/plugin_test_helper/extensions/initializer.rb +61 -61
- data/lib/plugin_test_helper/extensions/routing.rb +2 -2
- data/lib/plugin_test_helper/generator.rb +4 -3
- data/test/app_roots/empty/empty +0 -0
- data/test/app_roots/with_controller/app/controllers/people_controller.rb +2 -0
- data/test/app_roots/with_custom_application_controller/app/controllers/application.rb +5 -0
- data/test/app_roots/with_custom_config/config/environment.rb +16 -0
- data/test/app_roots/with_custom_config/vendor/plugins/acts_as_foo/init.rb +1 -0
- data/test/app_roots/with_custom_config/vendor/plugins/acts_as_foo/lib/acts_as_foo.rb +6 -0
- data/test/app_roots/with_fixtures/app/models/person.rb +2 -0
- data/test/app_roots/with_fixtures/db/migrate/001_create_people.rb +11 -0
- data/test/app_roots/with_helper/app/helpers/people_helper.rb +2 -0
- data/test/app_roots/with_migration/app/models/person.rb +2 -0
- data/test/app_roots/with_migration/db/migrate/001_create_people.rb +11 -0
- data/test/app_roots/with_model/app/models/person.rb +2 -0
- data/test/app_roots/with_routes/config/routes.rb +2 -0
- data/test/fixtures/people.yml +3 -0
- data/test/functional/plugin_test_helper_test.rb +95 -0
- data/test/test_helper.rb +3 -0
- metadata +59 -4
data/CHANGELOG
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
*SVN*
|
2
2
|
|
3
|
+
*0.1.1* (September 18th, 2007)
|
4
|
+
|
5
|
+
* Allow RAILS_FRAMEWORK_ROOT to be specified
|
6
|
+
|
7
|
+
* fixture_path should be a string, not an array
|
8
|
+
|
9
|
+
* Move test fixtures out of the test application root directory
|
10
|
+
|
11
|
+
*0.1.0* (September 5th, 2007)
|
12
|
+
|
13
|
+
* Fixtures are now expected to be in plugin_root/test/fixtures instead of plugin_root/test/app_root/test/fixtures
|
14
|
+
|
15
|
+
* Add support for running a console on the test application
|
16
|
+
|
17
|
+
* Add basic functional tests
|
18
|
+
|
19
|
+
* Convert dos newlines to unix newlines
|
20
|
+
|
3
21
|
*0.0.2* (August 15th, 2007)
|
4
22
|
|
5
23
|
* Autoload plugin even if the plugin doesn't define an app_root
|
@@ -15,3 +33,4 @@
|
|
15
33
|
*0.0.1* (May 31st, 2007)
|
16
34
|
|
17
35
|
* Initial release
|
36
|
+
|
data/README
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
= plugin_test_helper
|
2
2
|
|
3
|
-
plugin_test_helper simplifies plugin testing by creating an isolated Rails
|
3
|
+
+plugin_test_helper+ simplifies plugin testing by creating an isolated Rails
|
4
4
|
environment that simulates its usage in a real application.
|
5
5
|
|
6
6
|
== Resources
|
7
7
|
|
8
|
+
API
|
9
|
+
|
10
|
+
* http://api.pluginaweek.org/plugin_test_helper
|
11
|
+
|
8
12
|
Wiki
|
9
13
|
|
10
14
|
* http://wiki.pluginaweek.org/Plugin_test_helper
|
11
15
|
|
12
16
|
Announcement
|
13
17
|
|
14
|
-
* http://www.pluginaweek.org
|
18
|
+
* http://www.pluginaweek.org
|
15
19
|
|
16
20
|
Source
|
17
21
|
|
@@ -21,60 +25,49 @@ Development
|
|
21
25
|
|
22
26
|
* http://dev.pluginaweek.org/browser/trunk/plugins/test/plugin_test_helper
|
23
27
|
|
24
|
-
==
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
etc.
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
your_plugin/
|
49
|
-
your_plugin/test
|
50
|
-
your_plugin/test/app_root
|
51
|
-
your_plugin/test/app_root/app
|
52
|
-
your_plugin/test/app_root/config
|
53
|
-
your_plugin/test/app_root/db
|
54
|
-
etc.
|
55
|
-
|
56
|
-
The app_root directory is just like your run-of-the-mill Rails application. It
|
28
|
+
== Descriptiona
|
29
|
+
|
30
|
+
Plugins often need to initialize a full Rails environment, whether it be for
|
31
|
+
accessing a database or simulating controller access. Traditionally, this has
|
32
|
+
been done by just loading the application that the plugin was added to.
|
33
|
+
However, this can cause all sorts of environment variables to change, making it
|
34
|
+
seem as though the plugin is having problems when it may be something else. It
|
35
|
+
also means that the plugin cannot be tested individually.
|
36
|
+
|
37
|
+
+plugin_test_helper+ helps solve this problem by allowing plugins to create their
|
38
|
+
own basic Rails environment with the ability to override any part of it, be it
|
39
|
+
the database configuration, environment configuration, or adding models,
|
40
|
+
controllers, helpers, etc. The following testing structure is assumed:
|
41
|
+
|
42
|
+
your_plugin/
|
43
|
+
your_plugin/test
|
44
|
+
your_plugin/test/app_root
|
45
|
+
your_plugin/test/app_root/app
|
46
|
+
your_plugin/test/app_root/config
|
47
|
+
your_plugin/test/app_root/db
|
48
|
+
etc.
|
49
|
+
|
50
|
+
The +app_root+ directory is just like your run-of-the-mill Rails application. It
|
57
51
|
can contain the same directories as your full application.
|
58
52
|
|
59
|
-
|
60
|
-
|
61
|
-
plugin_test_helper creates stubs for testing a plugin, as described in http://www.pluginaweek.org/2006/11/24
|
62
|
-
|
63
|
-
The following generators are available:
|
53
|
+
To help generate the various parts of your test application, the following
|
54
|
+
generators are available:
|
64
55
|
* plugin_test_helper
|
65
56
|
* plugin_test_structure
|
66
57
|
* plugin_test_model
|
67
58
|
* plugin_test_controller
|
68
59
|
* plugin_test_migration
|
69
60
|
|
70
|
-
|
61
|
+
*NOTE* that you <b>DO NOT</b> need to generate the entire application structure. All
|
71
62
|
that is required is that your test helper load plugin_test_helper. If you do
|
72
63
|
not define a part of the test application (such as the environment
|
73
64
|
configurations or the database configuration), then it will use the existing
|
74
|
-
implementation in plugin_test_helper/generators/plugin_test_structure/templates
|
75
|
-
|
65
|
+
implementation in <tt>plugin_test_helper/generators/plugin_test_structure/templates</tt>.
|
66
|
+
*However*, you can override any of these files by simply defining them in your
|
76
67
|
plugin, using the same directory structure.
|
77
68
|
|
69
|
+
== Usage
|
70
|
+
|
78
71
|
=== plugin_test_helper
|
79
72
|
|
80
73
|
Generates a test helper file that should be required by all unit/functional/integration
|
@@ -94,7 +87,7 @@ Example:
|
|
94
87
|
=== plugin_test_structure
|
95
88
|
|
96
89
|
Generates the entire test application structure. If you keep all files within
|
97
|
-
your plugin, then you will not need to depend on the plugin_test_helper plugin
|
90
|
+
your plugin, then you will not need to depend on the +plugin_test_helper+ plugin
|
98
91
|
when testing it.
|
99
92
|
|
100
93
|
Example:
|
@@ -183,12 +176,27 @@ Example:
|
|
183
176
|
|
184
177
|
0 tests, 0 assertions, 0 failures, 0 errors
|
185
178
|
|
179
|
+
=== plugin_test_console
|
180
|
+
|
181
|
+
Generates a script for running an interactive console with your plugin's test
|
182
|
+
application.
|
183
|
+
|
184
|
+
Example:
|
185
|
+
|
186
|
+
$ ruby script/generate plugin_test_console acts_as_most_popular
|
187
|
+
create vendor/plugins/acts_as_most_popular/test/app_root/../../script
|
188
|
+
create vendor/plugins/acts_as_most_popular/test/app_root/../../script/console
|
189
|
+
Loaded suite script/generate
|
190
|
+
Started
|
191
|
+
|
192
|
+
Finished in 0.000267 seconds.
|
193
|
+
|
194
|
+
0 tests, 0 assertions, 0 failures, 0 errors
|
195
|
+
|
186
196
|
== Dependencies
|
187
197
|
|
188
|
-
This plugin does not depend on any other plugins.
|
198
|
+
This plugin does not depend on the presence of any other plugins.
|
189
199
|
|
190
|
-
==
|
200
|
+
== References
|
191
201
|
|
192
|
-
|
193
|
-
initial implementation of this plugin. His work has made testing our plugins so
|
194
|
-
much easier. Thanks Mark!
|
202
|
+
* {Mark Meves}[http://rationalexuberance.org] for the initial implementation
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require 'rake/gempackagetask'
|
|
4
4
|
require 'rake/contrib/sshpublisher'
|
5
5
|
|
6
6
|
PKG_NAME = 'plugin_test_helper'
|
7
|
-
PKG_VERSION = '0.
|
7
|
+
PKG_VERSION = '0.1.1'
|
8
8
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
9
9
|
RUBY_FORGE_PROJECT = 'pluginaweek'
|
10
10
|
|
@@ -33,7 +33,7 @@ spec = Gem::Specification.new do |s|
|
|
33
33
|
s.platform = Gem::Platform::RUBY
|
34
34
|
s.summary = 'Simplifies plugin testing by creating an isolated Rails environment that simulates its usage in a real application.'
|
35
35
|
|
36
|
-
s.files = FileList['{generators,lib}/**/*'].to_a + %w(CHANGELOG init.rb MIT-LICENSE Rakefile README)
|
36
|
+
s.files = FileList['{generators,lib,test}/**/*'].to_a + %w(CHANGELOG init.rb MIT-LICENSE Rakefile README)
|
37
37
|
s.require_path = 'lib'
|
38
38
|
s.autorequire = 'plugin_test_helper'
|
39
39
|
s.has_rdoc = true
|
@@ -76,4 +76,4 @@ task :release => [:gem, :package] do
|
|
76
76
|
|
77
77
|
ruby_forge.add_release(RUBY_FORGE_PROJECT, PKG_NAME, PKG_VERSION, file)
|
78
78
|
end
|
79
|
-
end
|
79
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Generates a test console for the plugin's test application
|
2
|
+
class PluginTestConsoleGenerator < Rails::Generator::NamedBase
|
3
|
+
def manifest #:nodoc:
|
4
|
+
record do |m|
|
5
|
+
plugin_root = "vendor/plugins/#{name}"
|
6
|
+
|
7
|
+
# Script directory.
|
8
|
+
m.directory File.join(plugin_root, 'script')
|
9
|
+
|
10
|
+
# Console class.
|
11
|
+
m.file 'console', File.join(plugin_root, 'script/console')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
2
|
+
libs = " -r irb/completion"
|
3
|
+
libs << " -r test/test_helper"
|
4
|
+
libs << " -r plugin_test_helper/console_with_fixtures"
|
5
|
+
libs << " -r console_app"
|
6
|
+
libs << " -r console_with_helpers"
|
7
|
+
exec "#{irb} #{libs} --simple-prompt"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Generates the class, helper, and view for a controller in a plugin's test application
|
2
2
|
class PluginTestControllerGenerator < PluginAWeek::PluginTestHelper::Generator
|
3
|
-
def manifest
|
3
|
+
def manifest #:nodoc:
|
4
4
|
record do |m|
|
5
5
|
# Check for class naming collisions.
|
6
6
|
m.class_collisions class_path, "#{class_name}Controller", "#{class_name}Helper"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Generates the test helper for a plugin
|
2
2
|
class PluginTestHelperGenerator < Rails::Generator::NamedBase
|
3
|
-
def manifest
|
3
|
+
def manifest #:nodoc:
|
4
4
|
record do |m|
|
5
5
|
plugin_test_root = "vendor/plugins/#{name}/test"
|
6
6
|
m.file 'test_helper.rb', "#{plugin_test_root}/test_helper.rb"
|
@@ -1,9 +1,9 @@
|
|
1
|
-
# If you want to change the default rails environment
|
2
|
-
# ENV['RAILS_ENV'] ||= 'your_env'
|
3
|
-
|
4
|
-
# Load the plugin testing framework
|
5
|
-
require 'rubygems'
|
6
|
-
require 'plugin_test_helper'
|
7
|
-
|
8
|
-
# Run the migrations (optional)
|
1
|
+
# If you want to change the default rails environment
|
2
|
+
# ENV['RAILS_ENV'] ||= 'your_env'
|
3
|
+
|
4
|
+
# Load the plugin testing framework
|
5
|
+
require 'rubygems'
|
6
|
+
require 'plugin_test_helper'
|
7
|
+
|
8
|
+
# Run the migrations (optional)
|
9
9
|
ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
|
@@ -2,18 +2,18 @@
|
|
2
2
|
class PluginTestModelGenerator < PluginAWeek::PluginTestHelper::Generator
|
3
3
|
default_options :skip_migration => false
|
4
4
|
|
5
|
-
def manifest
|
5
|
+
def manifest #:nodoc:
|
6
6
|
record do |m|
|
7
7
|
# Check for class naming collisions.
|
8
8
|
m.class_collisions class_path, class_name
|
9
9
|
|
10
10
|
# Model and fixture directories.
|
11
11
|
m.directory File.join(plugin_app_root, 'app/models', class_path)
|
12
|
-
m.directory File.join(
|
12
|
+
m.directory File.join(plugin_test_root, 'fixtures', class_path)
|
13
13
|
|
14
14
|
# Model class and fixtures.
|
15
15
|
m.template 'model.rb', File.join(plugin_app_root, 'app/models', class_path, "#{file_name}.rb")
|
16
|
-
m.template 'fixtures.yml', File.join(
|
16
|
+
m.template 'fixtures.yml', File.join(plugin_test_root, 'fixtures', class_path, "#{table_name}.yml")
|
17
17
|
|
18
18
|
unless options[:skip_migration]
|
19
19
|
m.migration_template 'migration.rb', "#{plugin_app_root}/db/migrate", :assigns => {
|
@@ -34,4 +34,4 @@ class PluginTestModelGenerator < PluginAWeek::PluginTestHelper::Generator
|
|
34
34
|
opt.on("--skip-migration",
|
35
35
|
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
36
36
|
end
|
37
|
-
end
|
37
|
+
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
# Generates the test structure for a plugin
|
2
|
-
class PluginTestStructureGenerator < Rails::Generator::NamedBase
|
3
|
-
def manifest
|
4
|
-
record do |m|
|
5
|
-
# Paths are relative to our template dir
|
6
|
-
plugin_test_root = "vendor/plugins/#{name}/test"
|
7
|
-
templates_root = "#{File.dirname(__FILE__)}/templates"
|
8
|
-
|
9
|
-
# Copy all directories and files. None of them are templated so that they
|
10
|
-
# can be reused during runtime
|
11
|
-
Dir["#{templates_root}/**/*"].each do |source_file|
|
12
|
-
|
13
|
-
target_file = File.join(plugin_test_root, relative_source_file)
|
14
|
-
|
15
|
-
if File.directory?(source_file)
|
16
|
-
m.directory target_file
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
protected
|
25
|
-
def banner
|
26
|
-
"Usage: #{$0} plugin_test_structure your_plugin"
|
27
|
-
end
|
28
|
-
end
|
1
|
+
# Generates the test structure for a plugin
|
2
|
+
class PluginTestStructureGenerator < Rails::Generator::NamedBase
|
3
|
+
def manifest #:nodoc:
|
4
|
+
record do |m|
|
5
|
+
# Paths are relative to our template dir
|
6
|
+
plugin_test_root = "vendor/plugins/#{name}/test"
|
7
|
+
templates_root = "#{File.dirname(__FILE__)}/templates"
|
8
|
+
|
9
|
+
# Copy all directories and files. None of them are templated so that they
|
10
|
+
# can be reused during runtime
|
11
|
+
Dir["#{templates_root}/**/*"].each do |source_file|
|
12
|
+
relative_source_file = source_file.sub(templates_root, '')
|
13
|
+
target_file = File.join(plugin_test_root, relative_source_file)
|
14
|
+
|
15
|
+
if File.directory?(source_file)
|
16
|
+
m.directory target_file
|
17
|
+
else
|
18
|
+
m.file relative_source_file, target_file
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
def banner
|
26
|
+
"Usage: #{$0} plugin_test_structure your_plugin"
|
27
|
+
end
|
28
|
+
end
|
@@ -9,9 +9,13 @@ unless defined?(RAILS_ROOT)
|
|
9
9
|
RAILS_ROOT = root_path
|
10
10
|
end
|
11
11
|
|
12
|
+
unless defined?(RAILS_FRAMEWORK_ROOT)
|
13
|
+
RAILS_FRAMEWORK_ROOT = ENV['RAILS_FRAMEWORK_ROOT'] || "#{RAILS_ROOT}/vendor/rails"
|
14
|
+
end
|
15
|
+
|
12
16
|
unless defined?(Rails::Initializer)
|
13
|
-
if File.directory?(
|
14
|
-
require "#{
|
17
|
+
if File.directory?(RAILS_FRAMEWORK_ROOT)
|
18
|
+
require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer"
|
15
19
|
else
|
16
20
|
require 'rubygems'
|
17
21
|
|
data/lib/plugin_test_helper.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
# Make sure our default RAILS_ROOT from the helper plugin is in the load path
|
2
|
-
|
2
|
+
unless defined?(HELPER_RAILS_ROOT)
|
3
|
+
HELPER_RAILS_ROOT = "#{File.dirname(__FILE__)}/../generators/plugin_test_structure/templates/app_root"
|
4
|
+
end
|
3
5
|
$:.unshift(HELPER_RAILS_ROOT)
|
4
6
|
|
5
7
|
# Determine the plugin's root test directory and add it to the load path
|
6
8
|
unless defined?(RAILS_ROOT)
|
7
9
|
root_path = File.join(File.expand_path('.'), 'test/app_root')
|
8
|
-
|
10
|
+
|
9
11
|
unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
|
10
12
|
require 'pathname'
|
11
13
|
root_path = Pathname.new(root_path).cleanpath(true).to_s
|
12
14
|
end
|
13
|
-
|
15
|
+
|
14
16
|
RAILS_ROOT = root_path
|
15
17
|
end
|
16
|
-
|
17
18
|
$:.unshift(RAILS_ROOT)
|
18
19
|
|
19
20
|
# Set the default environment to sqlite3's in_memory database
|
@@ -31,8 +32,8 @@ require 'plugin_test_helper/extensions/initializer'
|
|
31
32
|
require 'plugin_test_helper/extensions/routing'
|
32
33
|
|
33
34
|
# Load the Rails environment and testing framework
|
34
|
-
|
35
|
-
|
35
|
+
require_or_load 'config/environment'
|
36
|
+
require_or_load 'test_help'
|
36
37
|
|
37
38
|
# Undo changes to RAILS_ENV
|
38
39
|
silence_warnings { RAILS_ENV = ENV['RAILS_ENV'] }
|
@@ -41,4 +42,5 @@ silence_warnings { RAILS_ENV = ENV['RAILS_ENV'] }
|
|
41
42
|
class Test::Unit::TestCase #:nodoc:
|
42
43
|
self.use_transactional_fixtures = true
|
43
44
|
self.use_instantiated_fixtures = false
|
44
|
-
|
45
|
+
self.fixture_path = "#{RAILS_ROOT}/../fixtures"
|
46
|
+
end
|
@@ -1,61 +1,61 @@
|
|
1
|
-
module PluginAWeek #:nodoc:
|
2
|
-
module PluginTestHelper
|
3
|
-
module Extensions #:nodoc:
|
4
|
-
# Overrides some of the default values in the Rails configuration so that
|
5
|
-
# files can be reused from this test helper or overridden by the plugin
|
6
|
-
# using the helper
|
7
|
-
module Configuration
|
8
|
-
def self.included(base) #:nodoc:
|
9
|
-
base.class_eval do
|
10
|
-
alias_method_chain :environment_path, :test_helper
|
11
|
-
alias_method_chain :default_load_paths, :test_helper
|
12
|
-
alias_method_chain :default_database_configuration_file, :test_helper
|
13
|
-
alias_method_chain :default_controller_paths, :test_helper
|
14
|
-
alias_method_chain :default_plugin_paths, :test_helper
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# Load the environment file from the plugin or the helper
|
19
|
-
def environment_path_with_test_helper
|
20
|
-
environment_path = environment_path_without_test_helper
|
21
|
-
File.exists?(environment_path) ? environment_path : "#{HELPER_RAILS_ROOT}/config/environments/#{environment}.rb"
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def default_load_paths_with_test_helper
|
27
|
-
paths = default_load_paths_without_test_helper
|
28
|
-
paths.concat %w(
|
29
|
-
app
|
30
|
-
app/controllers
|
31
|
-
config
|
32
|
-
lib
|
33
|
-
vendor
|
34
|
-
).map { |dir| "#{HELPER_RAILS_ROOT}/#{dir}" }
|
35
|
-
end
|
36
|
-
|
37
|
-
# Load the database configuration from the plugin or the helper
|
38
|
-
def default_database_configuration_file_with_test_helper
|
39
|
-
database_file = default_database_configuration_file_without_test_helper
|
40
|
-
File.exists?(database_file) ? database_file : File.join(HELPER_RAILS_ROOT, 'config', 'database.yml')
|
41
|
-
end
|
42
|
-
|
43
|
-
# Add the helper's controllers path
|
44
|
-
def default_controller_paths_with_test_helper
|
45
|
-
paths = default_controller_paths_without_test_helper
|
46
|
-
paths << File.join(HELPER_RAILS_ROOT, 'app', 'controllers')
|
47
|
-
end
|
48
|
-
|
49
|
-
# Add the helper's vendor/plugins path
|
50
|
-
def default_plugin_paths_with_test_helper
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
Rails::Configuration.class_eval do
|
60
|
-
include PluginAWeek::PluginTestHelper::Extensions::Configuration
|
61
|
-
end
|
1
|
+
module PluginAWeek #:nodoc:
|
2
|
+
module PluginTestHelper
|
3
|
+
module Extensions #:nodoc:
|
4
|
+
# Overrides some of the default values in the Rails configuration so that
|
5
|
+
# files can be reused from this test helper or overridden by the plugin
|
6
|
+
# using the helper
|
7
|
+
module Configuration
|
8
|
+
def self.included(base) #:nodoc:
|
9
|
+
base.class_eval do
|
10
|
+
alias_method_chain :environment_path, :test_helper
|
11
|
+
alias_method_chain :default_load_paths, :test_helper
|
12
|
+
alias_method_chain :default_database_configuration_file, :test_helper
|
13
|
+
alias_method_chain :default_controller_paths, :test_helper
|
14
|
+
alias_method_chain :default_plugin_paths, :test_helper
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Load the environment file from the plugin or the helper
|
19
|
+
def environment_path_with_test_helper
|
20
|
+
environment_path = environment_path_without_test_helper
|
21
|
+
File.exists?(environment_path) ? environment_path : "#{HELPER_RAILS_ROOT}/config/environments/#{environment}.rb"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
# Add the helper's load paths
|
26
|
+
def default_load_paths_with_test_helper
|
27
|
+
paths = default_load_paths_without_test_helper
|
28
|
+
paths.concat %w(
|
29
|
+
app
|
30
|
+
app/controllers
|
31
|
+
config
|
32
|
+
lib
|
33
|
+
vendor
|
34
|
+
).map { |dir| "#{HELPER_RAILS_ROOT}/#{dir}" }
|
35
|
+
end
|
36
|
+
|
37
|
+
# Load the database configuration from the plugin or the helper
|
38
|
+
def default_database_configuration_file_with_test_helper
|
39
|
+
database_file = default_database_configuration_file_without_test_helper
|
40
|
+
File.exists?(database_file) ? database_file : File.join(HELPER_RAILS_ROOT, 'config', 'database.yml')
|
41
|
+
end
|
42
|
+
|
43
|
+
# Add the helper's controllers path
|
44
|
+
def default_controller_paths_with_test_helper
|
45
|
+
paths = default_controller_paths_without_test_helper
|
46
|
+
paths << File.join(HELPER_RAILS_ROOT, 'app', 'controllers')
|
47
|
+
end
|
48
|
+
|
49
|
+
# Add the helper's vendor/plugins path
|
50
|
+
def default_plugin_paths_with_test_helper
|
51
|
+
paths = default_plugin_paths_without_test_helper
|
52
|
+
paths << "#{HELPER_RAILS_ROOT}/vendor/plugins"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
Rails::Configuration.class_eval do
|
60
|
+
include PluginAWeek::PluginTestHelper::Extensions::Configuration
|
61
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module PluginAWeek #:nodoc:
|
2
|
-
module PluginTestHelper
|
2
|
+
module PluginTestHelper
|
3
3
|
module Extensions #:nodoc:
|
4
4
|
# Overrides where the path of the application routes is located so that
|
5
5
|
# it defaults to this helper's implementation or can be overridden by the
|
@@ -29,4 +29,4 @@ end
|
|
29
29
|
|
30
30
|
ActionController::Routing::RouteSet.class_eval do
|
31
31
|
include PluginAWeek::PluginTestHelper::Extensions::Routing
|
32
|
-
end
|
32
|
+
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'rails_generator'
|
2
2
|
|
3
3
|
module PluginAWeek #:nodoc:
|
4
|
-
module PluginTestHelper
|
4
|
+
module PluginTestHelper
|
5
|
+
# The base generator for creating parts of the test application
|
5
6
|
class Generator < Rails::Generator::NamedBase
|
6
7
|
attr_accessor :plugin_name
|
7
8
|
|
8
|
-
def initialize(*runtime_args)
|
9
|
+
def initialize(*runtime_args) #:nodoc:
|
9
10
|
@plugin_name = runtime_args.first.shift if runtime_args.first.is_a?(Array)
|
10
11
|
super(*runtime_args)
|
11
12
|
end
|
@@ -21,4 +22,4 @@ module PluginAWeek #:nodoc:
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
24
|
-
end
|
25
|
+
end
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'config/boot'
|
2
|
+
|
3
|
+
Rails::Initializer.run do |config|
|
4
|
+
config.log_level = :debug
|
5
|
+
config.cache_classes = false
|
6
|
+
config.whiny_nils = true
|
7
|
+
config.breakpoint_server = true
|
8
|
+
config.load_paths << "#{RAILS_ROOT}/../../lib"
|
9
|
+
config.plugin_paths << '..'
|
10
|
+
config.plugins = [
|
11
|
+
File.basename(File.expand_path('.')),
|
12
|
+
'acts_as_foo'
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
Dependencies.log_activity = true
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'acts_as_foo'
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class PluginTestHelperTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@original_load_path = $LOAD_PATH
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_load_with_no_app_root
|
10
|
+
load 'plugin_test_helper.rb'
|
11
|
+
assert_valid_environment
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_load_with_empty_app_root
|
15
|
+
initialize_app('empty')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_load_with_custom_application_controller
|
19
|
+
initialize_app('with_custom_application_controller')
|
20
|
+
|
21
|
+
assert ApplicationController.respond_to?(:custom?)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_load_with_custom_config
|
25
|
+
initialize_app('with_custom_config')
|
26
|
+
|
27
|
+
assert_not_nil PluginAWeek::Acts::Foo
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_load_with_controller
|
31
|
+
initialize_app('with_controller')
|
32
|
+
|
33
|
+
assert_not_nil PeopleController
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_load_with_model
|
37
|
+
initialize_app('with_model')
|
38
|
+
|
39
|
+
assert_not_nil Person
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_should_load_with_helper
|
43
|
+
initialize_app('with_helper')
|
44
|
+
|
45
|
+
assert_not_nil PeopleHelper
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_should_load_with_migration
|
49
|
+
initialize_app('with_migration')
|
50
|
+
|
51
|
+
ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
|
52
|
+
assert Person.table_exists?
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_should_load_with_fixtures
|
56
|
+
initialize_app('with_fixtures')
|
57
|
+
|
58
|
+
ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
|
59
|
+
Dir.glob("#{RAILS_ROOT}/test/fixtures/*.yml").each do |fixture_file|
|
60
|
+
Fixtures.create_fixtures("#{RAILS_ROOT}/test/fixtures", File.basename(fixture_file, '.*'))
|
61
|
+
end
|
62
|
+
|
63
|
+
assert Person.count > 0
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_should_load_with_routes
|
67
|
+
initialize_app('with_routes')
|
68
|
+
|
69
|
+
assert ActionController::Routing::Routes.routes.length == 0
|
70
|
+
end
|
71
|
+
|
72
|
+
def teardown
|
73
|
+
# Clear dependencies
|
74
|
+
ActiveRecord::Base.reset_subclasses
|
75
|
+
Dependencies.clear
|
76
|
+
ActiveRecord::Base.clear_reloadable_connections!
|
77
|
+
|
78
|
+
$LOAD_PATH.replace(@original_load_path)
|
79
|
+
FileUtils.rmtree('test/app_root')
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
def assert_valid_environment
|
84
|
+
assert_not_nil ApplicationController
|
85
|
+
assert ActiveRecord::Base.connection.active?
|
86
|
+
end
|
87
|
+
|
88
|
+
def initialize_app(name)
|
89
|
+
FileUtils.mkdir('test/app_root')
|
90
|
+
FileUtils.cp_r("test/app_roots/#{name}/.", 'test/app_root')
|
91
|
+
|
92
|
+
load 'plugin_test_helper.rb'
|
93
|
+
assert_valid_environment
|
94
|
+
end
|
95
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: plugin_test_helper
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.1.1
|
7
|
+
date: 2007-09-18 00:00:00 -04:00
|
8
8
|
summary: Simplifies plugin testing by creating an isolated Rails environment that simulates its usage in a real application.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,6 +30,7 @@ authors:
|
|
30
30
|
- Aaron Pfeifer, Neil Abraham
|
31
31
|
files:
|
32
32
|
- generators/plugin_test_migration
|
33
|
+
- generators/plugin_test_console
|
33
34
|
- generators/plugin_test_helper
|
34
35
|
- generators/plugin_test_model
|
35
36
|
- generators/plugin_test_controller
|
@@ -37,6 +38,9 @@ files:
|
|
37
38
|
- generators/plugin_test_migration/templates
|
38
39
|
- generators/plugin_test_migration/plugin_test_migration_generator.rb
|
39
40
|
- generators/plugin_test_migration/templates/migration.rb
|
41
|
+
- generators/plugin_test_console/plugin_test_console_generator.rb
|
42
|
+
- generators/plugin_test_console/templates
|
43
|
+
- generators/plugin_test_console/templates/console
|
40
44
|
- generators/plugin_test_helper/plugin_test_helper_generator.rb
|
41
45
|
- generators/plugin_test_helper/templates
|
42
46
|
- generators/plugin_test_helper/templates/test_helper.rb
|
@@ -71,17 +75,68 @@ files:
|
|
71
75
|
- generators/plugin_test_structure/templates/app_root/app/controllers/application.rb
|
72
76
|
- lib/plugin_test_helper
|
73
77
|
- lib/plugin_test_helper.rb
|
78
|
+
- lib/plugin_test_helper/console_with_fixtures.rb
|
74
79
|
- lib/plugin_test_helper/extensions
|
75
80
|
- lib/plugin_test_helper/generator.rb
|
76
81
|
- lib/plugin_test_helper/extensions/routing.rb
|
77
82
|
- lib/plugin_test_helper/extensions/initializer.rb
|
83
|
+
- test/test_helper.rb
|
84
|
+
- test/app_roots
|
85
|
+
- test/fixtures
|
86
|
+
- test/functional
|
87
|
+
- test/app_roots/with_fixtures
|
88
|
+
- test/app_roots/with_helper
|
89
|
+
- test/app_roots/with_model
|
90
|
+
- test/app_roots/with_controller
|
91
|
+
- test/app_roots/with_custom_application_controller
|
92
|
+
- test/app_roots/empty
|
93
|
+
- test/app_roots/with_migration
|
94
|
+
- test/app_roots/with_routes
|
95
|
+
- test/app_roots/with_custom_config
|
96
|
+
- test/app_roots/with_fixtures/app
|
97
|
+
- test/app_roots/with_fixtures/db
|
98
|
+
- test/app_roots/with_fixtures/app/models
|
99
|
+
- test/app_roots/with_fixtures/app/models/person.rb
|
100
|
+
- test/app_roots/with_fixtures/db/migrate
|
101
|
+
- test/app_roots/with_fixtures/db/migrate/001_create_people.rb
|
102
|
+
- test/app_roots/with_helper/app
|
103
|
+
- test/app_roots/with_helper/app/helpers
|
104
|
+
- test/app_roots/with_helper/app/helpers/people_helper.rb
|
105
|
+
- test/app_roots/with_model/app
|
106
|
+
- test/app_roots/with_model/app/models
|
107
|
+
- test/app_roots/with_model/app/models/person.rb
|
108
|
+
- test/app_roots/with_controller/app
|
109
|
+
- test/app_roots/with_controller/app/controllers
|
110
|
+
- test/app_roots/with_controller/app/controllers/people_controller.rb
|
111
|
+
- test/app_roots/with_custom_application_controller/app
|
112
|
+
- test/app_roots/with_custom_application_controller/app/controllers
|
113
|
+
- test/app_roots/with_custom_application_controller/app/controllers/application.rb
|
114
|
+
- test/app_roots/empty/empty
|
115
|
+
- test/app_roots/with_migration/app
|
116
|
+
- test/app_roots/with_migration/db
|
117
|
+
- test/app_roots/with_migration/app/models
|
118
|
+
- test/app_roots/with_migration/app/models/person.rb
|
119
|
+
- test/app_roots/with_migration/db/migrate
|
120
|
+
- test/app_roots/with_migration/db/migrate/001_create_people.rb
|
121
|
+
- test/app_roots/with_routes/config
|
122
|
+
- test/app_roots/with_routes/config/routes.rb
|
123
|
+
- test/app_roots/with_custom_config/vendor
|
124
|
+
- test/app_roots/with_custom_config/config
|
125
|
+
- test/app_roots/with_custom_config/vendor/plugins
|
126
|
+
- test/app_roots/with_custom_config/vendor/plugins/acts_as_foo
|
127
|
+
- test/app_roots/with_custom_config/vendor/plugins/acts_as_foo/lib
|
128
|
+
- test/app_roots/with_custom_config/vendor/plugins/acts_as_foo/init.rb
|
129
|
+
- test/app_roots/with_custom_config/vendor/plugins/acts_as_foo/lib/acts_as_foo.rb
|
130
|
+
- test/app_roots/with_custom_config/config/environment.rb
|
131
|
+
- test/fixtures/people.yml
|
132
|
+
- test/functional/plugin_test_helper_test.rb
|
78
133
|
- CHANGELOG
|
79
134
|
- init.rb
|
80
135
|
- MIT-LICENSE
|
81
136
|
- Rakefile
|
82
137
|
- README
|
83
|
-
test_files:
|
84
|
-
|
138
|
+
test_files:
|
139
|
+
- test/functional/plugin_test_helper_test.rb
|
85
140
|
rdoc_options: []
|
86
141
|
|
87
142
|
extra_rdoc_files: []
|