diff options
Diffstat (limited to 'railties')
23 files changed, 294 insertions, 130 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 61924745c8..c33a4d11dd 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,3 +1,9 @@ +*Rails 3.0.0 [Release Candidate] (unreleased)* + +* Abort generation/booting on Ruby 1.9.1. [fxn] +* Made the rails command work even when you're in a subdirectory [Chad Fowler] + + *Rails 3.0.0 [beta 4] (June 8th, 2010)* * Version bump diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index 41ea5d5822..cc6b84b814 100644 --- a/railties/guides/source/3_0_release_notes.textile +++ b/railties/guides/source/3_0_release_notes.textile @@ -32,11 +32,11 @@ h3. Upgrading to Rails 3 If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 2.3.5 and make sure your application still runs as expected before attempting to update to Rails 3. Then take heed of the following changes: -h4. Rails 3 requires Ruby 1.8.7+ +h4. Rails 3 requires at least Ruby 1.8.7 Rails 3.0 requires Ruby 1.8.7 or higher. Support for all of the previous Ruby versions has been dropped officially and you should upgrade as early as possible. Rails 3.0 is also compatible with Ruby 1.9.2. -TIP: Note that Ruby 1.8.7 p248 and p249 has marshaling bugs that crash Rails 3.0.0. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults on Rails 3.0.0, so if you want to use Rails 3 with 1.9.x jump on 1.9.2 for smooth sailing. +TIP: Note that Ruby 1.8.7 p248 and p249 has marshaling bugs that crash Rails 3.0. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults on Rails 3.0, so if you want to use Rails 3 with 1.9.x jump on 1.9.2 for smooth sailing. h4. Rails Application object diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 6edf07fd65..7d01759446 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -17,7 +17,7 @@ This guide is designed for beginners who want to get started with a Rails applic * The "Ruby":http://www.ruby-lang.org/en/downloads language version 1.8.7 or higher -TIP: Note that Ruby 1.8.7 p248 and p249 has marshaling bugs that crash Rails 3.0.0. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults on Rails 3.0.0, so if you want to use Rails 3 with 1.9.x jump on 1.9.2 for smooth sailing. +TIP: Note that Ruby 1.8.7 p248 and p249 has marshaling bugs that crash Rails 3.0. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults on Rails 3.0, so if you want to use Rails 3 with 1.9.x jump on 1.9.2 for smooth sailing. * The "RubyGems":http://rubyforge.org/frs/?group_id=126 packaging system * A working installation of the "SQLite3 Database":http://www.sqlite.org diff --git a/railties/lib/rails/cli.rb b/railties/lib/rails/cli.rb index 173f122445..d49431919d 100644 --- a/railties/lib/rails/cli.rb +++ b/railties/lib/rails/cli.rb @@ -1,23 +1,5 @@ require 'rbconfig' - -module Rails - module ScriptRailsLoader - RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"] - SCRIPT_RAILS = File.join('script', 'rails') - - def self.exec_script_rails! - cwd = Dir.pwd - exec RUBY, SCRIPT_RAILS, *ARGV if File.exists?(SCRIPT_RAILS) - Dir.chdir("..") do - # Recurse in a chdir block: if the search fails we want to be sure - # the application is generated in the original working directory. - exec_script_rails! unless cwd == Dir.pwd - end - rescue SystemCallError - # could not chdir, no problem just return - end - end -end +require 'rails/script_rails_loader' Rails::ScriptRailsLoader.exec_script_rails! diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index f01934f946..3b9fff2f4a 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -1,3 +1,5 @@ +require 'active_support/time' + module Rails module Generators class GeneratedAttribute @@ -13,7 +15,6 @@ module Rails when :time then :time_select when :datetime, :timestamp then :datetime_select when :date then :date_select - when :string then :text_field when :text then :text_area when :boolean then :check_box else diff --git a/railties/lib/rails/generators/rails/app/templates/README b/railties/lib/rails/generators/rails/app/templates/README index b8c84dd07d..9ec6db6d71 100644 --- a/railties/lib/rails/generators/rails/app/templates/README +++ b/railties/lib/rails/generators/rails/app/templates/README @@ -29,7 +29,7 @@ link:files/vendor/rails/actionpack/README.html. == Getting Started 1. At the command prompt, create a new Rails application: - <tt>rails myapp</tt> (where <tt>myapp</tt> is the application name) + <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name) 2. Change directory to <tt>myapp</tt> and start the web server: <tt>cd myapp; rails server</tt> (run with --help for options) @@ -44,31 +44,6 @@ the following resources handy: * Ruby on Rails Tutorial Book: http://www.railstutorial.org/ -== Web Servers - -By default, Rails will try to use Mongrel if it's installed when started with -<tt>rails server</tt>, otherwise Rails will use WEBrick, the web server that -ships with Ruby. - -Mongrel is a Ruby-based web server with a C component (which requires -compilation) that is suitable for development. If you have Ruby Gems installed, -getting up and running with mongrel is as easy as: - <tt>sudo gem install mongrel</tt>. - -You can find more info at: http://mongrel.rubyforge.org - -You can alternatively run Rails applications with other Ruby web servers, e.g., -{Thin}[http://code.macournoyer.com/thin/], {Ebb}[http://ebb.rubyforge.org/], and -Apache with {mod_rails}[http://www.modrails.com/]. However, <tt>rails server</tt> -doesn't search for or start them. - -For production use, often a web/proxy server, e.g., {Apache}[http://apache.org], -{Nginx}[http://nginx.net/], {LiteSpeed}[http://litespeedtech.com/], -{Lighttpd}[http://www.lighttpd.net/], or {IIS}[http://www.iis.net/], is deployed -as the front end server with the chosen Ruby web server running in the back end -and receiving the proxied requests via one of several protocols (HTTP, CGI, FCGI). - - == Debugging Rails Sometimes your application goes wrong. Fortunately there are a lot of tools that diff --git a/railties/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb b/railties/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb index f2569b3a77..e8065d9505 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb +++ b/railties/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb @@ -1,4 +1,3 @@ class ApplicationController < ActionController::Base protect_from_forgery - layout 'application' end diff --git a/railties/lib/rails/generators/rails/app/templates/public/index.html b/railties/lib/rails/generators/rails/app/templates/public/index.html index 9fb304a66b..c65593e8bc 100644 --- a/railties/lib/rails/generators/rails/app/templates/public/index.html +++ b/railties/lib/rails/generators/rails/app/templates/public/index.html @@ -211,23 +211,6 @@ <div id="sidebar"> <ul id="sidebar-items"> <li> - <form id="search" action="http://www.google.com/search" method="get" onSubmit="prepend();"> - <input type="hidden" name="hl" value="en" /> - <input type="text" id="search-text" name="q" value="site:rubyonrails.org " /> - <input type="submit" value="Search" /> the Rails site - </form> - </li> - - <li> - <h3>Join the community</h3> - <ul class="links"> - <li><a href="http://www.rubyonrails.org/">Ruby on Rails</a></li> - <li><a href="http://weblog.rubyonrails.org/">Official weblog</a></li> - <li><a href="http://wiki.rubyonrails.org/">Wiki</a></li> - </ul> - </li> - - <li> <h3>Browse the documentation</h3> <ul class="links"> <li><a href="http://api.rubyonrails.org/">Rails API</a></li> diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb index 952400e049..0dfb5cd1c9 100644 --- a/railties/lib/rails/generators/test_case.rb +++ b/railties/lib/rails/generators/test_case.rb @@ -189,18 +189,23 @@ module Rails end alias :assert_method :assert_instance_method - # Asserts the given field name gets translated to an attribute type - # properly. + # Asserts the given attribute type gets translated to a field type + # properly: # # assert_field_type :date, :date_select # - def assert_field_type(name, attribute_type) - assert_equal( - Rails::Generators::GeneratedAttribute.new('test', name.to_s).field_type, - attribute_type - ) + def assert_field_type(attribute_type, field_type) + assert_equal(field_type, create_generated_attribute(attribute_type).field_type) end - + + # Asserts the given attribute type gets a proper default value: + # + # assert_field_type :string, "MyString" + # + def assert_field_default_value(attribute_type, value) + assert_equal(value, create_generated_attribute(attribute_type).default) + end + # Runs the generator configured for this class. The first argument is an array like # command line arguments: # @@ -226,6 +231,15 @@ module Rails @generator ||= self.generator_class.new(args, options, config.reverse_merge(:destination_root => destination_root)) end + # Create a Rails::Generators::GeneratedAttribute by supplying the + # attribute type and, optionally, the attribute name: + # + # create_generated_attribute(:string, 'name') + # + def create_generated_attribute(attribute_type, name = 'test') + Rails::Generators::GeneratedAttribute.new(name, attribute_type.to_s) + end + protected def destination_root_is_set? #:nodoc: diff --git a/railties/lib/rails/ruby_version_check.rb b/railties/lib/rails/ruby_version_check.rb index 62d7804bf3..3b37c41c29 100644 --- a/railties/lib/rails/ruby_version_check.rb +++ b/railties/lib/rails/ruby_version_check.rb @@ -7,4 +7,10 @@ if ruby_release < min_release You're running #{ruby_release}; please upgrade to continue. end_message +elsif RUBY_VERSION == '1.9.1' + abort <<-EOS + + Rails 3 does not work with Ruby 1.9.1. Please upgrade to 1.9.2. + + EOS end diff --git a/railties/lib/rails/script_rails_loader.rb b/railties/lib/rails/script_rails_loader.rb new file mode 100644 index 0000000000..8fbd3bf492 --- /dev/null +++ b/railties/lib/rails/script_rails_loader.rb @@ -0,0 +1,28 @@ +require 'pathname' + +module Rails + module ScriptRailsLoader + RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"] + SCRIPT_RAILS = File.join('script', 'rails') + + def self.exec_script_rails! + cwd = Dir.pwd + exec RUBY, SCRIPT_RAILS, *ARGV if in_rails_application? + Dir.chdir("..") do + # Recurse in a chdir block: if the search fails we want to be sure + # the application is generated in the original working directory. + exec_script_rails! unless cwd == Dir.pwd + end + rescue SystemCallError + # could not chdir, no problem just return + end + + def self.in_rails_application? + File.exists?(SCRIPT_RAILS) || in_rails_application_subdirectory? + end + + def self.in_rails_application_subdirectory?(path = Pathname.new(Dir.pwd)) + File.exists?(File.join(path, SCRIPT_RAILS)) || !path.root? && in_rails_application_subdirectory?(path.parent) + end + end +end
\ No newline at end of file diff --git a/railties/lib/rails/tasks/annotations.rake b/railties/lib/rails/tasks/annotations.rake index 10a9311b2d..9067b03d00 100644 --- a/railties/lib/rails/tasks/annotations.rake +++ b/railties/lib/rails/tasks/annotations.rake @@ -1,13 +1,13 @@ require 'rails/source_annotation_extractor' -desc "Enumerate all annotations" +desc "Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)" task :notes do SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", :tag => true end namespace :notes do ["OPTIMIZE", "FIXME", "TODO"].each do |annotation| - desc "Enumerate all #{annotation} annotations" + # desc "Enumerate all #{annotation} annotations" task annotation.downcase.intern do SourceAnnotationExtractor.enumerate annotation end diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake index 19d1fd2354..492f05e3cc 100644 --- a/railties/lib/rails/tasks/documentation.rake +++ b/railties/lib/rails/tasks/documentation.rake @@ -1,13 +1,43 @@ require 'rake/rdoctask' +# Monkey-patch to remove redoc'ing and clobber descriptions to cut down on rake -T noise +class RDocTaskWithoutDescriptions < Rake::RDocTask + def define + task rdoc_task_name + + task rerdoc_task_name => [clobber_task_name, rdoc_task_name] + + task clobber_task_name do + rm_r rdoc_dir rescue nil + end + + task :clobber => [clobber_task_name] + + directory @rdoc_dir + task rdoc_task_name => [rdoc_target] + file rdoc_target => @rdoc_files + [Rake.application.rakefile] do + rm_r @rdoc_dir rescue nil + @before_running_rdoc.call if @before_running_rdoc + args = option_list + @rdoc_files + if @external + argstring = args.join(' ') + sh %{ruby -Ivendor vendor/rd #{argstring}} + else + require 'rdoc/rdoc' + RDoc::RDoc.new.document(args) + end + end + self + end +end + namespace :doc do def gem_path(gem_name) path = $LOAD_PATH.grep(/#{gem_name}[\w.-]*\/lib$/).first yield File.dirname(path) if path end - desc "Generate documentation for the application. Set custom template with TEMPLATE=/path/to/rdoc/template.rb or title with TITLE=\"Custom Title\"" - Rake::RDocTask.new("app") { |rdoc| + RDocTaskWithoutDescriptions.new("app") { |rdoc| rdoc.rdoc_dir = 'doc/app' rdoc.template = ENV['template'] if ENV['template'] rdoc.title = ENV['title'] || "Rails Application Documentation" @@ -17,9 +47,10 @@ namespace :doc do rdoc.rdoc_files.include('app/**/*.rb') rdoc.rdoc_files.include('lib/**/*.rb') } + Rake::Task['doc:app'].comment = "Generate docs for the app -- also availble doc:rails, doc:guides, doc:plugins (options: TEMPLATE=/rdoc-template.rb, TITLE=\"Custom Title\")" - desc 'Generate documentation for the Rails framework.' - Rake::RDocTask.new("rails") { |rdoc| + # desc 'Generate documentation for the Rails framework.' + RDocTaskWithoutDescriptions.new("rails") { |rdoc| rdoc.rdoc_dir = 'doc/api' rdoc.template = "#{ENV['template']}.rb" if ENV['template'] rdoc.title = "Rails Framework Documentation" @@ -71,15 +102,15 @@ namespace :doc do plugins = FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) } - desc "Generate documentation for all installed plugins" + # desc "Generate documentation for all installed plugins" task :plugins => plugins.collect { |plugin| "doc:plugins:#{plugin}" } - desc "Remove plugin documentation" + # desc "Remove plugin documentation" task :clobber_plugins do rm_rf 'doc/plugins' rescue nil end - desc "Generate Rails guides" + # desc "Generate Rails Guides" task :guides do # FIXME: Reaching outside lib directory is a bad idea require File.expand_path('../../../../guides/rails_guides', __FILE__) @@ -89,7 +120,7 @@ namespace :doc do namespace :plugins do # Define doc tasks for each plugin plugins.each do |plugin| - desc "Generate documentation for the #{plugin} plugin" + # desc "Generate documentation for the #{plugin} plugin" task(plugin => :environment) do plugin_base = "vendor/plugins/#{plugin}" options = [] diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index ac510eee2e..e7bd0c38dc 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -1,22 +1,22 @@ namespace :rails do namespace :freeze do - desc "The rails:freeze:gems is deprecated, please use bundle install instead" + # desc "The rails:freeze:gems is deprecated, please use bundle install instead" task :gems do abort "The rails:freeze:gems is deprecated, please use bundle install instead" end - desc 'The freeze:edge command has been deprecated, specify the path setting in your app Gemfile instead and bundle install' + # desc 'The freeze:edge command has been deprecated, specify the path setting in your app Gemfile instead and bundle install' task :edge do abort 'The freeze:edge command has been deprecated, specify the path setting in your app Gemfile instead and bundle install' end end - desc 'The unfreeze command has been deprecated, please use bundler commands instead' + # desc 'The unfreeze command has been deprecated, please use bundler commands instead' task :unfreeze do abort 'The unfreeze command has been deprecated, please use bundler commands instead' end - desc "Update both configs, scripts and public/javascripts from Rails" + desc "Update both configs and public/javascripts from Rails (or use just update:javascripts or update:configs)" task :update => [ "update:configs", "update:javascripts", "update:scripts", "update:application_controller" ] desc "Applies the template supplied by LOCATION=/path/to/template" @@ -31,7 +31,7 @@ namespace :rails do end namespace :templates do - desc "Copy all the templates from rails to the application directory for customization. Already existing local copies will be overwritten" + # desc "Copy all the templates from rails to the application directory for customization. Already existing local copies will be overwritten" task :copy do generators_lib = File.expand_path("../../generators", __FILE__) project_templates = "#{Rails.root}/lib/templates" @@ -69,23 +69,23 @@ namespace :rails do end end - desc "Update config/boot.rb from your current rails install" + # desc "Update config/boot.rb from your current rails install" task :configs do invoke_from_app_generator :create_boot_file invoke_from_app_generator :create_config_files end - desc "Update Prototype javascripts from your current rails install" + # desc "Update Prototype javascripts from your current rails install" task :javascripts do invoke_from_app_generator :create_prototype_files end - desc "Adds new scripts to the application script/ directory" + # desc "Adds new scripts to the application script/ directory" task :scripts do invoke_from_app_generator :create_script_files end - desc "Rename application.rb to application_controller.rb" + # desc "Rename application.rb to application_controller.rb" task :application_controller do old_style = Rails.root + '/app/controllers/application.rb' new_style = Rails.root + '/app/controllers/application_controller.rb' diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake index 0926707a04..c6c22d83bf 100644 --- a/railties/lib/rails/tasks/misc.rake +++ b/railties/lib/rails/tasks/misc.rake @@ -7,30 +7,30 @@ task :rails_env do end end -desc 'Generate a crytographically secure secret key. This is typically used to generate a secret for cookie sessions.' +desc 'Generate a crytographically secure secret key (this is typically used to generate a secret for cookie sessions).' task :secret do require 'active_support/secure_random' puts ActiveSupport::SecureRandom.hex(64) end -desc 'Explain the current environment' +desc 'List versions of all Rails frameworks and the environment' task :about do puts Rails::Info end namespace :time do namespace :zones do - desc 'Displays names of all time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6' + desc 'Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6' task :all do build_time_zone_list(:all) end - desc 'Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6' + # desc 'Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6' task :us do build_time_zone_list(:us_zones) end - desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time' + # desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time' task :local do require 'active_support' require 'active_support/time' diff --git a/railties/lib/rails/tasks/tmp.rake b/railties/lib/rails/tasks/tmp.rake index fea15058bb..3ee5452475 100644 --- a/railties/lib/rails/tasks/tmp.rake +++ b/railties/lib/rails/tasks/tmp.rake @@ -1,5 +1,5 @@ namespace :tmp do - desc "Clear session, cache, and socket files from tmp/" + desc "Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear)" task :clear => [ "tmp:sessions:clear", "tmp:cache:clear", "tmp:sockets:clear"] desc "Creates tmp directories for sessions, cache, sockets, and pids" @@ -8,28 +8,28 @@ namespace :tmp do end namespace :sessions do - desc "Clears all files in tmp/sessions" + # desc "Clears all files in tmp/sessions" task :clear do FileUtils.rm(Dir['tmp/sessions/[^.]*']) end end namespace :cache do - desc "Clears all files and directories in tmp/cache" + # desc "Clears all files and directories in tmp/cache" task :clear do FileUtils.rm_rf(Dir['tmp/cache/[^.]*']) end end namespace :sockets do - desc "Clears all files in tmp/sockets" + # desc "Clears all files in tmp/sockets" task :clear do FileUtils.rm(Dir['tmp/sockets/[^.]*']) end end namespace :pids do - desc "Clears all files in tmp/pids" + # desc "Clears all files in tmp/pids" task :clear do FileUtils.rm(Dir['tmp/pids/[^.]*']) end diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 79fa667ed1..4bddf7600a 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -1,5 +1,35 @@ require 'rake/testtask' +# Monkey-patch to silence the description from Rake::TestTask to cut down on rake -T noise +class TestTaskWithoutDescription < Rake::TestTask + # Create the tasks defined by this task lib. + def define + lib_path = @libs.join(File::PATH_SEPARATOR) + task @name do + run_code = '' + RakeFileUtils.verbose(@verbose) do + run_code = + case @loader + when :direct + "-e 'ARGV.each{|f| load f}'" + when :testrb + "-S testrb #{fix}" + when :rake + rake_loader + end + @ruby_opts.unshift( "-I\"#{lib_path}\"" ) + @ruby_opts.unshift( "-w" ) if @warning + ruby @ruby_opts.join(" ") + + " \"#{run_code}\" " + + file_list.collect { |fn| "\"#{fn}\"" }.join(' ') + + " #{option_list}" + end + end + self + end +end + + TEST_CHANGES_SINCE = Time.now - 600 # Look up tests for recently modified sources. @@ -40,7 +70,7 @@ module Kernel end end -desc 'Run all unit, functional and integration tests' +desc 'Runs test:unit, test:functional, test:integration together (also available: test:benchmark, test:profile, test:plugins)' task :test do errors = %w(test:units test:functionals test:integration).collect do |task| begin @@ -92,38 +122,33 @@ namespace :test do end Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)" - Rake::TestTask.new(:units => "test:prepare") do |t| + TestTaskWithoutDescription.new(:units => "test:prepare") do |t| t.libs << "test" t.pattern = 'test/unit/**/*_test.rb' end - Rake::Task['test:units'].comment = "Run the unit tests in test/unit" - Rake::TestTask.new(:functionals => "test:prepare") do |t| + TestTaskWithoutDescription.new(:functionals => "test:prepare") do |t| t.libs << "test" t.pattern = 'test/functional/**/*_test.rb' end - Rake::Task['test:functionals'].comment = "Run the functional tests in test/functional" - Rake::TestTask.new(:integration => "test:prepare") do |t| + TestTaskWithoutDescription.new(:integration => "test:prepare") do |t| t.libs << "test" t.pattern = 'test/integration/**/*_test.rb' end - Rake::Task['test:integration'].comment = "Run the integration tests in test/integration" - Rake::TestTask.new(:benchmark => 'test:prepare') do |t| + TestTaskWithoutDescription.new(:benchmark => 'test:prepare') do |t| t.libs << 'test' t.pattern = 'test/performance/**/*_test.rb' t.options = '-- --benchmark' end - Rake::Task['test:benchmark'].comment = 'Benchmark the performance tests' - Rake::TestTask.new(:profile => 'test:prepare') do |t| + TestTaskWithoutDescription.new(:profile => 'test:prepare') do |t| t.libs << 'test' t.pattern = 'test/performance/**/*_test.rb' end - Rake::Task['test:profile'].comment = 'Profile the performance tests' - Rake::TestTask.new(:plugins => :environment) do |t| + TestTaskWithoutDescription.new(:plugins => :environment) do |t| t.libs << "test" if ENV['PLUGIN'] @@ -132,5 +157,4 @@ namespace :test do t.pattern = 'vendor/plugins/*/**/test/**/*_test.rb' end end - Rake::Task['test:plugins'].comment = "Run the plugin tests in vendor/plugins/*/**/test (or specify with PLUGIN=name)" end diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 712c8bef36..cbf0decd07 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -64,6 +64,7 @@ module ApplicationTests # Initialize the application require "#{app_path}/config/environment" require "rails/generators" + Rails::Generators.configure! assert_equal :rspec, Rails::Generators.options[:rails][:test_framework] assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework] diff --git a/railties/test/application/initializers/check_ruby_version_test.rb b/railties/test/application/initializers/check_ruby_version_test.rb index 58782b2511..5b6196307d 100644 --- a/railties/test/application/initializers/check_ruby_version_test.rb +++ b/railties/test/application/initializers/check_ruby_version_test.rb @@ -9,9 +9,11 @@ module ApplicationTests boot_rails end - test "rails initializes with ruby 1.8.7 or later" do + test "rails initializes with ruby 1.8.7 or later, except for 1.9.1" do if RUBY_VERSION < '1.8.7' assert_rails_does_not_boot + elsif RUBY_VERSION == '1.9.1' + assert_rails_does_not_boot else assert_rails_boots end diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index aa75fed793..999f666a64 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -1,4 +1,5 @@ require 'isolation/abstract_unit' +require 'stringio' module ApplicationTests class MiddlewareTest < Test::Unit::TestCase @@ -163,6 +164,25 @@ module ApplicationTests assert_equal "1.1.1.1", remote_ip("REMOTE_ADDR" => "4.2.42.42,1.1.1.1") end + test "show exceptions middleware filter backtrace before logging" do + my_middleware = Struct.new(:app) do + def call(env) + raise "Failure" + end + end + + make_basic_app do |app| + app.config.middleware.use my_middleware + end + + stringio = StringIO.new + Rails.logger = Logger.new(stringio) + + env = Rack::MockRequest.env_for("/") + Rails.application.call(env) + assert_no_match(/action_dispatch/, stringio.string) + end + private def boot! diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 8bd9dc9f39..ffc5636467 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -59,7 +59,6 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_application_controller_and_layout_files run_generator - assert_file "app/controllers/application_controller.rb", /layout 'application'/ assert_file "app/views/layouts/application.html.erb", /stylesheet_link_tag :all/ assert_no_file "public/stylesheets/application.css" end @@ -272,4 +271,4 @@ protected def action(*args, &block) silence(:stdout){ generator.send(*args, &block) } end -end
\ No newline at end of file +end diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb index dacb06fb13..de7e4de2a6 100644 --- a/railties/test/generators/generated_attribute_test.rb +++ b/railties/test/generators/generated_attribute_test.rb @@ -5,36 +5,107 @@ class GeneratedAttributeTest < Rails::Generators::TestCase include GeneratorsTestHelper def test_field_type_returns_text_field - %w(integer float decimal string).each do |name| - assert_field_type name, :text_field + %w(integer float decimal string).each do |attribute_type| + assert_field_type attribute_type, :text_field end end def test_field_type_returns_datetime_select - %w(datetime timestamp).each do |name| - assert_field_type name, :datetime_select + %w(datetime timestamp).each do |attribute_type| + assert_field_type attribute_type, :datetime_select end end def test_field_type_returns_time_select - assert_field_type 'time', :time_select + assert_field_type :time, :time_select end def test_field_type_returns_date_select - assert_field_type 'date', :date_select + assert_field_type :date, :date_select end def test_field_type_returns_text_area - assert_field_type 'text', :text_area + assert_field_type :text, :text_area end def test_field_type_returns_check_box - assert_field_type 'boolean', :check_box + assert_field_type :boolean, :check_box end def test_field_type_with_unknown_type_returns_text_field - %w(foo bar baz).each do |name| - assert_field_type name, :text_field + %w(foo bar baz).each do |attribute_type| + assert_field_type attribute_type, :text_field + end + end + + def test_default_value_is_integer + assert_field_default_value :integer, 1 + end + + def test_default_value_is_float + assert_field_default_value :float, 1.5 + end + + def test_default_value_is_decimal + assert_field_default_value :decimal, '9.99' + end + + def test_default_value_is_datetime + %w(datetime timestamp time).each do |attribute_type| + assert_field_default_value attribute_type, Time.now.to_s(:db) + end + end + + def test_default_value_is_date + assert_field_default_value :date, Date.today.to_s(:db) + end + + def test_default_value_is_string + assert_field_default_value :string, 'MyString' + end + + def test_default_value_is_text + assert_field_default_value :text, 'MyText' + end + + def test_default_value_is_boolean + assert_field_default_value :boolean, false + end + + def test_default_value_is_nil + %w(references belongs_to).each do |attribute_type| + assert_field_default_value attribute_type, nil + end + end + + def test_default_value_is_empty_string + %w(foo bar baz).each do |attribute_type| + assert_field_default_value attribute_type, '' + end + end + + def test_human_name + assert_equal( + 'Full name', + create_generated_attribute(:string, 'full_name').human_name + ) + end + + def test_reference_is_true + %w(references belongs_to).each do |attribute_type| + assert_equal( + true, + create_generated_attribute(attribute_type).reference? + ) + end + end + + def test_reference_is_false + %w(foo bar baz).each do |attribute_type| + assert_equal( + false, + create_generated_attribute(attribute_type).reference? + ) end end end diff --git a/railties/test/script_rails_loader_test.rb b/railties/test/script_rails_loader_test.rb new file mode 100644 index 0000000000..2a87e5cb58 --- /dev/null +++ b/railties/test/script_rails_loader_test.rb @@ -0,0 +1,22 @@ +require 'abstract_unit' +require 'rails/script_rails_loader' + +class ScriptRailsLoaderTest < ActiveSupport::TestCase + + test "is in a rails application if script/rails exists" do + File.stubs(:exists?).returns(true) + assert Rails::ScriptRailsLoader.in_rails_application? + end + + test "is in a rails application if parent directory has script/rails" do + File.stubs(:exists?).with("/foo/bar/script/rails").returns(false) + File.stubs(:exists?).with("/foo/script/rails").returns(true) + assert Rails::ScriptRailsLoader.in_rails_application_subdirectory?(Pathname.new("/foo/bar")) + end + + test "is not in a rails application if at the root directory and doesn't have script/rails" do + Pathname.any_instance.stubs(:root?).returns true + assert !Rails::ScriptRailsLoader.in_rails_application? + end + +end
\ No newline at end of file |