diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index ef5399e48f..22a27fdac2 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -3,6 +3,10 @@ require 'active_support/secure_random' require 'rails/version' unless defined?(Rails::VERSION) module Rails::Generators + # We need to store the RAILS_DEV_PATH in a constant, otherwise the path + # can change in Ruby 1.8.7 when we FileUtils.cd. + RAILS_DEV_PATH = File.expand_path("../../../../../..", File.dirname(__FILE__)) + class AppGenerator < Base DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db ) add_shebang_option! @@ -15,17 +19,22 @@ module Rails::Generators class_option :template, :type => :string, :aliases => "-m", :desc => "Path to an application template (can be a filesystem path or URL)." + class_option :dev, :type => :boolean, :default => false, + :desc => "Setup the application with Gemfile pointing to your Rails checkout" + + class_option :edge, :type => :boolean, :default => false, + :desc => "Setup the application with Gemfile pointing to Rails repository" + class_option :skip_activerecord, :type => :boolean, :aliases => "-O", :default => false, - :desc => "Skip ActiveRecord files" + :desc => "Skip ActiveRecord files" class_option :skip_testunit, :type => :boolean, :aliases => "-T", :default => false, - :desc => "Skip TestUnit files" + :desc => "Skip TestUnit files" class_option :skip_prototype, :type => :boolean, :aliases => "-J", :default => false, - :desc => "Skip Prototype files" + :desc => "Skip Prototype files" - # Add Rails options - # + # Add bin/rails options class_option :version, :type => :boolean, :aliases => "-v", :group => :rails, :desc => "Show Rails version number and quit" @@ -173,7 +182,6 @@ module Rails::Generators end # Define file as an alias to create_file for backwards compatibility. - # def file(*args, &block) create_file(*args, &block) end @@ -190,6 +198,10 @@ module Rails::Generators ActiveSupport::SecureRandom.hex(64) end + def dev_or_edge? + options.dev? || options.edge? + end + def self.banner "#{$0} #{self.arguments.map(&:usage).join(' ')} [options]" end diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 8e851a64e7..59c6d333e2 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -1,9 +1,14 @@ # Edit this Gemfile to bundle your application's dependencies. - +<% if !dev_or_edge? %> gem "rails", "<%= Rails::VERSION::STRING %>" +<% end -%> ## Bundle edge rails: -# gem "rails", :git => "git://github.com/rails/rails.git" +<%- if options.dev? -%> +gem "rails", :path => "<%= Rails::Generators::RAILS_DEV_PATH %>" +<%- else -%> +<%= "# " unless options.edge? %>gem "rails", :git => "git://github.com/rails/rails.git" +<%- end -%> ## Bundle the gems you use: # gem "bj" diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 10d0bc6bc2..567555fdc5 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -149,6 +149,19 @@ class AppGeneratorTest < GeneratorsTestCase assert_file 'lib/test_file.rb', 'heres test data' end + def test_dev_option + run_generator ["--dev"] + rails_path = File.expand_path('../../..', Rails.root) + dev_gem = %(gem "rails", :path => #{rails_path.inspect}) + assert_file 'Gemfile', /^#{Regexp.escape(dev_gem)}$/ + end + + def test_edge_option + run_generator ["--edge"] + edge_gem = %(gem "rails", :git => "git://github.com/rails/rails.git") + assert_file 'Gemfile', /^#{Regexp.escape(edge_gem)}$/ + end + protected def run_generator(args=[])