plugin_test_helper 0.0.1

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.
Files changed (33) hide show
  1. data/CHANGELOG +5 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +186 -0
  4. data/Rakefile +79 -0
  5. data/generators/plugin_test_controller/plugin_test_controller_generator.rb +27 -0
  6. data/generators/plugin_test_controller/templates/controller.rb +10 -0
  7. data/generators/plugin_test_controller/templates/view.rhtml +2 -0
  8. data/generators/plugin_test_helper/plugin_test_helper_generator.rb +14 -0
  9. data/generators/plugin_test_helper/templates/test_helper.rb +14 -0
  10. data/generators/plugin_test_migration/plugin_test_migration_generator.rb +8 -0
  11. data/generators/plugin_test_migration/templates/migration.rb +7 -0
  12. data/generators/plugin_test_model/plugin_test_model_generator.rb +37 -0
  13. data/generators/plugin_test_model/templates/fixtures.yml +11 -0
  14. data/generators/plugin_test_model/templates/migration.rb +13 -0
  15. data/generators/plugin_test_model/templates/model.rb +2 -0
  16. data/generators/plugin_test_structure/plugin_test_structure_generator.rb +28 -0
  17. data/generators/plugin_test_structure/templates/app_root/app/controllers/application.rb +2 -0
  18. data/generators/plugin_test_structure/templates/app_root/config/boot.rb +43 -0
  19. data/generators/plugin_test_structure/templates/app_root/config/database.yml +22 -0
  20. data/generators/plugin_test_structure/templates/app_root/config/environment.rb +11 -0
  21. data/generators/plugin_test_structure/templates/app_root/config/environments/in_memory.rb +0 -0
  22. data/generators/plugin_test_structure/templates/app_root/config/environments/mysql.rb +0 -0
  23. data/generators/plugin_test_structure/templates/app_root/config/environments/postgresql.rb +0 -0
  24. data/generators/plugin_test_structure/templates/app_root/config/environments/sqlite.rb +0 -0
  25. data/generators/plugin_test_structure/templates/app_root/config/environments/sqlite3.rb +0 -0
  26. data/generators/plugin_test_structure/templates/app_root/config/routes.rb +2 -0
  27. data/generators/plugin_test_structure/templates/app_root/vendor/plugins/plugin_proxy/init.rb +4 -0
  28. data/init.rb +1 -0
  29. data/lib/plugin_test_helper/extensions/initializer.rb +61 -0
  30. data/lib/plugin_test_helper/extensions/routing.rb +32 -0
  31. data/lib/plugin_test_helper/generator.rb +24 -0
  32. data/lib/plugin_test_helper.rb +21 -0
  33. metadata +98 -0
data/CHANGELOG ADDED
@@ -0,0 +1,5 @@
1
+ *SVN*
2
+
3
+ *0.0.1* (May 31st, 2007)
4
+
5
+ * Initial release
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2005-2006 Aaron Pfeifer & Neil Abraham
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,186 @@
1
+ = plugin_test_helper
2
+
3
+ plugin_test_helper simplifies plugin testing by creating an isolated Rails
4
+ environment that simulates its usage in a real application.
5
+
6
+ == Resources
7
+
8
+ Wiki
9
+
10
+ * http://wiki.pluginaweek.org/Plugin_test_helper
11
+
12
+ Announcement
13
+
14
+ * http://www.pluginaweek.org/
15
+
16
+ Source
17
+
18
+ * http://svn.pluginaweek.org/trunk/plugins/test/plugin_test_helper
19
+
20
+ Development
21
+
22
+ * http://dev.pluginaweek.org/browser/trunk/plugins/test/plugin_test_helper
23
+
24
+ == Background
25
+
26
+ As described in http://www.pluginaweek.org/2006/11/24/plugin-tip-of-the-week-testing-your-plugins-the-right-way/,
27
+ plugins often need access to a full Rails environment, whether it be accessing a
28
+ database, simulating controller access, or something else. Whatever it may be,
29
+ you still need to initialize a Rails environment in order to get your tests
30
+ working.
31
+
32
+ Traditionally, this has been done by just loading the application that the
33
+ plugin was added to. This has many downfalls, the most important of which is
34
+ that loading the application can cause all sorts of things to change, making it
35
+ seem as though the plugin is having problems when it may be something else. The
36
+ other downfall of this technique is that the plugin cannot be tested individually.
37
+ Instead, it must be part of a Rails application.
38
+
39
+ == Solution
40
+
41
+ The solution to this problem is to have the plugin create its own basic Rails
42
+ environment with the ability to override any part of it, be it the database
43
+ configuration, environment configuration, or adding models, controllers, helpers,
44
+ etc.
45
+
46
+ plugin_test_helper assumes a testing structure like so:
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
57
+ can contain the same directories as your full application.
58
+
59
+ == How to use plugin_test_helper
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:
64
+ * plugin_test_helper
65
+ * plugin_test_structure
66
+ * plugin_test_model
67
+ * plugin_test_controller
68
+ * plugin_test_migration
69
+
70
+ === plugin_test_helper
71
+
72
+ Generates a test helper file that should be required by all unit/functional/integration
73
+ tests in your plugin.
74
+
75
+ Example:
76
+
77
+ $ ruby script/generate plugin_test_helper acts_as_most_popular
78
+ create vendor/plugins/acts_as_most_popular/test/test_helper.rb
79
+ Loaded suite script/generate
80
+ Started
81
+
82
+ Finished in 0.000439 seconds.
83
+
84
+ 0 tests, 0 assertions, 0 failures, 0 errors
85
+
86
+ === plugin_test_structure
87
+
88
+ Generates the entire test application structure. If you keep all files within
89
+ your plugin, then you will not need to depend on the plugin_test_helper plugin
90
+ when testing it.
91
+
92
+ Example:
93
+
94
+ $ ruby script/generate plugin_test_structure acts_as_most_popular
95
+ create vendor/plugins/acts_as_most_popular/test/app_root
96
+ create vendor/plugins/acts_as_most_popular/test/app_root/vendor
97
+ create vendor/plugins/acts_as_most_popular/test/app_root/config
98
+ create vendor/plugins/acts_as_most_popular/test/app_root/app
99
+ create vendor/plugins/acts_as_most_popular/test/app_root/lib
100
+ create vendor/plugins/acts_as_most_popular/test/app_root/vendor/plugins
101
+ create vendor/plugins/acts_as_most_popular/test/app_root/vendor/plugins/plugin_proxy
102
+ create vendor/plugins/acts_as_most_popular/test/app_root/vendor/plugins/plugin_proxy/init.rb
103
+ create vendor/plugins/acts_as_most_popular/test/app_root/config/environments
104
+ create vendor/plugins/acts_as_most_popular/test/app_root/config/routes.rb
105
+ create vendor/plugins/acts_as_most_popular/test/app_root/config/boot.rb
106
+ create vendor/plugins/acts_as_most_popular/test/app_root/config/environment.rb
107
+ create vendor/plugins/acts_as_most_popular/test/app_root/config/database.yml
108
+ create vendor/plugins/acts_as_most_popular/test/app_root/config/environments/sqlite.rb
109
+ create vendor/plugins/acts_as_most_popular/test/app_root/config/environments/sqlite3.rb
110
+ create vendor/plugins/acts_as_most_popular/test/app_root/config/environments/mysql.rb
111
+ create vendor/plugins/acts_as_most_popular/test/app_root/config/environments/in_memory.rb
112
+ create vendor/plugins/acts_as_most_popular/test/app_root/config/environments/postgresql.rb
113
+ create vendor/plugins/acts_as_most_popular/test/app_root/app/controllers
114
+ create vendor/plugins/acts_as_most_popular/test/app_root/app/controllers/application.rb
115
+ Loaded suite script/generate
116
+ Started
117
+
118
+ Finished in 0.000548 seconds.
119
+
120
+ 0 tests, 0 assertions, 0 failures, 0 errors
121
+
122
+ === plugin_test_model
123
+
124
+ Generates a model within your plugin's test application. This uses a similar
125
+ syntax to that of the Rails model generator.
126
+
127
+ Example:
128
+
129
+ $ ruby script/generate plugin_test_model acts_as_most_popular Person
130
+ create vendor/plugins/acts_as_most_popular/test/app_root/app/models/
131
+ create vendor/plugins/acts_as_most_popular/test/app_root/test/fixtures/
132
+ create vendor/plugins/acts_as_most_popular/test/app_root/app/models/person.rb
133
+ create vendor/plugins/acts_as_most_popular/test/app_root/test/fixtures/people.yml
134
+ create vendor/plugins/acts_as_most_popular/test/app_root/db/migrate
135
+ create vendor/plugins/acts_as_most_popular/test/app_root/db/migrate/001_create_people.rb
136
+ Loaded suite script/generate
137
+ Started
138
+
139
+ Finished in 0.000435 seconds.
140
+
141
+ 0 tests, 0 assertions, 0 failures, 0 errors
142
+
143
+ === plugin_test_controller
144
+
145
+ Generates a controller within your plugin's test application. This uses a similar
146
+ syntax to that of the Rails controller generator.
147
+
148
+ Example:
149
+
150
+ $ ruby script/generate plugin_test_controller acts_as_most_popular Person
151
+ create vendor/plugins/acts_as_most_popular/test/app_root/app/controllers/
152
+ create vendor/plugins/acts_as_most_popular/test/app_root/app/views/person
153
+ create vendor/plugins/acts_as_most_popular/test/app_root/app/controllers/person_controller.rb
154
+ Loaded suite script/generate
155
+ Started
156
+
157
+ Finished in 0.000432 seconds.
158
+
159
+ 0 tests, 0 assertions, 0 failures, 0 errors
160
+
161
+ === plugin_test_migration
162
+
163
+ Generates a migration within your plugin's test application. This uses a similar
164
+ syntax to that of the Rails migration generator.
165
+
166
+ Example:
167
+
168
+ $ ruby script/generate plugin_test_migration acts_as_most_popular CreatePeople
169
+ create vendor/plugins/acts_as_most_popular/test/app_root/db/migrate
170
+ create vendor/plugins/acts_as_most_popular/test/app_root/db/migrate/001_create_people.rb
171
+ Loaded suite script/generate
172
+ Started
173
+
174
+ Finished in 0.000443 seconds.
175
+
176
+ 0 tests, 0 assertions, 0 failures, 0 errors
177
+
178
+ == Dependencies
179
+
180
+ This plugin does not depend on any other plugins.
181
+
182
+ == Credits
183
+
184
+ Kudos to Mark Meves over at http://rationalexuberance.org/ for working on the
185
+ initial implementation of this plugin. His work has made testing our plugins so
186
+ much easier. Thanks Mark!
data/Rakefile ADDED
@@ -0,0 +1,79 @@
1
+ require 'rake/testtask'
2
+ require 'rake/rdoctask'
3
+ require 'rake/gempackagetask'
4
+ require 'rake/contrib/sshpublisher'
5
+
6
+ PKG_NAME = 'plugin_test_helper'
7
+ PKG_VERSION = '0.0.1'
8
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
9
+ RUBY_FORGE_PROJECT = 'pluginaweek'
10
+
11
+ desc 'Default: run unit tests.'
12
+ task :default => :test
13
+
14
+ desc 'Test the plugin_test_helper plugin.'
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << 'lib'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ t.verbose = true
19
+ end
20
+
21
+ desc 'Generate documentation for the plugin_test_helper plugin.'
22
+ Rake::RDocTask.new(:rdoc) do |rdoc|
23
+ rdoc.rdoc_dir = 'rdoc'
24
+ rdoc.title = 'PluginTestHelper'
25
+ rdoc.options << '--line-numbers' << '--inline-source'
26
+ rdoc.rdoc_files.include('README')
27
+ rdoc.rdoc_files.include('lib/**/*.rb')
28
+ end
29
+
30
+ spec = Gem::Specification.new do |s|
31
+ s.name = PKG_NAME
32
+ s.version = PKG_VERSION
33
+ s.platform = Gem::Platform::RUBY
34
+ s.summary = ''
35
+
36
+ s.files = FileList['{generators,lib}/**/*'].to_a + %w(CHANGELOG init.rb MIT-LICENSE Rakefile README)
37
+ s.require_path = 'lib'
38
+ s.autorequire = 'plugin_test_helper'
39
+ s.has_rdoc = true
40
+ s.test_files = Dir['test/**/*_test.rb']
41
+
42
+ s.author = 'Aaron Pfeifer, Neil Abraham'
43
+ s.email = 'info@pluginaweek.org'
44
+ s.homepage = 'http://www.pluginaweek.org'
45
+ end
46
+
47
+ Rake::GemPackageTask.new(spec) do |p|
48
+ p.gem_spec = spec
49
+ p.need_tar = true
50
+ p.need_zip = true
51
+ end
52
+
53
+ desc 'Publish the beta gem'
54
+ task :pgem => [:package] do
55
+ Rake::SshFilePublisher.new('pluginaweek@pluginaweek.org', '/home/pluginaweek/gems.pluginaweek.org/gems', 'pkg', "#{PKG_FILE_NAME}.gem").upload
56
+ end
57
+
58
+ desc 'Publish the API documentation'
59
+ task :pdoc => [:rdoc] do
60
+ Rake::SshDirPublisher.new('pluginaweek@pluginaweek.org', "/home/pluginaweek/api.pluginaweek.org/#{PKG_NAME}", 'rdoc').upload
61
+ end
62
+
63
+ desc 'Publish the API docs and gem'
64
+ task :publish => [:pdoc, :release]
65
+
66
+ desc 'Publish the release files to RubyForge.'
67
+ task :release => [:gem, :package] do
68
+ require 'rubyforge'
69
+
70
+ ruby_forge = RubyForge.new
71
+ ruby_forge.login
72
+
73
+ %w( gem tgz zip ).each do |ext|
74
+ file = "pkg/#{PKG_FILE_NAME}.#{ext}"
75
+ puts "Releasing #{File.basename(file)}..."
76
+
77
+ ruby_forge.add_release(RUBY_FORGE_PROJECT, PKG_NAME, PKG_VERSION, file)
78
+ end
79
+ end
@@ -0,0 +1,27 @@
1
+ # Generates the class, helper, and view for a controller in a plugin's test application
2
+ class PluginTestControllerGenerator < PluginAWeek::PluginTestHelper::Generator
3
+ def manifest
4
+ record do |m|
5
+ # Check for class naming collisions.
6
+ m.class_collisions class_path, "#{class_name}Controller", "#{class_name}Helper"
7
+
8
+ # Controller and views directories.
9
+ m.directory File.join(plugin_app_root, 'app/controllers', class_path)
10
+ m.directory File.join(plugin_app_root, 'app/views', class_path, file_name)
11
+
12
+ # Controller class.
13
+ m.template 'controller.rb',
14
+ File.join(plugin_app_root,
15
+ 'app/controllers',
16
+ class_path,
17
+ "#{file_name}_controller.rb")
18
+
19
+ # View template for each action.
20
+ actions.each do |action|
21
+ path = File.join(plugin_app_root, 'app/views', class_path, file_name, "#{action}.rhtml")
22
+ m.template 'view.rhtml', path,
23
+ :assigns => { :action => action, :path => path }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ class <%= class_name %>Controller < ApplicationController
2
+ <% if options[:scaffold] -%>
3
+ scaffold :<%= singular_name %>
4
+ <% end -%>
5
+ <% for action in actions -%>
6
+
7
+ def <%= action %>
8
+ end
9
+ <% end -%>
10
+ end
@@ -0,0 +1,2 @@
1
+ <h1><%= class_name %>#<%= action %></h1>
2
+ <p>Find me in <%= path %></p>
@@ -0,0 +1,14 @@
1
+ # Generates the test helper for a plugin
2
+ class PluginTestHelperGenerator < Rails::Generator::NamedBase
3
+ def manifest
4
+ record do |m|
5
+ plugin_test_root = "vendor/plugins/#{name}/test"
6
+ m.file 'test_helper.rb', "#{plugin_test_root}/test_helper.rb"
7
+ end
8
+ end
9
+
10
+ protected
11
+ def banner
12
+ "Usage: #{$0} plugin_test_helper your_plugin"
13
+ end
14
+ end
@@ -0,0 +1,14 @@
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 'plugin_test_helper'
6
+
7
+ # Load the Rails environment
8
+ require 'config/environment'
9
+
10
+ # Load the unit testing framework
11
+ require 'test/unit'
12
+
13
+ # Run the migrations (optional)
14
+ ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
@@ -0,0 +1,8 @@
1
+ # Generates migrations for a plugin's test application
2
+ class PluginTestMigrationGenerator < PluginAWeek::PluginTestHelper::Generator
3
+ def manifest
4
+ record do |m|
5
+ m.migration_template 'migration.rb', "#{plugin_app_root}/db/migrate"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ class <%= class_name.underscore.camelize %> < ActiveRecord::Migration
2
+ def self.up
3
+ end
4
+
5
+ def self.down
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ # Generates the class, fixtures, and migration for a model in a plugin's test application
2
+ class PluginTestModelGenerator < PluginAWeek::PluginTestHelper::Generator
3
+ default_options :skip_migration => false
4
+
5
+ def manifest
6
+ record do |m|
7
+ # Check for class naming collisions.
8
+ m.class_collisions class_path, class_name
9
+
10
+ # Model and fixture directories.
11
+ m.directory File.join(plugin_app_root, 'app/models', class_path)
12
+ m.directory File.join(plugin_app_root, 'test/fixtures', class_path)
13
+
14
+ # Model class and fixtures.
15
+ m.template 'model.rb', File.join(plugin_app_root, 'app/models', class_path, "#{file_name}.rb")
16
+ m.template 'fixtures.yml', File.join(plugin_app_root, 'test/fixtures', class_path, "#{table_name}.yml")
17
+
18
+ unless options[:skip_migration]
19
+ m.migration_template 'migration.rb', "#{plugin_app_root}/db/migrate", :assigns => {
20
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
21
+ }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
22
+ end
23
+ end
24
+ end
25
+
26
+ protected
27
+ def banner
28
+ "Usage: #{$0} generate your_plugin ModelName [field:type, field:type]"
29
+ end
30
+
31
+ def add_options!(opt)
32
+ opt.separator ''
33
+ opt.separator 'Options:'
34
+ opt.on("--skip-migration",
35
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
36
+ end
37
+ end
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ one:
3
+ id: 1
4
+ <% for attribute in attributes -%>
5
+ <%= attribute.name %>: <%= attribute.default %>
6
+ <% end -%>
7
+ two:
8
+ id: 2
9
+ <% for attribute in attributes -%>
10
+ <%= attribute.name %>: <%= attribute.default %>
11
+ <% end -%>
@@ -0,0 +1,13 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %> do |t|
4
+ <% for attribute in attributes -%>
5
+ t.column :<%= attribute.name %>, :<%= attribute.type %>
6
+ <% end -%>
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :<%= table_name %>
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ end
@@ -0,0 +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
+ 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
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,43 @@
1
+ unless defined?(RAILS_ROOT)
2
+ root_path = File.join(File.expand_path('.'), 'test/app_root')
3
+
4
+ unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
5
+ require 'pathname'
6
+ root_path = Pathname.new(root_path).cleanpath(true).to_s
7
+ end
8
+
9
+ RAILS_ROOT = root_path
10
+ end
11
+
12
+ unless defined?(Rails::Initializer)
13
+ if File.directory?("#{RAILS_ROOT}/vendor/rails")
14
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
15
+ else
16
+ require 'rubygems'
17
+
18
+ environment_without_comments = IO.readlines(File.dirname(__FILE__) + '/environment.rb').reject { |l| l =~ /^#/ }.join
19
+ environment_without_comments =~ /[^#]RAILS_GEM_VERSION = '([\d.]+)'/
20
+ rails_gem_version = $1
21
+
22
+ if version = defined?(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION : rails_gem_version
23
+ # Asking for 1.1.6 will give you 1.1.6.5206, if available -- makes it easier to use beta gems
24
+ rails_gem = Gem.cache.search('rails', "~>#{version}.0").sort_by { |g| g.version.version }.last
25
+
26
+ if rails_gem
27
+ gem "rails", "=#{rails_gem.version.version}"
28
+ require rails_gem.full_gem_path + '/lib/initializer'
29
+ else
30
+ STDERR.puts %(Cannot find gem for Rails ~>#{version}.0:
31
+ Install the missing gem with 'gem install -v=#{version} rails', or
32
+ change environment.rb to define RAILS_GEM_VERSION with your desired version.
33
+ )
34
+ exit 1
35
+ end
36
+ else
37
+ gem "rails"
38
+ require 'initializer'
39
+ end
40
+ end
41
+
42
+ Rails::Initializer.run(:set_load_path)
43
+ end
@@ -0,0 +1,22 @@
1
+ in_memory:
2
+ adapter: sqlite3
3
+ database: ":memory:"
4
+ verbosity: quiet
5
+ sqlite:
6
+ adapter: sqlite
7
+ dbfile: plugin_test.sqlite.db
8
+ sqlite3:
9
+ adapter: sqlite3
10
+ dbfile: plugin_test.sqlite3.db
11
+ postgresql:
12
+ adapter: postgresql
13
+ username: postgres
14
+ password: postgres
15
+ database: plugin_test
16
+ min_messages: ERROR
17
+ mysql:
18
+ adapter: mysql
19
+ host: localhost
20
+ username: root
21
+ password:
22
+ database: plugin_test
@@ -0,0 +1,11 @@
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
+ end
10
+
11
+ Dependencies.log_activity = true
@@ -0,0 +1,2 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ end
@@ -0,0 +1,4 @@
1
+ # Automatically load the plugin being tested as if it were being loaded in an
2
+ # actual application
3
+ init_path = "#{RAILS_ROOT}/../../init.rb"
4
+ silence_warnings { eval(IO.read(init_path), binding, init_path) } if File.exists?(init_path)
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'plugin_test_helper'
@@ -0,0 +1,61 @@
1
+ module PluginAWeek #:nodoc:
2
+ module PluginTestHelper #:nodoc:
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
@@ -0,0 +1,32 @@
1
+ module PluginAWeek #:nodoc:
2
+ module PluginTestHelper #:nodoc:
3
+ module Extensions #:nodoc:
4
+ # Overrides where the path of the application routes is located so that
5
+ # it defaults to this helper's implementation or can be overridden by the
6
+ # plugin using this helper
7
+ module Routing
8
+ def self.included(base)
9
+ base.class_eval do
10
+ alias_method :load_routes!, :load_routes_with_test_helper!
11
+ end
12
+ end
13
+
14
+ # Load routes from either the helper or the plugin
15
+ def load_routes_with_test_helper!
16
+ if defined?(RAILS_ROOT) && defined?(::ActionController::Routing::Routes) && self == ::ActionController::Routing::Routes
17
+ routes_path = File.join("#{RAILS_ROOT}/config/routes.rb")
18
+ routes_path = File.join("#{HELPER_RAILS_ROOT}/config/routes.rb") if !File.exists?(routes_path)
19
+
20
+ load File.join(routes_path)
21
+ else
22
+ add_route ":controller/:action/:id"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ ActionController::Routing::RouteSet.class_eval do
31
+ include PluginAWeek::PluginTestHelper::Extensions::Routing
32
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails_generator'
2
+
3
+ module PluginAWeek #:nodoc:
4
+ module PluginTestHelper #:nodoc:
5
+ class Generator < Rails::Generator::NamedBase
6
+ attr_accessor :plugin_name
7
+
8
+ def initialize(*runtime_args)
9
+ @plugin_name = runtime_args.first.shift if runtime_args.first.is_a?(Array)
10
+ super(*runtime_args)
11
+ end
12
+
13
+ private
14
+
15
+ def plugin_test_root
16
+ "vendor/plugins/#{plugin_name}/test"
17
+ end
18
+
19
+ def plugin_app_root
20
+ "#{plugin_test_root}/app_root"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ # Make sure our default RAILS_ROOT from the helper plugin is in the load path
2
+ HELPER_RAILS_ROOT = "#{File.dirname(__FILE__)}/../generators/plugin_test_structure/templates/app_root"
3
+ $:.unshift(HELPER_RAILS_ROOT)
4
+
5
+ # Set the default environment to sqlite3's in_memory database
6
+ ENV['RAILS_ENV'] ||= 'in_memory'
7
+
8
+ # Load the default framework libraries
9
+ require 'config/boot'
10
+ require 'active_support'
11
+ require 'action_controller'
12
+
13
+ # Load extensions for helping determine where certain environment files are
14
+ # located
15
+ require 'plugin_test_helper/generator'
16
+ require 'plugin_test_helper/extensions/initializer'
17
+ require 'plugin_test_helper/extensions/routing'
18
+
19
+ # Load the Rails environment and unit testing framework
20
+ require 'config/environment'
21
+ require 'test/unit'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: plugin_test_helper
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-05-31 00:00:00 -04:00
8
+ summary: ""
9
+ require_paths:
10
+ - lib
11
+ email: info@pluginaweek.org
12
+ homepage: http://www.pluginaweek.org
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: plugin_test_helper
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Aaron Pfeifer, Neil Abraham
31
+ files:
32
+ - generators/plugin_test_migration
33
+ - generators/plugin_test_model
34
+ - generators/plugin_test_helper
35
+ - generators/plugin_test_structure
36
+ - generators/plugin_test_controller
37
+ - generators/plugin_test_migration/plugin_test_migration_generator.rb
38
+ - generators/plugin_test_migration/templates
39
+ - generators/plugin_test_migration/templates/migration.rb
40
+ - generators/plugin_test_model/plugin_test_model_generator.rb
41
+ - generators/plugin_test_model/templates
42
+ - generators/plugin_test_model/templates/fixtures.yml
43
+ - generators/plugin_test_model/templates/model.rb
44
+ - generators/plugin_test_model/templates/migration.rb
45
+ - generators/plugin_test_helper/templates
46
+ - generators/plugin_test_helper/plugin_test_helper_generator.rb
47
+ - generators/plugin_test_helper/templates/test_helper.rb
48
+ - generators/plugin_test_structure/plugin_test_structure_generator.rb
49
+ - generators/plugin_test_structure/templates
50
+ - generators/plugin_test_structure/templates/app_root
51
+ - generators/plugin_test_structure/templates/app_root/vendor
52
+ - generators/plugin_test_structure/templates/app_root/config
53
+ - generators/plugin_test_structure/templates/app_root/app
54
+ - generators/plugin_test_structure/templates/app_root/lib
55
+ - generators/plugin_test_structure/templates/app_root/vendor/plugins
56
+ - generators/plugin_test_structure/templates/app_root/vendor/plugins/plugin_proxy
57
+ - generators/plugin_test_structure/templates/app_root/vendor/plugins/plugin_proxy/init.rb
58
+ - generators/plugin_test_structure/templates/app_root/config/environments
59
+ - generators/plugin_test_structure/templates/app_root/config/routes.rb
60
+ - generators/plugin_test_structure/templates/app_root/config/boot.rb
61
+ - generators/plugin_test_structure/templates/app_root/config/environment.rb
62
+ - generators/plugin_test_structure/templates/app_root/config/database.yml
63
+ - generators/plugin_test_structure/templates/app_root/config/environments/sqlite.rb
64
+ - generators/plugin_test_structure/templates/app_root/config/environments/sqlite3.rb
65
+ - generators/plugin_test_structure/templates/app_root/config/environments/mysql.rb
66
+ - generators/plugin_test_structure/templates/app_root/config/environments/in_memory.rb
67
+ - generators/plugin_test_structure/templates/app_root/config/environments/postgresql.rb
68
+ - generators/plugin_test_structure/templates/app_root/app/controllers
69
+ - generators/plugin_test_structure/templates/app_root/app/controllers/application.rb
70
+ - generators/plugin_test_controller/plugin_test_controller_generator.rb
71
+ - generators/plugin_test_controller/templates
72
+ - generators/plugin_test_controller/templates/view.rhtml
73
+ - generators/plugin_test_controller/templates/controller.rb
74
+ - lib/plugin_test_helper.rb
75
+ - lib/plugin_test_helper
76
+ - lib/plugin_test_helper/extensions
77
+ - lib/plugin_test_helper/generator.rb
78
+ - lib/plugin_test_helper/extensions/initializer.rb
79
+ - lib/plugin_test_helper/extensions/routing.rb
80
+ - CHANGELOG
81
+ - init.rb
82
+ - MIT-LICENSE
83
+ - Rakefile
84
+ - README
85
+ test_files: []
86
+
87
+ rdoc_options: []
88
+
89
+ extra_rdoc_files: []
90
+
91
+ executables: []
92
+
93
+ extensions: []
94
+
95
+ requirements: []
96
+
97
+ dependencies: []
98
+