aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-03-15 19:46:03 +0000
committerPratik Naik <pratiknaik@gmail.com>2010-03-15 19:46:03 +0000
commit03a62f4afedbef8bda72c8fdf9a0092273c0f2b0 (patch)
tree2155b65750757d26e3c8c8e0655ad32cc89d6c2e /railties
parentf53fddf3665e6582768f4ab0c82b286b39e7fb19 (diff)
parenta594a22267bfd3346e00923742c4aa7edad0cef7 (diff)
downloadrails-03a62f4afedbef8bda72c8fdf9a0092273c0f2b0.tar.gz
rails-03a62f4afedbef8bda72c8fdf9a0092273c0f2b0.tar.bz2
rails-03a62f4afedbef8bda72c8fdf9a0092273c0f2b0.zip
Merge remote branch 'mainstream/master'
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/generators/rails/app/app_generator.rb5
-rw-r--r--railties/lib/generators/rails/app/templates/script/rails7
-rw-r--r--railties/lib/rails/commands.rb8
-rw-r--r--railties/lib/rails/generators.rb4
-rw-r--r--railties/test/generators/app_generator_test.rb12
-rw-r--r--railties/test/generators_test.rb18
6 files changed, 44 insertions, 10 deletions
diff --git a/railties/lib/generators/rails/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb
index 92e0d37436..1e1acc1141 100644
--- a/railties/lib/generators/rails/app/app_generator.rb
+++ b/railties/lib/generators/rails/app/app_generator.rb
@@ -178,7 +178,8 @@ module Rails::Generators
end
def bundle_if_dev_or_edge
- run "bundle install" if dev_or_edge?
+ bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
+ run "#{bundle_command} install" if dev_or_edge?
end
protected
@@ -220,6 +221,8 @@ module Rails::Generators
raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers."
elsif RESERVED_NAMES.include?(app_name)
raise Error, "Invalid application name #{app_name}. Please give a name which does not match one of the reserved rails words."
+ elsif Object.const_defined?(app_const_base)
+ raise Error, "Invalid application name #{app_name}, constant #{app_const_base} is already in use. Please choose another application name."
end
end
diff --git a/railties/lib/generators/rails/app/templates/script/rails b/railties/lib/generators/rails/app/templates/script/rails
index 199fe1a6d3..b01d1ee183 100644
--- a/railties/lib/generators/rails/app/templates/script/rails
+++ b/railties/lib/generators/rails/app/templates/script/rails
@@ -1,5 +1,8 @@
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
-ENV_PATH = File.expand_path('../../config/environment', __FILE__)
-require File.expand_path('../../config/boot', __FILE__)
+ENV_PATH = File.expand_path('../../config/environment', __FILE__)
+BOOT_PATH = File.expand_path('../../config/boot', __FILE__)
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+
+require BOOT_PATH
require 'rails/commands'
diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb
index d4558be00f..12748da18b 100644
--- a/railties/lib/rails/commands.rb
+++ b/railties/lib/rails/commands.rb
@@ -34,13 +34,15 @@ when 'c', 'console'
Rails::Console.start(Rails::Application)
when 's', 'server'
require 'rails/commands/server'
+ # Initialize the server first, so environment options are set
server = Rails::Server.new
- require ENV_PATH
+ require APP_PATH
+
Dir.chdir(Rails::Application.root)
server.start
when 'db', 'dbconsole'
require 'rails/commands/dbconsole'
- require ENV_PATH
+ require APP_PATH
Rails::DBConsole.start(Rails::Application)
when 'application'
@@ -55,7 +57,7 @@ when 'profiler'
require ENV_PATH
require 'rails/commands/performance/profiler'
when 'plugin'
- require ENV_PATH
+ require APP_PATH
require 'rails/commands/plugin'
when 'runner'
require 'rails/commands/runner'
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 3c902ce0d4..9a51171cf5 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -202,6 +202,10 @@ module Rails
rails.delete("app")
print_list("rails", rails)
+ groups.delete("active_record") if options[:rails][:orm] == :active_record
+ groups.delete("test_unit") if options[:rails][:test_framework] == :test_unit
+ groups.delete("erb") if options[:rails][:template_engine] == :erb
+
groups.sort.each { |b, n| print_list(b, n) }
end
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 412034029e..4fc26563ff 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -9,6 +9,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
def setup
super
Rails::Generators::AppGenerator.instance_variable_set('@desc', nil)
+ @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
end
def teardown
@@ -65,6 +66,13 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_equal "Invalid application name 43-things. Please give a name which does not start with numbers.\n", content
end
+ def test_application_name_raises_an_error_if_name_already_used_constant
+ %w{ String Hash Class Module Set Symbol }.each do |ruby_class|
+ content = capture(:stderr){ run_generator [File.join(destination_root, ruby_class)] }
+ assert_equal "Invalid application name #{ruby_class}, constant #{ruby_class} is already in use. Please choose another application name.\n", content
+ end
+ end
+
def test_invalid_application_name_is_fixed
run_generator [File.join(destination_root, "things-43")]
assert_file "things-43/config/environment.rb", /Things43::Application\.initialize!/
@@ -161,14 +169,14 @@ class AppGeneratorTest < Rails::Generators::TestCase
end
def test_dev_option
- generator([destination_root], :dev => true).expects(:run).with("bundle install")
+ generator([destination_root], :dev => true).expects(:run).with("#{@bundle_command} install")
silence(:stdout){ generator.invoke }
rails_path = File.expand_path('../../..', Rails.root)
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/
end
def test_edge_option
- generator([destination_root], :edge => true).expects(:run).with("bundle install")
+ generator([destination_root], :edge => true).expects(:run).with("#{@bundle_command} install")
silence(:stdout){ generator.invoke }
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$/
end
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index dd17f8f756..2975e3e3ef 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -104,11 +104,25 @@ class GeneratorsTest < Rails::Generators::TestCase
def test_rails_generators_with_others_information
output = capture(:stdout){ Rails::Generators.help }
- assert_match /ActiveRecord:/, output
assert_match /Fixjour:/, output
+ assert_match /^ fixjour$/, output
+ end
+
+ def test_rails_generators_does_not_show_activerecord_info_if_its_the_default
+ output = capture(:stdout){ Rails::Generators.help }
+ assert_no_match /ActiveRecord:/, output
+ assert_no_match /^ active_record:model$/, output
+ assert_no_match /^ active_record:fixjour$/, output
+ end
+
+ def test_rails_generators_shows_activerecord_info_if_its_not_the_default
+ Rails::Generators.options[:rails][:orm] = :data_mapper
+ output = capture(:stdout){ Rails::Generators.help }
+ assert_match /ActiveRecord:/, output
assert_match /^ active_record:model$/, output
assert_match /^ active_record:fixjour$/, output
- assert_match /^ fixjour$/, output
+ ensure
+ Rails::Generators.options[:rails][:orm] = :active_record
end
def test_no_color_sets_proper_shell