diff options
78 files changed, 567 insertions, 1128 deletions
@@ -5,7 +5,8 @@ gem "rails", :path => File.dirname(__FILE__) gem "rake", ">= 0.8.7" gem "mocha", ">= 0.9.8" -gem "rdoc", "2.2" +gem "rdoc", ">= 2.5.9" +gem "horo" mri = !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" if mri && RUBY_VERSION < '1.9' @@ -1,8 +1,8 @@ -gem 'rdoc', '= 2.2' +gem 'rdoc', '>= 2.5.9' require 'rdoc' require 'rake' -require 'rake/rdoctask' +require 'rdoc/task' require 'rake/gempackagetask' PROJECTS = %w(activesupport activemodel actionpack actionmailer activeresource activerecord railties) @@ -10,7 +10,7 @@ PROJECTS = %w(activesupport activemodel actionpack actionmailer activeresource a desc 'Run all tests by default' task :default => %w(test test:isolated) -%w(test test:isolated rdoc package gem).each do |task_name| +%w(test test:isolated package gem).each do |task_name| desc "Run #{task_name} task for all projects" task task_name do errors = [] @@ -62,24 +62,15 @@ task :install => :gem do end desc "Generate documentation for the Rails framework" -Rake::RDocTask.new do |rdoc| +RDoc::Task.new do |rdoc| rdoc.rdoc_dir = 'doc/rdoc' rdoc.title = "Ruby on Rails Documentation" - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.options << '-A cattr_accessor=object' - rdoc.options << '--charset' << 'utf-8' - rdoc.options << '--main' << 'README.rdoc' + rdoc.options << '-f' << 'horo' + rdoc.options << '-c' << 'utf-8' + rdoc.options << '-m' << 'README.rdoc' - # Workaround: RDoc assumes that rdoc.template can be required, and that - # rdoc.template.upcase is a constant living in RDoc::Generator::HTML - # which holds the actual template class. - # - # We put 'doc/template' in the load path to be able to set the template - # to the string 'horo' and thus meet those RDoc's assumptions. - $:.unshift('doc/template') - - rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : 'horo' + rdoc.rdoc_files.include('README.rdoc') rdoc.rdoc_files.include('railties/CHANGELOG') rdoc.rdoc_files.include('railties/MIT-LICENSE') @@ -129,9 +120,6 @@ desc "Publish API docs for Rails as a whole and for each component" task :pdoc => :rdoc do require 'rake/contrib/sshpublisher' Rake::SshDirPublisher.new("rails@api.rubyonrails.org", "public_html/api", "doc/rdoc").upload - PROJECTS.each do |project| - system %(cd #{project} && #{$0} pdoc) - end end task :update_versions do diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile index 98aeae9818..a47426bd07 100644 --- a/actionmailer/Rakefile +++ b/actionmailer/Rakefile @@ -1,8 +1,8 @@ -gem 'rdoc', '= 2.2' +gem 'rdoc', '>= 2.5.9' require 'rdoc' require 'rake' require 'rake/testtask' -require 'rake/rdoctask' +require 'rdoc/task' require 'rake/packagetask' require 'rake/gempackagetask' @@ -26,12 +26,12 @@ namespace :test do end # Generate the RDoc documentation -Rake::RDocTask.new { |rdoc| +RDoc::Task.new { |rdoc| rdoc.rdoc_dir = 'doc' rdoc.title = "Action Mailer -- Easy email delivery and testing" - rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' rdoc.options << '--charset' << 'utf-8' - rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo' + rdoc.options << '-f' << 'horo' + rdoc.options << '--main' << 'README.rdoc' rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG') rdoc.rdoc_files.include('lib/action_mailer.rb') rdoc.rdoc_files.include('lib/action_mailer/*.rb') @@ -50,9 +50,3 @@ task :release => :package do Rake::Gemcutter::Tasks.new(spec).define Rake::Task['gem:push'].invoke end - -desc "Publish the API documentation" -task :pdoc => [:rdoc] do - require 'rake/contrib/sshpublisher' - Rake::SshDirPublisher.new("rails@api.rubyonrails.org", "public_html/am", "doc").upload -end diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb index d7b09b2dc6..ce6d8cc5b5 100644 --- a/actionmailer/lib/action_mailer/railtie.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -10,21 +10,16 @@ module ActionMailer end initializer "action_mailer.set_configs" do |app| - paths = app.config.paths - am = app.config.action_mailer + paths = app.config.paths + options = app.config.action_mailer - am.assets_dir ||= paths.public.to_a.first - am.javascripts_dir ||= paths.public.javascripts.to_a.first - am.stylesheets_dir ||= paths.public.stylesheets.to_a.first + options.assets_dir ||= paths.public.to_a.first + options.javascripts_dir ||= paths.public.javascripts.to_a.first + options.stylesheets_dir ||= paths.public.stylesheets.to_a.first ActiveSupport.on_load(:action_mailer) do - self.config.merge!(am) - include app.routes.url_helpers - - app.config.action_mailer.each do |k,v| - send "#{k}=", v - end + options.each { |k,v| send("#{k}=", v) } end end end diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index b91eed592a..f4d1bb59f1 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -28,7 +28,7 @@ module ActionMailer def determine_default_mailer(name) name.sub(/Test$/, '').constantize - rescue NameError => e + rescue NameError raise NonInferrableMailerError.new(name) end end diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index 5bc0491cff..e2b9df5d02 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -2,139 +2,17 @@ require 'abstract_unit' require 'active_support/time' +require 'mailers/base_mailer' +require 'mailers/proc_mailer' +require 'mailers/asset_mailer' + class BaseTest < ActiveSupport::TestCase # TODO Add some tests for implicity layout render and url helpers # so we can get rid of old base tests altogether with old base. - class BaseMailer < ActionMailer::Base - self.mailer_name = "base_mailer" - - default :to => 'system@test.lindsaar.net', - :from => 'jose@test.plataformatec.com', - :reply_to => 'mikel@test.lindsaar.net' - - def welcome(hash = {}) - headers['X-SPAM'] = "Not SPAM" - mail({:subject => "The first email on new API!"}.merge!(hash)) - end - - def welcome_with_headers(hash = {}) - headers hash - mail - end - - def welcome_from_another_path(path) - mail(:template_name => "welcome", :template_path => path) - end - - def html_only(hash = {}) - mail(hash) - end - - def plain_text_only(hash = {}) - mail(hash) - end - - def inline_attachment - attachments.inline['logo.png'] = "\312\213\254\232" - mail - end - - def attachment_with_content(hash = {}) - attachments['invoice.pdf'] = 'This is test File content' - mail(hash) - end - - def attachment_with_hash - attachments['invoice.jpg'] = { :data => "\312\213\254\232)b", - :mime_type => "image/x-jpg", - :transfer_encoding => "base64" } - mail - end - - def attachment_with_hash_default_encoding - attachments['invoice.jpg'] = { :data => "\312\213\254\232)b", - :mime_type => "image/x-jpg" } - mail - end - - def implicit_multipart(hash = {}) - attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments) - mail(hash) - end - - def implicit_with_locale(hash = {}) - mail(hash) - end - - def explicit_multipart(hash = {}) - attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments) - mail(hash) do |format| - format.text { render :text => "TEXT Explicit Multipart" } - format.html { render :text => "HTML Explicit Multipart" } - end - end - - def explicit_multipart_templates(hash = {}) - mail(hash) do |format| - format.html - format.text - end - end - def explicit_multipart_with_any(hash = {}) - mail(hash) do |format| - format.any(:text, :html){ render :text => "Format with any!" } - end - end - - def explicit_multipart_with_options(include_html = false) - mail do |format| - format.text(:content_transfer_encoding => "base64"){ render "welcome" } - format.html{ render "welcome" } if include_html - end - end - - def explicit_multipart_with_one_template(hash = {}) - mail(hash) do |format| - format.html - format.text - end - end - - def implicit_different_template(template_name='') - mail(:template_name => template_name) - end - - def explicit_different_template(template_name='') - mail do |format| - format.text { render :template => "#{mailer_name}/#{template_name}" } - format.html { render :template => "#{mailer_name}/#{template_name}" } - end - end - - def different_layout(layout_name='') - mail do |format| - format.text { render :layout => layout_name } - format.html { render :layout => layout_name } - end - end - end - - class ProcMailer < ActionMailer::Base - default :to => 'system@test.lindsaar.net', - 'X-Proc-Method' => Proc.new { Time.now.to_i.to_s }, - :subject => Proc.new { give_a_greeting } - - def welcome - mail - end - - private - - def give_a_greeting - "Thanks for signing up this afternoon" - end - + def teardown + ActionMailer::Base.asset_host = nil + ActionMailer::Base.assets_dir = nil end test "method call to mail does not raise error" do @@ -570,6 +448,26 @@ class BaseTest < ActiveSupport::TestCase assert_equal("Welcome from another path", mail.body.encoded) end + test "assets tags should use ActionMailer's asset_host settings" do + ActionMailer::Base.config.asset_host = "http://global.com" + ActionMailer::Base.config.assets_dir = "global/" + + mail = AssetMailer.welcome + + assert_equal(%{<img alt="Dummy" src="http://global.com/images/dummy.png" />}, mail.body.to_s.strip) + end + + test "assets tags should use a Mailer's asset_host settings when available" do + ActionMailer::Base.config.asset_host = "global.com" + ActionMailer::Base.config.assets_dir = "global/" + + AssetMailer.asset_host = "http://local.com" + + mail = AssetMailer.welcome + + assert_equal(%{<img alt="Dummy" src="http://local.com/images/dummy.png" />}, mail.body.to_s.strip) + end + # Before and After hooks class MyObserver diff --git a/actionmailer/test/fixtures/asset_mailer/welcome.html.erb b/actionmailer/test/fixtures/asset_mailer/welcome.html.erb new file mode 100644 index 0000000000..90d26130d9 --- /dev/null +++ b/actionmailer/test/fixtures/asset_mailer/welcome.html.erb @@ -0,0 +1 @@ +<%= image_tag "dummy.png" %>
\ No newline at end of file diff --git a/actionmailer/test/mailers/asset_mailer.rb b/actionmailer/test/mailers/asset_mailer.rb new file mode 100644 index 0000000000..f54a50d00d --- /dev/null +++ b/actionmailer/test/mailers/asset_mailer.rb @@ -0,0 +1,7 @@ +class AssetMailer < ActionMailer::Base + self.mailer_name = "asset_mailer" + + def welcome + mail + end +end diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb new file mode 100644 index 0000000000..2c6de36ccf --- /dev/null +++ b/actionmailer/test/mailers/base_mailer.rb @@ -0,0 +1,114 @@ +class BaseMailer < ActionMailer::Base + self.mailer_name = "base_mailer" + + default :to => 'system@test.lindsaar.net', + :from => 'jose@test.plataformatec.com', + :reply_to => 'mikel@test.lindsaar.net' + + def welcome(hash = {}) + headers['X-SPAM'] = "Not SPAM" + mail({:subject => "The first email on new API!"}.merge!(hash)) + end + + def welcome_with_headers(hash = {}) + headers hash + mail + end + + def welcome_from_another_path(path) + mail(:template_name => "welcome", :template_path => path) + end + + def html_only(hash = {}) + mail(hash) + end + + def plain_text_only(hash = {}) + mail(hash) + end + + def inline_attachment + attachments.inline['logo.png'] = "\312\213\254\232" + mail + end + + def attachment_with_content(hash = {}) + attachments['invoice.pdf'] = 'This is test File content' + mail(hash) + end + + def attachment_with_hash + attachments['invoice.jpg'] = { :data => "\312\213\254\232)b", + :mime_type => "image/x-jpg", + :transfer_encoding => "base64" } + mail + end + + def attachment_with_hash_default_encoding + attachments['invoice.jpg'] = { :data => "\312\213\254\232)b", + :mime_type => "image/x-jpg" } + mail + end + + def implicit_multipart(hash = {}) + attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments) + mail(hash) + end + + def implicit_with_locale(hash = {}) + mail(hash) + end + + def explicit_multipart(hash = {}) + attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments) + mail(hash) do |format| + format.text { render :text => "TEXT Explicit Multipart" } + format.html { render :text => "HTML Explicit Multipart" } + end + end + + def explicit_multipart_templates(hash = {}) + mail(hash) do |format| + format.html + format.text + end + end + + def explicit_multipart_with_any(hash = {}) + mail(hash) do |format| + format.any(:text, :html){ render :text => "Format with any!" } + end + end + + def explicit_multipart_with_options(include_html = false) + mail do |format| + format.text(:content_transfer_encoding => "base64"){ render "welcome" } + format.html{ render "welcome" } if include_html + end + end + + def explicit_multipart_with_one_template(hash = {}) + mail(hash) do |format| + format.html + format.text + end + end + + def implicit_different_template(template_name='') + mail(:template_name => template_name) + end + + def explicit_different_template(template_name='') + mail do |format| + format.text { render :template => "#{mailer_name}/#{template_name}" } + format.html { render :template => "#{mailer_name}/#{template_name}" } + end + end + + def different_layout(layout_name='') + mail do |format| + format.text { render :layout => layout_name } + format.html { render :layout => layout_name } + end + end +end diff --git a/actionmailer/test/mailers/proc_mailer.rb b/actionmailer/test/mailers/proc_mailer.rb new file mode 100644 index 0000000000..6a79cd71fc --- /dev/null +++ b/actionmailer/test/mailers/proc_mailer.rb @@ -0,0 +1,16 @@ +class ProcMailer < ActionMailer::Base + default :to => 'system@test.lindsaar.net', + 'X-Proc-Method' => Proc.new { Time.now.to_i.to_s }, + :subject => Proc.new { give_a_greeting } + + def welcome + mail + end + + private + + def give_a_greeting + "Thanks for signing up this afternoon" + end + +end diff --git a/actionpack/Rakefile b/actionpack/Rakefile index 3a988d832d..4af8ea167a 100644 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -1,8 +1,8 @@ -gem 'rdoc', '= 2.2' +gem 'rdoc', '>= 2.5.9' require 'rdoc' require 'rake' require 'rake/testtask' -require 'rake/rdoctask' +require 'rdoc/task' require 'rake/packagetask' require 'rake/gempackagetask' @@ -38,12 +38,12 @@ end # Genereate the RDoc documentation -Rake::RDocTask.new { |rdoc| +RDoc::Task.new { |rdoc| rdoc.rdoc_dir = 'doc' rdoc.title = "Action Pack -- On rails from request to response" - rdoc.options << '--line-numbers' << '--inline-source' rdoc.options << '--charset' << 'utf-8' - rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo' + rdoc.options << '-f' << 'horo' + rdoc.options << '--main' << 'README.rdoc' if ENV['DOC_FILES'] rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/)) else @@ -89,4 +89,4 @@ task :lines do end puts "Total: Lines #{total_lines}, LOC #{total_codelines}" -end
\ No newline at end of file +end diff --git a/actionpack/lib/abstract_controller/asset_paths.rb b/actionpack/lib/abstract_controller/asset_paths.rb index 6d6f6ac607..9ca2fb742f 100644 --- a/actionpack/lib/abstract_controller/asset_paths.rb +++ b/actionpack/lib/abstract_controller/asset_paths.rb @@ -3,7 +3,7 @@ module AbstractController extend ActiveSupport::Concern included do - config_accessor :assets_dir, :javascripts_dir, :stylesheets_dir + config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir, :stylesheets_dir end end end
\ No newline at end of file diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 1c6896d362..9dfffced75 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -63,7 +63,6 @@ module ActionController klass.helper :all end - config_accessor :asset_host, :asset_path ActiveSupport.run_load_hooks(:action_controller, self) end end diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 9261422f0b..cd2dfafbe6 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -5,8 +5,6 @@ require "action_view/railtie" require "active_support/deprecation/proxy_wrappers" require "active_support/deprecation" -require "action_controller/railties/url_helpers" - module ActionController class Railtie < Rails::Railtie config.action_controller = ActiveSupport::OrderedOptions.new @@ -33,21 +31,6 @@ module ActionController end end - initializer "action_controller.set_configs" do |app| - paths = app.config.paths - ac = app.config.action_controller - - ac.assets_dir ||= paths.public.to_a.first - ac.javascripts_dir ||= paths.public.javascripts.to_a.first - ac.stylesheets_dir ||= paths.public.stylesheets.to_a.first - ac.page_cache_directory ||= paths.public.to_a.first - ac.helpers_path ||= paths.app.helpers.to_a - - ActiveSupport.on_load(:action_controller) do - self.config.merge!(ac) - end - end - initializer "action_controller.logger" do ActiveSupport.on_load(:action_controller) { self.logger ||= Rails.logger } end @@ -56,11 +39,23 @@ module ActionController ActiveSupport.on_load(:action_controller) { self.cache_store ||= RAILS_CACHE } end - initializer "action_controller.url_helpers" do |app| + initializer "action_controller.set_configs" do |app| + paths = app.config.paths + options = app.config.action_controller + + options.assets_dir ||= paths.public.to_a.first + options.javascripts_dir ||= paths.public.javascripts.to_a.first + options.stylesheets_dir ||= paths.public.stylesheets.to_a.first + options.page_cache_directory ||= paths.public.to_a.first + options.helpers_path ||= paths.app.helpers.to_a + ActiveSupport.on_load(:action_controller) do - extend ::ActionController::Railties::UrlHelpers.with(app.routes) + include app.routes.url_helpers + options.each { |k,v| send("#{k}=", v) } end + end + initializer "action_controller.deprecated_routes" do |app| message = "ActionController::Routing::Routes is deprecated. " \ "Instead, use Rails.application.routes" diff --git a/actionpack/lib/action_controller/railties/url_helpers.rb b/actionpack/lib/action_controller/railties/url_helpers.rb deleted file mode 100644 index 9df5665542..0000000000 --- a/actionpack/lib/action_controller/railties/url_helpers.rb +++ /dev/null @@ -1,14 +0,0 @@ -module ActionController - module Railties - module UrlHelpers - def self.with(routes) - Module.new do - define_method(:inherited) do |klass| - super(klass) - klass.send(:include, routes.url_helpers) - end - end - end - end - end -end diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 650eb16ac0..e306697f4b 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -365,7 +365,7 @@ module ActionController def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil) @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' @request.env['HTTP_ACCEPT'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ') - returning __send__(request_method, action, parameters, session, flash) do + __send__(request_method, action, parameters, session, flash).tap do @request.env.delete 'HTTP_X_REQUESTED_WITH' @request.env.delete 'HTTP_ACCEPT' end diff --git a/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb b/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb index b3146a1c60..4904f0633d 100644 --- a/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb +++ b/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb @@ -500,7 +500,7 @@ module ActionDispatch end def add_conditions_for(conditions, method) - returning({:conditions => conditions.dup}) do |options| + {:conditions => conditions.dup}.tap do |options| options[:conditions][:method] = method unless method == :any end end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index a9b97a17eb..77688fe397 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -454,7 +454,7 @@ module ActionDispatch def url_for(options) finalize! - options = default_url_options.merge(options || {}) + options = (options || {}).reverse_merge!(default_url_options) handle_positional_args(options) diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index 662eb05c26..9b42f26289 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -129,7 +129,7 @@ module ActionDispatch when String options when nil, Hash - _routes.url_for(url_options.merge((options || {}).symbolize_keys)) + _routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys) else polymorphic_url(options) end diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 64eb6d8de7..8e58adaf59 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -319,7 +319,7 @@ module ActionDispatch reset! unless @integration_session # reset the html_document variable, but only for new get/post calls @html_document = nil unless %w(cookies assigns).include?(method) - returning @integration_session.__send__(method, *args) do + @integration_session.__send__(method, *args).tap do copy_session_variables! end end @@ -362,7 +362,7 @@ module ActionDispatch def method_missing(sym, *args, &block) reset! unless @integration_session if @integration_session.respond_to?(sym) - returning @integration_session.__send__(sym, *args, &block) do + @integration_session.__send__(sym, *args, &block).tap do copy_session_variables! end else diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index f9105ca364..89e95e8694 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -165,7 +165,7 @@ module ActionView def with_output_buffer(buf = nil) #:nodoc: unless buf buf = ActionView::OutputBuffer.new - buf.force_encoding(output_buffer.encoding) if output_buffer && buf.respond_to?(:force_encoding) + buf.force_encoding(output_buffer.encoding) if output_buffer.respond_to?(:encoding) && buf.respond_to?(:force_encoding) end self.output_buffer, old_buffer = buf, output_buffer yield diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 4c1b751160..9dac2d4538 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -1,6 +1,5 @@ require 'cgi' require 'action_view/helpers/tag_helper' -require 'active_support/core_ext/object/returning' require 'active_support/core_ext/object/blank' module ActionView @@ -527,7 +526,7 @@ module ActionView private def html_options_for_form(url_for_options, options, *parameters_for_url) - returning options.stringify_keys do |html_options| + options.stringify_keys.tap do |html_options| html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart") # The following URL is unescaped, this is just a hash of options, and it is the # responsability of the caller to escape all the values. diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index b493a0cb0e..a5c6718c58 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -95,7 +95,7 @@ module ActionView when String options when Hash - options = { :only_path => options[:host].nil? }.update(options.symbolize_keys) + options = options.symbolize_keys.reverse_merge!(:only_path => options[:host].nil?) super when :back controller.request.env["HTTP_REFERER"] || 'javascript:history.back()' diff --git a/actionpack/test/template/capture_helper_test.rb b/actionpack/test/template/capture_helper_test.rb index 9f3d68a639..f7c42c7f22 100644 --- a/actionpack/test/template/capture_helper_test.rb +++ b/actionpack/test/template/capture_helper_test.rb @@ -114,7 +114,7 @@ class CaptureHelperTest < ActionView::TestCase end def view_with_controller - returning(TestController.new.view_context) do |view| + TestController.new.view_context.tap do |view| view.output_buffer = ActionView::OutputBuffer.new end end diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index c5c2a6b952..1a899c6aee 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -89,6 +89,14 @@ class JavaScriptHelperTest < ActionView::TestCase link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/') end + def test_link_to_function_with_inner_block_does_not_raise_exception + html = link_to_function("Greet me!") do |page| + content_tag(:h1) { 'Hi' } + end + + assert_dom_equal %(<a href='#' onclick="; return false;">Greet me!</a>), html + end + def test_javascript_tag self.output_buffer = 'foo' diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 048f96c9a9..d59bbec4a9 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -1,6 +1,6 @@ # encoding: utf-8 require 'abstract_unit' -require 'active_support/ordered_options' +require 'active_support/ordered_hash' require 'controller/fake_controllers' class UrlHelperTest < ActiveSupport::TestCase @@ -31,17 +31,13 @@ class UrlHelperTest < ActiveSupport::TestCase {} end - def abcd(hash = {}) - hash_for(:a => :b, :c => :d).merge(hash) - end - - def hash_for(opts = {}) - {:controller => "foo", :action => "bar"}.merge(opts) + def hash_for(opts = []) + ActiveSupport::OrderedHash[*([:controller, "foo", :action, "bar"].concat(opts))] end alias url_hash hash_for def test_url_for_does_not_escape_urls - assert_equal "/?a=b&c=d", url_for(abcd) + assert_equal "/?a=b&c=d", url_for(hash_for([:a, :b, :c, :d])) end def test_url_for_with_back @@ -128,7 +124,7 @@ class UrlHelperTest < ActiveSupport::TestCase end def test_link_tag_with_host_option - hash = hash_for(:host => "www.example.com") + hash = hash_for([:host, "www.example.com"]) expected = %q{<a href="http://www.example.com/">Test Link</a>} assert_dom_equal(expected, link_to('Test Link', hash)) end @@ -294,7 +290,7 @@ class UrlHelperTest < ActiveSupport::TestCase def test_current_page_with_params_that_match @request = request_for_url("/?order=desc&page=1") - assert current_page?(hash_for(:order => "desc", :page => "1")) + assert current_page?(hash_for([:order, "desc", :page, "1"])) assert current_page?("http://www.example.com/?order=desc&page=1") end @@ -316,20 +312,20 @@ class UrlHelperTest < ActiveSupport::TestCase @request = request_for_url("/?order=desc&page=1") assert_equal "Showing", - link_to_unless_current("Showing", hash_for(:order=>'desc', :page=>'1')) + link_to_unless_current("Showing", hash_for([:order, 'desc', :page, '1'])) assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/?order=desc&page=1") @request = request_for_url("/?order=desc") assert_equal %{<a href="/?order=asc">Showing</a>}, - link_to_unless_current("Showing", hash_for(:order => :asc)) + link_to_unless_current("Showing", hash_for([:order, :asc])) assert_equal %{<a href="http://www.example.com/?order=asc">Showing</a>}, link_to_unless_current("Showing", "http://www.example.com/?order=asc") @request = request_for_url("/?order=desc") assert_equal %{<a href="/?order=desc&page=2\">Showing</a>}, - link_to_unless_current("Showing", hash_for(:order => "desc", :page => 2)) + link_to_unless_current("Showing", hash_for([:order, "desc", :page, 2])) assert_equal %{<a href="http://www.example.com/?order=desc&page=2">Showing</a>}, link_to_unless_current("Showing", "http://www.example.com/?order=desc&page=2") diff --git a/activemodel/Rakefile b/activemodel/Rakefile index 4e4bbcee96..3fffc0d021 100644 --- a/activemodel/Rakefile +++ b/activemodel/Rakefile @@ -1,6 +1,6 @@ dir = File.dirname(__FILE__) -gem 'rdoc', '= 2.2' +gem 'rdoc', '>= 2.5.9' require 'rdoc' require 'rake/testtask' @@ -23,15 +23,15 @@ namespace :test do end -require 'rake/rdoctask' +require 'rdoc/task' # Generate the RDoc documentation -Rake::RDocTask.new do |rdoc| +RDoc::Task.new do |rdoc| rdoc.rdoc_dir = "doc" rdoc.title = "Active Model" - rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' + rdoc.options << '-f' << 'horo' rdoc.options << '--charset' << 'utf-8' - rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo' + rdoc.options << '--main' << 'README.rdoc' rdoc.rdoc_files.include("README.rdoc", "CHANGELOG") rdoc.rdoc_files.include("lib/**/*.rb") end diff --git a/activerecord/Rakefile b/activerecord/Rakefile index d9124c9776..36cd7e3e6c 100644 --- a/activerecord/Rakefile +++ b/activerecord/Rakefile @@ -1,8 +1,8 @@ -gem 'rdoc', '= 2.2' +gem 'rdoc', '>= 2.5.9' require 'rdoc' require 'rake' require 'rake/testtask' -require 'rake/rdoctask' +require 'rdoc/task' require 'rake/packagetask' require 'rake/gempackagetask' @@ -166,12 +166,12 @@ task :rebuild_frontbase_databases => 'frontbase:rebuild_databases' # Generate the RDoc documentation -Rake::RDocTask.new { |rdoc| +RDoc::Task.new { |rdoc| rdoc.rdoc_dir = 'doc' rdoc.title = "Active Record -- Object-relation mapping put on rails" - rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' + rdoc.options << '-f' << 'horo' + rdoc.options << '--main' << 'README.rdoc' rdoc.options << '--charset' << 'utf-8' - rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo' rdoc.rdoc_files.include('README.rdoc', 'RUNNING_UNIT_TESTS', 'CHANGELOG') rdoc.rdoc_files.include('lib/**/*.rb') rdoc.rdoc_files.exclude('lib/active_record/vendor/*') @@ -224,9 +224,3 @@ task :release => :package do Rake::Gemcutter::Tasks.new(spec).define Rake::Task['gem:push'].invoke end - -desc "Publish the API documentation" -task :pdoc => [:rdoc] do - require 'rake/contrib/sshpublisher' - Rake::SshDirPublisher.new("rails@api.rubyonrails.org", "public_html/ar", "doc").upload -end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 6072481411..69a963c3d3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -34,16 +34,16 @@ module ActiveRecord include QueryCache include ActiveSupport::Callbacks + attr_accessor :runtime define_callbacks :checkout, :checkin - @@row_even = true - def initialize(connection, logger = nil) #:nodoc: @active = nil @connection, @logger = connection, logger @runtime = 0 @query_cache_enabled = false @query_cache = {} + @instrumenter = ActiveSupport::Notifications.instrumenter end # Returns the human-readable name of the adapter. Use mixed case - one @@ -199,15 +199,10 @@ module ActiveRecord def log(sql, name) name ||= "SQL" - instrumenter = ActiveSupport::Notifications.instrumenter - - result = instrumenter.instrument("sql.active_record", + @instrumenter.instrument("sql.active_record", :sql => sql, :name => name, :connection_id => object_id) do yield end - @runtime += instrumenter.elapsed - - result rescue Exception => e message = "#{e.class.name}: #{e.message}: #{sql}" @logger.debug message if @logger diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index 278e192e59..f7ae5587ed 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -6,6 +6,8 @@ module ActiveRecord end def sql(event) + connection = ActiveRecord::Base.connection + connection.runtime += event.duration return unless logger.debug? name = '%s (%.1fms)' % [event.payload[:name], event.duration] diff --git a/activerecord/lib/active_record/railties/controller_runtime.rb b/activerecord/lib/active_record/railties/controller_runtime.rb index aed1c59b00..cf74fa1655 100644 --- a/activerecord/lib/active_record/railties/controller_runtime.rb +++ b/activerecord/lib/active_record/railties/controller_runtime.rb @@ -11,9 +11,10 @@ module ActiveRecord def cleanup_view_runtime if ActiveRecord::Base.connected? - db_rt_before_render = ActiveRecord::Base.connection.reset_runtime + connection = ActiveRecord::Base.connection + db_rt_before_render = connection.reset_runtime runtime = super - db_rt_after_render = ActiveRecord::Base.connection.reset_runtime + db_rt_after_render = connection.reset_runtime self.db_runtime = db_rt_before_render + db_rt_after_render runtime - db_rt_after_render else diff --git a/activerecord/lib/active_record/session_store.rb b/activerecord/lib/active_record/session_store.rb index 7ea7fb5c51..766e63edc7 100644 --- a/activerecord/lib/active_record/session_store.rb +++ b/activerecord/lib/active_record/session_store.rb @@ -49,8 +49,34 @@ module ActiveRecord # The example SqlBypass class is a generic SQL session store. You may # use it as a basis for high-performance database-specific stores. class SessionStore < ActionDispatch::Session::AbstractStore + module ClassMethods # :nodoc: + def marshal(data) + ActiveSupport::Base64.encode64(Marshal.dump(data)) if data + end + + def unmarshal(data) + Marshal.load(ActiveSupport::Base64.decode64(data)) if data + end + + def drop_table! + connection.execute "DROP TABLE #{table_name}" + end + + def create_table! + connection.execute <<-end_sql + CREATE TABLE #{table_name} ( + id #{connection.type_to_sql(:primary_key)}, + #{connection.quote_column_name(session_id_column)} VARCHAR(255) UNIQUE, + #{connection.quote_column_name(data_column_name)} TEXT + ) + end_sql + end + end + # The default Active Record class. class Session < ActiveRecord::Base + extend ClassMethods + ## # :singleton-method: # Customizable data column name. Defaults to 'data'. @@ -62,7 +88,7 @@ module ActiveRecord class << self def data_column_size_limit - @data_column_size_limit ||= columns_hash[@@data_column_name].limit + @data_column_size_limit ||= columns_hash[data_column_name].limit end # Hook to set up sessid compatibility. @@ -71,29 +97,11 @@ module ActiveRecord find_by_session_id(session_id) end - def marshal(data) - ActiveSupport::Base64.encode64(Marshal.dump(data)) if data - end - - def unmarshal(data) - Marshal.load(ActiveSupport::Base64.decode64(data)) if data - end - - def create_table! - connection.execute <<-end_sql - CREATE TABLE #{table_name} ( - id INTEGER PRIMARY KEY, - #{connection.quote_column_name('session_id')} TEXT UNIQUE, - #{connection.quote_column_name(@@data_column_name)} TEXT(255) - ) - end_sql - end - - def drop_table! - connection.execute "DROP TABLE #{table_name}" - end - private + def session_id_column + 'session_id' + end + # Compatibility with tables using sessid instead of session_id. def setup_sessid_compatibility! # Reset column info since it may be stale. @@ -106,6 +114,8 @@ module ActiveRecord define_method(:session_id) { sessid } define_method(:session_id=) { |session_id| self.sessid = session_id } else + class << self; remove_method :find_by_session_id; end + def self.find_by_session_id(session_id) find :first, :conditions => {:session_id=>session_id} end @@ -113,6 +123,11 @@ module ActiveRecord end end + def initialize(attributes = nil) + @data = nil + super + end + # Lazy-unmarshal session state. def data @data ||= self.class.unmarshal(read_attribute(@@data_column_name)) || {} @@ -122,22 +137,22 @@ module ActiveRecord # Has the session been loaded yet? def loaded? - !!@data + @data end private def marshal_data! - return false if !loaded? - write_attribute(@@data_column_name, self.class.marshal(self.data)) + return false unless loaded? + write_attribute(@@data_column_name, self.class.marshal(data)) end # Ensures that the data about to be stored in the database is not # larger than the data storage column. Raises # ActionController::SessionOverflowError. def raise_on_session_data_overflow! - return false if !loaded? + return false unless loaded? limit = self.class.data_column_size_limit - if loaded? and limit and read_attribute(@@data_column_name).size > limit + if limit and read_attribute(@@data_column_name).size > limit raise ActionController::SessionOverflowError end end @@ -162,6 +177,8 @@ module ActiveRecord # binary session data in a +text+ column. For higher performance, # store in a +blob+ column instead and forgo the Base64 encoding. class SqlBypass + extend ClassMethods + ## # :singleton-method: # Use the ActiveRecord::Base.connection by default. @@ -186,6 +203,8 @@ module ActiveRecord @@data_column = 'data' class << self + alias :data_column_name :data_column + def connection @@connection ||= ActiveRecord::Base.connection end @@ -196,43 +215,21 @@ module ActiveRecord new(:session_id => session_id, :marshaled_data => record['data']) end end - - def marshal(data) - ActiveSupport::Base64.encode64(Marshal.dump(data)) if data - end - - def unmarshal(data) - Marshal.load(ActiveSupport::Base64.decode64(data)) if data - end - - def create_table! - @@connection.execute <<-end_sql - CREATE TABLE #{table_name} ( - id INTEGER PRIMARY KEY, - #{@@connection.quote_column_name(session_id_column)} TEXT UNIQUE, - #{@@connection.quote_column_name(data_column)} TEXT - ) - end_sql - end - - def drop_table! - @@connection.execute "DROP TABLE #{table_name}" - end end - attr_reader :session_id + attr_reader :session_id, :new_record + alias :new_record? :new_record + attr_writer :data # Look for normal and marshaled data, self.find_by_session_id's way of # telling us to postpone unmarshaling until the data is requested. # We need to handle a normal data attribute in case of a new record. def initialize(attributes) - @session_id, @data, @marshaled_data = attributes[:session_id], attributes[:data], attributes[:marshaled_data] - @new_record = @marshaled_data.nil? - end - - def new_record? - @new_record + @session_id = attributes[:session_id] + @data = attributes[:data] + @marshaled_data = attributes[:marshaled_data] + @new_record = @marshaled_data.nil? end # Lazy-unmarshal session state. @@ -248,39 +245,41 @@ module ActiveRecord end def loaded? - !!@data + @data end def save - return false if !loaded? + return false unless loaded? marshaled_data = self.class.marshal(data) + connect = connection if @new_record @new_record = false - @@connection.update <<-end_sql, 'Create session' - INSERT INTO #{@@table_name} ( - #{@@connection.quote_column_name(@@session_id_column)}, - #{@@connection.quote_column_name(@@data_column)} ) + connect.update <<-end_sql, 'Create session' + INSERT INTO #{table_name} ( + #{connect.quote_column_name(session_id_column)}, + #{connect.quote_column_name(data_column)} ) VALUES ( - #{@@connection.quote(session_id)}, - #{@@connection.quote(marshaled_data)} ) + #{connect.quote(session_id)}, + #{connect.quote(marshaled_data)} ) end_sql else - @@connection.update <<-end_sql, 'Update session' - UPDATE #{@@table_name} - SET #{@@connection.quote_column_name(@@data_column)}=#{@@connection.quote(marshaled_data)} - WHERE #{@@connection.quote_column_name(@@session_id_column)}=#{@@connection.quote(session_id)} + connect.update <<-end_sql, 'Update session' + UPDATE #{table_name} + SET #{connect.quote_column_name(data_column)}=#{connect.quote(marshaled_data)} + WHERE #{connect.quote_column_name(session_id_column)}=#{connect.quote(session_id)} end_sql end end def destroy - unless @new_record - @@connection.delete <<-end_sql, 'Destroy session' - DELETE FROM #{@@table_name} - WHERE #{@@connection.quote_column_name(@@session_id_column)}=#{@@connection.quote(session_id)} - end_sql - end + return if @new_record + + connect = connection + connect.delete <<-end_sql, 'Destroy session' + DELETE FROM #{table_name} + WHERE #{connect.quote_column_name(session_id_column)}=#{connect.quote(session_id)} + end_sql end end @@ -289,7 +288,7 @@ module ActiveRecord cattr_accessor :session_class self.session_class = Session - SESSION_RECORD_KEY = 'rack.session.record'.freeze + SESSION_RECORD_KEY = 'rack.session.record' private def get_session(env, sid) @@ -316,7 +315,7 @@ module ActiveRecord sid end - + def destroy(env) if sid = current_session_id(env) Base.silence do diff --git a/activerecord/test/cases/session_store/session_test.rb b/activerecord/test/cases/session_store/session_test.rb new file mode 100644 index 0000000000..6f1c170a0c --- /dev/null +++ b/activerecord/test/cases/session_store/session_test.rb @@ -0,0 +1,68 @@ +require 'cases/helper' +require 'action_dispatch' +require 'active_record/session_store' + +module ActiveRecord + class SessionStore + class SessionTest < ActiveRecord::TestCase + self.use_transactional_fixtures = false + + def setup + super + Session.drop_table! if Session.table_exists? + end + + def test_data_column_name + # default column name is 'data' + assert_equal 'data', Session.data_column_name + end + + def test_table_name + assert_equal 'sessions', Session.table_name + end + + def test_create_table! + assert !Session.table_exists? + Session.create_table! + assert Session.table_exists? + Session.drop_table! + assert !Session.table_exists? + end + + def test_find_by_sess_id_compat + klass = Class.new(Session) do + def self.session_id_column + 'sessid' + end + end + klass.create_table! + + assert klass.columns_hash['sessid'], 'sessid column exists' + session = klass.new(:data => 'hello') + session.sessid = "100" + session.save! + + found = klass.find_by_session_id("100") + assert_equal session, found + assert_equal session.sessid, found.session_id + ensure + klass.drop_table! + end + + def test_find_by_session_id + Session.create_table! + session_id = "10" + s = Session.create!(:data => 'world', :session_id => session_id) + t = Session.find_by_session_id(session_id) + assert_equal s, t + assert_equal s.data, t.data + Session.drop_table! + end + + def test_loaded? + s = Session.new + assert !s.loaded?, 'session is not loaded' + end + end + end +end diff --git a/activerecord/test/cases/session_store/sql_bypass.rb b/activerecord/test/cases/session_store/sql_bypass.rb new file mode 100644 index 0000000000..f0ba166465 --- /dev/null +++ b/activerecord/test/cases/session_store/sql_bypass.rb @@ -0,0 +1,56 @@ +require 'cases/helper' +require 'action_dispatch' +require 'active_record/session_store' + +module ActiveRecord + class SessionStore + class SqlBypassTest < ActiveRecord::TestCase + def setup + super + Session.drop_table! if Session.table_exists? + end + + def test_create_table + assert !Session.table_exists? + SqlBypass.create_table! + assert Session.table_exists? + SqlBypass.drop_table! + assert !Session.table_exists? + end + + def test_new_record? + s = SqlBypass.new :data => 'foo', :session_id => 10 + assert s.new_record?, 'this is a new record!' + end + + def test_not_loaded? + s = SqlBypass.new({}) + assert !s.loaded?, 'it is not loaded' + end + + def test_loaded? + s = SqlBypass.new :data => 'hello' + assert s.loaded?, 'it is loaded' + end + + def test_save + SqlBypass.create_table! unless Session.table_exists? + session_id = 20 + s = SqlBypass.new :data => 'hello', :session_id => session_id + s.save + t = SqlBypass.find_by_session_id session_id + assert_equal s.session_id, t.session_id + assert_equal s.data, t.data + end + + def test_destroy + SqlBypass.create_table! unless Session.table_exists? + session_id = 20 + s = SqlBypass.new :data => 'hello', :session_id => session_id + s.save + s.destroy + assert_nil SqlBypass.find_by_session_id session_id + end + end + end +end diff --git a/activerecord/test/models/company_in_module.rb b/activerecord/test/models/company_in_module.rb index 83d71b6909..2c8c30efb4 100644 --- a/activerecord/test/models/company_in_module.rb +++ b/activerecord/test/models/company_in_module.rb @@ -1,4 +1,4 @@ -require 'active_support/core_ext/object/misc' +require 'active_support/core_ext/object/with_options' module MyApplication module Business diff --git a/activeresource/Rakefile b/activeresource/Rakefile index b1e5ca91d3..2145f1017c 100644 --- a/activeresource/Rakefile +++ b/activeresource/Rakefile @@ -1,8 +1,8 @@ -gem 'rdoc', '= 2.2' +gem 'rdoc', '>= 2.5.9' require 'rdoc' require 'rake' require 'rake/testtask' -require 'rake/rdoctask' +require 'rdoc/task' require 'rake/packagetask' require 'rake/gempackagetask' @@ -29,12 +29,12 @@ end # Generate the RDoc documentation -Rake::RDocTask.new { |rdoc| +RDoc::Task.new { |rdoc| rdoc.rdoc_dir = 'doc' rdoc.title = "Active Resource -- Object-oriented REST services" - rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' + rdoc.options << '-f' << 'horo' + rdoc.options << '--main' << 'README.rdoc' rdoc.options << '--charset' << 'utf-8' - rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo' rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG') rdoc.rdoc_files.include('lib/**/*.rb') rdoc.rdoc_files.exclude('lib/activeresource.rb') @@ -80,9 +80,3 @@ task :release => :package do Rake::Gemcutter::Tasks.new(spec).define Rake::Task['gem:push'].invoke end - -desc "Publish the API documentation" -task :pdoc => [:rdoc] do - require 'rake/contrib/sshpublisher' - Rake::SshDirPublisher.new("rails@api.rubyonrails.org", "public_html/ar", "doc").upload -end diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 6c494a8bcc..1557e090e1 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -7,7 +7,6 @@ require 'active_support/core_ext/module/attr_accessor_with_default' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/module/aliasing' require 'active_support/core_ext/object/blank' -require 'active_support/core_ext/object/misc' require 'active_support/core_ext/object/to_query' require 'active_support/core_ext/object/duplicable' require 'set' diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index 4d036d73cc..a176c037d5 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -6,6 +6,7 @@ require "fixtures/sound" require "fixtures/beast" require "fixtures/proxy" require 'active_support/json' +require 'active_support/ordered_hash' require 'active_support/core_ext/hash/conversions' require 'mocha' @@ -555,7 +556,7 @@ class BaseTest < Test::Unit::TestCase assert_equal '/people.xml?name[]=bob&name[]=your+uncle%2Bme&name[]=&name[]=false', Person.collection_path(:name => ['bob', 'your uncle+me', nil, false]) - assert_equal '/people.xml?struct[a][]=2&struct[a][]=1&struct[b]=fred', Person.collection_path(:struct => {:a => [2,1], 'b' => 'fred'}) + assert_equal '/people.xml?struct[a][]=2&struct[a][]=1&struct[b]=fred', Person.collection_path(:struct => ActiveSupport::OrderedHash[:a, [2,1], 'b', 'fred']) end def test_custom_element_path diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 60586cf99a..8706a2aa0b 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.0.0 [Release Candidate] (unreleased)* +* Removed Object#returning, Object#tap should be used instead. [Santiago Pastorino] + * Deprecation behavior is no longer hardcoded to the name of the environment. Instead, it is set via config.active_support.deprecation and can be one of :log, :stderr or :notify. :notify is a new style that sends the warning diff --git a/activesupport/Rakefile b/activesupport/Rakefile index 77b1a8431d..8e2683ef89 100644 --- a/activesupport/Rakefile +++ b/activesupport/Rakefile @@ -1,7 +1,7 @@ -gem 'rdoc', '= 2.2' +gem 'rdoc', '>= 2.5.9' require 'rdoc' require 'rake/testtask' -require 'rake/rdoctask' +require 'rdoc/task' require 'rake/gempackagetask' task :default => :test @@ -22,12 +22,12 @@ dist_dirs = [ "lib", "test"] # Genereate the RDoc documentation -Rake::RDocTask.new { |rdoc| +RDoc::Task.new { |rdoc| rdoc.rdoc_dir = 'doc' rdoc.title = "Active Support -- Utility classes and standard library extensions from Rails" - rdoc.options << '--line-numbers' << '--inline-source' + rdoc.options << '-f' << 'horo' + rdoc.options << '--main' << 'README.rdoc' rdoc.options << '--charset' << 'utf-8' - rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo' rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG') rdoc.rdoc_files.include('lib/active_support.rb') rdoc.rdoc_files.include('lib/active_support/**/*.rb') @@ -45,9 +45,3 @@ task :release => :package do Rake::Gemcutter::Tasks.new(spec).define Rake::Task['gem:push'].invoke end - -desc "Publish the API documentation" -task :pdoc => [:rdoc] do - require 'rake/contrib/sshpublisher' - Rake::SshDirPublisher.new("rails@api.rubyonrails.org", "public_html/as", "doc").upload -end diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 565c9af7fb..2763af6121 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -83,7 +83,7 @@ class Hash case value.class.to_s when 'Hash' if value['type'] == 'array' - child_key, entries = Array.wrap(value.detect { |k,v| k != 'type' }) # child_key is throwaway + _, entries = Array.wrap(value.detect { |k,v| k != 'type' }) if entries.nil? || (c = value['__content__'] && c.blank?) [] else diff --git a/activesupport/lib/active_support/core_ext/kernel/requires.rb b/activesupport/lib/active_support/core_ext/kernel/requires.rb index d2238898d6..3bf46271d7 100644 --- a/activesupport/lib/active_support/core_ext/kernel/requires.rb +++ b/activesupport/lib/active_support/core_ext/kernel/requires.rb @@ -11,13 +11,13 @@ module Kernel # 1. Requiring the module is unsuccessful, maybe it's a gem and nobody required rubygems yet. Try. begin require 'rubygems' - rescue LoadError => rubygems_not_installed + rescue LoadError # => rubygems_not_installed raise cannot_require end # 2. Rubygems is installed and loaded. Try to load the library again begin require library_name - rescue LoadError => gem_not_installed + rescue LoadError # => gem_not_installed raise cannot_require end end diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index 27618b55c6..790a26f5c1 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -5,9 +5,7 @@ require 'active_support/core_ext/object/try' require 'active_support/core_ext/object/conversions' require 'active_support/core_ext/object/instance_variables' -require 'active_support/core_ext/object/misc' -require 'active_support/core_ext/object/returning' require 'active_support/core_ext/object/to_json' require 'active_support/core_ext/object/to_param' require 'active_support/core_ext/object/to_query' diff --git a/activesupport/lib/active_support/core_ext/object/misc.rb b/activesupport/lib/active_support/core_ext/object/misc.rb deleted file mode 100644 index 3e3af03cc5..0000000000 --- a/activesupport/lib/active_support/core_ext/object/misc.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'active_support/core_ext/object/returning' -require 'active_support/core_ext/object/with_options' diff --git a/activesupport/lib/active_support/core_ext/object/returning.rb b/activesupport/lib/active_support/core_ext/object/returning.rb deleted file mode 100644 index 0dc2e1266a..0000000000 --- a/activesupport/lib/active_support/core_ext/object/returning.rb +++ /dev/null @@ -1,42 +0,0 @@ -class Object - # Returns +value+ after yielding +value+ to the block. This simplifies the - # process of constructing an object, performing work on the object, and then - # returning the object from a method. It is a Ruby-ized realization of the K - # combinator, courtesy of Mikael Brockman. - # - # ==== Examples - # - # # Without returning - # def foo - # values = [] - # values << "bar" - # values << "baz" - # return values - # end - # - # foo # => ['bar', 'baz'] - # - # # returning with a local variable - # def foo - # returning values = [] do - # values << 'bar' - # values << 'baz' - # end - # end - # - # foo # => ['bar', 'baz'] - # - # # returning with a block argument - # def foo - # returning [] do |values| - # values << 'bar' - # values << 'baz' - # end - # end - # - # foo # => ['bar', 'baz'] - def returning(value) - yield(value) - value - end -end diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 7d5143ba37..9a6da38b1c 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -592,7 +592,7 @@ module ActiveSupport #:nodoc: # Convert the provided const desc to a qualified constant name (as a string). # A module, class, symbol, or string may be provided. def to_constant_name(desc) #:nodoc: - name = case desc + case desc when String then desc.sub(/^::/, '') when Symbol then desc.to_s when Module diff --git a/activesupport/lib/active_support/descendants_tracker.rb b/activesupport/lib/active_support/descendants_tracker.rb index 6cba84d79e..4d1cfacc95 100644 --- a/activesupport/lib/active_support/descendants_tracker.rb +++ b/activesupport/lib/active_support/descendants_tracker.rb @@ -11,9 +11,9 @@ module ActiveSupport end def self.descendants(klass) - @@direct_descendants[klass].inject([]) do |descendants, klass| - descendants << klass - descendants.concat klass.descendants + @@direct_descendants[klass].inject([]) do |descendants, _klass| + descendants << _klass + descendants.concat _klass.descendants end end @@ -40,4 +40,4 @@ module ActiveSupport DescendantsTracker.descendants(self) end end -end
\ No newline at end of file +end diff --git a/activesupport/lib/active_support/json/backends/yaml.rb b/activesupport/lib/active_support/json/backends/yaml.rb index 215b3d6f90..4cb9d01077 100644 --- a/activesupport/lib/active_support/json/backends/yaml.rb +++ b/activesupport/lib/active_support/json/backends/yaml.rb @@ -13,7 +13,7 @@ module ActiveSupport json = json.read end YAML.load(convert_json_to_yaml(json)) - rescue ArgumentError => e + rescue ArgumentError raise ParseError, "Invalid JSON string" end diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb index 11c72d873b..3d80f5fa58 100644 --- a/activesupport/lib/active_support/multibyte/unicode.rb +++ b/activesupport/lib/active_support/multibyte/unicode.rb @@ -99,15 +99,15 @@ module ActiveSupport current = codepoints[pos] if ( # CR X LF - one = ( previous == database.boundary[:cr] and current == database.boundary[:lf] ) or + ( previous == database.boundary[:cr] and current == database.boundary[:lf] ) or # L X (L|V|LV|LVT) - two = ( database.boundary[:l] === previous and in_char_class?(current, [:l,:v,:lv,:lvt]) ) or + ( database.boundary[:l] === previous and in_char_class?(current, [:l,:v,:lv,:lvt]) ) or # (LV|V) X (V|T) - three = ( in_char_class?(previous, [:lv,:v]) and in_char_class?(current, [:v,:t]) ) or + ( in_char_class?(previous, [:lv,:v]) and in_char_class?(current, [:v,:t]) ) or # (LVT|T) X (T) - four = ( in_char_class?(previous, [:lvt,:t]) and database.boundary[:t] === current ) or + ( in_char_class?(previous, [:lvt,:t]) and database.boundary[:t] === current ) or # X Extend - five = (database.boundary[:extend] === current) + (database.boundary[:extend] === current) ) else unpacked << codepoints[marker..pos-1] @@ -238,7 +238,6 @@ module ActiveSupport bytes.each_index do |i| byte = bytes[i] - is_ascii = byte < 128 is_cont = byte > 127 && byte < 192 is_lead = byte > 191 && byte < 245 is_unused = byte > 240 diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 93d1907edc..886d7183eb 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -41,10 +41,30 @@ module ActiveSupport autoload :Event, 'active_support/notifications/instrumenter' autoload :Fanout, 'active_support/notifications/fanout' + @instrumenters = Hash.new { |h,k| h[k] = notifier.listening?(k) } + class << self attr_writer :notifier - delegate :publish, :subscribe, :unsubscribe, :to => :notifier - delegate :instrument, :to => :instrumenter + delegate :publish, :unsubscribe, :to => :notifier + + def instrument(name, payload = {}) + if @instrumenters[name] + instrumenter.instrument(name, payload) { yield payload if block_given? } + else + yield payload if block_given? + end + end + + def subscribe(*args, &block) + notifier.subscribe(*args, &block).tap do + @instrumenters.clear + end + end + + def unsubscribe(*args) + notifier.unsubscribe(*args) + @instrumenters.clear + end def notifier @notifier ||= Fanout.new diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 64f315cb6a..adc34f3286 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -9,15 +9,16 @@ module ActiveSupport end def subscribe(pattern = nil, block = Proc.new) - @listeners_for.clear - Subscriber.new(pattern, block).tap do |s| + subscriber = Subscriber.new(pattern, block).tap do |s| @subscribers << s end + @listeners_for.clear + subscriber end def unsubscribe(subscriber) - @listeners_for.clear @subscribers.reject! {|s| s.matches?(subscriber)} + @listeners_for.clear end def publish(name, *args) @@ -28,6 +29,10 @@ module ActiveSupport @listeners_for[name] ||= @subscribers.select { |s| s.subscribed_to?(name) } end + def listening?(name) + listeners_for(name).any? + end + # This is a sync queue, so there is not waiting. def wait end diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index e98189f899..441fefb491 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -9,30 +9,24 @@ module ActiveSupport def initialize(notifier) @id = unique_id @notifier = notifier - @started = nil - @finished = nil end # Instrument the given block by measuring the time taken to execute it # and publish it. Notice that events get sent even if an error occurs # in the passed-in block def instrument(name, payload={}) + started = Time.now + begin - @started = Time.now - yield(payload) if block_given? + yield rescue Exception => e payload[:exception] = [e.class.name, e.message] raise e ensure - @finished = Time.now - @notifier.publish(name, @started, @finished, @id, payload) + @notifier.publish(name, started, Time.now, @id, payload) end end - def elapsed - 1000.0 * (@finished.to_f - @started.to_f) - end - private def unique_id SecureRandom.hex(10) diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb index d8942c3974..b2d9ddfeb7 100644 --- a/activesupport/lib/active_support/testing/setup_and_teardown.rb +++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb @@ -96,7 +96,7 @@ module ActiveSupport protected def retrieve_mocha_counter(result) #:nodoc: - if using_mocha = respond_to?(:mocha_verify) + if respond_to?(:mocha_verify) # using mocha if defined?(Mocha::TestCaseAdapter::AssertionCounter) Mocha::TestCaseAdapter::AssertionCounter.new(result) else diff --git a/activesupport/lib/active_support/xml_mini/libxml.rb b/activesupport/lib/active_support/xml_mini/libxml.rb index 9cf187302f..7fdcb11465 100644 --- a/activesupport/lib/active_support/xml_mini/libxml.rb +++ b/activesupport/lib/active_support/xml_mini/libxml.rb @@ -1,5 +1,4 @@ require 'libxml' -require 'active_support/core_ext/object/returning' require 'active_support/core_ext/object/blank' # = XmlMini LibXML implementation diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 3e14c754b7..212c1f82a8 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -279,7 +279,7 @@ module CacheStoreBehavior assert_equal 'bar', @cache.read('foo') raise ArgumentError.new end - rescue ArgumentError => e + rescue ArgumentError end assert_equal "bar", @cache.read('foo') Time.stubs(:now).returns(time + 71) diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 39ee0ac748..5d9cdf22c2 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -147,7 +147,7 @@ class ModuleTest < Test::Unit::TestCase end assert_nothing_raised do - child = Class.new(parent) do + Class.new(parent) do class << self delegate :parent_method, :to => :superclass end diff --git a/activesupport/test/core_ext/object/to_query_test.rb b/activesupport/test/core_ext/object/to_query_test.rb index 4d655913cc..e28b4cd493 100644 --- a/activesupport/test/core_ext/object/to_query_test.rb +++ b/activesupport/test/core_ext/object/to_query_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/ordered_hash' require 'active_support/core_ext/object/to_query' class ToQueryTest < Test::Unit::TestCase @@ -18,12 +19,12 @@ class ToQueryTest < Test::Unit::TestCase def test_nested_conversion assert_query_equal 'person[login]=seckar&person[name]=Nicholas', - :person => {:name => 'Nicholas', :login => 'seckar'} + :person => ActiveSupport::OrderedHash[:login, 'seckar', :name, 'Nicholas'] end def test_multiple_nested assert_query_equal 'account[person][id]=20&person[id]=10', - :person => {:id => 10}, :account => {:person => {:id => 20}} + ActiveSupport::OrderedHash[:account, {:person => {:id => 20}}, :person, {:id => 10}] end def test_array_values diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index c7088638c7..d7bde185bd 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -117,6 +117,7 @@ class DependenciesTest < Test::Unit::TestCase assert_equal true, $checked_verbose, 'After first load warnings should be left alone.' assert ActiveSupport::Dependencies.loaded.include?(expanded) + ActiveSupport::Dependencies.warnings_on_first_load = old_warnings end end @@ -418,7 +419,6 @@ class DependenciesTest < Test::Unit::TestCase def test_removal_from_tree_should_be_detected with_loading 'dependencies' do - root = ActiveSupport::Dependencies.autoload_paths.first c = ServiceOne ActiveSupport::Dependencies.clear assert ! defined?(ServiceOne) @@ -433,7 +433,6 @@ class DependenciesTest < Test::Unit::TestCase def test_references_should_work with_loading 'dependencies' do - root = ActiveSupport::Dependencies.autoload_paths.first c = ActiveSupport::Dependencies.ref("ServiceOne") service_one_first = ServiceOne assert_equal service_one_first, c.get diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index a679efb41e..1527d02d16 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -148,7 +148,7 @@ class TestJSONEncoding < Test::Unit::TestCase :latitude => 123.234 } } - result = ActiveSupport::JSON.encode(hash) + ActiveSupport::JSON.encode(hash) end end diff --git a/activesupport/test/load_paths_test.rb b/activesupport/test/load_paths_test.rb index 9c83d6f061..c8bc1a2ffe 100644 --- a/activesupport/test/load_paths_test.rb +++ b/activesupport/test/load_paths_test.rb @@ -8,8 +8,8 @@ class LoadPathsTest < Test::Unit::TestCase paths[expanded_path] += 1 paths } + load_paths_count[File.expand_path('../../lib', __FILE__)] -= 1 - # CI has a bunch of duplicate load paths - # assert_equal [], load_paths_count.select { |k, v| v > 1 }, $LOAD_PATH.inspect + assert_equal [], load_paths_count.select { |k, v| v > 1 }, $LOAD_PATH.inspect end end diff --git a/activesupport/test/memoizable_test.rb b/activesupport/test/memoizable_test.rb index 195e3eaa42..b11fa8d346 100644 --- a/activesupport/test/memoizable_test.rb +++ b/activesupport/test/memoizable_test.rb @@ -134,7 +134,6 @@ class MemoizableTest < ActiveSupport::TestCase end def test_reloadable - counter = @calculator.counter assert_equal 1, @calculator.counter assert_equal 2, @calculator.counter(:reload) assert_equal 2, @calculator.counter diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index 78232d8eb5..6ebbfdf334 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -234,7 +234,7 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase def test_include_raises_when_nil_is_passed @chars.include?(nil) flunk "Expected chars.include?(nil) to raise TypeError or NoMethodError" - rescue Exception => e + rescue Exception end def test_index_should_return_character_offset diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 41e8ca4ae7..9faa11efbc 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -172,15 +172,6 @@ module Notifications :exception => ["RuntimeError", "FAIL"]], @events.last.payload end - def test_elapsed - instrument(:something) do - sleep(0.001) - end - - # Elapsed returns duration in ms - assert_in_delta 1, ActiveSupport::Notifications.instrumenter.elapsed, 100 - end - def test_event_is_pushed_even_without_block instrument(:awesome, :payload => "notifications") assert_equal 1, @events.size diff --git a/activesupport/test/option_merger_test.rb b/activesupport/test/option_merger_test.rb index b898292c9c..33e3e69666 100644 --- a/activesupport/test/option_merger_test.rb +++ b/activesupport/test/option_merger_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/core_ext/object/misc' +require 'active_support/core_ext/object/with_options' class OptionMergerTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index d340bed444..f47e896487 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -214,7 +214,7 @@ class OrderedHashTest < Test::Unit::TestCase def test_alternate_initialization_raises_exception_on_odd_length_args begin - alternate = ActiveSupport::OrderedHash[1,2,3,4,5] + ActiveSupport::OrderedHash[1,2,3,4,5] flunk "Hash::[] should have raised an exception on initialization " + "with an odd number of parameters" rescue diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index 3092fe01ae..633d3b212b 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -49,8 +49,8 @@ class AssertDifferenceTest < ActiveSupport::TestCase end def test_expression_is_evaluated_in_the_appropriate_scope - local_scope = 'foo' silence_warnings do + local_scope = 'foo' assert_difference('local_scope; @object.num') { @object.increment } end end diff --git a/doc/template/horo.rb b/doc/template/horo.rb deleted file mode 100644 index b38fa28cde..0000000000 --- a/doc/template/horo.rb +++ /dev/null @@ -1,618 +0,0 @@ -# Horo RDoc template -# Author: Hongli Lai - http://izumi.plan99.net/blog/ -# -# Based on the Jamis template: -# http://weblog.jamisbuck.org/2005/4/8/rdoc-template - -if defined?(RDoc::Diagram) - RDoc::Diagram.class_eval do - remove_const(:FONT) - const_set(:FONT, "\"Bitstream Vera Sans\"") - end -end - -require 'rdoc/generator/html' - -module RDoc -module Generator -class HTML -class HORO - -FONTS = "\"Bitstream Vera Sans\", Verdana, Arial, Helvetica, sans-serif" - -STYLE = <<CSS -a { - color: #00F; - text-decoration: none; -} - -a:hover { - color: #77F; - text-decoration: underline; -} - -body, td, p { - font-family: <%= values['fonts'] %>; - background: #FFF; - color: #000; - margin: 0px; - font-size: small; -} - -p { - margin-top: 0.5em; - margin-bottom: 0.5em; -} - -#content { - margin: 2em; - margin-left: 3.5em; - margin-right: 3.5em; -} - -#description p { - margin-bottom: 0.5em; -} - -.sectiontitle { - margin-top: 1em; - margin-bottom: 1em; - padding: 0.5em; - padding-left: 2em; - background: #005; - color: #FFF; - font-weight: bold; -} - -.attr-rw { - padding-left: 1em; - padding-right: 1em; - text-align: center; - color: #055; -} - -.attr-name { - font-weight: bold; -} - -.attr-desc { -} - -.attr-value { - font-family: monospace; -} - -.file-title-prefix { - font-size: large; -} - -.file-title { - font-size: large; - font-weight: bold; - background: #005; - color: #FFF; -} - -.banner { - background: #005; - color: #FFF; - border: 1px solid black; - padding: 1em; -} - -.banner td { - background: transparent; - color: #FFF; -} - -h1 a, h2 a, .sectiontitle a, .banner a { - color: #FF0; -} - -h1 a:hover, h2 a:hover, .sectiontitle a:hover, .banner a:hover { - color: #FF7; -} - -.dyn-source { - display: none; - background: #fffde8; - color: #000; - border: #ffe0bb dotted 1px; - margin: 0.5em 2em 0.5em 2em; - padding: 0.5em; -} - -.dyn-source .cmt { - color: #00F; - font-style: italic; -} - -.dyn-source .kw { - color: #070; - font-weight: bold; -} - -.method { - margin-left: 1em; - margin-right: 1em; - margin-bottom: 1em; -} - -.description pre { - padding: 0.5em; - border: #ffe0bb dotted 1px; - background: #fffde8; -} - -.method .title { - font-family: monospace; - font-size: large; - border-bottom: 1px dashed black; - margin-bottom: 0.3em; - padding-bottom: 0.1em; -} - -.method .description, .method .sourcecode { - margin-left: 1em; -} - -.description p, .sourcecode p { - margin-bottom: 0.5em; -} - -.method .sourcecode p.source-link { - text-indent: 0em; - margin-top: 0.5em; -} - -.method .aka { - margin-top: 0.3em; - margin-left: 1em; - font-style: italic; - text-indent: 2em; -} - -h1 { - padding: 1em; - margin-left: -1.5em; - font-size: x-large; - font-weight: bold; - color: #FFF; - background: #007; -} - -h2 { - padding: 0.5em 1em 0.5em 1em; - margin-left: -1.5em; - font-size: large; - font-weight: bold; - color: #FFF; - background: #009; -} - -h3, h4, h5, h6 { - color: #220088; - border-bottom: #5522bb solid 1px; -} - -.sourcecode > pre { - padding: 0.5em; - border: 1px dotted black; - background: #FFE; -} - -dt { - font-weight: bold -} - -dd { - margin-bottom: 0.7em; -} -CSS - -XHTML_PREAMBLE = %{<?xml version="1.0" encoding="<%= values['charset'] %>"?> -<!DOCTYPE html - PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -} - -XHTML_FRAMESET_PREAMBLE = %{ -<!DOCTYPE html - PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> -} - -HEADER = XHTML_PREAMBLE + <<ENDHEADER -<html> - <head> - <title><%= values['title'] %></title> - <meta http-equiv="Content-Type" content="text/html; charset=<%= values['charset'] %>" /> - <link rel="stylesheet" href="<%= values['style_url'] %>" type="text/css" media="screen" /> - - <script language="JavaScript" type="text/javascript"> - // <![CDATA[ - - function toggleSource( id ) - { - var elem - var link - - if( document.getElementById ) - { - elem = document.getElementById( id ) - link = document.getElementById( "l_" + id ) - } - else if ( document.all ) - { - elem = eval( "document.all." + id ) - link = eval( "document.all.l_" + id ) - } - else - return false; - - if( elem.style.display == "block" ) - { - elem.style.display = "none" - link.innerHTML = "show source" - } - else - { - elem.style.display = "block" - link.innerHTML = "hide source" - } - } - - function openCode( url ) - { - window.open( url, "SOURCE_CODE", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=480,width=750" ).focus(); - } - // ]]> - </script> - </head> - - <body> -ENDHEADER - -FILE_PAGE = <<HTML -<table border='0' cellpadding='0' cellspacing='0' width="100%" class='banner'> - <tr><td> - <table width="100%" border='0' cellpadding='0' cellspacing='0'><tr> - <td class="file-title" colspan="2"><span class="file-title-prefix">File</span><br /><%= values['short_name'] %></td> - <td align="right"> - <table border='0' cellspacing="0" cellpadding="2"> - <tr> - <td>Path:</td> - <td><%= values['full_path'] %> -<% if values['cvsurl'] %> - (<a href="<%= values['cvsurl'] %>">CVS</a>) -<% end %> - </td> - </tr> - <tr> - <td>Modified:</td> - <td><%= values['dtm_modified'] %></td> - </tr> - </table> - </td></tr> - </table> - </td></tr> -</table><br /> -HTML - -################################################################### - -CLASS_PAGE = <<HTML -<table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr> - <td class="file-title"><span class="file-title-prefix"><%= values['classmod'] %></span><br /><%= values['full_name'] %></td> - <td align="right"> - <table cellspacing="0" cellpadding="2"> - <tr valign="top"> - <td>In:</td> - <td> -<% values['infiles'].each do |infile| %> -<%= href infile['full_path_url'], infile['full_path'] %>: -<% if infile['cvsurl'] %> - (<a href="<%= infile['cvsurl'] %>">CVS</a>) -<% end %> -<% end %> - </td> - </tr> -<% if values['parent'] %> - <tr> - <td>Parent:</td> - <td> -<% if values['par_url'] %> - <a href="<%= values['par_url'] %>"> -<% end %> -<%= values['parent'] %> -<% if values['par_url'] %> - </a> -<% end %> - </td> - </tr> -<% end %> - </table> - </td> - </tr> - </table> -HTML - -################################################################### - -METHOD_LIST = <<HTML - <div id="content"> -<% if values['diagram'] %> - <table cellpadding='0' cellspacing='0' border='0' width="100%"><tr><td align="center"> - <%= values['diagram'] %> - </td></tr></table> -<% end %> - -<% if values['description'] %> - <div class="description"><%= values['description'] %></div> -<% end %> - -<% if values['requires'] %> - <div class="sectiontitle">Required Files</div> - <ul> -<% values['requires'].each do |require| %> - <li><%= href require['aref'], require['name'] %>:</li> -<% end %> - </ul> -<% end %> - -<% if values['toc'] %> - <div class="sectiontitle">Contents</div> - <ul> -<% values['toc'].each do |toc| %> - <li><a href="#<%= toc['href'] %>"><%= toc['secname'] %></a></li> -<% end %> - </ul> -<% end %> - -<% if values['methods'] %> - <div class="sectiontitle">Methods</div> - <ul> -<% values['methods'].each do |method| %> - <li><%= href method['aref'], method['name'] %></li> -<% end %> - </ul> -<% end %> - -<% if values['includes'] %> -<div class="sectiontitle">Included Modules</div> -<ul> -<% values['includes'].each do |include| %> - <li><%= href include['aref'], include['name'] %>:</li> -<% end %> -</ul> -<% end %> - -<% values['sections'].each do |section| %> -<% if section['sectitle'] %> -<div class="sectiontitle"><a name="<%= section['secsequence'] %>"><%= section['sectitle'] %></a></div> -<% if section['seccomment'] %> -<div class="description"> -<%= section['seccomment'] %> -</div> -<% end %> -<% end %> - -<% if section['classlist'] %> - <div class="sectiontitle">Classes and Modules</div> - <%= section['classlist'] %> -<% end %> - -<% if section['constants'] %> - <div class="sectiontitle">Constants</div> - <table border='0' cellpadding='5'> -<% section['constants'].each do |constant| %> - <tr valign='top'> - <td class="attr-name"><%= constant['name'] %></td> - <td>=</td> - <td class="attr-value"><%= constant['value'] %></td> - </tr> -<% if constant['desc'] %> - <tr valign='top'> - <td> </td> - <td colspan="2" class="attr-desc"><%= constant['desc'] %></td> - </tr> -<% end %> -<% end %> - </table> -<% end %> - -<% if section['attributes'] %> - <div class="sectiontitle">Attributes</div> - <table border='0' cellpadding='5'> -<% section['attributes'].each do |attribute| %> - <tr valign='top'> - <td class='attr-rw'> -<% if attribute['rw'] %> -[<%= attribute['rw'] %>] -<% end %> - </td> - <td class='attr-name'><%= attribute['name'] %></td> - <td class='attr-desc'><%= attribute['a_desc'] %></td> - </tr> -<% end %> - </table> -<% end %> - -<% if section['method_list'] %> -<% section['method_list'].each do |method_list| %> -<% if method_list['methods'] %> -<div class="sectiontitle"><%= method_list['type'] %> <%= method_list['category'] %> methods</div> -<% method_list['methods'].each do |method| %> -<div class="method"> - <div class="title"> -<% if method['callseq'] %> - <a name="<%= method['aref'] %>"></a><b><%= method['callseq'] %></b> -<% end %> -<% unless method['callseq'] %> - <a name="<%= method['aref'] %>"></a><b><%= method['name'] %></b><%= method['params'] %> -<% end %> -<% if method['codeurl'] %> -[ <a href="<%= method['codeurl'] %>" target="SOURCE_CODE" onclick="javascript:openCode('<%= method['codeurl'] %>'); return false;">source</a> ] -<% end %> - </div> -<% if method['m_desc'] %> - <div class="description"> - <%= method['m_desc'] %> - </div> -<% end %> -<% if method['aka'] %> -<div class="aka"> - This method is also aliased as -<% method['aka'].each do |aka| %> - <a href="<%= aka['aref'] %>"><%= aka['name'] %></a> -<% end %> -</div> -<% end %> -<% if method['sourcecode'] %> -<div class="sourcecode"> - <p class="source-link">[ <a href="javascript:toggleSource('<%= method['aref'] %>_source')" id="l_<%= method['aref'] %>_source">show source</a> ]</p> - <div id="<%= method['aref'] %>_source" class="dyn-source"> -<pre> -<%= method['sourcecode'] %> -</pre> - </div> -</div> -<% end %> -</div> -<% end %> -<% end %> -<% end %> -<% end %> -<% end %> -</div> -HTML - -FOOTER = <<ENDFOOTER - </body> -</html> -ENDFOOTER - -BODY = HEADER + <<ENDBODY - <%= template_include %> <!-- banner header --> - - <div id="bodyContent"> - #{METHOD_LIST} - </div> - - #{FOOTER} -ENDBODY - -########################## Source code ########################## - -SRC_PAGE = XHTML_PREAMBLE + <<HTML -<html> -<head><title><%= values['title'] %></title> -<meta http-equiv="Content-Type" content="text/html; charset=<%= values['charset'] %>" /> -<style type="text/css"> -.ruby-comment { color: green; font-style: italic } -.ruby-constant { color: #4433aa; font-weight: bold; } -.ruby-identifier { color: #222222; } -.ruby-ivar { color: #2233dd; } -.ruby-keyword { color: #3333FF; font-weight: bold } -.ruby-node { color: #777777; } -.ruby-operator { color: #111111; } -.ruby-regexp { color: #662222; } -.ruby-value { color: #662222; font-style: italic } - .kw { color: #3333FF; font-weight: bold } - .cmt { color: green; font-style: italic } - .str { color: #662222; font-style: italic } - .re { color: #662222; } -</style> -</head> -<body bgcolor="white"> -<pre><%= values['code'] %></pre> -</body> -</html> -HTML - -########################## Index ################################ - -FR_INDEX_BODY = <<HTML -<%= template_include %> -HTML - -FILE_INDEX = XHTML_PREAMBLE + <<HTML -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=<%= values['charset'] %>" /> -<title>Index</title> -<style type="text/css"> -<!-- - body { - background-color: #EEE; - font-family: #{FONTS}; - color: #000; - margin: 0px; - } - .banner { - background: #005; - color: #FFF; - padding: 0.2em; - font-size: small; - font-weight: bold; - text-align: center; - } - .entries { - margin: 0.25em 1em 0 1em; - font-size: x-small; - } - a { - color: #00F; - text-decoration: none; - white-space: nowrap; - } - a:hover { - color: #77F; - text-decoration: underline; - } ---> -</style> -<base target="docwin" /> -</head> -<body> -<div class="banner"><%= values['list_title'] %></div> -<div class="entries"> -<% values['entries'].each do |entrie| %> -<a href="<%= entrie['href'] %>"><%= entrie['name'] %></a><br /> -<% end %> -</div> -</body></html> -HTML - -CLASS_INDEX = FILE_INDEX -METHOD_INDEX = FILE_INDEX - -INDEX = XHTML_FRAMESET_PREAMBLE + <<HTML -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head> - <title><%= values['title'] %></title> - <meta http-equiv="Content-Type" content="text/html; charset=<%= values['charset'] %>" /> -</head> - -<frameset cols="20%,*"> - <frameset rows="15%,55%,30%"> - <frame src="fr_file_index.html" title="Files" name="Files" /> - <frame src="fr_class_index.html" name="Classes" /> - <frame src="fr_method_index.html" name="Methods" /> - </frameset> - <frame src="<%= values['initial_page'] %>" name="docwin" /> - <noframes> - <body bgcolor="white"> - Click <a href="html/index.html">here</a> for a non-frames - version of this page. - </body> - </noframes> -</frameset> - -</html> -HTML - -end -end -end -end diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 6a8db7c4a6..3cd9647799 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,8 @@ *Rails 3.0.0 [Release Candidate] (unreleased)* +* Application generation: --skip-testunit and --skip-activerecord become --skip-test-unit + and --skip-active-record respectively. [fxn] + * Added console to Rails::Railtie as a hook called just after console starts. [José Valim] * Rails no longer autoload code in lib for application. You need to explicitly require it. [José Valim] diff --git a/railties/Rakefile b/railties/Rakefile index 19c860f257..8e78d2ff4a 100644 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -1,8 +1,8 @@ -gem 'rdoc', '= 2.2' +gem 'rdoc', '>= 2.5.9' require 'rdoc' require 'rake' require 'rake/testtask' -require 'rake/rdoctask' +require 'rdoc/task' require 'rake/gempackagetask' require 'date' @@ -35,6 +35,13 @@ end # Update spinoffs ------------------------------------------------------------------- +desc "Updates application README to the latest version Railties README" +task :update_readme do + readme = "lib/rails/generators/rails/app/templates/README" + rm readme + cp "./README.rdoc", readme +end + desc 'Generate guides (for authors), use ONLY=foo to process just "foo.textile"' task :generate_guides do ENV["WARN_BROKEN_LINKS"] = "1" # authors can't disable this @@ -53,12 +60,12 @@ end # Generate documentation ------------------------------------------------------------------ -Rake::RDocTask.new { |rdoc| +RDoc::Task.new { |rdoc| rdoc.rdoc_dir = 'doc' rdoc.title = "Railties -- Gluing the Engine to the Rails" - rdoc.options << '--line-numbers' << '--inline-source' << '--accessor' << 'cattr_accessor=object' + rdoc.options << '-f' << 'horo' + rdoc.options << '--main' << 'README.rdoc' rdoc.options << '--charset' << 'utf-8' - rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo' rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG') rdoc.rdoc_files.include('lib/**/*.rb') rdoc.rdoc_files.exclude('lib/rails/generators/**/templates/*') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index e53c7715bb..d14a531abe 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -157,21 +157,6 @@ WARNING. Using +duplicable?+ is discouraged because it depends on a hard-coded l NOTE: Defined in +active_support/core_ext/object/duplicable.rb+. -h4. +returning+ - -The method +returning+ yields its argument to a block and returns it. You typically use it with a mutable object that gets modified in the block: - -<ruby> -def html_options_for_form(url_for_options, options, *parameters_for_url) - returning options.stringify_keys do |html_options| - html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart") - html_options["action"] = url_for(url_for_options, *parameters_for_url) - end -end -</ruby> - -NOTE: Defined in +active_support/core_ext/object/returning.rb+. - h4. +try+ Sometimes you want to call a method provided the receiver object is not +nil+, which is something you usually check first. diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index c99aa3c0cd..1324cc1f67 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -168,7 +168,7 @@ module Rails :desc => "Path to an application builder (can be a filesystem path or URL)" class_option :template, :type => :string, :aliases => "-m", - :desc => "Path to an application template (can be a filesystem path or URL)." + :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" @@ -179,11 +179,11 @@ module Rails class_option :skip_gemfile, :type => :boolean, :default => false, :desc => "Don't create a Gemfile" - class_option :skip_activerecord, :type => :boolean, :aliases => "-O", :default => false, - :desc => "Skip ActiveRecord files" + class_option :skip_active_record, :type => :boolean, :aliases => "-O", :default => false, + :desc => "Skip Active Record files" - class_option :skip_testunit, :type => :boolean, :aliases => "-T", :default => false, - :desc => "Skip TestUnit files" + class_option :skip_test_unit, :type => :boolean, :aliases => "-T", :default => false, + :desc => "Skip Test::Unit files" class_option :skip_prototype, :type => :boolean, :aliases => "-J", :default => false, :desc => "Skip Prototype files" @@ -205,7 +205,7 @@ module Rails super - if !options[:skip_activerecord] && !DATABASES.include?(options[:database]) + if !options[:skip_active_record] && !DATABASES.include?(options[:database]) raise Error, "Invalid value for --database option. Supported for preconfiguration are: #{DATABASES.join(", ")}." end end @@ -239,8 +239,8 @@ module Rails template "config/boot.rb" end - def create_activerecord_files - return if options[:skip_activerecord] + def create_active_record_files + return if options[:skip_active_record] build(:database_yml) end @@ -281,7 +281,7 @@ module Rails end def create_test_files - build(:test) unless options[:skip_testunit] + build(:test) unless options[:skip_test_unit] end def create_tmp_files diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 190ab04cf5..7d63e99e05 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -1,6 +1,6 @@ require File.expand_path('../boot', __FILE__) -<% unless options[:skip_activerecord] -%> +<% unless options[:skip_active_record] -%> require 'rails/all' <% else -%> # Pick the frameworks you want: diff --git a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt index 86564031f5..a8f7aeac7d 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt @@ -3,7 +3,7 @@ require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase -<% unless options[:skip_activerecord] -%> +<% unless options[:skip_active_record] -%> # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb index 0dfb5cd1c9..36bc542ffe 100644 --- a/railties/lib/rails/generators/test_case.rb +++ b/railties/lib/rails/generators/test_case.rb @@ -51,7 +51,7 @@ module Rails # Sets default arguments on generator invocation. This can be overwritten when # invoking it. # - # arguments %w(app_name --skip-activerecord) + # arguments %w(app_name --skip-active-record) # def self.arguments(array) self.default_arguments = array @@ -214,8 +214,8 @@ module Rails # destination File.expand_path("../tmp", File.dirname(__FILE__)) # teardown :cleanup_destination_root # - # test "database.yml is not created when skipping activerecord" do - # run_generator %w(myapp --skip-activerecord) + # test "database.yml is not created when skipping Active Record" do + # run_generator %w(myapp --skip-active-record) # assert_no_file "config/database.yml" # end # end diff --git a/railties/lib/rails/info.rb b/railties/lib/rails/info.rb index e9c3ebe685..96f2d9296e 100644 --- a/railties/lib/rails/info.rb +++ b/railties/lib/rails/info.rb @@ -1,4 +1,3 @@ -require "active_support/core_ext/object/misc" require "cgi" require "active_support/core_ext/cgi" diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index ed06b4c767..db9f06be5c 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -38,7 +38,7 @@ module ApplicationTests ], middleware end - test "removing activerecord omits its middleware" do + test "removing Active Record omits its middleware" do use_frameworks [] boot! assert !middleware.include?("ActiveRecord::ConnectionAdapters::ConnectionManagement") diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 7018816af0..aca30e92b6 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -65,7 +65,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_options_before_application_name_raises_an_error - content = capture(:stderr){ run_generator(["--skip-activerecord", destination_root]) } + content = capture(:stderr){ run_generator(["--skip-active-record", destination_root]) } assert_equal "Options should be given after the application name. For details run: rails --help\n", content end @@ -117,13 +117,13 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile", /^gem\s+["']mysql["']$/ end - def test_config_database_is_not_added_if_skip_activerecord_is_given - run_generator [destination_root, "--skip-activerecord"] + def test_config_database_is_not_added_if_skip_active_record_is_given + run_generator [destination_root, "--skip-active-record"] assert_no_file "config/database.yml" end - def test_activerecord_is_removed_from_frameworks_if_skip_activerecord_is_given - run_generator [destination_root, "--skip-activerecord"] + def test_active_record_is_removed_from_frameworks_if_skip_active_record_is_given + run_generator [destination_root, "--skip-active-record"] assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ end @@ -137,7 +137,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_prototype_and_test_unit_are_skipped_if_required - run_generator [destination_root, "--skip-prototype", "--skip-testunit"] + run_generator [destination_root, "--skip-prototype", "--skip-test-unit"] assert_file "config/application.rb", /^\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(\)/ assert_file "public/javascripts/application.js" assert_no_file "public/javascripts/prototype.js" diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 74a09d4bde..f93800a5ae 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -108,7 +108,7 @@ class GeneratorsTest < Rails::Generators::TestCase assert_match /^ fixjour$/, output end - def test_rails_generators_does_not_show_activerecord_hooks + def test_rails_generators_does_not_show_active_record_hooks output = capture(:stdout){ Rails::Generators.help } assert_match /ActiveRecord:/, output assert_match /^ active_record:fixjour$/, output |