diff options
Diffstat (limited to 'railties')
18 files changed, 71 insertions, 39 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 93f4f8fa28..27d4313862 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -6,6 +6,8 @@ * Plugins check for the gem init path (rails/init.rb) before the standard plugin init path (init.rb) [Jacek Becela] +* Changed all generated tests to use the test/do declaration style [DHH] + * Wrapped Rails.env in StringInquirer so you can do Rails.env.development? [DHH] * Fixed that RailsInfoController wasn't considering all requests local in development mode (Edgard Castro) [#310 state:resolved] diff --git a/railties/Rakefile b/railties/Rakefile index a1d1095c37..78fe8e6662 100644 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -267,6 +267,7 @@ Rake::RDocTask.new { |rdoc| rdoc.template = "#{ENV['template']}.rb" if ENV['template'] rdoc.rdoc_files.include('README', 'CHANGELOG') rdoc.rdoc_files.include('lib/*.rb') + rdoc.rdoc_files.include('lib/rails/*.rb') rdoc.rdoc_files.include('lib/rails_generator/*.rb') rdoc.rdoc_files.include('lib/commands/**/*.rb') } @@ -331,10 +332,15 @@ end # Publishing ------------------------------------------------------- -desc "Publish the API documentation" +desc "Publish the rails gem" task :pgem => [:gem] do - Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload - `ssh davidhh@wrath.rubyonrails.org './gemupdate.sh'` + Rake::SshFilePublisher.new("wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload + `ssh wrath.rubyonrails.org './gemupdate.sh'` +end + +desc "Publish the API documentation" +task :pdoc => :rdoc do + # railties API isn't separately published end desc "Publish the release files to RubyForge." diff --git a/railties/configs/initializers/inflections.rb b/railties/configs/initializers/inflections.rb index 09158b865c..d531b8bb82 100644 --- a/railties/configs/initializers/inflections.rb +++ b/railties/configs/initializers/inflections.rb @@ -2,7 +2,7 @@ # Add new inflection rules using the following format # (all these examples are active by default): -# Inflector.inflections do |inflect| +# ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' diff --git a/railties/helpers/performance_test.rb b/railties/helpers/performance_test.rb new file mode 100644 index 0000000000..7c89816570 --- /dev/null +++ b/railties/helpers/performance_test.rb @@ -0,0 +1,8 @@ +require 'performance/test_helper' + +# Profiling results for each test method are written to tmp/performance. +class BrowsingTest < ActionController::PerformanceTest + def test_homepage + get '/' + end +end diff --git a/railties/helpers/performance_test_helper.rb b/railties/helpers/performance_test_helper.rb new file mode 100644 index 0000000000..3c4c7fb740 --- /dev/null +++ b/railties/helpers/performance_test_helper.rb @@ -0,0 +1,6 @@ +require 'test_helper' +require 'action_controller/performance_test' + +ActionController::Base.perform_caching = true +ActiveSupport::Dependencies.mechanism = :require +Rails.logger.level = ActiveSupport::BufferedLogger::INFO diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 2f2dd82682..80e8eabfd3 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -51,6 +51,8 @@ class AppGenerator < Rails::Generator::Base m.template "helpers/application.rb", "app/controllers/application.rb", :assigns => { :app_name => @app_name, :app_secret => md5.hexdigest } m.template "helpers/application_helper.rb", "app/helpers/application_helper.rb" m.template "helpers/test_helper.rb", "test/test_helper.rb" + m.template "helpers/performance_test_helper.rb", "test/performance/test_helper.rb" + m.template "helpers/performance_test.rb", "test/performance/browsing_test.rb" # database.yml and routes.rb m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => { @@ -155,6 +157,7 @@ class AppGenerator < Rails::Generator::Base test/fixtures test/functional test/integration + test/performance test/unit vendor vendor/plugins diff --git a/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb index 38e0ae7123..62fa5d86fd 100644 --- a/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb +++ b/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb @@ -2,7 +2,7 @@ require 'test_helper' class <%= class_name %>ControllerTest < ActionController::TestCase # Replace this with your real tests. - def test_truth + test "the truth" do assert true end end diff --git a/railties/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb b/railties/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb index 149b987d81..2c57158b1c 100644 --- a/railties/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +++ b/railties/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb @@ -1,10 +1,10 @@ require 'test_helper' class <%= class_name %>Test < ActionController::IntegrationTest - # fixtures :your, :models + fixtures :all # Replace this with your real tests. - def test_truth + test "the truth" do assert true end end diff --git a/railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb index 0b4b2ec60a..1b7bcfef08 100644 --- a/railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +++ b/railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class <%= class_name %>Test < ActionMailer::TestCase tests <%= class_name %> <% for action in actions -%> - def test_<%= action %> + test "<%= action %>" do @expected.subject = '<%= class_name %>#<%= action %>' @expected.body = read_fixture('<%= action %>') @expected.date = Time.now @@ -14,7 +14,7 @@ class <%= class_name %>Test < ActionMailer::TestCase <% end -%> <% if actions.blank? -%> # replace this with your real tests - def test_truth + test "the truth" do assert true end <% end -%> diff --git a/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb index 96bd34adab..3e0bc29d3a 100644 --- a/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb +++ b/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb @@ -2,7 +2,7 @@ require 'test_helper' class <%= class_name %>Test < ActiveSupport::TestCase # Replace this with your real tests. - def test_truth + test "the truth" do assert true end end diff --git a/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb index 1faf8ed9ac..cae38e9a2a 100644 --- a/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb +++ b/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb @@ -2,7 +2,7 @@ require 'test_helper' class <%= class_name %>ObserverTest < Test::Unit::TestCase # Replace this with your real tests. - def test_truth + test "the truth" do assert true end end diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/plugin/templates/unit_test.rb index 9028b84b7d..6ede6ef1d2 100644 --- a/railties/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +++ b/railties/lib/rails_generator/generators/components/plugin/templates/unit_test.rb @@ -2,7 +2,7 @@ require 'test/unit' class <%= class_name %>Test < Test::Unit::TestCase # Replace this with your real tests. - def test_this_plugin - flunk + test "the truth" do + assert true end end diff --git a/railties/lib/rails_generator/generators/components/resource/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/resource/templates/functional_test.rb index fbb69fcca7..b1bb1dacbf 100644 --- a/railties/lib/rails_generator/generators/components/resource/templates/functional_test.rb +++ b/railties/lib/rails_generator/generators/components/resource/templates/functional_test.rb @@ -2,7 +2,7 @@ require 'test_helper' class <%= controller_class_name %>ControllerTest < ActionController::TestCase # Replace this with your real tests. - def test_truth + test "the truth" do assert true end end diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb index 3b430a2061..2d9d635944 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb @@ -1,18 +1,18 @@ require 'test_helper' class <%= controller_class_name %>ControllerTest < ActionController::TestCase - def test_should_get_index + test "should get index" do get :index assert_response :success assert_not_nil assigns(:<%= table_name %>) end - def test_should_get_new + test "should get new" do get :new assert_response :success end - def test_should_create_<%= file_name %> + test "should create <%= file_name %>" do assert_difference('<%= class_name %>.count') do post :create, :<%= file_name %> => { } end @@ -20,22 +20,22 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>)) end - def test_should_show_<%= file_name %> + test "should show <%= file_name %>" do get :show, :id => <%= table_name %>(:one).id assert_response :success end - def test_should_get_edit + test "should get edit" do get :edit, :id => <%= table_name %>(:one).id assert_response :success end - def test_should_update_<%= file_name %> + test "should update <%= file_name %>" do put :update, :id => <%= table_name %>(:one).id, :<%= file_name %> => { } assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>)) end - def test_should_destroy_<%= file_name %> + test "should destroy <%= file_name %>" do assert_difference('<%= class_name %>.count', -1) do delete :destroy, :id => <%= table_name %>(:one).id end diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 8077d0a401..75fba8b45a 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -264,13 +264,15 @@ namespace :db do end namespace :test do - desc "Recreate the test database from the current environment's database schema" - task :clone => %w(db:schema:dump db:test:purge) do + desc "Recreate the test database from the current schema.rb" + task :load => 'db:test:purge' do ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']) ActiveRecord::Schema.verbose = false Rake::Task["db:schema:load"].invoke end + desc "Recreate the test database from the current environment's database schema" + task :clone => %w(db:schema:dump db:test:load) desc "Recreate the test databases from the development structure" task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do @@ -337,10 +339,10 @@ namespace :db do end end - desc 'Prepare the test database and load the schema' - task :prepare => %w(environment db:abort_if_pending_migrations) do + desc 'Check for pending migrations and load the test schema' + task :prepare => 'db:abort_if_pending_migrations' do if defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank? - Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:clone" }[ActiveRecord::Base.schema_format]].invoke + Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:load" }[ActiveRecord::Base.schema_format]].invoke end end end diff --git a/railties/lib/tasks/testing.rake b/railties/lib/tasks/testing.rake index cc2376cbb3..c8ba6eed94 100644 --- a/railties/lib/tasks/testing.rake +++ b/railties/lib/tasks/testing.rake @@ -103,6 +103,21 @@ namespace :test do end Rake::Task['test:integration'].comment = "Run the integration tests in test/integration" + Rake::TestTask.new(:benchmark => 'db:test:prepare') do |t| + t.libs << 'test' + t.pattern = 'test/performance/**/*_test.rb' + t.verbose = true + t.options = '-- --benchmark' + end + Rake::Task['test:benchmark'].comment = 'Benchmark the performance tests' + + Rake::TestTask.new(:profile => 'db:test:prepare') do |t| + t.libs << 'test' + t.pattern = 'test/performance/**/*_test.rb' + t.verbose = true + end + Rake::Task['test:profile'].comment = 'Profile the performance tests' + Rake::TestTask.new(:plugins => :environment) do |t| t.libs << "test" diff --git a/railties/lib/test_help.rb b/railties/lib/test_help.rb index 22ce9ab609..3cc61d7932 100644 --- a/railties/lib/test_help.rb +++ b/railties/lib/test_help.rb @@ -8,7 +8,6 @@ require 'test/unit' require 'active_support/test_case' require 'active_record/fixtures' require 'action_controller/test_case' -require 'action_controller/test_process' require 'action_controller/integration' require 'action_mailer/test_case' if defined?(ActionMailer) @@ -25,4 +24,4 @@ begin Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings) rescue LoadError # ruby-debug wasn't available so neither can the debugging be -end
\ No newline at end of file +end diff --git a/railties/lib/webrick_server.rb b/railties/lib/webrick_server.rb index ad4ca926ba..2f60151b22 100644 --- a/railties/lib/webrick_server.rb +++ b/railties/lib/webrick_server.rb @@ -43,8 +43,6 @@ end # can change this behavior by setting ActionController::Base.allow_concurrency # to true. class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet - REQUEST_MUTEX = Mutex.new - # Start the WEBrick server with the given options, mounting the # DispatchServlet at <tt>/</tt>. def self.dispatch(options = {}) @@ -73,15 +71,8 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet def service(req, res) #:nodoc: unless handle_file(req, res) - begin - REQUEST_MUTEX.lock unless ActionController::Base.allow_concurrency - unless handle_dispatch(req, res) - raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found." - end - ensure - unless ActionController::Base.allow_concurrency - REQUEST_MUTEX.unlock if REQUEST_MUTEX.locked? - end + unless handle_dispatch(req, res) + raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found." end end end |