plugin_test_helper 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. data/CHANGELOG.rdoc +8 -1
  2. data/LICENSE +1 -1
  3. data/README.rdoc +2 -2
  4. data/Rakefile +1 -1
  5. data/generators/plugin_test_console/plugin_test_console_generator.rb +5 -3
  6. data/generators/plugin_test_controller/plugin_test_controller_generator.rb +5 -1
  7. data/generators/plugin_test_helper/plugin_test_helper_generator.rb +5 -3
  8. data/generators/plugin_test_migration/plugin_test_migration_generator.rb +5 -1
  9. data/generators/plugin_test_model/plugin_test_model_generator.rb +11 -16
  10. data/generators/plugin_test_model/templates/migration.rb +0 -3
  11. data/generators/plugin_test_structure/USAGE +1 -1
  12. data/generators/plugin_test_structure/plugin_test_structure_generator.rb +5 -2
  13. data/generators/plugin_test_structure/templates/app_root/app/controllers/{application.rb → application_controller.rb} +0 -0
  14. data/generators/plugin_test_structure/templates/app_root/config/boot.rb +2 -1
  15. data/generators/plugin_test_structure/templates/app_root/config/database.yml +10 -0
  16. data/generators/plugin_test_structure/templates/app_root/config/environment.rb +1 -0
  17. data/generators/plugin_test_structure/templates/test_helper.rb +3 -2
  18. data/lib/plugin_test_helper/extensions/{initializer.rb → configuration.rb} +0 -30
  19. data/lib/plugin_test_helper/generator.rb +7 -2
  20. data/lib/plugin_test_helper.rb +6 -8
  21. data/test/app_roots/with_custom_application_controller/app/controllers/{application.rb → application_controller.rb} +0 -0
  22. data/test/functional/plugin_test_helper_test.rb +1 -0
  23. data/test/functional/plugin_test_structure_generator_test.rb +1 -1
  24. data/test/test_helper.rb +25 -11
  25. metadata +6 -6
data/CHANGELOG.rdoc CHANGED
@@ -1,6 +1,13 @@
1
1
  == master
2
2
 
3
- == 0.2.1 / 2008-01-11
3
+ == 0.3.0 / 2009-04-13
4
+
5
+ * Fix environment being loaded twice when generators are loaded
6
+ * Clean up / simplify generators
7
+ * Rename application.rb to application_controller.rb
8
+ * Add dependency on Rails 2.3
9
+
10
+ == 0.2.1 / 2009-01-11
4
11
 
5
12
  * Remove init.rb since the library should never be loaded automatically
6
13
  * Fix fixtures not being loaded within the test application console [Sergei Kozlov]
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2008 Aaron Pfeifer
1
+ Copyright (c) 2006-2009 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
data/README.rdoc CHANGED
@@ -104,7 +104,7 @@ Example:
104
104
  create vendor/plugins/acts_as_most_popular/test/app_root/config/environments/in_memory.rb
105
105
  create vendor/plugins/acts_as_most_popular/test/app_root/config/environments/postgresql.rb
106
106
  create vendor/plugins/acts_as_most_popular/test/app_root/app/controllers
107
- create vendor/plugins/acts_as_most_popular/test/app_root/app/controllers/application.rb
107
+ create vendor/plugins/acts_as_most_popular/test/app_root/app/controllers/application_controller.rb
108
108
  Loaded suite script/generate
109
109
  Started
110
110
 
@@ -187,7 +187,7 @@ Example:
187
187
 
188
188
  == Dependencies
189
189
 
190
- Rails 2.1 or later
190
+ Rails 2.3 or later
191
191
 
192
192
  == References
193
193
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/contrib/sshpublisher'
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = 'plugin_test_helper'
8
- s.version = '0.2.1'
8
+ s.version = '0.3.0'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = 'Simplifies plugin testing by creating an isolated Rails environment that simulates its usage in a real application.'
11
11
 
@@ -1,9 +1,11 @@
1
+ require 'plugin_test_helper/generator'
2
+
1
3
  # Generates a test console for the plugin's test application.
2
- class PluginTestConsoleGenerator < Rails::Generator::NamedBase
4
+ class PluginTestConsoleGenerator < Rails::Generator::Base
5
+ include PluginTestHelper::Generator
6
+
3
7
  def manifest #:nodoc:
4
8
  record do |m|
5
- plugin_root = "vendor/plugins/#{name}"
6
-
7
9
  # Script directory
8
10
  m.directory File.join(plugin_root, 'script')
9
11
 
@@ -1,5 +1,9 @@
1
+ require 'plugin_test_helper/generator'
2
+
1
3
  # Generates the class and view for a controller in a plugin's test application
2
- class PluginTestControllerGenerator < PluginTestHelper::Generator
4
+ class PluginTestControllerGenerator < Rails::Generator::NamedBase
5
+ include PluginTestHelper::Generator
6
+
3
7
  def manifest #:nodoc:
4
8
  record do |m|
5
9
  # Check for class naming collisions
@@ -1,9 +1,11 @@
1
+ require 'plugin_test_helper/generator'
2
+
1
3
  # Generates the test helper for a plugin
2
- class PluginTestHelperGenerator < Rails::Generator::NamedBase
4
+ class PluginTestHelperGenerator < Rails::Generator::Base
5
+ include PluginTestHelper::Generator
6
+
3
7
  def manifest #:nodoc:
4
8
  record do |m|
5
- plugin_root = "vendor/plugins/#{name}"
6
-
7
9
  # Test directory
8
10
  m.directory File.join(plugin_root, 'test')
9
11
 
@@ -1,5 +1,9 @@
1
+ require 'plugin_test_helper/generator'
2
+
1
3
  # Generates migrations for a plugin's test application
2
- class PluginTestMigrationGenerator < PluginTestHelper::Generator
4
+ class PluginTestMigrationGenerator < Rails::Generator::NamedBase
5
+ include PluginTestHelper::Generator
6
+
3
7
  def manifest #:nodoc:
4
8
  record do |m|
5
9
  m.migration_template 'migration.rb', "#{plugin_app_root}/db/migrate"
@@ -1,25 +1,26 @@
1
+ require 'plugin_test_helper/generator'
2
+
1
3
  # Generates the class, fixtures, and migration for a model in a plugin's test application
2
- class PluginTestModelGenerator < PluginTestHelper::Generator
3
- default_options :skip_migration => false
4
+ class PluginTestModelGenerator < Rails::Generator::NamedBase
5
+ include PluginTestHelper::Generator
4
6
 
5
7
  def manifest #:nodoc:
6
8
  record do |m|
7
- # Check for class naming collisions.
9
+ # Check for class naming collisions
8
10
  m.class_collisions class_path, class_name
9
11
 
10
- # Model and fixture directories.
12
+ # Model and fixture directories
11
13
  m.directory File.join(plugin_app_root, 'app/models', class_path)
12
14
  m.directory File.join(plugin_test_root, 'fixtures', class_path)
13
15
 
14
- # Model class and fixtures.
16
+ # Model class and fixtures
15
17
  m.template 'model.rb', File.join(plugin_app_root, 'app/models', class_path, "#{file_name}.rb")
16
18
  m.template 'fixtures.yml', File.join(plugin_test_root, 'fixtures', class_path, "#{table_name}.yml")
17
19
 
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
20
+ # Migration
21
+ m.migration_template 'migration.rb', "#{plugin_app_root}/db/migrate", :assigns => {
22
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
23
+ }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
23
24
  end
24
25
  end
25
26
 
@@ -27,10 +28,4 @@ class PluginTestModelGenerator < PluginTestHelper::Generator
27
28
  def banner
28
29
  "Usage: #{$0} generate your_plugin ModelName [field:type, field:type]"
29
30
  end
30
-
31
- def add_options!(opt)
32
- opt.separator ''
33
- opt.separator 'Options:'
34
- opt.on('--skip-migration', "Don't generate a migration file for this model") {|v| options[:skip_migration] = v}
35
- end
36
31
  end
@@ -3,9 +3,6 @@ class <%= migration_name %> < ActiveRecord::Migration
3
3
  create_table :<%= table_name %> do |t|
4
4
  <% for attribute in attributes -%>
5
5
  t.<%= attribute.type %> :<%= attribute.name %>
6
- <% end -%>
7
- <% unless options[:skip_timestamps] %>
8
- t.timestamps
9
6
  <% end -%>
10
7
  end
11
8
  end
@@ -8,7 +8,7 @@ Examples:
8
8
 
9
9
  creates test, controller and application configurations:
10
10
  Test Helper: test/test_helper.rb
11
- Controller: test/app_root/app/controllers/application.rb
11
+ Controller: test/app_root/app/controllers/application_controller.rb
12
12
  Configurations: test/app_root/config/boot.rb
13
13
  test/app_root/config/database.yml
14
14
  test/app_root/config/environment.rb
@@ -1,10 +1,13 @@
1
+ require 'plugin_test_helper/generator'
2
+
1
3
  # Generates the test structure for a plugin with no dependencies on the
2
4
  # plugin_test_helper library
3
- class PluginTestStructureGenerator < Rails::Generator::NamedBase
5
+ class PluginTestStructureGenerator < Rails::Generator::Base
6
+ include PluginTestHelper::Generator
7
+
4
8
  def manifest #:nodoc:
5
9
  record do |m|
6
10
  # Paths are relative to our template dir
7
- plugin_test_root = "vendor/plugins/#{name}/test"
8
11
  templates_root = "#{File.dirname(__FILE__)}/templates"
9
12
 
10
13
  # Root test directory
@@ -47,6 +47,7 @@ module Rails
47
47
  def load_initializer
48
48
  require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer"
49
49
  Rails::Initializer.run(:install_gem_spec_stubs)
50
+ Rails::GemDependency.add_frozen_gem_path
50
51
  end
51
52
  end
52
53
 
@@ -85,7 +86,7 @@ module Rails
85
86
 
86
87
  def load_rubygems
87
88
  require 'rubygems'
88
- min_version = '1.1.1'
89
+ min_version = '1.3.1'
89
90
  unless rubygems_version >= min_version
90
91
  $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
91
92
  exit 1
@@ -2,20 +2,30 @@ in_memory:
2
2
  adapter: sqlite3
3
3
  database: ":memory:"
4
4
  verbosity: quiet
5
+ pool: 5
6
+ timeout: 5000
5
7
  sqlite:
6
8
  adapter: sqlite
7
9
  dbfile: plugin_test.sqlite.db
10
+ pool: 5
11
+ timeout: 5000
8
12
  sqlite3:
9
13
  adapter: sqlite3
10
14
  dbfile: plugin_test.sqlite3.db
15
+ pool: 5
16
+ timeout: 5000
11
17
  postgresql:
12
18
  adapter: postgresql
13
19
  username: postgres
14
20
  password: postgres
15
21
  database: plugin_test
22
+ pool: 5
23
+ timeout: 5000
16
24
  mysql:
17
25
  adapter: mysql
18
26
  host: localhost
19
27
  username: root
20
28
  password:
21
29
  database: plugin_test
30
+ pool: 5
31
+ timeout: 5000
@@ -3,6 +3,7 @@ require File.join(File.dirname(__FILE__), 'boot')
3
3
  Rails::Initializer.run do |config|
4
4
  config.cache_classes = false
5
5
  config.whiny_nils = true
6
+ config.action_controller.session = {:key => 'rails_session', :secret => 'd229e4d22437432705ab3985d4d246'}
6
7
  config.plugin_locators.unshift(
7
8
  Class.new(Rails::Plugin::Locator) do
8
9
  def plugins
@@ -4,7 +4,6 @@ ENV['RAILS_ENV'] ||= 'in_memory'
4
4
  # Load the Rails environment and testing framework
5
5
  require "#{File.dirname(__FILE__)}/app_root/config/environment"
6
6
  require 'test_help'
7
- require 'action_view/test_case' # Load additional test classes not done automatically by < Rails 2.2.2
8
7
 
9
8
  # Undo changes to RAILS_ENV
10
9
  silence_warnings {RAILS_ENV = ENV['RAILS_ENV']}
@@ -13,8 +12,10 @@ silence_warnings {RAILS_ENV = ENV['RAILS_ENV']}
13
12
  ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
14
13
 
15
14
  # Set default fixture loading properties
16
- Test::Unit::TestCase.class_eval do
15
+ ActiveSupport::TestCase.class_eval do
17
16
  self.use_transactional_fixtures = true
18
17
  self.use_instantiated_fixtures = false
19
18
  self.fixture_path = "#{File.dirname(__FILE__)}/fixtures"
19
+
20
+ fixtures :all
20
21
  end
@@ -2,24 +2,6 @@ require 'plugin_test_helper/plugin_locator'
2
2
 
3
3
  module PluginTestHelper
4
4
  module Extensions #:nodoc:
5
- # Adds in hooks for extending other parts of the Rails framework *after*
6
- # Rails has loaded those frameworks
7
- module Initializer
8
- def self.included(base)
9
- base.class_eval do
10
- alias_method :require_frameworks_without_test_helper, :require_frameworks
11
- alias_method :require_frameworks, :require_frameworks_with_test_helper
12
- end
13
- end
14
-
15
- # Load the needed frameworks and then our extensions to them
16
- def require_frameworks_with_test_helper
17
- require_frameworks_without_test_helper
18
-
19
- require 'plugin_test_helper/generator'
20
- end
21
- end
22
-
23
5
  # Overrides some of the default values in the Rails configuration so that
24
6
  # files can be reused from this test helper or overridden by the plugin
25
7
  # using the helper
@@ -31,7 +13,6 @@ module PluginTestHelper
31
13
  alias_method_chain base, :default_routes_configuration_file, :test_helper
32
14
  alias_method_chain base, :default_controller_paths, :test_helper
33
15
  alias_method_chain base, :default_plugin_locators, :test_helper
34
- alias_method_chain base, :default_plugin_paths, :test_helper
35
16
  end
36
17
 
37
18
  # Defines a "lite" version of ActiveSupport's alias chaining extensions.
@@ -60,7 +41,6 @@ module PluginTestHelper
60
41
  app/controllers
61
42
  config
62
43
  lib
63
- vendor
64
44
  ).map {|dir| "#{HELPER_RAILS_ROOT}/#{dir}"}
65
45
  end
66
46
 
@@ -87,20 +67,10 @@ module PluginTestHelper
87
67
  locators = default_plugin_locators_without_test_helper
88
68
  locators.unshift(PluginTestHelper::PluginLocator)
89
69
  end
90
-
91
- # Add the helper's vendor/plugins path
92
- def default_plugin_paths_with_test_helper
93
- paths = default_plugin_paths_without_test_helper
94
- paths << File.join(HELPER_RAILS_ROOT, 'vendor/plugins')
95
- end
96
70
  end
97
71
  end
98
72
  end
99
73
 
100
- Rails::Initializer.class_eval do
101
- include PluginTestHelper::Extensions::Initializer
102
- end
103
-
104
74
  Rails::Configuration.class_eval do
105
75
  include PluginTestHelper::Extensions::Configuration
106
76
  end
@@ -3,7 +3,7 @@ require 'rails_generator'
3
3
  module PluginTestHelper
4
4
  # The base generator for creating parts of the test application. The first
5
5
  # argument of the generator is always the name of the plugin.
6
- class Generator < Rails::Generator::NamedBase
6
+ module Generator
7
7
  attr_accessor :plugin_name
8
8
 
9
9
  def initialize(*runtime_args) #:nodoc:
@@ -12,9 +12,14 @@ module PluginTestHelper
12
12
  end
13
13
 
14
14
  private
15
+ # The root path of the plugin's directory
16
+ def plugin_root
17
+ "vendor/plugins/#{plugin_name}"
18
+ end
19
+
15
20
  # The root path of the plugin's test directory
16
21
  def plugin_test_root
17
- "vendor/plugins/#{plugin_name}/test"
22
+ "#{plugin_root}/test"
18
23
  end
19
24
 
20
25
  # The root path of the plugin's test app
@@ -12,23 +12,21 @@ ENV['RAILS_ENV'] ||= 'in_memory'
12
12
  # First boot the Rails framework
13
13
  require 'config/boot'
14
14
 
15
- # Extend it so that we can hook into the initialization process
16
- require 'plugin_test_helper/extensions/initializer'
15
+ # Extend it so that we can hook into the configuration process
16
+ require 'plugin_test_helper/extensions/configuration'
17
17
 
18
18
  # Load the Rails environment and testing framework
19
19
  require 'config/environment'
20
20
  require 'test_help'
21
21
 
22
- # Load additional test classes not done automatically by < Rails 2.2.2
23
- # TODO: Remove in Rails 2.2.3 / 2.3 (whichever includes the fix)
24
- require 'action_view/test_case'
25
-
26
22
  # Undo changes to RAILS_ENV
27
23
  silence_warnings {RAILS_ENV = ENV['RAILS_ENV']}
28
24
 
29
25
  # Set default fixture loading properties
30
- Test::Unit::TestCase.class_eval do
26
+ ActiveSupport::TestCase.class_eval do
31
27
  self.use_transactional_fixtures = true
32
28
  self.use_instantiated_fixtures = false
33
- self.fixture_path = "#{Rails.root}/../fixtures"
29
+ self.fixture_path = "#{File.dirname(__FILE__)}/fixtures"
30
+
31
+ fixtures :all
34
32
  end
@@ -8,6 +8,7 @@ class PluginTestHelperTest < Test::Unit::TestCase
8
8
 
9
9
  def test_should_load_with_no_app_root
10
10
  load 'plugin_test_helper.rb'
11
+
11
12
  assert_valid_environment
12
13
  end
13
14
 
@@ -15,7 +15,7 @@ class PluginTestStructureGeneratorTest < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  def test_should_create_application_controller
18
- assert File.exists?("#{Rails.root}/vendor/plugins/acts_as_foo/test/app_root/app/controllers/application.rb")
18
+ assert File.exists?("#{Rails.root}/vendor/plugins/acts_as_foo/test/app_root/app/controllers/application_controller.rb")
19
19
  end
20
20
 
21
21
  def test_should_create_in_memory_environment
data/test/test_helper.rb CHANGED
@@ -14,6 +14,25 @@ require 'stringio'
14
14
  Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(StringIO.new))
15
15
 
16
16
  Test::Unit::TestCase.class_eval do
17
+ def self.reset_environment
18
+ # Clear dependencies
19
+ ActiveRecord::Base.reset_subclasses
20
+ ActiveSupport::Dependencies.clear
21
+
22
+ # Clear configurations
23
+ ActionController::Routing.controller_paths.clear
24
+ ActionController::Routing::Routes.configuration_files.clear
25
+ Rails::Rack::Metal.requested_metals.clear if Rails::Rack::Metal.requested_metals
26
+ Rails::Rack::Metal.metal_paths.clear if Rails::Rack::Metal.metal_paths
27
+
28
+ # Reset open streams
29
+ ActiveRecord::Base.clear_reloadable_connections!
30
+
31
+ # Forget that the environment files were loaded so that a new app environment
32
+ # can be set up again
33
+ $".delete_if {|path| path =~ /(config\/environment\.rb|test_help\.rb)$/}
34
+ end
35
+
17
36
  private
18
37
  def assert_valid_environment
19
38
  assert_not_nil ApplicationController
@@ -29,19 +48,14 @@ Test::Unit::TestCase.class_eval do
29
48
  end
30
49
 
31
50
  def teardown_app
32
- # Clear dependencies
33
- self.class.use_transactional_fixtures = false
34
- ActiveRecord::Base.reset_subclasses
35
- ActiveSupport::Dependencies.clear
36
-
37
- # Reset open streams
38
- ActiveRecord::Base.clear_reloadable_connections!
39
-
40
- # Forget that the environment files were loaded so that a new app environment
41
- # can be set up again
42
- $".delete_if {|path| path =~ /(config\/environment\.rb|test_help\.rb)$/}
51
+ self.class.reset_environment
43
52
 
44
53
  # Remove the app folder
45
54
  FileUtils.rm_r(Dir['test/app_root/*'])
46
55
  end
47
56
  end
57
+
58
+ # Load the helper once before tests start so that the Rails library paths
59
+ # don't get lost betweeen environment loads
60
+ require 'plugin_test_helper'
61
+ Test::Unit::TestCase.reset_environment
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plugin_test_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Pfeifer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-11 00:00:00 -05:00
12
+ date: 2009-04-13 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -58,7 +58,7 @@ files:
58
58
  - generators/plugin_test_structure/templates/app_root/config/routes.rb
59
59
  - generators/plugin_test_structure/templates/app_root/app
60
60
  - generators/plugin_test_structure/templates/app_root/app/controllers
61
- - generators/plugin_test_structure/templates/app_root/app/controllers/application.rb
61
+ - generators/plugin_test_structure/templates/app_root/app/controllers/application_controller.rb
62
62
  - generators/plugin_test_structure/plugin_test_structure_generator.rb
63
63
  - generators/plugin_test_structure/USAGE
64
64
  - generators/plugin_test_controller
@@ -76,7 +76,7 @@ files:
76
76
  - lib/plugin_test_helper
77
77
  - lib/plugin_test_helper/plugin_locator.rb
78
78
  - lib/plugin_test_helper/extensions
79
- - lib/plugin_test_helper/extensions/initializer.rb
79
+ - lib/plugin_test_helper/extensions/configuration.rb
80
80
  - lib/plugin_test_helper/generator.rb
81
81
  - lib/plugin_test_helper/console_with_fixtures.rb
82
82
  - test/fixtures
@@ -123,7 +123,7 @@ files:
123
123
  - test/app_roots/with_custom_application_controller
124
124
  - test/app_roots/with_custom_application_controller/app
125
125
  - test/app_roots/with_custom_application_controller/app/controllers
126
- - test/app_roots/with_custom_application_controller/app/controllers/application.rb
126
+ - test/app_roots/with_custom_application_controller/app/controllers/application_controller.rb
127
127
  - test/app_roots/with_model
128
128
  - test/app_roots/with_model/app
129
129
  - test/app_roots/with_model/app/models
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  requirements: []
165
165
 
166
166
  rubyforge_project: pluginaweek
167
- rubygems_version: 1.2.0
167
+ rubygems_version: 1.3.1
168
168
  signing_key:
169
169
  specification_version: 2
170
170
  summary: Simplifies plugin testing by creating an isolated Rails environment that simulates its usage in a real application.