diff options
Diffstat (limited to 'railties')
21 files changed, 94 insertions, 60 deletions
diff --git a/railties/Rakefile b/railties/Rakefile index 1b469543cc..26fa0bf6a5 100755 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -18,7 +18,7 @@ namespace :test do Dir["test/#{dir}/*_test.rb"].each do |file| next true if file.include?("fixtures") ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME')) - system(ruby, '-Itest', "-I#{File.dirname(__FILE__)}/../activesupport/lib", file) + sh(ruby, '-Itest', "-I#{File.dirname(__FILE__)}/../activesupport/lib", file) end end end diff --git a/railties/guides/rails_guides.rb b/railties/guides/rails_guides.rb index dfbb06cc76..feb5fe3937 100644 --- a/railties/guides/rails_guides.rb +++ b/railties/guides/rails_guides.rb @@ -24,14 +24,14 @@ rescue LoadError end begin - gem 'RedCloth', '>= 4.1.1' require 'redcloth' rescue Gem::LoadError + # This can happen if doc:guides is executed in an application. $stderr.puts('Generating guides requires RedCloth 4.1.1+.') $stderr.puts(<<ERROR) if bundler? Please add - gem 'RedCloth', '>= 4.1.1' + gem 'RedCloth', '~> 4.2' to the Gemfile, run diff --git a/railties/guides/source/contribute.textile b/railties/guides/source/contribute.textile index 3d4607de1d..8d19d78324 100644 --- a/railties/guides/source/contribute.textile +++ b/railties/guides/source/contribute.textile @@ -13,8 +13,8 @@ h3. How to Contribute? * Assets are stored in the +railties/guides/assets+ directory. * Sample format : "Active Record Associations":http://github.com/lifo/docrails/blob/3e56a3832415476fdd1cb963980d0ae390ac1ed3/railties/guides/source/association_basics.textile. * Sample output : "Active Record Associations":association_basics.html. -* You can build the Guides during testing by running +rake generate_guides+ in the +railties+ directory. -* You're encouraged to validate XHTML for the generated guides before commiting your changes by running +rake validate_guides+ in the +railties+ directory. +* You can build the Guides during testing by running +bundle exec rake generate_guides+ in the +railties+ directory. +* You're encouraged to validate XHTML for the generated guides before commiting your changes by running +bundle exec rake validate_guides+ in the +railties+ directory. * Edge guides "can be consulted online":http://edgeguides.rubyonrails.org/. That website is generated periodically from docrails. h3. What to Contribute? diff --git a/railties/guides/source/ruby_on_rails_guides_guidelines.textile b/railties/guides/source/ruby_on_rails_guides_guidelines.textile index 07f86edfb7..6576758856 100644 --- a/railties/guides/source/ruby_on_rails_guides_guidelines.textile +++ b/railties/guides/source/ruby_on_rails_guides_guidelines.textile @@ -45,7 +45,7 @@ h3. HTML Generation To generate all the guides just cd into the +railties+ directory and execute <plain> -rake generate_guides +bundle exec rake generate_guides </plain> You'll need the gems erubis, i18n, and RedCloth. @@ -53,7 +53,7 @@ You'll need the gems erubis, i18n, and RedCloth. To process +my_guide.textile+ and nothing else use the +ONLY+ environment variable: <plain> -rake generate_guides ONLY=my_guide +bundle exec rake generate_guides ONLY=my_guide </plain> Although by default guides that have not been modified are not processed, so +ONLY+ is rarely needed in practice. diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 8cd496781b..c74bcbedf2 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -6,25 +6,28 @@ module Rails class Configuration < ::Rails::Engine::Configuration attr_accessor :allow_concurrency, :asset_host, :cache_classes, :cache_store, :encoding, :consider_all_requests_local, :dependency_loading, - :filter_parameters, :helpers_paths, :log_level, :logger, + :filter_parameters, :helpers_paths, :logger, :preload_frameworks, :reload_plugins, :secret_token, :serve_static_assets, :session_options, :time_zone, :whiny_nils + attr_writer :log_level + def initialize(*) super self.encoding = "utf-8" - @allow_concurrency = false + @allow_concurrency = false @consider_all_requests_local = false - @filter_parameters = [] - @helpers_paths = [] - @dependency_loading = true - @serve_static_assets = true - @session_store = :cookie_store - @session_options = {} - @time_zone = "UTC" - @middleware = app_middleware - @generators = app_generators + @filter_parameters = [] + @helpers_paths = [] + @dependency_loading = true + @serve_static_assets = true + @session_store = :cookie_store + @session_options = {} + @time_zone = "UTC" + @log_level = nil + @middleware = app_middleware + @generators = app_generators end def compiled_asset_path diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 66c4088a68..29e693dfb0 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -155,7 +155,7 @@ module Rails # commands. def self.invoke(namespace, args=ARGV, config={}) names = namespace.to_s.split(':') - if klass = find_by_namespace(names.pop, names.shift) + if klass = find_by_namespace(names.pop, names.any? && names.join(':')) args << "--help" if args.empty? && klass.arguments.any? { |a| a.required? } klass.start(args, config) else diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 7766050632..ab7ed4eb9e 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -112,12 +112,7 @@ module Rails end def database_gemfile_entry - entry = "" - unless options[:skip_active_record] - entry = "gem '#{gem_for_database}'" - entry << ", :require => '#{require_for_database}'" if require_for_database - end - entry + options[:skip_active_record] ? "" : "gem '#{gem_for_database}'" end def rails_gemfile_entry @@ -150,19 +145,12 @@ gem 'rails', '#{Rails::VERSION::STRING}' case options[:database] when "oracle" then "ruby-oci8" when "postgresql" then "pg" - when "sqlite3" then "sqlite3-ruby" when "frontbase" then "ruby-frontbase" when "mysql" then "mysql2" else options[:database] end end - def require_for_database - case options[:database] - when "sqlite3" then "sqlite3" - end - end - def bundle_if_dev_or_edge bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle') run "#{bundle_command} install" if dev_or_edge? diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index f97f3db588..131eb6ff6f 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -274,7 +274,7 @@ module Rails # Use Rails default banner. # def self.banner - "rails generate #{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]" + "rails generate #{namespace.sub(/^rails:/,'')} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]".gsub(/\s+/, ' ') end # Sets the base_name taking into account the current class namespace. diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 86b9e8f40c..7d5a865b80 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -17,7 +17,7 @@ source 'http://rubygems.org' # Bundle the extra gems: # gem 'bj' # gem 'nokogiri' -# gem 'sqlite3-ruby', :require => 'sqlite3' +# gem 'sqlite3' # gem 'aws-s3', :require => 'aws/s3' # Bundle gems for the local environment. Make sure to @@ -26,3 +26,6 @@ source 'http://rubygems.org' # group :development, :test do # gem 'webrat' # end + +# Needed for guides generation +# gem "RedCloth", "~> 4.2" diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml index 025d62a8d8..90d87cc295 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml @@ -1,5 +1,5 @@ # SQLite version 3.x -# gem install sqlite3-ruby (not necessary on OS X Leopard) +# gem install sqlite3 development: adapter: sqlite3 database: db/development.sqlite3 diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 9461589ff5..8b1aed974f 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -16,7 +16,7 @@ module Rails end def readme - copy_file "README.rdoc" + template "README.rdoc" end def gemfile @@ -44,7 +44,7 @@ module Rails end def config - template "config/routes.rb" if mountable? + template "config/routes.rb" if full? end def test diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/config/routes.rb b/railties/lib/rails/generators/rails/plugin_new/templates/config/routes.rb index 42ddf380d8..8e158d5831 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/config/routes.rb +++ b/railties/lib/rails/generators/rails/plugin_new/templates/config/routes.rb @@ -1,3 +1,6 @@ +<% if mountable? -%> <%= camelized %>::Engine.routes.draw do - +<% else -%> +Rails.application.routes.draw do +<% end -%> end diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 8570fc7b3f..d15887f561 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -134,10 +134,10 @@ module Rails @root = root @glob = options[:glob] - autoload_once! if options[:autoload_once] - eager_load! if options[:eager_load] - autoload! if options[:autoload] - load_path! if options[:load_path] + options[:autoload_once] ? autoload_once! : skip_autoload_once! + options[:eager_load] ? eager_load! : skip_eager_load! + options[:autoload] ? autoload! : skip_autoload! + options[:load_path] ? load_path! : skip_load_path! end def children diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb index b3dc1f894c..32acc66f10 100644 --- a/railties/lib/rails/rack/logger.rb +++ b/railties/lib/rails/rack/logger.rb @@ -21,7 +21,7 @@ module Rails request = ActionDispatch::Request.new(env) path = request.fullpath - info "\n\nStarted #{env["REQUEST_METHOD"]} \"#{path}\" " \ + info "\n\nStarted #{request.request_method} \"#{path}\" " \ "for #{request.ip} at #{Time.now.to_default_s}" end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 23cd2378c7..822a6bf032 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -63,5 +63,24 @@ module ApplicationTests RUBY assert_match 'cart GET /cart(.:format)', Dir.chdir(app_path){ `rake routes` } end + + def test_model_and_migration_generator_with_change_syntax + Dir.chdir(app_path) do + `rails generate model user username:string password:string` + `rails generate migration add_email_to_users email:string` + end + + output = Dir.chdir(app_path){ `rake db:migrate` } + assert_match /create_table\(:users\)/, output + assert_match /CreateUsers: migrated/, output + assert_match /add_column\(:users, :email, :string\)/, output + assert_match /AddEmailToUsers: migrated/, output + + output = Dir.chdir(app_path){ `rake db:rollback STEP=2` } + assert_match /drop_table\("users"\)/, output + assert_match /CreateUsers: reverted/, output + assert_match /remove_column\("users", :email\)/, output + assert_match /AddEmailToUsers: reverted/, output + end end end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 0fe5cdc4a8..28b20d4206 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -106,7 +106,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_config_database_is_added_by_default run_generator assert_file "config/database.yml", /sqlite3/ - assert_file "Gemfile", /^gem\s+["']sqlite3-ruby["'],\s+:require\s+=>\s+["']sqlite3["']$/ + assert_file "Gemfile", /^gem\s+["']sqlite3["']$/ end def test_config_another_database diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 288ec30460..6eecfc8e2e 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -34,15 +34,10 @@ class MigrationGeneratorTest < Rails::Generators::TestCase run_generator [migration, "title:string", "body:text"] assert_migration "db/migrate/#{migration}.rb" do |content| - assert_method :up, content do |up| + assert_method :change, content do |up| assert_match /add_column :posts, :title, :string/, up assert_match /add_column :posts, :body, :text/, up end - - assert_method :down, content do |down| - assert_match /remove_column :posts, :title/, down - assert_match /remove_column :posts, :body/, down - end end end diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 552b7eb30a..b86859666e 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -99,15 +99,11 @@ class ModelGeneratorTest < Rails::Generators::TestCase run_generator ["product", "name:string", "supplier_id:integer"] assert_migration "db/migrate/create_products.rb" do |m| - assert_method :up, m do |up| + assert_method :change, m do |up| assert_match /create_table :products/, up assert_match /t\.string :name/, up assert_match /t\.integer :supplier_id/, up end - - assert_method :down, m do |down| - assert_match /drop_table :products/, down - end end end @@ -141,7 +137,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase run_generator ["account", "--no-timestamps"] assert_migration "db/migrate/create_accounts.rb" do |m| - assert_method :up, m do |up| + assert_method :change, m do |up| assert_no_match /t.timestamps/, up end end diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 2a9e8046b8..2a8b337144 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -38,8 +38,10 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "things-43/lib/things-43.rb", /module Things43/ end - def test_generating_test_files + def test_generating_without_options run_generator + assert_file "README.rdoc", /Bukkits/ + assert_no_file "config/routes.rb" assert_file "test/test_helper.rb" assert_file "test/bukkits_test.rb", /assert_kind_of Module, Bukkits/ end @@ -66,7 +68,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_database_entry_is_assed_by_default_in_full_mode run_generator([destination_root, "--full"]) assert_file "test/dummy/config/database.yml", /sqlite/ - assert_file "Gemfile", /^gem\s+["']sqlite3-ruby["'],\s+:require\s+=>\s+["']sqlite3["']$/ + assert_file "Gemfile", /^gem\s+["']sqlite3["']$/ end def test_config_another_database @@ -151,6 +153,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_creating_engine_in_full_mode run_generator [destination_root, "--full"] + assert_file "config/routes.rb", /Rails.application.routes.draw do/ assert_file "lib/bukkits/engine.rb", /module Bukkits\n class Engine < Rails::Engine\n end\nend/ assert_file "lib/bukkits.rb", /require "bukkits\/engine"/ end diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 346c9ceb9d..99c9d790eb 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -94,6 +94,14 @@ class GeneratorsTest < Rails::Generators::TestCase assert_match /Rails 2\.x generator/, output end + def test_invoke_with_nested_namespaces + model_generator = mock('ModelGenerator') do + expects(:start).with(["Account"], {}) + end + Rails::Generators.expects(:find_by_namespace).with('namespace', 'my:awesome').returns(model_generator) + Rails::Generators.invoke 'my:awesome:namespace', ["Account"] + end + def test_rails_generators_help_with_builtin_information output = capture(:stdout){ Rails::Generators.help } assert_match /Rails:/, output @@ -120,6 +128,16 @@ class GeneratorsTest < Rails::Generators::TestCase assert_match /^ active_record:fixjour$/, output end + def test_default_banner_should_show_generator_namespace + klass = Rails::Generators.find_by_namespace(:foobar) + assert_match /^rails generate foobar:foobar/, klass.banner + end + + def test_default_banner_should_not_show_rails_generator_namespace + klass = Rails::Generators.find_by_namespace(:model) + assert_match /^rails generate model/, klass.banner + end + def test_no_color_sets_proper_shell Rails::Generators.no_color! assert_equal Thor::Shell::Basic, Thor::Base.shell diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index 31ba2eaca2..3eb79d57c8 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -294,7 +294,7 @@ YAML boot_rails - assert_equal %W( + expected_locales = %W( #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml @@ -302,7 +302,13 @@ YAML #{@plugin.path}/config/locales/en.yml #{app_path}/config/locales/en.yml #{app_path}/app/locales/en.yml - ).map { |path| File.expand_path(path) }, I18n.load_path.map { |path| File.expand_path(path) } + ).map { |path| File.expand_path(path) } + + actual_locales = I18n.load_path.map { |path| + File.expand_path(path) + } & expected_locales # remove locales external to Rails + + assert_equal expected_locales, actual_locales assert_equal "2", I18n.t(:foo) assert_equal "1", I18n.t(:bar) |