aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Rakefile1
-rw-r--r--actionpack/RUNNING_UNIT_TESTS2
-rw-r--r--actionpack/lib/abstract_controller/callbacks.rb2
-rw-r--r--actionpack/lib/action_controller/metal/responder.rb2
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb2
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb33
-rw-r--r--actionpack/lib/action_view/helpers/translation_helper.rb23
-rw-r--r--actionpack/lib/action_view/test_case.rb164
-rw-r--r--actionpack/test/controller/mime_responds_test.rb13
-rw-r--r--actionpack/test/fixtures/test/array_translation.erb1
-rw-r--r--actionpack/test/fixtures/test/scoped_array_translation.erb1
-rw-r--r--actionpack/test/fixtures/test/scoped_translation.erb1
-rw-r--r--actionpack/test/template/form_tag_helper_test.rb6
-rw-r--r--actionpack/test/template/test_case_test.rb279
-rw-r--r--actionpack/test/template/text_helper_test.rb58
-rw-r--r--actionpack/test/template/translation_helper_test.rb22
-rw-r--r--activerecord/test/cases/calculations_test.rb5
-rw-r--r--activeresource/lib/active_resource/base.rb6
-rw-r--r--activeresource/test/cases/base_test.rb7
-rw-r--r--activesupport/activesupport.gemspec2
-rwxr-xr-x[-rw-r--r--]activesupport/lib/active_support/core_ext/object/to_param.rb4
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb2
-rw-r--r--railties/Rakefile6
-rw-r--r--railties/guides/source/activerecord_validations_callbacks.textile7
-rw-r--r--railties/guides/source/contribute.textile1
-rw-r--r--railties/guides/source/credits.html.erb2
-rw-r--r--railties/guides/source/form_helpers.textile8
-rw-r--r--railties/guides/source/getting_started.textile3
-rw-r--r--railties/guides/source/initialization.textile66
-rw-r--r--railties/guides/w3c_validator.rb67
-rw-r--r--railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb2
-rw-r--r--railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb2
32 files changed, 517 insertions, 283 deletions
diff --git a/Rakefile b/Rakefile
index 2fa1f756d9..0ee7647a12 100644
--- a/Rakefile
+++ b/Rakefile
@@ -66,6 +66,7 @@ Rake::RDocTask.new do |rdoc|
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.options << '-A cattr_accessor=object'
rdoc.options << '--charset' << 'utf-8'
+ rdoc.options << '--main' << 'railties/README'
rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : './doc/template/horo'
diff --git a/actionpack/RUNNING_UNIT_TESTS b/actionpack/RUNNING_UNIT_TESTS
index 16b119878a..95a8bc7497 100644
--- a/actionpack/RUNNING_UNIT_TESTS
+++ b/actionpack/RUNNING_UNIT_TESTS
@@ -11,7 +11,7 @@ Rake can be found at http://rake.rubyforge.org
If you only want to run a single test suite, or don't want to bother with Rake,
you can do so with something like:
- ruby controller/base_tests.rb
+ ruby -Itest test/controller/base_tests.rb
== Dependency on ActiveRecord and database setup
diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb
index ee496dadc5..67efeb7063 100644
--- a/actionpack/lib/abstract_controller/callbacks.rb
+++ b/actionpack/lib/abstract_controller/callbacks.rb
@@ -20,7 +20,7 @@ module AbstractController
end
module ClassMethods
- # If :only or :accept are used, convert the options into the
+ # If :only or :except are used, convert the options into the
# primitive form (:per_key) used by ActiveSupport::Callbacks.
# The basic idea is that :only => :index gets converted to
# :if => proc {|c| c.action_name == "index" }, but that the
diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb
index 6ad9a23542..22bdcd0f3c 100644
--- a/actionpack/lib/action_controller/metal/responder.rb
+++ b/actionpack/lib/action_controller/metal/responder.rb
@@ -217,7 +217,7 @@ module ActionController #:nodoc:
# the verb is POST.
#
def default_action
- @action ||= ACTIONS_FOR_VERBS[request.method_symbol]
+ @action ||= ACTIONS_FOR_VERBS[request.request_method_symbol]
end
end
end
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index 2a3f826c15..796268628a 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -293,7 +293,7 @@ module ActionView
escape = options.key?("escape") ? options.delete("escape") : true
content = html_escape(content) if escape
- content_tag :textarea, content.html_safe, { "name" => name, "id" => sanitize_to_id(name) }.update(options)
+ content_tag :textarea, content.to_s.html_safe, { "name" => name, "id" => sanitize_to_id(name) }.update(options)
end
# Creates a check box form input tag.
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index 0e1bc139ff..41423d4e2e 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -537,9 +537,14 @@ module ActionView
end
AUTO_LINK_RE = %r{
- ( https?:// | www\. )
+ (?: ([\w+.:-]+:)// | www\. )
[^\s<]+
- }x unless const_defined?(:AUTO_LINK_RE)
+ }x
+
+ # regexps for determining context, used high-volume
+ AUTO_LINK_CRE = [/<[^>]+$/, /^[^>]*>/, /<a\b.*?>/i, /<\/a>/i]
+
+ AUTO_EMAIL_RE = /[\w.!#\$%+-]+@[\w-]+(?:\.[\w-]+)+/
BRACKETS = { ']' => '[', ')' => '(', '}' => '{' }
@@ -548,11 +553,10 @@ module ActionView
def auto_link_urls(text, html_options = {})
link_attributes = html_options.stringify_keys
text.gsub(AUTO_LINK_RE) do
- href = $&
+ scheme, href = $1, $&
punctuation = []
- left, right = $`, $'
- # detect already linked URLs and URLs in the middle of a tag
- if left =~ /<[^>]+$/ && right =~ /^[^>]*>/
+
+ if auto_linked?($`, $')
# do not change string; URL is already linked
href
else
@@ -566,9 +570,9 @@ module ActionView
end
link_text = block_given?? yield(href) : href
- href = 'http://' + href unless href =~ %r{^[a-z]+://}i
+ href = 'http://' + href unless scheme
- content_tag(:a, h(link_text), link_attributes.merge('href' => href)) + punctuation.reverse.join('')
+ content_tag(:a, link_text, link_attributes.merge('href' => href)) + punctuation.reverse.join('')
end
end
end
@@ -576,11 +580,10 @@ module ActionView
# Turns all email addresses into clickable links. If a block is given,
# each email is yielded and the result is used as the link text.
def auto_link_email_addresses(text, html_options = {})
- body = text.dup
- text.gsub(/([\w\.!#\$%\-+]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do
- text = $1
+ text.gsub(AUTO_EMAIL_RE) do
+ text = $&
- if body.match(/<a\b[^>]*>(.*)(#{Regexp.escape(text)})(.*)<\/a>/)
+ if auto_linked?($`, $')
text
else
display_text = (block_given?) ? yield(text) : text
@@ -588,6 +591,12 @@ module ActionView
end
end
end
+
+ # Detects already linked context or position in the middle of a tag
+ def auto_linked?(left, right)
+ (left =~ AUTO_LINK_CRE[0] and right =~ AUTO_LINK_CRE[1]) or
+ (left.rindex(AUTO_LINK_CRE[2]) and $' !~ AUTO_LINK_CRE[3])
+ end
end
end
end
diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb
index 086ad261c8..0d2b2aa7b1 100644
--- a/actionpack/lib/action_view/helpers/translation_helper.rb
+++ b/actionpack/lib/action_view/helpers/translation_helper.rb
@@ -3,7 +3,7 @@ require 'action_view/helpers/tag_helper'
module ActionView
module Helpers
module TranslationHelper
- # Delegates to I18n#translate but also performs three additional functions. First, it'll catch MissingTranslationData exceptions
+ # Delegates to I18n#translate but also performs three additional functions. First, it'll catch MissingTranslationData exceptions
# and turn them into inline spans that contains the missing key, such that you can see in a view what is missing where.
#
# Second, it'll scope the key by the current partial if the key starts with a period. So if you call translate(".foo") from the
@@ -11,16 +11,14 @@ module ActionView
# to translate many keys within the same partials and gives you a simple framework for scoping them consistently. If you don't
# prepend the key with a period, nothing is converted.
#
- # Third, it’ll mark the translation as safe HTML if the key has the suffix "_html" or the last element of the key is the word
- # "html". For example, calling translate("footer_html") or translate("footer.html") will return a safe HTML string that won’t
- # be escaped by other HTML helper methods. This naming convention helps to identify translations that include HTML tags so that
+ # Third, it’ll mark the translation as safe HTML if the key has the suffix "_html" or the last element of the key is the word
+ # "html". For example, calling translate("footer_html") or translate("footer.html") will return a safe HTML string that won’t
+ # be escaped by other HTML helper methods. This naming convention helps to identify translations that include HTML tags so that
# you know what kind of output to expect when you call translate in a template.
def translate(key, options = {})
- options[:raise] = true
- translation = I18n.translate(scope_key_by_partial(key), options)
- translation = (translation.respond_to?(:join) ? translation.join : translation)
- if html_safe_translation_key?(key)
+ translation = I18n.translate(scope_key_by_partial(key), options.merge!(:raise => true))
+ if html_safe_translation_key?(key) && translation.respond_to?(:html_safe)
translation.html_safe
else
translation
@@ -38,12 +36,10 @@ module ActionView
alias :l :localize
private
-
def scope_key_by_partial(key)
- strkey = key.respond_to?(:join) ? key.join : key.to_s
- if strkey.first == "."
+ if key.to_s.first == "."
if @_virtual_path
- @_virtual_path.gsub(%r{/_?}, ".") + strkey
+ @_virtual_path.gsub(%r{/_?}, ".") + key.to_s
else
raise "Cannot use t(#{key.inspect}) shortcut because path is not available"
end
@@ -53,8 +49,7 @@ module ActionView
end
def html_safe_translation_key?(key)
- key = key.is_a?(Array) ? key.last : key.to_s
- key =~ /(\b|_|\.)html$/
+ key.to_s =~ /(\b|_|\.)html$/
end
end
end
diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb
index 5517a56fb9..4dbbd2eb6a 100644
--- a/actionpack/lib/action_view/test_case.rb
+++ b/actionpack/lib/action_view/test_case.rb
@@ -10,11 +10,16 @@ module ActionView
attr_accessor :request, :response, :params
- def self.controller_path
- ''
+ class << self
+ attr_writer :controller_path
+ end
+
+ def controller_path=(path)
+ self.class.controller_path=(path)
end
def initialize
+ self.class.controller_path = ""
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@@ -24,80 +29,99 @@ module ActionView
end
end
- include ActionDispatch::Assertions, ActionDispatch::TestProcess
- include ActionController::TemplateAssertions
- include ActionView::Context
+ module Behavior
+ extend ActiveSupport::Concern
- include ActionController::PolymorphicRoutes
- include ActionController::RecordIdentifier
+ include ActionDispatch::Assertions, ActionDispatch::TestProcess
+ include ActionController::TemplateAssertions
+ include ActionView::Context
- include AbstractController::Helpers
- include ActionView::Helpers
+ include ActionController::PolymorphicRoutes
+ include ActionController::RecordIdentifier
- class_inheritable_accessor :helper_class
- attr_accessor :controller, :output_buffer, :rendered
+ include AbstractController::Helpers
+ include ActionView::Helpers
- setup :setup_with_controller
- def setup_with_controller
- @controller = TestController.new
- @output_buffer = ActiveSupport::SafeBuffer.new
- @rendered = ''
+ attr_accessor :controller, :output_buffer, :rendered
+
+ module ClassMethods
+ def tests(helper_class)
+ self.helper_class = helper_class
+ end
- self.class.send(:include_helper_modules!)
- make_test_case_available_to_view!
- end
+ def determine_default_helper_class(name)
+ mod = name.sub(/Test$/, '').constantize
+ mod.is_a?(Class) ? nil : mod
+ rescue NameError
+ nil
+ end
- def config
- @controller.config if @controller.respond_to?(:config)
- end
+ def helper_method(*methods)
+ # Almost a duplicate from ActionController::Helpers
+ methods.flatten.each do |method|
+ _helpers.module_eval <<-end_eval
+ def #{method}(*args, &block) # def current_user(*args, &block)
+ _test_case.send(%(#{method}), *args, &block) # test_case.send(%(current_user), *args, &block)
+ end # end
+ end_eval
+ end
+ end
- def render(options = {}, local_assigns = {}, &block)
- @rendered << output = _view.render(options, local_assigns, &block)
- output
- end
+ attr_writer :helper_class
- def protect_against_forgery?
- false
- end
+ def helper_class
+ @helper_class ||= determine_default_helper_class(name)
+ end
- class << self
- def tests(helper_class)
- self.helper_class = helper_class
- end
+ private
- def helper_class
- if current_helper_class = read_inheritable_attribute(:helper_class)
- current_helper_class
- else
- self.helper_class = determine_default_helper_class(name)
+ def include_helper_modules!
+ helper(helper_class) if helper_class
+ include _helpers
end
+
end
- def determine_default_helper_class(name)
- name.sub(/Test$/, '').constantize
- rescue NameError
- nil
+ def setup_with_controller
+ @controller = ActionView::TestCase::TestController.new
+ @output_buffer = ActiveSupport::SafeBuffer.new
+ @rendered = ''
+
+ self.class.send(:include_helper_modules!)
+ make_test_case_available_to_view!
+ say_no_to_protect_against_forgery!
end
- def helper_method(*methods)
- # Almost a duplicate from ActionController::Helpers
- methods.flatten.each do |method|
- _helpers.module_eval <<-end_eval, __FILE__, __LINE__ + 1
- def #{method}(*args, &block) # def current_user(*args, &block)
- _test_case.send(%(#{method}), *args, &block) # test_case.send(%(current_user), *args, &block)
- end # end
- end_eval
- end
+ def config
+ @controller.config if @controller.respond_to?(:config)
end
- private
- def include_helper_modules!
- helper(helper_class) if helper_class
- include _helpers
- end
- end
+ def render(options = {}, local_assigns = {}, &block)
+ @rendered << output = _view.render(options, local_assigns, &block)
+ output
+ end
+
+ included do
+ setup :setup_with_controller
+ end
private
+
+ # Support the selector assertions
+ #
+ # Need to experiment if this priority is the best one: rendered => output_buffer
+ def response_from_page_or_rjs
+ HTML::Document.new(@rendered.blank? ? @output_buffer : @rendered).root
+ end
+
+ def say_no_to_protect_against_forgery!
+ _helpers.module_eval do
+ def protect_against_forgery?
+ false
+ end
+ end
+ end
+
def make_test_case_available_to_view!
test_case_instance = self
_helpers.module_eval do
@@ -110,29 +134,30 @@ module ActionView
view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller)
view.singleton_class.send :include, _helpers
view.singleton_class.send :include, @controller._router.url_helpers
+ view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash"
view.output_buffer = self.output_buffer
view
end
- # Support the selector assertions
- #
- # Need to experiment if this priority is the best one: rendered => output_buffer
- def response_from_page_or_rjs
- HTML::Document.new(rendered.blank? ? output_buffer : rendered).root
- end
-
EXCLUDE_IVARS = %w{
+ @_result
@output_buffer
- @fixture_cache
+ @rendered
+ @templates
+ @view_context_class
+ @layouts
+ @partials
+ @controller
+
@method_name
- @_result
+ @fixture_cache
@loaded_fixtures
@test_passed
- @view
}
def _instance_variables
instance_variables - EXCLUDE_IVARS
+ instance_variables
end
def _assigns
@@ -155,5 +180,10 @@ module ActionView
super
end
end
+
+ end
+
+ include Behavior
+
end
end
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index c8ba8bcaf3..d654338dba 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -668,6 +668,19 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
+ def test_using_resource_for_put_with_html_rerender_on_failure_even_on_method_override
+ with_test_route_set do
+ errors = { :name => :invalid }
+ Customer.any_instance.stubs(:errors).returns(errors)
+ @request.env["rack.methodoverride.original_method"] = "POST"
+ put :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 200, @response.status
+ assert_equal "Edit world!\n", @response.body
+ assert_nil @response.location
+ end
+ end
+
def test_using_resource_for_put_with_xml_yields_ok_on_success
@request.accept = "application/xml"
put :using_resource
diff --git a/actionpack/test/fixtures/test/array_translation.erb b/actionpack/test/fixtures/test/array_translation.erb
deleted file mode 100644
index def3a1a0c1..0000000000
--- a/actionpack/test/fixtures/test/array_translation.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= t(['foo', 'bar', 'html']) %> \ No newline at end of file
diff --git a/actionpack/test/fixtures/test/scoped_array_translation.erb b/actionpack/test/fixtures/test/scoped_array_translation.erb
deleted file mode 100644
index 0a0c79f717..0000000000
--- a/actionpack/test/fixtures/test/scoped_array_translation.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= t(['.foo', '.bar']) %> \ No newline at end of file
diff --git a/actionpack/test/fixtures/test/scoped_translation.erb b/actionpack/test/fixtures/test/scoped_translation.erb
new file mode 100644
index 0000000000..30baa61c77
--- /dev/null
+++ b/actionpack/test/fixtures/test/scoped_translation.erb
@@ -0,0 +1 @@
+<%= t('.foo.bar') %> \ No newline at end of file
diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb
index 1c095b621e..b75863bb6a 100644
--- a/actionpack/test/template/form_tag_helper_test.rb
+++ b/actionpack/test/template/form_tag_helper_test.rb
@@ -206,6 +206,12 @@ class FormTagHelperTest < ActionView::TestCase
assert_dom_equal expected, actual
end
+ def test_text_area_tag_unescaped_nil_content
+ actual = text_area_tag "body", nil, :escape => false
+ expected = %(<textarea id="body" name="body"></textarea>)
+ assert_dom_equal expected, actual
+ end
+
def test_text_field_tag
actual = text_field_tag "title", "Hello!"
expected = %(<input id="title" name="title" type="text" value="Hello!" />)
diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb
index c1a38a25de..16e5ee4f72 100644
--- a/actionpack/test/template/test_case_test.rb
+++ b/actionpack/test/template/test_case_test.rb
@@ -2,21 +2,23 @@ require 'abstract_unit'
require 'controller/fake_controllers'
module ActionView
- class TestCase
- module ATestHelper
- end
- module AnotherTestHelper
- def from_another_helper
- 'Howdy!'
- end
+ module ATestHelper
+ end
+
+ module AnotherTestHelper
+ def from_another_helper
+ 'Howdy!'
end
+ end
- module ASharedTestHelper
- def from_shared_helper
- 'Holla!'
- end
+ module ASharedTestHelper
+ def from_shared_helper
+ 'Holla!'
end
+ end
+
+ class TestCase
helper ASharedTestHelper
module SharedTests
@@ -29,161 +31,186 @@ module ActionView
end
end
end
+ end
- class GeneralViewTest < ActionView::TestCase
- include SharedTests
- test_case = self
+ class GeneralViewTest < ActionView::TestCase
+ include SharedTests
+ test_case = self
- test "works without testing a helper module" do
- assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy'))
- end
+ test "works without testing a helper module" do
+ assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy'))
+ end
- test "can render a layout with block" do
- assert_equal "Before (ChrisCruft)\n!\nAfter",
- render(:layout => "test/layout_for_partial", :locals => {:name => "ChrisCruft"}) {"!"}
- end
+ test "can render a layout with block" do
+ assert_equal "Before (ChrisCruft)\n!\nAfter",
+ render(:layout => "test/layout_for_partial", :locals => {:name => "ChrisCruft"}) {"!"}
+ end
- helper AnotherTestHelper
- test "additional helper classes can be specified as in a controller" do
- assert test_case.ancestors.include?(AnotherTestHelper)
- assert_equal 'Howdy!', from_another_helper
- end
+ helper AnotherTestHelper
+ test "additional helper classes can be specified as in a controller" do
+ assert test_case.ancestors.include?(AnotherTestHelper)
+ assert_equal 'Howdy!', from_another_helper
+ end
+
+ test "determine_default_helper_class returns nil if name.sub(/Test$/, '').constantize resolves to a class" do
+ assert_nil self.class.determine_default_helper_class("String")
end
- class ClassMethodsTest < ActionView::TestCase
- include SharedTests
- test_case = self
+ test "delegates notice to request.flash" do
+ _view.request.flash.expects(:notice).with("this message")
+ _view.notice("this message")
+ end
- tests ATestHelper
- test "tests the specified helper module" do
- assert_equal ATestHelper, test_case.helper_class
- assert test_case.ancestors.include?(ATestHelper)
- end
+ test "delegates alert to request.flash" do
+ _view.request.flash.expects(:alert).with("this message")
+ _view.alert("this message")
+ end
+ end
- helper AnotherTestHelper
- test "additional helper classes can be specified as in a controller" do
- assert test_case.ancestors.include?(AnotherTestHelper)
- assert_equal 'Howdy!', from_another_helper
+ class ClassMethodsTest < ActionView::TestCase
+ include SharedTests
+ test_case = self
- test_case.helper_class.module_eval do
- def render_from_helper
- from_another_helper
- end
- end
- assert_equal 'Howdy!', render(:partial => 'test/from_helper')
- end
+ tests ATestHelper
+ test "tests the specified helper module" do
+ assert_equal ATestHelper, test_case.helper_class
+ assert test_case.ancestors.include?(ATestHelper)
end
- class ATestHelperTest < ActionView::TestCase
- include SharedTests
- test_case = self
+ helper AnotherTestHelper
+ test "additional helper classes can be specified as in a controller" do
+ assert test_case.ancestors.include?(AnotherTestHelper)
+ assert_equal 'Howdy!', from_another_helper
- test "inflects the name of the helper module to test from the test case class" do
- assert_equal ATestHelper, test_case.helper_class
- assert test_case.ancestors.include?(ATestHelper)
+ test_case.helper_class.module_eval do
+ def render_from_helper
+ from_another_helper
+ end
end
+ assert_equal 'Howdy!', render(:partial => 'test/from_helper')
+ end
+ end
- test "a configured test controller is available" do
- assert_kind_of ActionController::Base, controller
- assert_equal '', controller.controller_path
+ class HelperInclusionTest < ActionView::TestCase
+ module RenderHelper
+ def render_from_helper
+ render :partial => 'customer', :collection => @customers
end
+ end
- test "helper class that is being tested is always included in view instance" do
- # This ensure is a hidious hack to deal with these tests bleeding
- # methods between eachother
- begin
- self.class.helper_class.module_eval do
- def render_from_helper
- render :partial => 'customer', :collection => @customers
- end
- end
+ helper RenderHelper
- TestController.stubs(:controller_path).returns('test')
+ test "helper class that is being tested is always included in view instance" do
+ @controller.controller_path = 'test'
- @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
- assert_match /Hello: EloyHello: Manfred/, render(:partial => 'test/from_helper')
+ @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
+ assert_match /Hello: EloyHello: Manfred/, render(:partial => 'test/from_helper')
+ end
+ end
- ensure
- self.class.helper_class.send(:remove_method, :render_from_helper)
- end
+ class HelperExposureTest < ActionView::TestCase
+ helper(Module.new do
+ def render_from_helper
+ from_test_case
end
+ end)
+ test "is able to make methods available to the view" do
+ assert_equal 'Word!', render(:partial => 'test/from_helper')
+ end
- test "no additional helpers should shared across test cases" do
- assert !test_case.ancestors.include?(AnotherTestHelper)
- assert_raise(NoMethodError) { send :from_another_helper }
- end
+ def from_test_case; 'Word!'; end
+ helper_method :from_test_case
+ end
- test "is able to use routes" do
- controller.request.assign_parameters(@routes, 'foo', 'index')
- assert_equal '/foo', url_for
- assert_equal '/bar', url_for(:controller => 'bar')
+ class IgnoreProtectAgainstForgeryTest < ActionView::TestCase
+ module HelperThatInvokesProtectAgainstForgery
+ def help_me
+ protect_against_forgery?
end
+ end
- test "is able to use named routes" do
- with_routing do |set|
- set.draw { |map| resources :contents }
- assert_equal 'http://test.host/contents/new', new_content_url
- assert_equal 'http://test.host/contents/1', content_url(:id => 1)
- end
- end
+ helper HelperThatInvokesProtectAgainstForgery
- test "named routes can be used from helper included in view" do
- with_routing do |set|
- set.draw { |map| resources :contents }
- _helpers.module_eval do
- def render_from_helper
- new_content_url
- end
- end
+ test "protect_from_forgery? in any helpers returns false" do
+ assert !_view.help_me
+ end
- assert_equal 'http://test.host/contents/new', render(:partial => 'test/from_helper')
- end
- end
+ end
- test "is able to render partials with local variables" do
- assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy'))
- assert_equal 'Eloy', render(:partial => 'developers/developer',
- :locals => { :developer => stub(:name => 'Eloy') })
- end
+ class ATestHelperTest < ActionView::TestCase
+ include SharedTests
+ test_case = self
+
+ test "inflects the name of the helper module to test from the test case class" do
+ assert_equal ATestHelper, test_case.helper_class
+ assert test_case.ancestors.include?(ATestHelper)
+ end
+
+ test "a configured test controller is available" do
+ assert_kind_of ActionController::Base, controller
+ assert_equal '', controller.controller_path
+ end
- test "is able to render partials from templates and also use instance variables" do
- TestController.stubs(:controller_path).returns('test')
+ test "no additional helpers should shared across test cases" do
+ assert !test_case.ancestors.include?(AnotherTestHelper)
+ assert_raise(NoMethodError) { send :from_another_helper }
+ end
- @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
- assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
+ test "is able to use routes" do
+ controller.request.assign_parameters(@routes, 'foo', 'index')
+ assert_equal '/foo', url_for
+ assert_equal '/bar', url_for(:controller => 'bar')
+ end
+
+ test "is able to use named routes" do
+ with_routing do |set|
+ set.draw { |map| resources :contents }
+ assert_equal 'http://test.host/contents/new', new_content_url
+ assert_equal 'http://test.host/contents/1', content_url(:id => 1)
end
+ end
- test "is able to make methods available to the view" do
- # This ensure is a hidious hack to deal with these tests bleeding
- # methods between eachother
- begin
- _helpers.module_eval do
- def render_from_helper; from_test_case end
+ test "named routes can be used from helper included in view" do
+ with_routing do |set|
+ set.draw { |map| resources :contents }
+ _helpers.module_eval do
+ def render_from_helper
+ new_content_url
end
- assert_equal 'Word!', render(:partial => 'test/from_helper')
- ensure
- _helpers.send(:remove_method, :render_from_helper)
end
+
+ assert_equal 'http://test.host/contents/new', render(:partial => 'test/from_helper')
end
+ end
- def from_test_case; 'Word!'; end
- helper_method :from_test_case
+ test "is able to render partials with local variables" do
+ assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy'))
+ assert_equal 'Eloy', render(:partial => 'developers/developer',
+ :locals => { :developer => stub(:name => 'Eloy') })
end
- class AssertionsTest < ActionView::TestCase
- def render_from_helper
- form_tag('/foo') do
- safe_concat render(:text => '<ul><li>foo</li></ul>')
- end
+ test "is able to render partials from templates and also use instance variables" do
+ @controller.controller_path = "test"
+
+ @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
+ assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
+ end
+
+ end
+
+ class AssertionsTest < ActionView::TestCase
+ def render_from_helper
+ form_tag('/foo') do
+ safe_concat render(:text => '<ul><li>foo</li></ul>')
end
- helper_method :render_from_helper
+ end
+ helper_method :render_from_helper
- test "uses the output_buffer for assert_select" do
- render(:partial => 'test/from_helper')
+ test "uses the output_buffer for assert_select" do
+ render(:partial => 'test/from_helper')
- assert_select 'form' do
- assert_select 'li', :text => 'foo'
- end
+ assert_select 'form' do
+ assert_select 'li', :text => 'foo'
end
end
end
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 8b6c107a21..0b84c8f811 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -304,6 +304,7 @@ class TextHelperTest < ActionView::TestCase
assert_equal %(<p>Link #{link_result_with_options}</p>), auto_link("<p>Link #{link_raw}</p>", :all, {:target => "_blank"})
assert_equal %(Go to #{link_result}.), auto_link(%(Go to #{link_raw}.))
assert_equal %(<p>Go to #{link_result}, then say hello to #{email_result}.</p>), auto_link(%(<p>Go to #{link_raw}, then say hello to #{email_raw}.</p>))
+ assert_equal %(#{link_result} #{link_result}), auto_link(%(#{link_result} #{link_raw}))
email2_raw = '+david@loudthinking.com'
email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>}
@@ -376,24 +377,38 @@ class TextHelperTest < ActionView::TestCase
end
def test_auto_link_other_protocols
- silence_warnings do
- begin
- old_re_value = ActionView::Helpers::TextHelper::AUTO_LINK_RE
- ActionView::Helpers::TextHelper.const_set :AUTO_LINK_RE, %r{(ftp://)[^\s<]+}
- link_raw = 'ftp://example.com/file.txt'
- link_result = generate_result(link_raw)
- assert_equal %(Download #{link_result}), auto_link("Download #{link_raw}")
- ensure
- ActionView::Helpers::TextHelper.const_set :AUTO_LINK_RE, old_re_value
- end
- end
+ ftp_raw = 'ftp://example.com/file.txt'
+ assert_equal %(Download #{generate_result(ftp_raw)}), auto_link("Download #{ftp_raw}")
+
+ file_scheme = 'file:///home/username/RomeoAndJuliet.pdf'
+ z39_scheme = 'z39.50r://host:696/db'
+ chrome_scheme = 'chrome://package/section/path'
+ view_source = 'view-source:http://en.wikipedia.org/wiki/URI_scheme'
+ assert_equal generate_result(z39_scheme), auto_link(z39_scheme)
+ assert_equal generate_result(chrome_scheme), auto_link(chrome_scheme)
+ assert_equal generate_result(view_source), auto_link(view_source)
end
def test_auto_link_already_linked
linked1 = generate_result('Ruby On Rails', 'http://www.rubyonrails.com')
- linked2 = generate_result('www.rubyonrails.com', 'http://www.rubyonrails.com')
+ linked2 = %('<a href="http://www.example.com">www.example.com</a>')
+ linked3 = %('<a href="http://www.example.com" rel="nofollow">www.example.com</a>')
+ linked4 = %('<a href="http://www.example.com"><b>www.example.com</b></a>')
+ linked5 = %('<a href="#close">close</a> <a href="http://www.example.com"><b>www.example.com</b></a>')
assert_equal linked1, auto_link(linked1)
assert_equal linked2, auto_link(linked2)
+ assert_equal linked3, auto_link(linked3)
+ assert_equal linked4, auto_link(linked4)
+ assert_equal linked5, auto_link(linked5)
+
+ linked_email = %Q(<a href="mailto:david@loudthinking.com">Mail me</a>)
+ assert_equal linked_email, auto_link(linked_email)
+ end
+
+ def test_auto_link_within_tags
+ link_raw = 'http://www.rubyonrails.org/images/rails.png'
+ link_result = %Q(<img src="#{link_raw}" />)
+ assert_equal link_result, auto_link(link_result)
end
def test_auto_link_with_brackets
@@ -413,12 +428,6 @@ class TextHelperTest < ActionView::TestCase
assert_equal "{link: #{link3_result}}", auto_link("{link: #{link3_raw}}")
end
- def test_auto_link_in_tags
- link_raw = 'http://www.rubyonrails.org/images/rails.png'
- link_result = %Q(<img src="#{link_raw}" />)
- assert_equal link_result, auto_link(link_result)
- end
-
def test_auto_link_at_eol
url1 = "http://api.rubyonrails.com/Foo.html"
url2 = "http://www.ruby-doc.org/core/Bar.html"
@@ -432,6 +441,19 @@ class TextHelperTest < ActionView::TestCase
assert_equal %(<p><a href="#{url}">#{url[0...7]}...</a><br /><a href="mailto:#{email}">#{email[0...7]}...</a><br /></p>), auto_link("<p>#{url}<br />#{email}<br /></p>") { |url| truncate(url, :length => 10) }
end
+
+ def test_auto_link_with_block_with_html
+ pic = "http://example.com/pic.png"
+ url = "http://example.com/album?a&b=c"
+
+ assert_equal %(My pic: <a href="#{pic}"><img src="#{pic}" width="160px"></a> -- full album here #{generate_result(url)}), auto_link("My pic: #{pic} -- full album here #{url}") { |link|
+ if link =~ /\.(jpg|gif|png|bmp|tif)$/i
+ raw %(<img src="#{link}" width="160px">)
+ else
+ link
+ end
+ }
+ end
def test_auto_link_with_options_hash
assert_dom_equal 'Welcome to my new blog at <a href="http://www.myblog.com/" class="menu" target="_blank">http://www.myblog.com/</a>. Please e-mail me at <a href="mailto:me@email.com" class="menu" target="_blank">me@email.com</a>.',
diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb
index b382b5eb22..1be418a206 100644
--- a/actionpack/test/template/translation_helper_test.rb
+++ b/actionpack/test/template/translation_helper_test.rb
@@ -18,16 +18,9 @@ class TranslationHelperTest < ActiveSupport::TestCase
assert_equal expected, translate(:foo)
end
- def test_translation_of_an_array
- I18n.expects(:translate).with(["foo", "bar"], :raise => true).returns(["foo", "bar"])
- assert_equal "foobar", translate(["foo", "bar"])
- end
-
- def test_translation_of_an_array_with_html
- expected = '<a href="#">foo</a><a href="#">bar</a>'
- I18n.expects(:translate).with(["foo", "bar", "html"], :raise => true).returns(['<a href="#">foo</a>', '<a href="#">bar</a>'])
- @view = ActionView::Base.new(ActionController::Base.view_paths, {})
- assert_equal expected, @view.render(:file => "test/array_translation")
+ def test_translation_returning_an_array
+ I18n.expects(:translate).with(:foo, :raise => true).returns(["foo", "bar"])
+ assert_equal ["foo", "bar"], translate(:foo)
end
def test_delegates_localize_to_i18n
@@ -43,9 +36,9 @@ class TranslationHelperTest < ActiveSupport::TestCase
end
def test_scoping_by_partial_of_an_array
- I18n.expects(:translate).with("test.scoped_array_translation.foo.bar", :raise => true).returns(["foo", "bar"])
+ I18n.expects(:translate).with("test.scoped_translation.foo.bar", :raise => true).returns(["foo", "bar"])
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
- assert_equal "foobar", @view.render(:file => "test/scoped_array_translation")
+ assert_equal "foobar", @view.render(:file => "test/scoped_translation")
end
def test_translate_does_not_mark_plain_text_as_safe_html
@@ -62,4 +55,9 @@ class TranslationHelperTest < ActiveSupport::TestCase
I18n.expects(:translate).with("hello_html", :raise => true).returns("<a>Hello World</a>")
assert translate("hello_html").html_safe?
end
+
+ def test_translation_returning_an_array_ignores_html_suffix
+ I18n.expects(:translate).with(:foo_html, :raise => true).returns(["foo", "bar"])
+ assert_equal ["foo", "bar"], translate(:foo_html)
+ end
end
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index 8473150338..329dd7d761 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -287,11 +287,8 @@ class CalculationsTest < ActiveRecord::TestCase
# Oracle adapter returns floating point value 636.0 after SUM
if current_adapter?(:OracleAdapter)
assert_equal 636, Account.sum("2 * credit_limit")
- elsif current_adapter?(:SQLite3Adapter)
- # Future versions of the SQLite3 adapter will return a number
- assert_equal 636, Account.sum("2 * credit_limit").to_i
else
- assert_equal '636', Account.sum("2 * credit_limit")
+ assert_equal 636, Account.sum("2 * credit_limit").to_i
end
end
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 6397fbc280..b89097ac4b 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -1044,11 +1044,6 @@ module ActiveResource
attributes[self.class.primary_key] = id
end
- # Allows Active Resource objects to be used as parameters in Action Pack URL generation.
- def to_param
- id && id.to_s
- end
-
# Test for equality. Resource are equal if and only if +other+ is the same object or
# is an instance of the same class, is not <tt>new?</tt>, and has the same +id+.
#
@@ -1411,6 +1406,7 @@ module ActiveResource
class Base
extend ActiveModel::Naming
include CustomMethods, Observing, Validations
+ include ActiveModel::Conversion
include ActiveModel::Serializers::JSON
include ActiveModel::Serializers::Xml
end
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb
index 15084802f8..35c3f4c6ef 100644
--- a/activeresource/test/cases/base_test.rb
+++ b/activeresource/test/cases/base_test.rb
@@ -1081,6 +1081,13 @@ class BaseTest < Test::Unit::TestCase
assert_equal '1', matz.to_param
end
+ def test_to_key_quacks_like_active_record
+ new_person = Person.new
+ assert_nil new_person.to_key
+ matz = Person.find(1)
+ assert_equal [1], matz.to_key
+ end
+
def test_parse_deep_nested_resources
luis = Customer.find(1)
assert_kind_of Customer, luis
diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec
index cfd85f61c9..09635c2f18 100644
--- a/activesupport/activesupport.gemspec
+++ b/activesupport/activesupport.gemspec
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.has_rdoc = true
- s.add_dependency('i18n', '~> 0.4.0.beta1')
+ s.add_dependency('i18n', '~> 0.4.0')
s.add_dependency('tzinfo', '~> 0.3.16')
s.add_dependency('builder', '~> 2.1.2')
s.add_dependency('memcache-client', '>= 1.7.5')
diff --git a/activesupport/lib/active_support/core_ext/object/to_param.rb b/activesupport/lib/active_support/core_ext/object/to_param.rb
index 49e41e919a..06f077e920 100644..100755
--- a/activesupport/lib/active_support/core_ext/object/to_param.rb
+++ b/activesupport/lib/active_support/core_ext/object/to_param.rb
@@ -38,9 +38,9 @@ class Hash
# passed to enclose the param names (see example below).
#
# ==== Examples
- # { :name => 'David', :nationality => 'Danish' }.to_query # => "name=David&nationality=Danish"
+ # { :name => 'David', :nationality => 'Danish' }.to_param # => "name=David&nationality=Danish"
#
- # { :name => 'David', :nationality => 'Danish' }.to_query('user') # => "user[name]=David&user[nationality]=Danish"
+ # { :name => 'David', :nationality => 'Danish' }.to_param('user') # => "user[name]=David&user[nationality]=Danish"
def to_param(namespace = nil)
collect do |key, value|
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 77b1893f77..2cf5bd6ea9 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -326,7 +326,7 @@ class TimeWithZoneTest < Test::Unit::TestCase
def test_is_a
assert_kind_of Time, @twz
assert_kind_of Time, @twz
- assert ActiveSupport::TimeWithZone, @twz
+ assert_kind_of ActiveSupport::TimeWithZone, @twz
end
def test_class_name
diff --git a/railties/Rakefile b/railties/Rakefile
index daffd8ce30..efdb31cbd8 100644
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -50,6 +50,12 @@ task :update_prototype_ujs do
system "curl http://github.com/rails/prototype-ujs/raw/master/src/rails.js > lib/rails/generators/rails/app/templates/public/javascripts/rails.js"
end
+# Validate guides -------------------------------------------------------------------------
+desc 'Validate guides, use ONLY=foo to process just "foo.html"'
+task :validate_guides do
+ ruby "guides/w3c_validator.rb"
+end
+
# Generate documentation ------------------------------------------------------------------
Rake::RDocTask.new { |rdoc|
diff --git a/railties/guides/source/activerecord_validations_callbacks.textile b/railties/guides/source/activerecord_validations_callbacks.textile
index ee30f3963b..857551c9d5 100644
--- a/railties/guides/source/activerecord_validations_callbacks.textile
+++ b/railties/guides/source/activerecord_validations_callbacks.textile
@@ -139,7 +139,7 @@ end
+invalid?+ is simply the inverse of +valid?+. +invalid?+ triggers your validations and returns true if any errors were added to the object, and false otherwise.
-h4. +errors[]+
+h4(#validations_overview-errors). +errors[]+
To verify whether or not a particular attribute of an object is valid, you can use +errors[:attribute]+ that returns an array with all attribute errors, when there are no errors on the specified attribute, an empty array is returned.
@@ -597,7 +597,7 @@ In addition to the +valid?+ and +invalid?+ methods covered earlier, Rails provid
The following is a list of the most commonly used methods. Please refer to the +ActiveRecord::Errors+ documentation for a list of all the available methods.
-h4. +errors+
+h4(#working_with_validation_errors-errors). +errors+
Returns an OrderedHash with all errors. Each key is the attribute name and value is an array of strings with all errors.
@@ -617,7 +617,7 @@ person.valid? # => true
person.errors # => []
</ruby>
-h4. +errors[]+
+h4(#working_with_validation_errors-errors-2). +errors[]+
+errors[]+ is used when you want to check the error messages for a specific attribute. It returns an array of strings with all error messages for the given attribute, each string with one error message. If there are no errors related to the attribute returns an empty array.
@@ -1162,6 +1162,7 @@ h3. Changelog
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks
+* May 24, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
* May 15, 2010: Validation Errors section updated by "Emili Parreño":http://www.eparreno.com
* March 7, 2009: Callbacks revision by Trevor Turk
* February 10, 2009: Observers revision by Trevor Turk
diff --git a/railties/guides/source/contribute.textile b/railties/guides/source/contribute.textile
index 66f24e5c7e..88c5c79e9d 100644
--- a/railties/guides/source/contribute.textile
+++ b/railties/guides/source/contribute.textile
@@ -14,6 +14,7 @@ h3. How to Contribute?
* Sample format : "Active Record Associations":http://github.com/lifo/docrails/blob/3e56a3832415476fdd1cb963980d0ae390ac1ed3/railties/guides/source/association_basics.textile.
* Sample output : "Active Record Associations":association_basics.html.
* You can build the Guides during testing by running +rake generate_guides+ in the +railties+ directory.
+* You're encouraged to validate XHTML for the generated guides before commiting your changes by running +rake validate_guides+ in the +railties+ directory.
* Edge guides "can be consulted online":http://edgeguides.rubyonrails.org/. That website is generated periodically from docrails.
h3. What to Contribute?
diff --git a/railties/guides/source/credits.html.erb b/railties/guides/source/credits.html.erb
index e9eb31bcae..825e042628 100644
--- a/railties/guides/source/credits.html.erb
+++ b/railties/guides/source/credits.html.erb
@@ -44,7 +44,7 @@ Ruby on Rails Guides: Credits
<% end %>
<%= author('Mikel Lindsaar', 'raasdnil') do %>
- Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby <a hred="http://github.com/mikel/mail">Mail gem</a> and core contributor (he helped re-write Action Mailer's API). Mikel is the founder of <a href="http://rubyx.com/">RubyX</a>, has a <a href="http://lindsaar.net/">blog</a> and <a href="http://twitter.com/raasdnil">tweets</a>.
+ Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby <a href="http://github.com/mikel/mail">Mail gem</a> and core contributor (he helped re-write Action Mailer's API). Mikel is the founder of <a href="http://rubyx.com/">RubyX</a>, has a <a href="http://lindsaar.net/">blog</a> and <a href="http://twitter.com/raasdnil">tweets</a>.
<% end %>
<%= author('Cássio Marques', 'cmarques') do %>
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index 0c0a4e2263..515b3aad39 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -255,7 +255,7 @@ You can create a similar binding without actually creating +&lt;form&gt;+ tags
<erb>
<%= form_for :person, @person, :url => { :action => "create" } do |person_form| %>
<%= person_form.text_field :name %>
- <% fields_for @person.contact_detail do |contact_details_form| %>
+ <%= fields_for @person.contact_detail do |contact_details_form| %>
<%= contact_details_form.text_field :phone_number %>
<% end %>
<% end %>
@@ -697,7 +697,7 @@ You might want to render a form with a set of edit fields for each of a person's
<%= form_for @person do |person_form| %>
<%= person_form.text_field :name %>
<% for address in @person.addresses %>
- <% person_form.fields_for address, :index => address do |address_form|%>
+ <%= person_form.fields_for address, :index => address do |address_form|%>
<%= address_form.text_field :city %>
<% end %>
<% end %>
@@ -725,7 +725,7 @@ Rails knows that all these inputs should be part of the person hash because you
To create more intricate nestings, you can specify the first part of the input name (+person[address]+ in the previous example) explicitly, for example
<erb>
-<% fields_for 'person[address][primary]', address, :index => address do |address_form| %>
+<%= fields_for 'person[address][primary]', address, :index => address do |address_form| %>
<%= address_form.text_field :city %>
<% end %>
</erb>
@@ -741,7 +741,7 @@ As a general rule the final input name is the concatenation of the name given to
As a shortcut you can append [] to the name and omit the +:index+ option. This is the same as specifying +:index => address+ so
<erb>
-<% fields_for 'person[address][primary][]', address do |address_form| %>
+<%= fields_for 'person[address][primary][]', address do |address_form| %>
<%= address_form.text_field :city %>
<% end %>
</erb>
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index dd4e94a9e1..fe623e969f 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1486,8 +1486,7 @@ h3. Changelog
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/2
-* May 16, 2010: Added a section on configuration gotchas to address common encoding
- problems that people might have
+* May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by "Yehuda Katz":http://www.yehudakatz.com
* April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com
* April 25, 2010: Couple of more minor fixups "Mikel Lindsaar":credits.html#raasdnil
* April 1, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 96d6998e1c..cccbb9df06 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -1819,7 +1819,7 @@ On the surface, this looks like a simple class inheritance. There's more underne
end
</ruby>
-We do not already have a +Rails.application+, so instead this resorts to calling +super+. +Rails::Application+ descends from +Rails::Engine+ and so will call the +inherited+ method in +Rails::Engine+, but before that it's important to note that +called_from+ is defined an +attr_accessor+ on +Rails::Engine+:
+We do not already have a +Rails.application+, so instead this resorts to calling +super+. +Rails::Application+ descends from +Rails::Engine+ and so will call the +inherited+ method in +Rails::Engine+ (in _railties/lib/rails/engine.rb_), but before that it's important to note that +called_from+ is defined an +attr_accessor+ on +Rails::Engine+ and that +YourApp::Application+ is not an +abstract_railtie+:
<ruby>
def inherited(base)
@@ -1835,8 +1835,68 @@ We do not already have a +Rails.application+, so instead this resorts to calling
end
</ruby>
-This +called_from+ setting looks a little overwhelming to begin with, but the short end of it is that it returns the route to your application's config directory, something like: _/home/you/yourapp/config_. After +called_from+ has been set, +super+ is again called and this means the +Rails::Railtie#inherited+ method.
-
+This +called_from+ setting looks a little overwhelming to begin with, but the short end of it is that it returns the route to your application's config directory, something like: _/home/you/yourapp/config_. After +called_from+ has been set, +super+ is again called and this means the +Rails::Railtie#inherited+ method (in _railties/lib/rails/railtie.rb_):
+
+<ruby>
+ def inherited(base)
+ unless base.abstract_railtie?
+ base.send(:include, self::Configurable)
+ subclasses << base
+ end
+ end
+</ruby>
+
+Again, +YourApp::Application+ will return false for +abstract_railtie+ and so the code inside the +unless+ will be ran. The first line:
+
+<ruby>
+ base.send(:include, self::Configurable)
+</ruby>
+
+includes the +self::Configurable+ module, with self being +Rails::Application+ in this context:
+
+<ruby>
+ module Rails
+ class Application
+ module Configurable
+ def self.included(base)
+ base.extend ClassMethods
+ end
+
+ module ClassMethods
+ def inherited(base)
+ raise "You cannot inherit from a Rails::Application child"
+ end
+ end
+
+ def config
+ @config ||= Application::Configuration.new(self.class.find_root_with_flag("config.ru", Dir.pwd))
+ end
+ end
+ end
+ end
+</ruby>
+
+The inclusion of the +Rails::Application::Configurable+ module triggers the +included+ method in here which extends +YourApp::Application+ with the +Rails::Application::Configurable::ClassMethods+.
+
+Now that the chain of +super+ calls is done, we'll go back to the original +inherited+ method in +Rails::Application+ and the final line in this method:
+
+<ruby>
+ Rails.application = base.instance
+</ruby>
+
++base+ in this case is +YourApp::Application+ and calling +instance+ on this will return an instance of +YourApp::Application+ through the +instance+ method defined here:
+
+<ruby>
+ def instance
+ if self == Rails::Application
+ Rails.application
+ else
+ @@instance ||= new
+ end
+ end
+</ruby>
+
++self+ in this case is +YourApp::Application+, so it won't match to +Rails::Application+ so instead the +new+ method is called which calls the +initialize+ method.
diff --git a/railties/guides/w3c_validator.rb b/railties/guides/w3c_validator.rb
new file mode 100644
index 0000000000..b55645a7a9
--- /dev/null
+++ b/railties/guides/w3c_validator.rb
@@ -0,0 +1,67 @@
+# ---------------------------------------------------------------------------
+#
+# This script validates the generated guides against the W3C Validator.
+#
+# Guides are taken from the output directory, from where all .html files are
+# submitted to the validator.
+#
+# This script is prepared to be launched from the railties directory as a rake task:
+#
+# rake validate_guides
+#
+# If nothing is specified, all files will be validated, but you can check just
+# some of them using this environment variable:
+#
+# ONLY
+# Use ONLY if you want to validate only one or a set of guides. Prefixes are
+# enough:
+#
+# # validates only association_basics.html
+# ONLY=assoc rake validate_guides
+#
+# Separate many using commas:
+#
+# # validates only
+# ONLY=assoc,migrations rake validate_guides
+#
+# ---------------------------------------------------------------------------
+
+require 'rubygems'
+require 'w3c_validators'
+include W3CValidators
+
+module RailsGuides
+ class Validator
+
+ def validate
+ validator = MarkupValidator.new
+
+ guides_to_validate.each do |f|
+ puts "Validating #{f}"
+ results = validator.validate_file(f)
+
+ if !results.validity
+ puts "#{f} FAILED W3C validation with #{results.errors.size} error(s):"
+ results.errors.each do |error|
+ puts error.to_s
+ end
+ end
+ end
+ end
+
+ private
+ def guides_to_validate
+ guides = Dir["./guides/output/*.html"]
+ ENV.key?('ONLY') ? select_only(guides) : guides
+ end
+
+ def select_only(guides)
+ prefixes = ENV['ONLY'].split(",").map(&:strip)
+ guides.select do |guide|
+ prefixes.any? {|p| guide.start_with?("./guides/output/#{p}")}
+ end
+ end
+ end
+end
+
+RailsGuides::Validator.new.validate \ No newline at end of file
diff --git a/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb b/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb
index 2c57158b1c..de0823749c 100644
--- a/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb
+++ b/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb
@@ -1,6 +1,6 @@
require 'test_helper'
-class <%= class_name %>Test < ActionController::IntegrationTest
+class <%= class_name %>Test < ActionDispatch::IntegrationTest
fixtures :all
# Replace this with your real tests.
diff --git a/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
index 362e3dc09f..e827aa918f 100644
--- a/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
+++ b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
@@ -1,7 +1,7 @@
require 'test_helper'
require 'rails/performance_test_help'
-class <%= class_name %>Test < ActionController::PerformanceTest
+class <%= class_name %>Test < ActionDispatch::PerformanceTest
# Replace this with your real tests.
def test_homepage
get '/'