plugin_test_helper 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/CHANGELOG +10 -0
  2. data/MIT-LICENSE +2 -2
  3. data/README +3 -7
  4. data/Rakefile +5 -5
  5. data/generators/plugin_test_console/plugin_test_console_generator.rb +2 -2
  6. data/generators/plugin_test_controller/plugin_test_controller_generator.rb +7 -12
  7. data/generators/plugin_test_controller/templates/controller.rb +1 -4
  8. data/generators/plugin_test_controller/templates/{view.rhtml → view.html.erb} +0 -0
  9. data/generators/plugin_test_helper/templates/test_helper.rb +1 -1
  10. data/generators/plugin_test_migration/templates/migration.rb +1 -1
  11. data/generators/plugin_test_model/templates/fixtures.yml +11 -3
  12. data/generators/plugin_test_model/templates/migration.rb +4 -1
  13. data/generators/plugin_test_structure/templates/app_root/config/boot.rb +101 -34
  14. data/generators/plugin_test_structure/templates/app_root/config/database.yml +1 -2
  15. data/generators/plugin_test_structure/templates/app_root/config/environment.rb +0 -3
  16. data/generators/plugin_test_structure/templates/app_root/config/routes.rb +2 -0
  17. data/lib/plugin_test_helper.rb +5 -21
  18. data/lib/plugin_test_helper/console_with_fixtures.rb +2 -2
  19. data/lib/plugin_test_helper/extensions/initializer.rb +36 -4
  20. data/lib/plugin_test_helper/extensions/routing.rb +19 -2
  21. data/lib/plugin_test_helper/generator.rb +0 -1
  22. data/lib/plugin_test_helper/plugin_locator.rb +10 -0
  23. data/test/app_roots/with_custom_config/config/environment.rb +0 -10
  24. data/test/app_roots/with_custom_config/vendor/plugins/acts_as_foo/lib/acts_as_foo.rb +1 -3
  25. data/test/app_roots/with_fixtures/db/migrate/001_create_people.rb +1 -1
  26. data/test/app_roots/with_migration/db/migrate/001_create_people.rb +1 -1
  27. data/test/fixtures/people.yml +0 -1
  28. data/test/functional/plugin_test_helper_test.rb +17 -32
  29. data/test/test_helper.rb +27 -0
  30. data/test/unit/plugin_locator_test.rb +19 -0
  31. metadata +112 -100
data/CHANGELOG CHANGED
@@ -1,5 +1,15 @@
1
1
  *SVN*
2
2
 
3
+ *0.1.3* (May 5th, 2008)
4
+
5
+ * Update documentation
6
+
7
+ * Update to be compatible with Rails 2.1
8
+
9
+ * Add PluginAWeek::PluginTestHelper::PluginLocator so that you don't have to explicitly define config.plugins if the test app has anything under vendor/plugins
10
+
11
+ * Add default routes
12
+
3
13
  *0.1.2* (October 15th, 2007)
4
14
 
5
15
  * Don't create vendor/plugins in the plugin_test_structure generator
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2007 Aaron Pfeifer & Neil Abraham
1
+ Copyright (c) 2006-2008 Aaron Pfeifer
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
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.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README CHANGED
@@ -5,10 +5,6 @@ environment that simulates its usage in a real application.
5
5
 
6
6
  == Resources
7
7
 
8
- Announcement
9
-
10
- * http://www.pluginaweek.org
11
-
12
8
  Wiki
13
9
 
14
10
  * http://wiki.pluginaweek.org/Plugin_test_helper
@@ -19,11 +15,11 @@ API
19
15
 
20
16
  Development
21
17
 
22
- * http://dev.pluginaweek.org/browser/trunk/plugins/test/plugin_test_helper
18
+ * http://dev.pluginaweek.org/browser/trunk/plugin_test_helper
23
19
 
24
20
  Source
25
21
 
26
- * http://svn.pluginaweek.org/trunk/plugins/test/plugin_test_helper
22
+ * http://svn.pluginaweek.org/trunk/plugin_test_helper
27
23
 
28
24
  == Description
29
25
 
@@ -191,7 +187,7 @@ Example:
191
187
 
192
188
  == Dependencies
193
189
 
194
- This plugin does not depend on the presence of any other plugins.
190
+ None.
195
191
 
196
192
  == References
197
193
 
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.1.2'
7
+ PKG_VERSION = '0.1.3'
8
8
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
9
9
  RUBY_FORGE_PROJECT = 'pluginaweek'
10
10
 
@@ -39,8 +39,8 @@ spec = Gem::Specification.new do |s|
39
39
  s.has_rdoc = true
40
40
  s.test_files = Dir['test/**/*_test.rb']
41
41
 
42
- s.author = 'Aaron Pfeifer, Neil Abraham'
43
- s.email = 'info@pluginaweek.org'
42
+ s.author = 'Aaron Pfeifer'
43
+ s.email = 'aaron@pluginaweek.org'
44
44
  s.homepage = 'http://www.pluginaweek.org'
45
45
  end
46
46
 
@@ -52,12 +52,12 @@ end
52
52
 
53
53
  desc 'Publish the beta gem'
54
54
  task :pgem => [:package] do
55
- Rake::SshFilePublisher.new('pluginaweek@pluginaweek.org', '/home/pluginaweek/gems.pluginaweek.org/gems', 'pkg', "#{PKG_FILE_NAME}.gem").upload
55
+ Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{PKG_FILE_NAME}.gem").upload
56
56
  end
57
57
 
58
58
  desc 'Publish the API documentation'
59
59
  task :pdoc => [:rdoc] do
60
- Rake::SshDirPublisher.new('pluginaweek@pluginaweek.org', "/home/pluginaweek/api.pluginaweek.org/#{PKG_NAME}", 'rdoc').upload
60
+ Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{PKG_NAME}", 'rdoc').upload
61
61
  end
62
62
 
63
63
  desc 'Publish the API docs and gem'
@@ -4,10 +4,10 @@ class PluginTestConsoleGenerator < Rails::Generator::NamedBase
4
4
  record do |m|
5
5
  plugin_root = "vendor/plugins/#{name}"
6
6
 
7
- # Script directory.
7
+ # Script directory
8
8
  m.directory File.join(plugin_root, 'script')
9
9
 
10
- # Console class.
10
+ # Console class
11
11
  m.file 'console', File.join(plugin_root, 'script/console')
12
12
  end
13
13
  end
@@ -2,25 +2,20 @@
2
2
  class PluginTestControllerGenerator < PluginAWeek::PluginTestHelper::Generator
3
3
  def manifest #:nodoc:
4
4
  record do |m|
5
- # Check for class naming collisions.
5
+ # Check for class naming collisions
6
6
  m.class_collisions class_path, "#{class_name}Controller", "#{class_name}Helper"
7
7
 
8
- # Controller and views directories.
8
+ # Controller and views directories
9
9
  m.directory File.join(plugin_app_root, 'app/controllers', class_path)
10
10
  m.directory File.join(plugin_app_root, 'app/views', class_path, file_name)
11
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")
12
+ # Controller class
13
+ m.template 'controller.rb', File.join(plugin_app_root, 'app/controllers', class_path, "#{file_name}_controller.rb")
18
14
 
19
- # View template for each action.
15
+ # View template for each action
20
16
  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 }
17
+ path = File.join(plugin_app_root, 'app/views', class_path, file_name, "#{action}.html.erb")
18
+ m.template 'view.html.erb', path, :assigns => {:action => action, :path => path}
24
19
  end
25
20
  end
26
21
  end
@@ -1,10 +1,7 @@
1
1
  class <%= class_name %>Controller < ApplicationController
2
- <% if options[:scaffold] -%>
3
- scaffold :<%= singular_name %>
4
- <% end -%>
5
2
  <% for action in actions -%>
6
-
7
3
  def <%= action %>
8
4
  end
5
+
9
6
  <% end -%>
10
7
  end
@@ -6,4 +6,4 @@ require 'rubygems'
6
6
  require 'plugin_test_helper'
7
7
 
8
8
  # Run the migrations (optional)
9
- ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
9
+ # ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
@@ -1,7 +1,7 @@
1
1
  class <%= class_name.underscore.camelize %> < ActiveRecord::Migration
2
2
  def self.up
3
3
  end
4
-
4
+
5
5
  def self.down
6
6
  end
7
7
  end
@@ -1,11 +1,19 @@
1
1
  # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ <% unless attributes.empty? -%>
2
4
  one:
3
- id: 1
4
5
  <% for attribute in attributes -%>
5
6
  <%= attribute.name %>: <%= attribute.default %>
6
7
  <% end -%>
8
+
7
9
  two:
8
- id: 2
9
10
  <% for attribute in attributes -%>
10
11
  <%= attribute.name %>: <%= attribute.default %>
11
- <% end -%>
12
+ <% end -%>
13
+ <% else -%>
14
+ # one:
15
+ # column: value
16
+ #
17
+ # two:
18
+ # column: value
19
+ <% end -%>
@@ -2,7 +2,10 @@ class <%= migration_name %> < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :<%= table_name %> do |t|
4
4
  <% for attribute in attributes -%>
5
- t.column :<%= attribute.name %>, :<%= attribute.type %>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <% end -%>
7
+ <% unless options[:skip_timestamps] %>
8
+ t.timestamps
6
9
  <% end -%>
7
10
  end
8
11
  end
@@ -1,47 +1,114 @@
1
- unless defined?(RAILS_ROOT)
2
- root_path = File.join(File.expand_path('.'), 'test/app_root')
1
+ # Allow customization of the rails framework path
2
+ RAILS_FRAMEWORK_ROOT = (ENV['RAILS_FRAMEWORK_ROOT'] || "#{RAILS_ROOT}/vendor/rails") unless defined?(RAILS_FRAMEWORK_ROOT)
3
3
 
4
- unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
5
- require 'pathname'
6
- root_path = Pathname.new(root_path).cleanpath(true).to_s
7
- end
4
+ # Don't change this file!
5
+ # Configure your app in config/environment.rb and config/environments/*.rb
8
6
 
9
- RAILS_ROOT = root_path
10
- end
7
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
11
8
 
12
- unless defined?(RAILS_FRAMEWORK_ROOT)
13
- RAILS_FRAMEWORK_ROOT = ENV['RAILS_FRAMEWORK_ROOT'] || "#{RAILS_ROOT}/vendor/rails"
14
- end
9
+ module Rails
10
+ class << self
11
+ def boot!
12
+ unless booted?
13
+ preinitialize
14
+ pick_boot.run
15
+ end
16
+ end
15
17
 
16
- unless defined?(Rails::Initializer)
17
- if File.directory?(RAILS_FRAMEWORK_ROOT)
18
- require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer"
19
- else
20
- require 'rubygems'
18
+ def booted?
19
+ defined? Rails::Initializer
20
+ end
21
21
 
22
- environment_without_comments = IO.readlines(File.dirname(__FILE__) + '/environment.rb').reject { |l| l =~ /^#/ }.join
23
- environment_without_comments =~ /[^#]RAILS_GEM_VERSION = '([\d.]+)'/
24
- rails_gem_version = $1
22
+ def pick_boot
23
+ (vendor_rails? ? VendorBoot : GemBoot).new
24
+ end
25
25
 
26
- if version = defined?(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION : rails_gem_version
27
- # Asking for 1.1.6 will give you 1.1.6.5206, if available -- makes it easier to use beta gems
28
- rails_gem = Gem.cache.search('rails', "~>#{version}.0").sort_by { |g| g.version.version }.last
26
+ def vendor_rails?
27
+ File.exist?(RAILS_FRAMEWORK_ROOT)
28
+ end
29
+
30
+ def preinitialize
31
+ load(preinitializer_path) if File.exist?(preinitializer_path)
32
+ end
33
+
34
+ def preinitializer_path
35
+ "#{RAILS_ROOT}/config/preinitializer.rb"
36
+ end
37
+ end
38
+
39
+ class Boot
40
+ def run
41
+ load_initializer
42
+ Rails::Initializer.run(:set_load_path)
43
+ end
44
+ end
45
+
46
+ class VendorBoot < Boot
47
+ def load_initializer
48
+ require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer"
49
+ Rails::Initializer.run(:install_gem_spec_stubs)
50
+ end
51
+ end
29
52
 
30
- if rails_gem
31
- gem "rails", "=#{rails_gem.version.version}"
32
- require rails_gem.full_gem_path + '/lib/initializer'
53
+ class GemBoot < Boot
54
+ def load_initializer
55
+ self.class.load_rubygems
56
+ load_rails_gem
57
+ require 'initializer'
58
+ end
59
+
60
+ def load_rails_gem
61
+ if version = self.class.gem_version
62
+ gem 'rails', version
33
63
  else
34
- STDERR.puts %(Cannot find gem for Rails ~>#{version}.0:
35
- Install the missing gem with 'gem install -v=#{version} rails', or
36
- change environment.rb to define RAILS_GEM_VERSION with your desired version.
37
- )
64
+ gem 'rails'
65
+ end
66
+ rescue Gem::LoadError => load_error
67
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
68
+ exit 1
69
+ end
70
+
71
+ class << self
72
+ def rubygems_version
73
+ Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
74
+ end
75
+
76
+ def gem_version
77
+ if defined? RAILS_GEM_VERSION
78
+ RAILS_GEM_VERSION
79
+ elsif ENV.include?('RAILS_GEM_VERSION')
80
+ ENV['RAILS_GEM_VERSION']
81
+ else
82
+ parse_gem_version(read_environment_rb)
83
+ end
84
+ end
85
+
86
+ def load_rubygems
87
+ require 'rubygems'
88
+
89
+ unless rubygems_version >= '0.9.4'
90
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
91
+ exit 1
92
+ end
93
+
94
+ rescue LoadError
95
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
38
96
  exit 1
39
97
  end
40
- else
41
- gem "rails"
42
- require 'initializer'
98
+
99
+ def parse_gem_version(text)
100
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
101
+ end
102
+
103
+ private
104
+ def read_environment_rb
105
+ environment_rb = "#{RAILS_ROOT}/config/environment.rb"
106
+ environment_rb = "#{HELPER_RAILS_ROOT}/config/environment.rb" unless File.exists?(environment_rb)
107
+ File.read(environment_rb)
108
+ end
43
109
  end
44
110
  end
45
-
46
- Rails::Initializer.run(:set_load_path)
47
111
  end
112
+
113
+ # All that for this:
114
+ Rails.boot!
@@ -13,10 +13,9 @@ postgresql:
13
13
  username: postgres
14
14
  password: postgres
15
15
  database: plugin_test
16
- min_messages: ERROR
17
16
  mysql:
18
17
  adapter: mysql
19
18
  host: localhost
20
19
  username: root
21
20
  password:
22
- database: plugin_test
21
+ database: plugin_test
@@ -1,9 +1,6 @@
1
1
  require 'config/boot'
2
2
 
3
3
  Rails::Initializer.run do |config|
4
- config.plugin_paths << '..'
5
- config.plugins = [File.basename(File.expand_path('.'))]
6
4
  config.cache_classes = false
7
- config.frameworks -= [:action_web_service]
8
5
  config.whiny_nils = true
9
6
  end
@@ -1,2 +1,4 @@
1
1
  ActionController::Routing::Routes.draw do |map|
2
+ map.connect ':controller/:action/:id'
3
+ map.connect ':controller/:action/:id.:format'
2
4
  end
@@ -1,42 +1,26 @@
1
1
  # Make sure our default RAILS_ROOT from the helper plugin is in the load path
2
- unless defined?(HELPER_RAILS_ROOT)
3
- HELPER_RAILS_ROOT = "#{File.dirname(__FILE__)}/../generators/plugin_test_structure/templates/app_root"
4
- end
2
+ HELPER_RAILS_ROOT = "#{File.dirname(__FILE__)}/../generators/plugin_test_structure/templates/app_root" unless defined?(HELPER_RAILS_ROOT)
5
3
  $:.unshift(HELPER_RAILS_ROOT)
6
4
 
7
5
  # Determine the plugin's root test directory and add it to the load path
8
- unless defined?(RAILS_ROOT)
9
- root_path = File.join(File.expand_path('.'), 'test/app_root')
10
-
11
- unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
12
- require 'pathname'
13
- root_path = Pathname.new(root_path).cleanpath(true).to_s
14
- end
15
-
16
- RAILS_ROOT = root_path
17
- end
6
+ RAILS_ROOT = (File.directory?('./test/app_root') ? './test/app_root' : HELPER_RAILS_ROOT) unless defined?(RAILS_ROOT)
18
7
  $:.unshift(RAILS_ROOT)
19
8
 
20
9
  # Set the default environment to sqlite3's in_memory database
21
10
  ENV['RAILS_ENV'] ||= 'in_memory'
22
11
 
23
- # Load the default framework libraries
12
+ # First boost the Rails framework
24
13
  require 'config/boot'
25
- require 'active_support'
26
- require 'action_controller'
27
14
 
28
- # Load extensions for helping determine where certain environment files are
29
- # located
30
- require 'plugin_test_helper/generator'
15
+ # Extend it so that we can hook into the initialization process
31
16
  require 'plugin_test_helper/extensions/initializer'
32
- require 'plugin_test_helper/extensions/routing'
33
17
 
34
18
  # Load the Rails environment and testing framework
35
19
  require_or_load 'config/environment'
36
20
  require_or_load 'test_help'
37
21
 
38
22
  # Undo changes to RAILS_ENV
39
- silence_warnings { RAILS_ENV = ENV['RAILS_ENV'] }
23
+ silence_warnings {RAILS_ENV = ENV['RAILS_ENV']}
40
24
 
41
25
  # Set default fixture loading properties
42
26
  class Test::Unit::TestCase #:nodoc:
@@ -1,3 +1,3 @@
1
- (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
2
- Fixtures.create_fixtures(File.join(RAILS_ROOT, 'test/fixtures'), File.basename(fixture_file, '.*'))
1
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, '../fixtures/*.{yml,csv}'))).each do |fixture_file|
2
+ Fixtures.create_fixtures(File.join(RAILS_ROOT, '../fixtures'), File.basename(fixture_file, '.*'))
3
3
  end
@@ -1,6 +1,27 @@
1
+ require 'active_support'
2
+ require 'plugin_test_helper/plugin_locator'
3
+
1
4
  module PluginAWeek #:nodoc:
2
5
  module PluginTestHelper
3
6
  module Extensions #:nodoc:
7
+ # Adds in hooks for extending other parts of the Rails framework *after*
8
+ # Rails has loaded those frameworks
9
+ module Initializer
10
+ def self.included(base)
11
+ base.class_eval do
12
+ alias_method_chain :require_frameworks, :test_helper
13
+ end
14
+ end
15
+
16
+ # Load the needed frameworks and then our extensions to them
17
+ def require_frameworks_with_test_helper
18
+ require_frameworks_without_test_helper
19
+
20
+ require 'plugin_test_helper/generator'
21
+ require 'plugin_test_helper/extensions/routing'
22
+ end
23
+ end
24
+
4
25
  # Overrides some of the default values in the Rails configuration so that
5
26
  # files can be reused from this test helper or overridden by the plugin
6
27
  # using the helper
@@ -11,6 +32,7 @@ module PluginAWeek #:nodoc:
11
32
  alias_method_chain :default_load_paths, :test_helper
12
33
  alias_method_chain :default_database_configuration_file, :test_helper
13
34
  alias_method_chain :default_controller_paths, :test_helper
35
+ alias_method_chain :default_plugin_locators, :test_helper
14
36
  alias_method_chain :default_plugin_paths, :test_helper
15
37
  end
16
38
  end
@@ -31,31 +53,41 @@ module PluginAWeek #:nodoc:
31
53
  config
32
54
  lib
33
55
  vendor
34
- ).map { |dir| "#{HELPER_RAILS_ROOT}/#{dir}" }
56
+ ).map {|dir| "#{HELPER_RAILS_ROOT}/#{dir}"}
35
57
  end
36
58
 
37
59
  # Load the database configuration from the plugin or the helper
38
60
  def default_database_configuration_file_with_test_helper
39
61
  database_file = default_database_configuration_file_without_test_helper
40
- File.exists?(database_file) ? database_file : File.join(HELPER_RAILS_ROOT, 'config', 'database.yml')
62
+ File.exists?(database_file) ? database_file : File.join(HELPER_RAILS_ROOT, 'config/database.yml')
41
63
  end
42
64
 
43
65
  # Add the helper's controllers path
44
66
  def default_controller_paths_with_test_helper
45
67
  paths = default_controller_paths_without_test_helper
46
- paths << File.join(HELPER_RAILS_ROOT, 'app', 'controllers')
68
+ paths << File.join(HELPER_RAILS_ROOT, 'app/controllers')
69
+ end
70
+
71
+ # Adds a custom plugin locator for loading the plugin being tested
72
+ def default_plugin_locators_with_test_helper
73
+ locators = default_plugin_locators_without_test_helper
74
+ locators.unshift(PluginAWeek::PluginTestHelper::PluginLocator)
47
75
  end
48
76
 
49
77
  # Add the helper's vendor/plugins path
50
78
  def default_plugin_paths_with_test_helper
51
79
  paths = default_plugin_paths_without_test_helper
52
- paths << "#{HELPER_RAILS_ROOT}/vendor/plugins"
80
+ paths << File.join(HELPER_RAILS_ROOT, '/vendor/plugins')
53
81
  end
54
82
  end
55
83
  end
56
84
  end
57
85
  end
58
86
 
87
+ Rails::Initializer.class_eval do
88
+ include PluginAWeek::PluginTestHelper::Extensions::Initializer
89
+ end
90
+
59
91
  Rails::Configuration.class_eval do
60
92
  include PluginAWeek::PluginTestHelper::Extensions::Configuration
61
93
  end
@@ -7,17 +7,34 @@ module PluginAWeek #:nodoc:
7
7
  module Routing
8
8
  def self.included(base)
9
9
  base.class_eval do
10
- alias_method :load_routes!, :load_routes_with_test_helper!
10
+ alias_method_chain :reload, :test_helper
11
+ alias_method_chain :load_routes!, :test_helper
11
12
  end
12
13
  end
13
14
 
15
+ # Load routes from either the helper or the plugin
16
+ def reload_with_test_helper
17
+ if @routes_last_modified && defined?(RAILS_ROOT)
18
+ routes_path = File.join("#{RAILS_ROOT}/config/routes.rb")
19
+ routes_path = File.join("#{HELPER_RAILS_ROOT}/config/routes.rb") unless File.exists?(routes_path)
20
+
21
+ mtime = File.stat(routes_path).mtime
22
+ # if it hasn't been changed, then just return
23
+ return if mtime == @routes_last_modified
24
+ # if it has changed then record the new time and fall to the load! below
25
+ @routes_last_modified = mtime
26
+ end
27
+ load!
28
+ end
29
+
14
30
  # Load routes from either the helper or the plugin
15
31
  def load_routes_with_test_helper!
16
32
  if defined?(RAILS_ROOT) && defined?(::ActionController::Routing::Routes) && self == ::ActionController::Routing::Routes
17
33
  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)
34
+ routes_path = File.join("#{HELPER_RAILS_ROOT}/config/routes.rb") unless File.exists?(routes_path)
19
35
 
20
36
  load File.join(routes_path)
37
+ @routes_last_modified = File.stat(routes_path).mtime
21
38
  else
22
39
  add_route ":controller/:action/:id"
23
40
  end
@@ -12,7 +12,6 @@ module PluginAWeek #:nodoc:
12
12
  end
13
13
 
14
14
  private
15
-
16
15
  def plugin_test_root
17
16
  "vendor/plugins/#{plugin_name}/test"
18
17
  end
@@ -0,0 +1,10 @@
1
+ module PluginAWeek #:nodoc:
2
+ module PluginTestHelper
3
+ # Assists in the initialization process by locating the plugin being tested
4
+ class PluginLocator < Rails::Plugin::Locator
5
+ def plugins
6
+ [Rails::Plugin.new(File.expand_path('.'))]
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,16 +1,6 @@
1
1
  require 'config/boot'
2
2
 
3
3
  Rails::Initializer.run do |config|
4
- config.log_level = :debug
5
4
  config.cache_classes = false
6
5
  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
6
  end
15
-
16
- Dependencies.log_activity = true
@@ -1,6 +1,4 @@
1
1
  module PluginAWeek
2
- module Acts
3
- module Foo
4
- end
2
+ module ActsAsFoo
5
3
  end
6
4
  end
@@ -1,7 +1,7 @@
1
1
  class CreatePeople < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :people do |t|
4
- t.column :name, :string
4
+ t.string :name
5
5
  end
6
6
  end
7
7
 
@@ -1,7 +1,7 @@
1
1
  class CreatePeople < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :people do |t|
4
- t.column :name, :string
4
+ t.string :name
5
5
  end
6
6
  end
7
7
 
@@ -1,3 +1,2 @@
1
1
  bob:
2
- id: 1
3
2
  name: Bob
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
2
  require 'fileutils'
3
3
 
4
4
  class PluginTestHelperTest < Test::Unit::TestCase
@@ -12,84 +12,69 @@ class PluginTestHelperTest < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_should_load_with_empty_app_root
15
- initialize_app('empty')
15
+ setup_app('empty')
16
16
  end
17
17
 
18
18
  def test_should_load_with_custom_application_controller
19
- initialize_app('with_custom_application_controller')
19
+ setup_app('with_custom_application_controller')
20
20
 
21
21
  assert ApplicationController.respond_to?(:custom?)
22
22
  end
23
23
 
24
24
  def test_should_load_with_custom_config
25
- initialize_app('with_custom_config')
25
+ setup_app('with_custom_config')
26
26
 
27
- assert_not_nil PluginAWeek::Acts::Foo
27
+ assert_not_nil PluginAWeek::ActsAsFoo
28
28
  end
29
29
 
30
30
  def test_should_load_with_controller
31
- initialize_app('with_controller')
31
+ setup_app('with_controller')
32
32
 
33
33
  assert_not_nil PeopleController
34
34
  end
35
35
 
36
36
  def test_should_load_with_model
37
- initialize_app('with_model')
37
+ setup_app('with_model')
38
38
 
39
39
  assert_not_nil Person
40
40
  end
41
41
 
42
42
  def test_should_load_with_helper
43
- initialize_app('with_helper')
43
+ setup_app('with_helper')
44
44
 
45
45
  assert_not_nil PeopleHelper
46
46
  end
47
47
 
48
48
  def test_should_load_with_migration
49
- initialize_app('with_migration')
49
+ setup_app('with_migration')
50
50
 
51
51
  ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
52
52
  assert Person.table_exists?
53
53
  end
54
54
 
55
55
  def test_should_load_with_fixtures
56
- initialize_app('with_fixtures')
56
+ setup_app('with_fixtures')
57
57
 
58
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, '.*'))
59
+
60
+ fixtures_path = "#{File.dirname(__FILE__)}/../fixtures"
61
+ Dir.glob("#{fixtures_path}/*.yml").each do |fixture_file|
62
+ Fixtures.create_fixtures(fixtures_path, File.basename(fixture_file, '.*'))
61
63
  end
62
64
 
63
65
  assert Person.count > 0
64
66
  end
65
67
 
66
68
  def test_should_load_with_routes
67
- initialize_app('with_routes')
69
+ setup_app('with_routes')
68
70
 
69
71
  assert ActionController::Routing::Routes.routes.length == 0
70
72
  end
71
73
 
72
74
  def teardown
73
- # Clear dependencies
74
- ActiveRecord::Base.reset_subclasses
75
- Dependencies.clear
76
- ActiveRecord::Base.clear_reloadable_connections!
75
+ teardown_app
77
76
 
78
77
  $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
78
+ FileUtils.rm_r(Dir.glob('test/app_root/*'))
94
79
  end
95
80
  end
data/test/test_helper.rb CHANGED
@@ -1,3 +1,30 @@
1
1
  require 'test/unit'
2
+ require 'fileutils'
2
3
 
3
4
  $:.unshift("#{File.dirname(__FILE__)}/../lib")
5
+
6
+ FileUtils.rmtree('test/app_root')
7
+ FileUtils.mkdir('test/app_root')
8
+
9
+ class Test::Unit::TestCase
10
+ private
11
+ def assert_valid_environment
12
+ assert_not_nil ApplicationController
13
+ assert ActiveRecord::Base.connection.active?
14
+ end
15
+
16
+ def setup_app(name)
17
+ FileUtils.cp_r(Dir.glob("test/app_roots/#{name}/*"), 'test/app_root')
18
+
19
+ load 'plugin_test_helper.rb'
20
+ assert_valid_environment
21
+ end
22
+
23
+ def teardown_app
24
+ # Clear dependencies
25
+ self.class.use_transactional_fixtures = false
26
+ ActiveRecord::Base.reset_subclasses
27
+ Dependencies.clear
28
+ ActiveRecord::Base.clear_reloadable_connections!
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class PluginLocatorTest < Test::Unit::TestCase
4
+ def setup
5
+ @original_load_path = $LOAD_PATH
6
+ setup_app('empty')
7
+ end
8
+
9
+ def test_should_locate_plugin_being_tested
10
+ locator = PluginAWeek::PluginTestHelper::PluginLocator.new(nil)
11
+ assert_equal ['plugin_test_helper'], locator.plugins.map(&:name)
12
+ end
13
+
14
+ def teardown
15
+ teardown_app
16
+ $LOAD_PATH.replace(@original_load_path)
17
+ FileUtils.rm_r(Dir.glob('test/app_root/*'))
18
+ end
19
+ end
metadata CHANGED
@@ -1,149 +1,161 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: plugin_test_helper
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.2
7
- date: 2007-10-15 00:00:00 -04:00
8
- summary: Simplifies plugin testing by creating an isolated Rails environment that simulates its usage in a real application.
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:
4
+ version: 0.1.3
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
- - Aaron Pfeifer, Neil Abraham
7
+ - Aaron Pfeifer
8
+ autorequire: plugin_test_helper
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-05 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: aaron@pluginaweek.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
31
24
  files:
32
25
  - generators/plugin_test_migration
33
- - generators/plugin_test_console
34
- - generators/plugin_test_helper
35
- - generators/plugin_test_model
36
- - generators/plugin_test_controller
37
- - generators/plugin_test_structure
38
26
  - generators/plugin_test_migration/templates
39
- - generators/plugin_test_migration/plugin_test_migration_generator.rb
40
27
  - 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
44
- - generators/plugin_test_helper/plugin_test_helper_generator.rb
45
- - generators/plugin_test_helper/templates
46
- - generators/plugin_test_helper/templates/test_helper.rb
47
- - generators/plugin_test_model/templates
48
- - generators/plugin_test_model/plugin_test_model_generator.rb
49
- - generators/plugin_test_model/templates/migration.rb
50
- - generators/plugin_test_model/templates/model.rb
51
- - generators/plugin_test_model/templates/fixtures.yml
52
- - generators/plugin_test_controller/templates
53
- - generators/plugin_test_controller/plugin_test_controller_generator.rb
54
- - generators/plugin_test_controller/templates/controller.rb
55
- - generators/plugin_test_controller/templates/view.rhtml
28
+ - generators/plugin_test_migration/plugin_test_migration_generator.rb
29
+ - generators/plugin_test_structure
56
30
  - generators/plugin_test_structure/templates
57
- - generators/plugin_test_structure/plugin_test_structure_generator.rb
58
31
  - generators/plugin_test_structure/templates/app_root
59
- - generators/plugin_test_structure/templates/app_root/lib
60
32
  - generators/plugin_test_structure/templates/app_root/config
61
- - generators/plugin_test_structure/templates/app_root/app
62
33
  - generators/plugin_test_structure/templates/app_root/config/routes.rb
63
- - generators/plugin_test_structure/templates/app_root/config/environments
64
- - generators/plugin_test_structure/templates/app_root/config/boot.rb
65
- - generators/plugin_test_structure/templates/app_root/config/database.yml
66
34
  - generators/plugin_test_structure/templates/app_root/config/environment.rb
35
+ - generators/plugin_test_structure/templates/app_root/config/boot.rb
36
+ - generators/plugin_test_structure/templates/app_root/config/environments
67
37
  - generators/plugin_test_structure/templates/app_root/config/environments/sqlite.rb
68
- - generators/plugin_test_structure/templates/app_root/config/environments/mysql.rb
69
38
  - generators/plugin_test_structure/templates/app_root/config/environments/sqlite3.rb
70
39
  - generators/plugin_test_structure/templates/app_root/config/environments/in_memory.rb
40
+ - generators/plugin_test_structure/templates/app_root/config/environments/mysql.rb
71
41
  - generators/plugin_test_structure/templates/app_root/config/environments/postgresql.rb
42
+ - generators/plugin_test_structure/templates/app_root/config/database.yml
43
+ - generators/plugin_test_structure/templates/app_root/app
72
44
  - generators/plugin_test_structure/templates/app_root/app/controllers
73
45
  - generators/plugin_test_structure/templates/app_root/app/controllers/application.rb
74
- - lib/plugin_test_helper
46
+ - generators/plugin_test_structure/templates/app_root/lib
47
+ - generators/plugin_test_structure/plugin_test_structure_generator.rb
48
+ - generators/plugin_test_controller
49
+ - generators/plugin_test_controller/templates
50
+ - generators/plugin_test_controller/templates/view.html.erb
51
+ - generators/plugin_test_controller/templates/controller.rb
52
+ - generators/plugin_test_controller/plugin_test_controller_generator.rb
53
+ - generators/plugin_test_model
54
+ - generators/plugin_test_model/templates
55
+ - generators/plugin_test_model/templates/model.rb
56
+ - generators/plugin_test_model/templates/fixtures.yml
57
+ - generators/plugin_test_model/templates/migration.rb
58
+ - generators/plugin_test_model/plugin_test_model_generator.rb
59
+ - generators/plugin_test_console
60
+ - generators/plugin_test_console/templates
61
+ - generators/plugin_test_console/templates/console
62
+ - generators/plugin_test_console/plugin_test_console_generator.rb
63
+ - generators/plugin_test_helper
64
+ - generators/plugin_test_helper/templates
65
+ - generators/plugin_test_helper/templates/test_helper.rb
66
+ - generators/plugin_test_helper/plugin_test_helper_generator.rb
75
67
  - lib/plugin_test_helper.rb
68
+ - lib/plugin_test_helper
69
+ - lib/plugin_test_helper/plugin_locator.rb
70
+ - lib/plugin_test_helper/generator.rb
76
71
  - lib/plugin_test_helper/console_with_fixtures.rb
77
72
  - lib/plugin_test_helper/extensions
78
- - lib/plugin_test_helper/generator.rb
79
- - lib/plugin_test_helper/extensions/routing.rb
80
73
  - lib/plugin_test_helper/extensions/initializer.rb
81
- - test/test_helper.rb
82
- - test/app_roots
74
+ - lib/plugin_test_helper/extensions/routing.rb
83
75
  - test/fixtures
76
+ - test/fixtures/people.yml
77
+ - test/app_root
84
78
  - test/functional
85
- - test/app_roots/with_fixtures
86
- - test/app_roots/with_helper
87
- - test/app_roots/with_model
88
- - test/app_roots/with_controller
89
- - test/app_roots/with_custom_application_controller
79
+ - test/functional/plugin_test_helper_test.rb
80
+ - test/test_helper.rb
81
+ - test/app_roots
90
82
  - test/app_roots/empty
83
+ - test/app_roots/empty/empty
91
84
  - test/app_roots/with_migration
92
- - test/app_roots/with_routes
85
+ - test/app_roots/with_migration/db
86
+ - test/app_roots/with_migration/db/migrate
87
+ - test/app_roots/with_migration/db/migrate/001_create_people.rb
88
+ - test/app_roots/with_migration/app
89
+ - test/app_roots/with_migration/app/models
90
+ - test/app_roots/with_migration/app/models/person.rb
91
+ - test/app_roots/with_custom_application_controller
92
+ - test/app_roots/with_custom_application_controller/app
93
+ - test/app_roots/with_custom_application_controller/app/controllers
94
+ - test/app_roots/with_custom_application_controller/app/controllers/application.rb
93
95
  - test/app_roots/with_custom_config
94
- - test/app_roots/with_fixtures/app
95
- - test/app_roots/with_fixtures/db
96
- - test/app_roots/with_fixtures/app/models
97
- - test/app_roots/with_fixtures/app/models/person.rb
98
- - test/app_roots/with_fixtures/db/migrate
99
- - test/app_roots/with_fixtures/db/migrate/001_create_people.rb
96
+ - test/app_roots/with_custom_config/vendor
97
+ - test/app_roots/with_custom_config/vendor/plugins
98
+ - test/app_roots/with_custom_config/vendor/plugins/acts_as_foo
99
+ - test/app_roots/with_custom_config/vendor/plugins/acts_as_foo/init.rb
100
+ - test/app_roots/with_custom_config/vendor/plugins/acts_as_foo/lib
101
+ - test/app_roots/with_custom_config/vendor/plugins/acts_as_foo/lib/acts_as_foo.rb
102
+ - test/app_roots/with_custom_config/config
103
+ - test/app_roots/with_custom_config/config/environment.rb
104
+ - test/app_roots/with_helper
100
105
  - test/app_roots/with_helper/app
101
106
  - test/app_roots/with_helper/app/helpers
102
107
  - test/app_roots/with_helper/app/helpers/people_helper.rb
108
+ - test/app_roots/with_model
103
109
  - test/app_roots/with_model/app
104
110
  - test/app_roots/with_model/app/models
105
111
  - test/app_roots/with_model/app/models/person.rb
112
+ - test/app_roots/with_controller
106
113
  - test/app_roots/with_controller/app
107
114
  - test/app_roots/with_controller/app/controllers
108
115
  - test/app_roots/with_controller/app/controllers/people_controller.rb
109
- - test/app_roots/with_custom_application_controller/app
110
- - test/app_roots/with_custom_application_controller/app/controllers
111
- - test/app_roots/with_custom_application_controller/app/controllers/application.rb
112
- - test/app_roots/empty/empty
113
- - test/app_roots/with_migration/app
114
- - test/app_roots/with_migration/db
115
- - test/app_roots/with_migration/app/models
116
- - test/app_roots/with_migration/app/models/person.rb
117
- - test/app_roots/with_migration/db/migrate
118
- - test/app_roots/with_migration/db/migrate/001_create_people.rb
116
+ - test/app_roots/with_routes
119
117
  - test/app_roots/with_routes/config
120
118
  - test/app_roots/with_routes/config/routes.rb
121
- - test/app_roots/with_custom_config/vendor
122
- - test/app_roots/with_custom_config/config
123
- - test/app_roots/with_custom_config/vendor/plugins
124
- - test/app_roots/with_custom_config/vendor/plugins/acts_as_foo
125
- - test/app_roots/with_custom_config/vendor/plugins/acts_as_foo/lib
126
- - test/app_roots/with_custom_config/vendor/plugins/acts_as_foo/init.rb
127
- - test/app_roots/with_custom_config/vendor/plugins/acts_as_foo/lib/acts_as_foo.rb
128
- - test/app_roots/with_custom_config/config/environment.rb
129
- - test/fixtures/people.yml
130
- - test/functional/plugin_test_helper_test.rb
119
+ - test/app_roots/with_fixtures
120
+ - test/app_roots/with_fixtures/db
121
+ - test/app_roots/with_fixtures/db/migrate
122
+ - test/app_roots/with_fixtures/db/migrate/001_create_people.rb
123
+ - test/app_roots/with_fixtures/app
124
+ - test/app_roots/with_fixtures/app/models
125
+ - test/app_roots/with_fixtures/app/models/person.rb
126
+ - test/unit
127
+ - test/unit/plugin_locator_test.rb
131
128
  - CHANGELOG
132
129
  - init.rb
133
130
  - MIT-LICENSE
134
131
  - Rakefile
135
132
  - README
136
- test_files:
137
- - test/functional/plugin_test_helper_test.rb
133
+ has_rdoc: true
134
+ homepage: http://www.pluginaweek.org
135
+ post_install_message:
138
136
  rdoc_options: []
139
137
 
140
- extra_rdoc_files: []
141
-
142
- executables: []
143
-
144
- extensions: []
145
-
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: "0"
145
+ version:
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: "0"
151
+ version:
146
152
  requirements: []
147
153
 
148
- dependencies: []
149
-
154
+ rubyforge_project:
155
+ rubygems_version: 1.1.0
156
+ signing_key:
157
+ specification_version: 2
158
+ summary: Simplifies plugin testing by creating an isolated Rails environment that simulates its usage in a real application.
159
+ test_files:
160
+ - test/functional/plugin_test_helper_test.rb
161
+ - test/unit/plugin_locator_test.rb