aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-06-23 19:10:42 +0200
committerJosé Valim <jose.valim@gmail.com>2009-06-23 19:10:42 +0200
commit4494a752c3c568c65fa899c54486153a1a5fa187 (patch)
tree60149451a075242bd36c5298ea9838d1d2d50f2f
parent75fbd7393606b9b026418229eb3eb38542753d43 (diff)
downloadrails-4494a752c3c568c65fa899c54486153a1a5fa187.tar.gz
rails-4494a752c3c568c65fa899c54486153a1a5fa187.tar.bz2
rails-4494a752c3c568c65fa899c54486153a1a5fa187.zip
Change current sstructure.
-rwxr-xr-xrailties/bin/gen8
-rwxr-xr-xrailties/bin/rails4
-rw-r--r--railties/lib/generators.rb (renamed from railties/lib/generator.rb)9
-rw-r--r--railties/lib/generators/actions.rb (renamed from railties/lib/generator/actions.rb)0
-rw-r--r--railties/lib/generators/base.rb (renamed from railties/lib/generator/base.rb)4
-rw-r--r--railties/lib/generators/generated_attribute.rb (renamed from railties/lib/generator/generated_attribute.rb)0
-rw-r--r--railties/lib/generators/named_base.rb (renamed from railties/lib/generator/named_base.rb)4
-rw-r--r--railties/lib/generators/rails/app/USAGE (renamed from railties/lib/generator/generators/app/USAGE)0
-rw-r--r--railties/lib/generators/rails/app/app_generator.rb (renamed from railties/lib/generator/generators/app/app_generator.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/README (renamed from railties/lib/generator/generators/app/templates/README)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/Rakefile (renamed from railties/lib/generator/generators/app/templates/Rakefile)0
-rw-r--r--railties/lib/generators/rails/app/templates/app/controllers/application_controller.rb (renamed from railties/lib/generator/generators/app/templates/app/controllers/application_controller.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/app/helpers/application_helper.rb (renamed from railties/lib/generator/generators/app/templates/app/helpers/application_helper.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/app/models/.empty_directory (renamed from railties/lib/generator/generators/app/templates/app/models/.empty_directory)0
-rw-r--r--railties/lib/generators/rails/app/templates/app/views/layouts/.empty_directory (renamed from railties/lib/generator/generators/app/templates/app/views/layouts/.empty_directory)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/boot.rb (renamed from railties/lib/generator/generators/app/templates/config/boot.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/databases/frontbase.yml (renamed from railties/lib/generator/generators/app/templates/config/databases/frontbase.yml)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/databases/ibm_db.yml (renamed from railties/lib/generator/generators/app/templates/config/databases/ibm_db.yml)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/databases/mysql.yml (renamed from railties/lib/generator/generators/app/templates/config/databases/mysql.yml)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/databases/oracle.yml (renamed from railties/lib/generator/generators/app/templates/config/databases/oracle.yml)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/databases/postgresql.yml (renamed from railties/lib/generator/generators/app/templates/config/databases/postgresql.yml)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/databases/sqlite2.yml (renamed from railties/lib/generator/generators/app/templates/config/databases/sqlite2.yml)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/databases/sqlite3.yml (renamed from railties/lib/generator/generators/app/templates/config/databases/sqlite3.yml)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/environment.rb (renamed from railties/lib/generator/generators/app/templates/config/environment.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/environments/development.rb (renamed from railties/lib/generator/generators/app/templates/config/environments/development.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/environments/production.rb (renamed from railties/lib/generator/generators/app/templates/config/environments/production.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/environments/test.rb (renamed from railties/lib/generator/generators/app/templates/config/environments/test.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/initializers/backtrace_silencers.rb (renamed from railties/lib/generator/generators/app/templates/config/initializers/backtrace_silencers.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/initializers/inflections.rb (renamed from railties/lib/generator/generators/app/templates/config/initializers/inflections.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/initializers/mime_types.rb (renamed from railties/lib/generator/generators/app/templates/config/initializers/mime_types.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/initializers/new_rails_defaults.rb (renamed from railties/lib/generator/generators/app/templates/config/initializers/new_rails_defaults.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt (renamed from railties/lib/generator/generators/app/templates/config/initializers/session_store.rb.tt)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/locales/en.yml (renamed from railties/lib/generator/generators/app/templates/config/locales/en.yml)0
-rw-r--r--railties/lib/generators/rails/app/templates/config/routes.rb (renamed from railties/lib/generator/generators/app/templates/config/routes.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/db/seeds.rb (renamed from railties/lib/generator/generators/app/templates/db/seeds.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/dispatchers/config.ru (renamed from railties/lib/generator/generators/app/templates/dispatchers/config.ru)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/dispatchers/dispatch.fcgi (renamed from railties/lib/generator/generators/app/templates/dispatchers/dispatch.fcgi)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/dispatchers/dispatch.rb (renamed from railties/lib/generator/generators/app/templates/dispatchers/dispatch.rb)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/dispatchers/gateway.cgi (renamed from railties/lib/generator/generators/app/templates/dispatchers/gateway.cgi)0
-rw-r--r--railties/lib/generators/rails/app/templates/doc/README_FOR_APP (renamed from railties/lib/generator/generators/app/templates/doc/README_FOR_APP)0
-rw-r--r--railties/lib/generators/rails/app/templates/public/404.html (renamed from railties/lib/generator/generators/app/templates/public/404.html)0
-rw-r--r--railties/lib/generators/rails/app/templates/public/422.html (renamed from railties/lib/generator/generators/app/templates/public/422.html)0
-rw-r--r--railties/lib/generators/rails/app/templates/public/500.html (renamed from railties/lib/generator/generators/app/templates/public/500.html)0
-rw-r--r--railties/lib/generators/rails/app/templates/public/favicon.ico (renamed from railties/lib/generator/generators/app/templates/public/favicon.ico)0
-rw-r--r--railties/lib/generators/rails/app/templates/public/images/rails.png (renamed from railties/lib/generator/generators/app/templates/public/images/rails.png)bin6646 -> 6646 bytes
-rw-r--r--railties/lib/generators/rails/app/templates/public/index.html (renamed from railties/lib/generator/generators/app/templates/public/index.html)0
-rw-r--r--railties/lib/generators/rails/app/templates/public/javascripts/application.js (renamed from railties/lib/generator/generators/app/templates/public/javascripts/application.js)0
-rw-r--r--railties/lib/generators/rails/app/templates/public/javascripts/controls.js (renamed from railties/lib/generator/generators/app/templates/public/javascripts/controls.js)0
-rw-r--r--railties/lib/generators/rails/app/templates/public/javascripts/dragdrop.js (renamed from railties/lib/generator/generators/app/templates/public/javascripts/dragdrop.js)0
-rw-r--r--railties/lib/generators/rails/app/templates/public/javascripts/effects.js (renamed from railties/lib/generator/generators/app/templates/public/javascripts/effects.js)0
-rw-r--r--railties/lib/generators/rails/app/templates/public/javascripts/prototype.js (renamed from railties/lib/generator/generators/app/templates/public/javascripts/prototype.js)0
-rw-r--r--railties/lib/generators/rails/app/templates/public/robots.txt (renamed from railties/lib/generator/generators/app/templates/public/robots.txt)0
-rw-r--r--railties/lib/generators/rails/app/templates/public/stylesheets/.empty_directory (renamed from railties/lib/generator/generators/app/templates/public/stylesheets/.empty_directory)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/about.tt (renamed from railties/lib/generator/generators/app/templates/script/about.tt)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/console.tt (renamed from railties/lib/generator/generators/app/templates/script/console.tt)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/dbconsole.tt (renamed from railties/lib/generator/generators/app/templates/script/dbconsole.tt)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/destroy.tt (renamed from railties/lib/generator/generators/app/templates/script/destroy.tt)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/generate.tt (renamed from railties/lib/generator/generators/app/templates/script/generate.tt)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/performance/benchmarker.tt (renamed from railties/lib/generator/generators/app/templates/script/performance/benchmarker.tt)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/performance/profiler.tt (renamed from railties/lib/generator/generators/app/templates/script/performance/profiler.tt)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/plugin.tt (renamed from railties/lib/generator/generators/app/templates/script/plugin.tt)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/runner.tt (renamed from railties/lib/generator/generators/app/templates/script/runner.tt)0
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/server.tt (renamed from railties/lib/generator/generators/app/templates/script/server.tt)0
-rw-r--r--railties/lib/generators/rails/app/templates/test/fixtures/.empty_directory (renamed from railties/lib/generator/generators/app/templates/test/fixtures/.empty_directory)0
-rw-r--r--railties/lib/generators/rails/app/templates/test/functional/.empty_directory (renamed from railties/lib/generator/generators/app/templates/test/functional/.empty_directory)0
-rw-r--r--railties/lib/generators/rails/app/templates/test/integration/.empty_directory (renamed from railties/lib/generator/generators/app/templates/test/integration/.empty_directory)0
-rw-r--r--railties/lib/generators/rails/app/templates/test/performance/performance_test.rb (renamed from railties/lib/generator/generators/app/templates/test/performance/performance_test.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/test/test_helper.rb (renamed from railties/lib/generator/generators/app/templates/test/test_helper.rb)0
-rw-r--r--railties/lib/generators/rails/app/templates/test/unit/.empty_directory (renamed from railties/lib/generator/generators/app/templates/test/unit/.empty_directory)0
-rw-r--r--railties/lib/generators/rails/metal/USAGE (renamed from railties/lib/generator/generators/metal/USAGE)0
-rw-r--r--railties/lib/generators/rails/metal/metal_generator.rb (renamed from railties/lib/generator/generators/metal/metal_generator.rb)0
-rw-r--r--railties/lib/generators/rails/metal/templates/metal.rb (renamed from railties/lib/generator/generators/metal/templates/metal.rb)0
-rw-r--r--railties/test/generator/generator_test_helper.rb55
-rw-r--r--railties/test/generators/actions_test.rb (renamed from railties/test/generator/actions_test.rb)4
-rw-r--r--railties/test/generators/app_test.rb (renamed from railties/test/generator/app_test.rb)2
-rw-r--r--railties/test/generators/generator_test_helper.rb305
-rw-r--r--railties/test/rails_generator/generator_test_helper.rb303
-rw-r--r--railties/test/rails_generator/rails_controller_generator_test.rb (renamed from railties/test/generators/rails_controller_generator_test.rb)0
-rw-r--r--railties/test/rails_generator/rails_helper_generator_test.rb (renamed from railties/test/generators/rails_helper_generator_test.rb)0
-rw-r--r--railties/test/rails_generator/rails_mailer_generator_test.rb (renamed from railties/test/generators/rails_mailer_generator_test.rb)0
-rw-r--r--railties/test/rails_generator/rails_model_generator_test.rb (renamed from railties/test/generators/rails_model_generator_test.rb)0
-rw-r--r--railties/test/rails_generator/rails_model_subclass_generator_test.rb (renamed from railties/test/generators/rails_model_subclass_generator_test.rb)0
-rw-r--r--railties/test/rails_generator/rails_resource_generator_test.rb (renamed from railties/test/generators/rails_resource_generator_test.rb)0
-rw-r--r--railties/test/rails_generator/rails_scaffold_generator_test.rb (renamed from railties/test/generators/rails_scaffold_generator_test.rb)0
84 files changed, 351 insertions, 347 deletions
diff --git a/railties/bin/gen b/railties/bin/gen
index f054d4e853..6cc66ac455 100755
--- a/railties/bin/gen
+++ b/railties/bin/gen
@@ -14,16 +14,18 @@ else ARGV.size == 1
ARGV << "--help"
end
-require File.dirname(__FILE__) + '/../lib/generator'
+require File.dirname(__FILE__) + '/../lib/generators'
-Rails::Generators.builtin.each do |name|
- require "generator/generators/#{name}/#{name}_generator"
+Rails::Generators.builtin.each do |group, name|
+ require "generators/#{group}/#{name}/#{name}_generator"
end
name = ARGV.shift
if klass = Thor::Util.find_by_namespace("rails:generators:#{name}")
klass.start
+elsif klass = Thor::Util.find_by_namespace(name)
+ klass.start
else
puts "Could not find generator #{name}."
end
diff --git a/railties/bin/rails b/railties/bin/rails
index 57eb8809ed..538d0cbc84 100755
--- a/railties/bin/rails
+++ b/railties/bin/rails
@@ -9,7 +9,7 @@ end
ARGV << "--help" if ARGV.empty?
-require File.dirname(__FILE__) + '/../lib/generator'
-require 'generator/generators/app/app_generator'
+require File.dirname(__FILE__) + '/../lib/generators'
+require 'generators/rails/app/app_generator'
Rails::Generators::AppGenerator.start
diff --git a/railties/lib/generator.rb b/railties/lib/generators.rb
index cc3a983d60..5d22ff5e62 100644
--- a/railties/lib/generator.rb
+++ b/railties/lib/generators.rb
@@ -10,15 +10,16 @@ require 'thor'
$:.unshift(File.dirname(__FILE__))
require 'rails/version' unless defined?(Rails::VERSION)
-require 'generator/base'
-require 'generator/named_base'
+require 'generators/base'
+require 'generators/named_base'
module Rails
module Generators
def self.builtin
- Dir[File.dirname(__FILE__) + '/generator/generators/*'].collect do |file|
- File.basename(file)
+ Dir[File.dirname(__FILE__) + '/generators/*/*'].collect do |file|
+ file.split('/')[-2, 2]
end
end
end
end
+
diff --git a/railties/lib/generator/actions.rb b/railties/lib/generators/actions.rb
index c905f17f61..c905f17f61 100644
--- a/railties/lib/generator/actions.rb
+++ b/railties/lib/generators/actions.rb
diff --git a/railties/lib/generator/base.rb b/railties/lib/generators/base.rb
index 8e778e1d15..5f0b3eb369 100644
--- a/railties/lib/generator/base.rb
+++ b/railties/lib/generators/base.rb
@@ -1,4 +1,4 @@
-require 'generator/actions'
+require 'generators/actions'
module Rails
module Generators
@@ -12,7 +12,7 @@ module Rails
# Automatically sets the source root based on the class name.
#
def self.source_root
- @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'generators', generator_name, 'templates'))
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rails', generator_name, 'templates'))
end
# Convenience method to get the namespace from the class name.
diff --git a/railties/lib/generator/generated_attribute.rb b/railties/lib/generators/generated_attribute.rb
index 0ead945281..0ead945281 100644
--- a/railties/lib/generator/generated_attribute.rb
+++ b/railties/lib/generators/generated_attribute.rb
diff --git a/railties/lib/generator/named_base.rb b/railties/lib/generators/named_base.rb
index 6035d71060..223b34ce57 100644
--- a/railties/lib/generator/named_base.rb
+++ b/railties/lib/generators/named_base.rb
@@ -1,5 +1,5 @@
-require 'generator/base'
-require 'generator/generated_attribute'
+require 'generators/base'
+require 'generators/generated_attribute'
module Rails
module Generators
diff --git a/railties/lib/generator/generators/app/USAGE b/railties/lib/generators/rails/app/USAGE
index 36d6061a59..36d6061a59 100644
--- a/railties/lib/generator/generators/app/USAGE
+++ b/railties/lib/generators/rails/app/USAGE
diff --git a/railties/lib/generator/generators/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb
index 45e46aed02..45e46aed02 100644
--- a/railties/lib/generator/generators/app/app_generator.rb
+++ b/railties/lib/generators/rails/app/app_generator.rb
diff --git a/railties/lib/generator/generators/app/templates/README b/railties/lib/generators/rails/app/templates/README
index 37ec8ea211..37ec8ea211 100644
--- a/railties/lib/generator/generators/app/templates/README
+++ b/railties/lib/generators/rails/app/templates/README
diff --git a/railties/lib/generator/generators/app/templates/Rakefile b/railties/lib/generators/rails/app/templates/Rakefile
index 3bb0e8592a..3bb0e8592a 100755
--- a/railties/lib/generator/generators/app/templates/Rakefile
+++ b/railties/lib/generators/rails/app/templates/Rakefile
diff --git a/railties/lib/generator/generators/app/templates/app/controllers/application_controller.rb b/railties/lib/generators/rails/app/templates/app/controllers/application_controller.rb
index 6635a3f487..6635a3f487 100644
--- a/railties/lib/generator/generators/app/templates/app/controllers/application_controller.rb
+++ b/railties/lib/generators/rails/app/templates/app/controllers/application_controller.rb
diff --git a/railties/lib/generator/generators/app/templates/app/helpers/application_helper.rb b/railties/lib/generators/rails/app/templates/app/helpers/application_helper.rb
index 22a7940eb2..22a7940eb2 100644
--- a/railties/lib/generator/generators/app/templates/app/helpers/application_helper.rb
+++ b/railties/lib/generators/rails/app/templates/app/helpers/application_helper.rb
diff --git a/railties/lib/generator/generators/app/templates/app/models/.empty_directory b/railties/lib/generators/rails/app/templates/app/models/.empty_directory
index e69de29bb2..e69de29bb2 100644
--- a/railties/lib/generator/generators/app/templates/app/models/.empty_directory
+++ b/railties/lib/generators/rails/app/templates/app/models/.empty_directory
diff --git a/railties/lib/generator/generators/app/templates/app/views/layouts/.empty_directory b/railties/lib/generators/rails/app/templates/app/views/layouts/.empty_directory
index e69de29bb2..e69de29bb2 100644
--- a/railties/lib/generator/generators/app/templates/app/views/layouts/.empty_directory
+++ b/railties/lib/generators/rails/app/templates/app/views/layouts/.empty_directory
diff --git a/railties/lib/generator/generators/app/templates/config/boot.rb b/railties/lib/generators/rails/app/templates/config/boot.rb
index 0ad0f787f8..0ad0f787f8 100644
--- a/railties/lib/generator/generators/app/templates/config/boot.rb
+++ b/railties/lib/generators/rails/app/templates/config/boot.rb
diff --git a/railties/lib/generator/generators/app/templates/config/databases/frontbase.yml b/railties/lib/generators/rails/app/templates/config/databases/frontbase.yml
index c0c3588be1..c0c3588be1 100644
--- a/railties/lib/generator/generators/app/templates/config/databases/frontbase.yml
+++ b/railties/lib/generators/rails/app/templates/config/databases/frontbase.yml
diff --git a/railties/lib/generator/generators/app/templates/config/databases/ibm_db.yml b/railties/lib/generators/rails/app/templates/config/databases/ibm_db.yml
index a9716ddb44..a9716ddb44 100644
--- a/railties/lib/generator/generators/app/templates/config/databases/ibm_db.yml
+++ b/railties/lib/generators/rails/app/templates/config/databases/ibm_db.yml
diff --git a/railties/lib/generator/generators/app/templates/config/databases/mysql.yml b/railties/lib/generators/rails/app/templates/config/databases/mysql.yml
index 6bf2f7b1fd..6bf2f7b1fd 100644
--- a/railties/lib/generator/generators/app/templates/config/databases/mysql.yml
+++ b/railties/lib/generators/rails/app/templates/config/databases/mysql.yml
diff --git a/railties/lib/generator/generators/app/templates/config/databases/oracle.yml b/railties/lib/generators/rails/app/templates/config/databases/oracle.yml
index a1883f6256..a1883f6256 100644
--- a/railties/lib/generator/generators/app/templates/config/databases/oracle.yml
+++ b/railties/lib/generators/rails/app/templates/config/databases/oracle.yml
diff --git a/railties/lib/generator/generators/app/templates/config/databases/postgresql.yml b/railties/lib/generators/rails/app/templates/config/databases/postgresql.yml
index f600e054cf..f600e054cf 100644
--- a/railties/lib/generator/generators/app/templates/config/databases/postgresql.yml
+++ b/railties/lib/generators/rails/app/templates/config/databases/postgresql.yml
diff --git a/railties/lib/generator/generators/app/templates/config/databases/sqlite2.yml b/railties/lib/generators/rails/app/templates/config/databases/sqlite2.yml
index 46f01cb42c..46f01cb42c 100644
--- a/railties/lib/generator/generators/app/templates/config/databases/sqlite2.yml
+++ b/railties/lib/generators/rails/app/templates/config/databases/sqlite2.yml
diff --git a/railties/lib/generator/generators/app/templates/config/databases/sqlite3.yml b/railties/lib/generators/rails/app/templates/config/databases/sqlite3.yml
index 025d62a8d8..025d62a8d8 100644
--- a/railties/lib/generator/generators/app/templates/config/databases/sqlite3.yml
+++ b/railties/lib/generators/rails/app/templates/config/databases/sqlite3.yml
diff --git a/railties/lib/generator/generators/app/templates/config/environment.rb b/railties/lib/generators/rails/app/templates/config/environment.rb
index d1080cb529..d1080cb529 100644
--- a/railties/lib/generator/generators/app/templates/config/environment.rb
+++ b/railties/lib/generators/rails/app/templates/config/environment.rb
diff --git a/railties/lib/generator/generators/app/templates/config/environments/development.rb b/railties/lib/generators/rails/app/templates/config/environments/development.rb
index 85c9a6080e..85c9a6080e 100644
--- a/railties/lib/generator/generators/app/templates/config/environments/development.rb
+++ b/railties/lib/generators/rails/app/templates/config/environments/development.rb
diff --git a/railties/lib/generator/generators/app/templates/config/environments/production.rb b/railties/lib/generators/rails/app/templates/config/environments/production.rb
index 1fc9f6b923..1fc9f6b923 100644
--- a/railties/lib/generator/generators/app/templates/config/environments/production.rb
+++ b/railties/lib/generators/rails/app/templates/config/environments/production.rb
diff --git a/railties/lib/generator/generators/app/templates/config/environments/test.rb b/railties/lib/generators/rails/app/templates/config/environments/test.rb
index 496eb9572b..496eb9572b 100644
--- a/railties/lib/generator/generators/app/templates/config/environments/test.rb
+++ b/railties/lib/generators/rails/app/templates/config/environments/test.rb
diff --git a/railties/lib/generator/generators/app/templates/config/initializers/backtrace_silencers.rb b/railties/lib/generators/rails/app/templates/config/initializers/backtrace_silencers.rb
index 839d4cde19..839d4cde19 100644
--- a/railties/lib/generator/generators/app/templates/config/initializers/backtrace_silencers.rb
+++ b/railties/lib/generators/rails/app/templates/config/initializers/backtrace_silencers.rb
diff --git a/railties/lib/generator/generators/app/templates/config/initializers/inflections.rb b/railties/lib/generators/rails/app/templates/config/initializers/inflections.rb
index d531b8bb82..d531b8bb82 100644
--- a/railties/lib/generator/generators/app/templates/config/initializers/inflections.rb
+++ b/railties/lib/generators/rails/app/templates/config/initializers/inflections.rb
diff --git a/railties/lib/generator/generators/app/templates/config/initializers/mime_types.rb b/railties/lib/generators/rails/app/templates/config/initializers/mime_types.rb
index 72aca7e441..72aca7e441 100644
--- a/railties/lib/generator/generators/app/templates/config/initializers/mime_types.rb
+++ b/railties/lib/generators/rails/app/templates/config/initializers/mime_types.rb
diff --git a/railties/lib/generator/generators/app/templates/config/initializers/new_rails_defaults.rb b/railties/lib/generators/rails/app/templates/config/initializers/new_rails_defaults.rb
index 8ec3186c84..8ec3186c84 100644
--- a/railties/lib/generator/generators/app/templates/config/initializers/new_rails_defaults.rb
+++ b/railties/lib/generators/rails/app/templates/config/initializers/new_rails_defaults.rb
diff --git a/railties/lib/generator/generators/app/templates/config/initializers/session_store.rb.tt b/railties/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt
index 4499ab84b6..4499ab84b6 100644
--- a/railties/lib/generator/generators/app/templates/config/initializers/session_store.rb.tt
+++ b/railties/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt
diff --git a/railties/lib/generator/generators/app/templates/config/locales/en.yml b/railties/lib/generators/rails/app/templates/config/locales/en.yml
index f265c068d8..f265c068d8 100644
--- a/railties/lib/generator/generators/app/templates/config/locales/en.yml
+++ b/railties/lib/generators/rails/app/templates/config/locales/en.yml
diff --git a/railties/lib/generator/generators/app/templates/config/routes.rb b/railties/lib/generators/rails/app/templates/config/routes.rb
index ea14ce1bfc..ea14ce1bfc 100644
--- a/railties/lib/generator/generators/app/templates/config/routes.rb
+++ b/railties/lib/generators/rails/app/templates/config/routes.rb
diff --git a/railties/lib/generator/generators/app/templates/db/seeds.rb b/railties/lib/generators/rails/app/templates/db/seeds.rb
index 3174d0cb8a..3174d0cb8a 100644
--- a/railties/lib/generator/generators/app/templates/db/seeds.rb
+++ b/railties/lib/generators/rails/app/templates/db/seeds.rb
diff --git a/railties/lib/generator/generators/app/templates/dispatchers/config.ru b/railties/lib/generators/rails/app/templates/dispatchers/config.ru
index acbfe4e9ae..acbfe4e9ae 100644
--- a/railties/lib/generator/generators/app/templates/dispatchers/config.ru
+++ b/railties/lib/generators/rails/app/templates/dispatchers/config.ru
diff --git a/railties/lib/generator/generators/app/templates/dispatchers/dispatch.fcgi b/railties/lib/generators/rails/app/templates/dispatchers/dispatch.fcgi
index f5b3b71875..f5b3b71875 100755
--- a/railties/lib/generator/generators/app/templates/dispatchers/dispatch.fcgi
+++ b/railties/lib/generators/rails/app/templates/dispatchers/dispatch.fcgi
diff --git a/railties/lib/generator/generators/app/templates/dispatchers/dispatch.rb b/railties/lib/generators/rails/app/templates/dispatchers/dispatch.rb
index 48e888113a..48e888113a 100755
--- a/railties/lib/generator/generators/app/templates/dispatchers/dispatch.rb
+++ b/railties/lib/generators/rails/app/templates/dispatchers/dispatch.rb
diff --git a/railties/lib/generator/generators/app/templates/dispatchers/gateway.cgi b/railties/lib/generators/rails/app/templates/dispatchers/gateway.cgi
index bdc1055a22..bdc1055a22 100755
--- a/railties/lib/generator/generators/app/templates/dispatchers/gateway.cgi
+++ b/railties/lib/generators/rails/app/templates/dispatchers/gateway.cgi
diff --git a/railties/lib/generator/generators/app/templates/doc/README_FOR_APP b/railties/lib/generators/rails/app/templates/doc/README_FOR_APP
index fe41f5cc24..fe41f5cc24 100644
--- a/railties/lib/generator/generators/app/templates/doc/README_FOR_APP
+++ b/railties/lib/generators/rails/app/templates/doc/README_FOR_APP
diff --git a/railties/lib/generator/generators/app/templates/public/404.html b/railties/lib/generators/rails/app/templates/public/404.html
index eff660b90c..eff660b90c 100644
--- a/railties/lib/generator/generators/app/templates/public/404.html
+++ b/railties/lib/generators/rails/app/templates/public/404.html
diff --git a/railties/lib/generator/generators/app/templates/public/422.html b/railties/lib/generators/rails/app/templates/public/422.html
index b54e4a3cad..b54e4a3cad 100644
--- a/railties/lib/generator/generators/app/templates/public/422.html
+++ b/railties/lib/generators/rails/app/templates/public/422.html
diff --git a/railties/lib/generator/generators/app/templates/public/500.html b/railties/lib/generators/rails/app/templates/public/500.html
index ec3bbf02c4..ec3bbf02c4 100644
--- a/railties/lib/generator/generators/app/templates/public/500.html
+++ b/railties/lib/generators/rails/app/templates/public/500.html
diff --git a/railties/lib/generator/generators/app/templates/public/favicon.ico b/railties/lib/generators/rails/app/templates/public/favicon.ico
index e69de29bb2..e69de29bb2 100644
--- a/railties/lib/generator/generators/app/templates/public/favicon.ico
+++ b/railties/lib/generators/rails/app/templates/public/favicon.ico
diff --git a/railties/lib/generator/generators/app/templates/public/images/rails.png b/railties/lib/generators/rails/app/templates/public/images/rails.png
index d5edc04e65..d5edc04e65 100644
--- a/railties/lib/generator/generators/app/templates/public/images/rails.png
+++ b/railties/lib/generators/rails/app/templates/public/images/rails.png
Binary files differ
diff --git a/railties/lib/generator/generators/app/templates/public/index.html b/railties/lib/generators/rails/app/templates/public/index.html
index cd337dc74c..cd337dc74c 100644
--- a/railties/lib/generator/generators/app/templates/public/index.html
+++ b/railties/lib/generators/rails/app/templates/public/index.html
diff --git a/railties/lib/generator/generators/app/templates/public/javascripts/application.js b/railties/lib/generators/rails/app/templates/public/javascripts/application.js
index fe4577696b..fe4577696b 100644
--- a/railties/lib/generator/generators/app/templates/public/javascripts/application.js
+++ b/railties/lib/generators/rails/app/templates/public/javascripts/application.js
diff --git a/railties/lib/generator/generators/app/templates/public/javascripts/controls.js b/railties/lib/generators/rails/app/templates/public/javascripts/controls.js
index ca29aefdd1..ca29aefdd1 100644
--- a/railties/lib/generator/generators/app/templates/public/javascripts/controls.js
+++ b/railties/lib/generators/rails/app/templates/public/javascripts/controls.js
diff --git a/railties/lib/generator/generators/app/templates/public/javascripts/dragdrop.js b/railties/lib/generators/rails/app/templates/public/javascripts/dragdrop.js
index 07229f986f..07229f986f 100644
--- a/railties/lib/generator/generators/app/templates/public/javascripts/dragdrop.js
+++ b/railties/lib/generators/rails/app/templates/public/javascripts/dragdrop.js
diff --git a/railties/lib/generator/generators/app/templates/public/javascripts/effects.js b/railties/lib/generators/rails/app/templates/public/javascripts/effects.js
index 5a639d2dea..5a639d2dea 100644
--- a/railties/lib/generator/generators/app/templates/public/javascripts/effects.js
+++ b/railties/lib/generators/rails/app/templates/public/javascripts/effects.js
diff --git a/railties/lib/generator/generators/app/templates/public/javascripts/prototype.js b/railties/lib/generators/rails/app/templates/public/javascripts/prototype.js
index dfe8ab4e13..dfe8ab4e13 100644
--- a/railties/lib/generator/generators/app/templates/public/javascripts/prototype.js
+++ b/railties/lib/generators/rails/app/templates/public/javascripts/prototype.js
diff --git a/railties/lib/generator/generators/app/templates/public/robots.txt b/railties/lib/generators/rails/app/templates/public/robots.txt
index 085187fa58..085187fa58 100644
--- a/railties/lib/generator/generators/app/templates/public/robots.txt
+++ b/railties/lib/generators/rails/app/templates/public/robots.txt
diff --git a/railties/lib/generator/generators/app/templates/public/stylesheets/.empty_directory b/railties/lib/generators/rails/app/templates/public/stylesheets/.empty_directory
index e69de29bb2..e69de29bb2 100644
--- a/railties/lib/generator/generators/app/templates/public/stylesheets/.empty_directory
+++ b/railties/lib/generators/rails/app/templates/public/stylesheets/.empty_directory
diff --git a/railties/lib/generator/generators/app/templates/script/about.tt b/railties/lib/generators/rails/app/templates/script/about.tt
index 9604485fd2..9604485fd2 100755
--- a/railties/lib/generator/generators/app/templates/script/about.tt
+++ b/railties/lib/generators/rails/app/templates/script/about.tt
diff --git a/railties/lib/generator/generators/app/templates/script/console.tt b/railties/lib/generators/rails/app/templates/script/console.tt
index 307b7c09c4..307b7c09c4 100755
--- a/railties/lib/generator/generators/app/templates/script/console.tt
+++ b/railties/lib/generators/rails/app/templates/script/console.tt
diff --git a/railties/lib/generator/generators/app/templates/script/dbconsole.tt b/railties/lib/generators/rails/app/templates/script/dbconsole.tt
index 7ce41645a6..7ce41645a6 100755
--- a/railties/lib/generator/generators/app/templates/script/dbconsole.tt
+++ b/railties/lib/generators/rails/app/templates/script/dbconsole.tt
diff --git a/railties/lib/generator/generators/app/templates/script/destroy.tt b/railties/lib/generators/rails/app/templates/script/destroy.tt
index 9f22a9dbca..9f22a9dbca 100755
--- a/railties/lib/generator/generators/app/templates/script/destroy.tt
+++ b/railties/lib/generators/rails/app/templates/script/destroy.tt
diff --git a/railties/lib/generator/generators/app/templates/script/generate.tt b/railties/lib/generators/rails/app/templates/script/generate.tt
index 9a9e17ab29..9a9e17ab29 100755
--- a/railties/lib/generator/generators/app/templates/script/generate.tt
+++ b/railties/lib/generators/rails/app/templates/script/generate.tt
diff --git a/railties/lib/generator/generators/app/templates/script/performance/benchmarker.tt b/railties/lib/generators/rails/app/templates/script/performance/benchmarker.tt
index 3abf448c15..3abf448c15 100755
--- a/railties/lib/generator/generators/app/templates/script/performance/benchmarker.tt
+++ b/railties/lib/generators/rails/app/templates/script/performance/benchmarker.tt
diff --git a/railties/lib/generator/generators/app/templates/script/performance/profiler.tt b/railties/lib/generators/rails/app/templates/script/performance/profiler.tt
index 66f851a079..66f851a079 100755
--- a/railties/lib/generator/generators/app/templates/script/performance/profiler.tt
+++ b/railties/lib/generators/rails/app/templates/script/performance/profiler.tt
diff --git a/railties/lib/generator/generators/app/templates/script/plugin.tt b/railties/lib/generators/rails/app/templates/script/plugin.tt
index f0603c33c4..f0603c33c4 100755
--- a/railties/lib/generator/generators/app/templates/script/plugin.tt
+++ b/railties/lib/generators/rails/app/templates/script/plugin.tt
diff --git a/railties/lib/generator/generators/app/templates/script/runner.tt b/railties/lib/generators/rails/app/templates/script/runner.tt
index 7302825f6c..7302825f6c 100755
--- a/railties/lib/generator/generators/app/templates/script/runner.tt
+++ b/railties/lib/generators/rails/app/templates/script/runner.tt
diff --git a/railties/lib/generator/generators/app/templates/script/server.tt b/railties/lib/generators/rails/app/templates/script/server.tt
index 893db31a20..893db31a20 100755
--- a/railties/lib/generator/generators/app/templates/script/server.tt
+++ b/railties/lib/generators/rails/app/templates/script/server.tt
diff --git a/railties/lib/generator/generators/app/templates/test/fixtures/.empty_directory b/railties/lib/generators/rails/app/templates/test/fixtures/.empty_directory
index e69de29bb2..e69de29bb2 100644
--- a/railties/lib/generator/generators/app/templates/test/fixtures/.empty_directory
+++ b/railties/lib/generators/rails/app/templates/test/fixtures/.empty_directory
diff --git a/railties/lib/generator/generators/app/templates/test/functional/.empty_directory b/railties/lib/generators/rails/app/templates/test/functional/.empty_directory
index e69de29bb2..e69de29bb2 100644
--- a/railties/lib/generator/generators/app/templates/test/functional/.empty_directory
+++ b/railties/lib/generators/rails/app/templates/test/functional/.empty_directory
diff --git a/railties/lib/generator/generators/app/templates/test/integration/.empty_directory b/railties/lib/generators/rails/app/templates/test/integration/.empty_directory
index e69de29bb2..e69de29bb2 100644
--- a/railties/lib/generator/generators/app/templates/test/integration/.empty_directory
+++ b/railties/lib/generators/rails/app/templates/test/integration/.empty_directory
diff --git a/railties/lib/generator/generators/app/templates/test/performance/performance_test.rb b/railties/lib/generators/rails/app/templates/test/performance/performance_test.rb
index 4b60558b43..4b60558b43 100644
--- a/railties/lib/generator/generators/app/templates/test/performance/performance_test.rb
+++ b/railties/lib/generators/rails/app/templates/test/performance/performance_test.rb
diff --git a/railties/lib/generator/generators/app/templates/test/test_helper.rb b/railties/lib/generators/rails/app/templates/test/test_helper.rb
index b9fe2517c8..b9fe2517c8 100644
--- a/railties/lib/generator/generators/app/templates/test/test_helper.rb
+++ b/railties/lib/generators/rails/app/templates/test/test_helper.rb
diff --git a/railties/lib/generator/generators/app/templates/test/unit/.empty_directory b/railties/lib/generators/rails/app/templates/test/unit/.empty_directory
index e69de29bb2..e69de29bb2 100644
--- a/railties/lib/generator/generators/app/templates/test/unit/.empty_directory
+++ b/railties/lib/generators/rails/app/templates/test/unit/.empty_directory
diff --git a/railties/lib/generator/generators/metal/USAGE b/railties/lib/generators/rails/metal/USAGE
index 123ec6c03f..123ec6c03f 100644
--- a/railties/lib/generator/generators/metal/USAGE
+++ b/railties/lib/generators/rails/metal/USAGE
diff --git a/railties/lib/generator/generators/metal/metal_generator.rb b/railties/lib/generators/rails/metal/metal_generator.rb
index ba062b30be..ba062b30be 100644
--- a/railties/lib/generator/generators/metal/metal_generator.rb
+++ b/railties/lib/generators/rails/metal/metal_generator.rb
diff --git a/railties/lib/generator/generators/metal/templates/metal.rb b/railties/lib/generators/rails/metal/templates/metal.rb
index e94982b69a..e94982b69a 100644
--- a/railties/lib/generator/generators/metal/templates/metal.rb
+++ b/railties/lib/generators/rails/metal/templates/metal.rb
diff --git a/railties/test/generator/generator_test_helper.rb b/railties/test/generator/generator_test_helper.rb
deleted file mode 100644
index ebd3547e5e..0000000000
--- a/railties/test/generator/generator_test_helper.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-require 'test/unit'
-require 'fileutils'
-
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
-
-# For this while, let's load all generators by hand
-require 'generator/generators/app/app_generator'
-
-class GeneratorTestCase < Test::Unit::TestCase
- include FileUtils
-
- def destination_root
- @destination_root ||= File.expand_path("#{File.dirname(__FILE__)}/../fixtures/tmp")
- end
-
- def setup
- mkdir_p(destination_root)
- rm_rf(destination_root)
- end
-
- def test_truth
- # don't complain, test/unit
- end
-
- def capture(stream)
- begin
- stream = stream.to_s
- eval "$#{stream} = StringIO.new"
- yield
- result = eval("$#{stream}").string
- ensure
- eval("$#{stream} = #{stream.upcase}")
- end
-
- result
- end
- alias :silence :capture
-
- def assert_file(relative, content=nil)
- absolute = File.join(destination_root, relative)
- assert File.exists?(absolute)
-
- case content
- when String
- assert_equal content, File.read(absolute)
- when Regexp
- assert_match content, File.read(absolute)
- end
- end
-
- def assert_no_file(relative, content=nil)
- absolute = File.join(destination_root, relative)
- assert !File.exists?(absolute)
- end
-end
diff --git a/railties/test/generator/actions_test.rb b/railties/test/generators/actions_test.rb
index 60db8905d7..6030504fa3 100644
--- a/railties/test/generator/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -1,5 +1,5 @@
require 'abstract_unit'
-require 'generator/generator_test_helper'
+require 'generators/generator_test_helper'
class ActionsTest < GeneratorTestCase
def setup
@@ -170,7 +170,7 @@ class ActionsTest < GeneratorTestCase
protected
def run_generator
- silence(:stdout) { Rails::Generators::App.start [destination_root] }
+ silence(:stdout) { Rails::Generators::AppGenerator.start [destination_root] }
end
def generator(config={})
diff --git a/railties/test/generator/app_test.rb b/railties/test/generators/app_test.rb
index af1be03e59..a67f7e4926 100644
--- a/railties/test/generator/app_test.rb
+++ b/railties/test/generators/app_test.rb
@@ -1,5 +1,5 @@
require 'abstract_unit'
-require 'generator/generator_test_helper'
+require 'generators/generator_test_helper'
class AppTest < GeneratorTestCase
diff --git a/railties/test/generators/generator_test_helper.rb b/railties/test/generators/generator_test_helper.rb
index 01bf1c90bd..2b988bde7a 100644
--- a/railties/test/generators/generator_test_helper.rb
+++ b/railties/test/generators/generator_test_helper.rb
@@ -1,303 +1,56 @@
require 'test/unit'
require 'fileutils'
-# Mock out what we need from AR::Base
-module ActiveRecord
- class Base
- class << self
- attr_accessor :pluralize_table_names, :timestamped_migrations
- end
- self.pluralize_table_names = true
- self.timestamped_migrations = true
- end
-
- module ConnectionAdapters
- class Column
- attr_reader :name, :default, :type, :limit, :null, :sql_type, :precision, :scale
-
- def initialize(name, default, sql_type = nil)
- @name = name
- @default = default
- @type = @sql_type = sql_type
- end
-
- def human_name
- @name.humanize
- end
- end
- end
-end
-
-# Mock up necessities from ActionView
-module ActionView
- module Helpers
- module ActionRecordHelper; end
- class InstanceTag; end
- end
-end
-
-# Set RAILS_ROOT appropriately fixture generation
-tmp_dir = "#{File.dirname(__FILE__)}/../fixtures/tmp"
-
-if defined? RAILS_ROOT
- RAILS_ROOT.replace tmp_dir
-else
- RAILS_ROOT = tmp_dir
-end
-FileUtils.mkdir_p RAILS_ROOT
-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
-require 'initializer'
-# Mocks out the configuration
-module Rails
- def self.configuration
- Rails::Configuration.new
- end
-end
-
-require 'rails_generator'
+# For this while, let's load all generators by hand
+require 'generators'
+require 'generators/rails/app/app_generator'
class GeneratorTestCase < Test::Unit::TestCase
include FileUtils
- def setup
- ActiveRecord::Base.pluralize_table_names = true
-
- mkdir_p "#{RAILS_ROOT}/app/views/layouts"
- mkdir_p "#{RAILS_ROOT}/config"
- mkdir_p "#{RAILS_ROOT}/db"
- mkdir_p "#{RAILS_ROOT}/test/fixtures"
- mkdir_p "#{RAILS_ROOT}/public/stylesheets"
-
- File.open("#{RAILS_ROOT}/config/routes.rb", 'w') do |f|
- f << "ActionController::Routing::Routes.draw do |map|\n\nend"
- end
+ def destination_root
+ @destination_root ||= File.expand_path("#{File.dirname(__FILE__)}/../fixtures/tmp")
end
- def teardown
- rm_rf "#{RAILS_ROOT}/app"
- rm_rf "#{RAILS_ROOT}/test"
- rm_rf "#{RAILS_ROOT}/config"
- rm_rf "#{RAILS_ROOT}/db"
- rm_rf "#{RAILS_ROOT}/public"
+ def setup
+ mkdir_p(destination_root)
+ rm_rf(destination_root)
end
def test_truth
# don't complain, test/unit
end
- # Instantiates the Generator.
- def build_generator(name, params)
- Rails::Generator::Base.instance(name, params)
- end
-
- # Runs the +create+ command (like the command line does).
- def run_generator(name, params)
- silence_generator do
- build_generator(name, params).command(:create).invoke!
- end
- end
-
- # Silences the logger temporarily and returns the output as a String.
- def silence_generator
- logger_original = Rails::Generator::Base.logger
- myout = StringIO.new
- Rails::Generator::Base.logger = Rails::Generator::SimpleLogger.new(myout)
- yield if block_given?
- Rails::Generator::Base.logger = logger_original
- myout.string
- end
-
- # Asserts that the given controller was generated.
- # It takes a name or symbol without the <tt>_controller</tt> part and an optional super class.
- # The contents of the class source file is passed to a block.
- def assert_generated_controller_for(name, parent = "ApplicationController")
- assert_generated_class "app/controllers/#{name.to_s.underscore}_controller", parent do |body|
- yield body if block_given?
- end
- end
-
- # Asserts that the given model was generated.
- # It takes a name or symbol and an optional super class.
- # The contents of the class source file is passed to a block.
- def assert_generated_model_for(name, parent = "ActiveRecord::Base")
- assert_generated_class "app/models/#{name.to_s.underscore}", parent do |body|
- yield body if block_given?
- end
- end
-
- # Asserts that the given helper was generated.
- # It takes a name or symbol without the <tt>_helper</tt> part.
- # The contents of the module source file is passed to a block.
- def assert_generated_helper_for(name)
- assert_generated_module "app/helpers/#{name.to_s.underscore}_helper" do |body|
- yield body if block_given?
- end
- end
-
- # Asserts that the given functional test was generated.
- # It takes a name or symbol without the <tt>_controller_test</tt> part and an optional super class.
- # The contents of the class source file is passed to a block.
- def assert_generated_functional_test_for(name, parent = "ActionController::TestCase")
- assert_generated_class "test/functional/#{name.to_s.underscore}_controller_test",parent do |body|
- yield body if block_given?
- end
- end
-
- # Asserts that the given helper test test was generated.
- # It takes a name or symbol without the <tt>_helper_test</tt> part and an optional super class.
- # The contents of the class source file is passed to a block.
- def assert_generated_helper_test_for(name, parent = "ActionView::TestCase")
- path = "test/unit/helpers/#{name.to_s.underscore}_helper_test"
- # Have to pass the path without the "test/" part so that class_name_from_path will return a correct result
- class_name = class_name_from_path(path.gsub(/^test\//, ''))
-
- assert_generated_class path,parent,class_name do |body|
- yield body if block_given?
- end
- end
-
- # Asserts that the given unit test was generated.
- # It takes a name or symbol without the <tt>_test</tt> part and an optional super class.
- # The contents of the class source file is passed to a block.
- def assert_generated_unit_test_for(name, parent = "ActiveSupport::TestCase")
- assert_generated_class "test/unit/#{name.to_s.underscore}_test", parent do |body|
- yield body if block_given?
- end
- end
-
- # Asserts that the given file was generated.
- # The contents of the file is passed to a block.
- def assert_generated_file(path)
- assert_file_exists(path)
- File.open("#{RAILS_ROOT}/#{path}") do |f|
- yield f.read if block_given?
- end
- end
-
- # asserts that the given file exists
- def assert_file_exists(path)
- assert File.exist?("#{RAILS_ROOT}/#{path}"),
- "The file '#{RAILS_ROOT}/#{path}' should exist"
- end
-
- # Asserts that the given class source file was generated.
- # It takes a path without the <tt>.rb</tt> part and an optional super class.
- # The contents of the class source file is passed to a block.
- def assert_generated_class(path, parent = nil, class_name = class_name_from_path(path))
- assert_generated_file("#{path}.rb") do |body|
- assert_match /class #{class_name}#{parent.nil? ? '':" < #{parent}"}/, body, "the file '#{path}.rb' should be a class"
- yield body if block_given?
- end
- end
-
- def class_name_from_path(path)
- # FIXME: Sucky way to detect namespaced classes
- if path.split('/').size > 3
- path =~ /\/?(\d+_)?(\w+)\/(\w+)$/
- "#{$2.camelize}::#{$3.camelize}"
- else
- path =~ /\/?(\d+_)?(\w+)$/
- $2.camelize
- end
- end
-
- # Asserts that the given module source file was generated.
- # It takes a path without the <tt>.rb</tt> part.
- # The contents of the class source file is passed to a block.
- def assert_generated_module(path)
- # FIXME: Sucky way to detect namespaced modules
- if path.split('/').size > 3
- path =~ /\/?(\w+)\/(\w+)$/
- module_name = "#{$1.camelize}::#{$2.camelize}"
- else
- path =~ /\/?(\w+)$/
- module_name = $1.camelize
+ def capture(stream)
+ begin
+ stream = stream.to_s
+ eval "$#{stream} = StringIO.new"
+ yield
+ result = eval("$#{stream}").string
+ ensure
+ eval("$#{stream} = #{stream.upcase}")
end
- assert_generated_file("#{path}.rb") do |body|
- assert_match /module #{module_name}/, body, "the file '#{path}.rb' should be a module"
- yield body if block_given?
- end
- end
-
- # Asserts that the given CSS stylesheet file was generated.
- # It takes a path without the <tt>.css</tt> part.
- # The contents of the stylesheet source file is passed to a block.
- def assert_generated_stylesheet(path)
- assert_generated_file("public/stylesheets/#{path}.css") do |body|
- yield body if block_given?
- end
- end
-
- # Asserts that the given YAML file was generated.
- # It takes a path without the <tt>.yml</tt> part.
- # The parsed YAML tree is passed to a block.
- def assert_generated_yaml(path)
- assert_generated_file("#{path}.yml") do |body|
- yaml = YAML.load(body)
- assert yaml, 'YAML data missing'
- yield yaml if block_given?
- end
- end
-
- # Asserts that the given fixtures YAML file was generated.
- # It takes a fixture name without the <tt>.yml</tt> part.
- # The parsed YAML tree is passed to a block.
- def assert_generated_fixtures_for(name)
- assert_generated_yaml "test/fixtures/#{name.to_s.underscore}" do |yaml|
- yield yaml if block_given?
- end
+ result
end
+ alias :silence :capture
- # Asserts that the given views were generated.
- # It takes a controller name and a list of views (including extensions).
- # The body of each view is passed to a block.
- def assert_generated_views_for(name, *actions)
- actions.each do |action|
- assert_generated_file("app/views/#{name.to_s.underscore}/#{action}") do |body|
- yield body if block_given?
- end
- end
- end
-
- def assert_generated_migration(name, parent = "ActiveRecord::Migration")
- file = Dir.glob("#{RAILS_ROOT}/db/migrate/*_#{name.to_s.underscore}.rb").first
- file = file.match(/db\/migrate\/[0-9]+_\w+/).to_s
- assert_generated_class file, parent do |body|
- assert_match /timestamps/, body, "should have timestamps defined"
- yield body if block_given?
- end
- end
-
- # Asserts that the given migration file was not generated.
- # It takes the name of the migration as a parameter.
- def assert_skipped_migration(name)
- migration_file = "#{RAILS_ROOT}/db/migrate/001_#{name.to_s.underscore}.rb"
- assert !File.exist?(migration_file), "should not create migration #{migration_file}"
- end
-
- # Asserts that the given resource was added to the routes.
- def assert_added_route_for(name)
- assert_generated_file("config/routes.rb") do |body|
- assert_match /map.resources :#{name.to_s.underscore}/, body,
- "should add route for :#{name.to_s.underscore}"
- end
- end
+ def assert_file(relative, content=nil)
+ absolute = File.join(destination_root, relative)
+ assert File.exists?(absolute)
- # Asserts that the given methods are defined in the body.
- # This does assume standard rails code conventions with regards to the source code.
- # The body of each individual method is passed to a block.
- def assert_has_method(body, *methods)
- methods.each do |name|
- assert body =~ /^ def #{name}(\(.+\))?\n((\n| .*\n)*) end/, "should have method #{name}"
- yield(name, $2) if block_given?
+ case content
+ when String
+ assert_equal content, File.read(absolute)
+ when Regexp
+ assert_match content, File.read(absolute)
end
end
- # Asserts that the given column is defined in the migration.
- def assert_generated_column(body, name, type)
- assert_match /t\.#{type.to_s} :#{name.to_s}/, body, "should have column #{name.to_s} defined"
+ def assert_no_file(relative, content=nil)
+ absolute = File.join(destination_root, relative)
+ assert !File.exists?(absolute)
end
end
diff --git a/railties/test/rails_generator/generator_test_helper.rb b/railties/test/rails_generator/generator_test_helper.rb
new file mode 100644
index 0000000000..01bf1c90bd
--- /dev/null
+++ b/railties/test/rails_generator/generator_test_helper.rb
@@ -0,0 +1,303 @@
+require 'test/unit'
+require 'fileutils'
+
+# Mock out what we need from AR::Base
+module ActiveRecord
+ class Base
+ class << self
+ attr_accessor :pluralize_table_names, :timestamped_migrations
+ end
+ self.pluralize_table_names = true
+ self.timestamped_migrations = true
+ end
+
+ module ConnectionAdapters
+ class Column
+ attr_reader :name, :default, :type, :limit, :null, :sql_type, :precision, :scale
+
+ def initialize(name, default, sql_type = nil)
+ @name = name
+ @default = default
+ @type = @sql_type = sql_type
+ end
+
+ def human_name
+ @name.humanize
+ end
+ end
+ end
+end
+
+# Mock up necessities from ActionView
+module ActionView
+ module Helpers
+ module ActionRecordHelper; end
+ class InstanceTag; end
+ end
+end
+
+# Set RAILS_ROOT appropriately fixture generation
+tmp_dir = "#{File.dirname(__FILE__)}/../fixtures/tmp"
+
+if defined? RAILS_ROOT
+ RAILS_ROOT.replace tmp_dir
+else
+ RAILS_ROOT = tmp_dir
+end
+FileUtils.mkdir_p RAILS_ROOT
+
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
+require 'initializer'
+
+# Mocks out the configuration
+module Rails
+ def self.configuration
+ Rails::Configuration.new
+ end
+end
+
+require 'rails_generator'
+
+class GeneratorTestCase < Test::Unit::TestCase
+ include FileUtils
+
+ def setup
+ ActiveRecord::Base.pluralize_table_names = true
+
+ mkdir_p "#{RAILS_ROOT}/app/views/layouts"
+ mkdir_p "#{RAILS_ROOT}/config"
+ mkdir_p "#{RAILS_ROOT}/db"
+ mkdir_p "#{RAILS_ROOT}/test/fixtures"
+ mkdir_p "#{RAILS_ROOT}/public/stylesheets"
+
+ File.open("#{RAILS_ROOT}/config/routes.rb", 'w') do |f|
+ f << "ActionController::Routing::Routes.draw do |map|\n\nend"
+ end
+ end
+
+ def teardown
+ rm_rf "#{RAILS_ROOT}/app"
+ rm_rf "#{RAILS_ROOT}/test"
+ rm_rf "#{RAILS_ROOT}/config"
+ rm_rf "#{RAILS_ROOT}/db"
+ rm_rf "#{RAILS_ROOT}/public"
+ end
+
+ def test_truth
+ # don't complain, test/unit
+ end
+
+ # Instantiates the Generator.
+ def build_generator(name, params)
+ Rails::Generator::Base.instance(name, params)
+ end
+
+ # Runs the +create+ command (like the command line does).
+ def run_generator(name, params)
+ silence_generator do
+ build_generator(name, params).command(:create).invoke!
+ end
+ end
+
+ # Silences the logger temporarily and returns the output as a String.
+ def silence_generator
+ logger_original = Rails::Generator::Base.logger
+ myout = StringIO.new
+ Rails::Generator::Base.logger = Rails::Generator::SimpleLogger.new(myout)
+ yield if block_given?
+ Rails::Generator::Base.logger = logger_original
+ myout.string
+ end
+
+ # Asserts that the given controller was generated.
+ # It takes a name or symbol without the <tt>_controller</tt> part and an optional super class.
+ # The contents of the class source file is passed to a block.
+ def assert_generated_controller_for(name, parent = "ApplicationController")
+ assert_generated_class "app/controllers/#{name.to_s.underscore}_controller", parent do |body|
+ yield body if block_given?
+ end
+ end
+
+ # Asserts that the given model was generated.
+ # It takes a name or symbol and an optional super class.
+ # The contents of the class source file is passed to a block.
+ def assert_generated_model_for(name, parent = "ActiveRecord::Base")
+ assert_generated_class "app/models/#{name.to_s.underscore}", parent do |body|
+ yield body if block_given?
+ end
+ end
+
+ # Asserts that the given helper was generated.
+ # It takes a name or symbol without the <tt>_helper</tt> part.
+ # The contents of the module source file is passed to a block.
+ def assert_generated_helper_for(name)
+ assert_generated_module "app/helpers/#{name.to_s.underscore}_helper" do |body|
+ yield body if block_given?
+ end
+ end
+
+ # Asserts that the given functional test was generated.
+ # It takes a name or symbol without the <tt>_controller_test</tt> part and an optional super class.
+ # The contents of the class source file is passed to a block.
+ def assert_generated_functional_test_for(name, parent = "ActionController::TestCase")
+ assert_generated_class "test/functional/#{name.to_s.underscore}_controller_test",parent do |body|
+ yield body if block_given?
+ end
+ end
+
+ # Asserts that the given helper test test was generated.
+ # It takes a name or symbol without the <tt>_helper_test</tt> part and an optional super class.
+ # The contents of the class source file is passed to a block.
+ def assert_generated_helper_test_for(name, parent = "ActionView::TestCase")
+ path = "test/unit/helpers/#{name.to_s.underscore}_helper_test"
+ # Have to pass the path without the "test/" part so that class_name_from_path will return a correct result
+ class_name = class_name_from_path(path.gsub(/^test\//, ''))
+
+ assert_generated_class path,parent,class_name do |body|
+ yield body if block_given?
+ end
+ end
+
+ # Asserts that the given unit test was generated.
+ # It takes a name or symbol without the <tt>_test</tt> part and an optional super class.
+ # The contents of the class source file is passed to a block.
+ def assert_generated_unit_test_for(name, parent = "ActiveSupport::TestCase")
+ assert_generated_class "test/unit/#{name.to_s.underscore}_test", parent do |body|
+ yield body if block_given?
+ end
+ end
+
+ # Asserts that the given file was generated.
+ # The contents of the file is passed to a block.
+ def assert_generated_file(path)
+ assert_file_exists(path)
+ File.open("#{RAILS_ROOT}/#{path}") do |f|
+ yield f.read if block_given?
+ end
+ end
+
+ # asserts that the given file exists
+ def assert_file_exists(path)
+ assert File.exist?("#{RAILS_ROOT}/#{path}"),
+ "The file '#{RAILS_ROOT}/#{path}' should exist"
+ end
+
+ # Asserts that the given class source file was generated.
+ # It takes a path without the <tt>.rb</tt> part and an optional super class.
+ # The contents of the class source file is passed to a block.
+ def assert_generated_class(path, parent = nil, class_name = class_name_from_path(path))
+ assert_generated_file("#{path}.rb") do |body|
+ assert_match /class #{class_name}#{parent.nil? ? '':" < #{parent}"}/, body, "the file '#{path}.rb' should be a class"
+ yield body if block_given?
+ end
+ end
+
+ def class_name_from_path(path)
+ # FIXME: Sucky way to detect namespaced classes
+ if path.split('/').size > 3
+ path =~ /\/?(\d+_)?(\w+)\/(\w+)$/
+ "#{$2.camelize}::#{$3.camelize}"
+ else
+ path =~ /\/?(\d+_)?(\w+)$/
+ $2.camelize
+ end
+ end
+
+ # Asserts that the given module source file was generated.
+ # It takes a path without the <tt>.rb</tt> part.
+ # The contents of the class source file is passed to a block.
+ def assert_generated_module(path)
+ # FIXME: Sucky way to detect namespaced modules
+ if path.split('/').size > 3
+ path =~ /\/?(\w+)\/(\w+)$/
+ module_name = "#{$1.camelize}::#{$2.camelize}"
+ else
+ path =~ /\/?(\w+)$/
+ module_name = $1.camelize
+ end
+
+ assert_generated_file("#{path}.rb") do |body|
+ assert_match /module #{module_name}/, body, "the file '#{path}.rb' should be a module"
+ yield body if block_given?
+ end
+ end
+
+ # Asserts that the given CSS stylesheet file was generated.
+ # It takes a path without the <tt>.css</tt> part.
+ # The contents of the stylesheet source file is passed to a block.
+ def assert_generated_stylesheet(path)
+ assert_generated_file("public/stylesheets/#{path}.css") do |body|
+ yield body if block_given?
+ end
+ end
+
+ # Asserts that the given YAML file was generated.
+ # It takes a path without the <tt>.yml</tt> part.
+ # The parsed YAML tree is passed to a block.
+ def assert_generated_yaml(path)
+ assert_generated_file("#{path}.yml") do |body|
+ yaml = YAML.load(body)
+ assert yaml, 'YAML data missing'
+ yield yaml if block_given?
+ end
+ end
+
+ # Asserts that the given fixtures YAML file was generated.
+ # It takes a fixture name without the <tt>.yml</tt> part.
+ # The parsed YAML tree is passed to a block.
+ def assert_generated_fixtures_for(name)
+ assert_generated_yaml "test/fixtures/#{name.to_s.underscore}" do |yaml|
+ yield yaml if block_given?
+ end
+ end
+
+ # Asserts that the given views were generated.
+ # It takes a controller name and a list of views (including extensions).
+ # The body of each view is passed to a block.
+ def assert_generated_views_for(name, *actions)
+ actions.each do |action|
+ assert_generated_file("app/views/#{name.to_s.underscore}/#{action}") do |body|
+ yield body if block_given?
+ end
+ end
+ end
+
+ def assert_generated_migration(name, parent = "ActiveRecord::Migration")
+ file = Dir.glob("#{RAILS_ROOT}/db/migrate/*_#{name.to_s.underscore}.rb").first
+ file = file.match(/db\/migrate\/[0-9]+_\w+/).to_s
+ assert_generated_class file, parent do |body|
+ assert_match /timestamps/, body, "should have timestamps defined"
+ yield body if block_given?
+ end
+ end
+
+ # Asserts that the given migration file was not generated.
+ # It takes the name of the migration as a parameter.
+ def assert_skipped_migration(name)
+ migration_file = "#{RAILS_ROOT}/db/migrate/001_#{name.to_s.underscore}.rb"
+ assert !File.exist?(migration_file), "should not create migration #{migration_file}"
+ end
+
+ # Asserts that the given resource was added to the routes.
+ def assert_added_route_for(name)
+ assert_generated_file("config/routes.rb") do |body|
+ assert_match /map.resources :#{name.to_s.underscore}/, body,
+ "should add route for :#{name.to_s.underscore}"
+ end
+ end
+
+ # Asserts that the given methods are defined in the body.
+ # This does assume standard rails code conventions with regards to the source code.
+ # The body of each individual method is passed to a block.
+ def assert_has_method(body, *methods)
+ methods.each do |name|
+ assert body =~ /^ def #{name}(\(.+\))?\n((\n| .*\n)*) end/, "should have method #{name}"
+ yield(name, $2) if block_given?
+ end
+ end
+
+ # Asserts that the given column is defined in the migration.
+ def assert_generated_column(body, name, type)
+ assert_match /t\.#{type.to_s} :#{name.to_s}/, body, "should have column #{name.to_s} defined"
+ end
+end
diff --git a/railties/test/generators/rails_controller_generator_test.rb b/railties/test/rails_generator/rails_controller_generator_test.rb
index 43fbe972e2..43fbe972e2 100644
--- a/railties/test/generators/rails_controller_generator_test.rb
+++ b/railties/test/rails_generator/rails_controller_generator_test.rb
diff --git a/railties/test/generators/rails_helper_generator_test.rb b/railties/test/rails_generator/rails_helper_generator_test.rb
index 8d05f555e6..8d05f555e6 100644
--- a/railties/test/generators/rails_helper_generator_test.rb
+++ b/railties/test/rails_generator/rails_helper_generator_test.rb
diff --git a/railties/test/generators/rails_mailer_generator_test.rb b/railties/test/rails_generator/rails_mailer_generator_test.rb
index de61e6736d..de61e6736d 100644
--- a/railties/test/generators/rails_mailer_generator_test.rb
+++ b/railties/test/rails_generator/rails_mailer_generator_test.rb
diff --git a/railties/test/generators/rails_model_generator_test.rb b/railties/test/rails_generator/rails_model_generator_test.rb
index aea2abafba..aea2abafba 100644
--- a/railties/test/generators/rails_model_generator_test.rb
+++ b/railties/test/rails_generator/rails_model_generator_test.rb
diff --git a/railties/test/generators/rails_model_subclass_generator_test.rb b/railties/test/rails_generator/rails_model_subclass_generator_test.rb
index 30066b5a3c..30066b5a3c 100644
--- a/railties/test/generators/rails_model_subclass_generator_test.rb
+++ b/railties/test/rails_generator/rails_model_subclass_generator_test.rb
diff --git a/railties/test/generators/rails_resource_generator_test.rb b/railties/test/rails_generator/rails_resource_generator_test.rb
index 1f5bd0ef1e..1f5bd0ef1e 100644
--- a/railties/test/generators/rails_resource_generator_test.rb
+++ b/railties/test/rails_generator/rails_resource_generator_test.rb
diff --git a/railties/test/generators/rails_scaffold_generator_test.rb b/railties/test/rails_generator/rails_scaffold_generator_test.rb
index 70829a77fd..70829a77fd 100644
--- a/railties/test/generators/rails_scaffold_generator_test.rb
+++ b/railties/test/rails_generator/rails_scaffold_generator_test.rb