Permalink
Browse files

Merge branch 'master' of git://github.com/rails/rails

  • Loading branch information...
Isaac Sanders
Isaac Sanders committed May 7, 2012
2 parents d22a58f + fef110d commit 5e58fd889b4ba89ee2ac33b367a7366173e110b1
Showing with 698 additions and 157 deletions.
  1. +5 −1 actionpack/CHANGELOG.md
  2. +3 −0 actionpack/lib/action_controller/metal/exceptions.rb
  3. +1 −2 actionpack/lib/action_controller/metal/mime_responds.rb
  4. +3 −2 actionpack/lib/action_controller/metal/params_wrapper.rb
  5. +21 −6 actionpack/lib/action_controller/test_case.rb
  6. +7 −6 actionpack/lib/action_dispatch/middleware/cookies.rb
  7. +1 −0 actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
  8. +1 −1 actionpack/lib/action_dispatch/middleware/flash.rb
  9. +2 −2 actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
  10. +1 −1 actionpack/lib/action_dispatch/request/session.rb
  11. +2 −1 actionpack/lib/action_dispatch/routing/route_set.rb
  12. +3 −3 actionpack/lib/action_view/helpers/date_helper.rb
  13. +1 −1 actionpack/lib/action_view/helpers/form_tag_helper.rb
  14. +1 −1 actionpack/lib/action_view/helpers/tags/collection_helpers.rb
  15. +37 −0 actionpack/test/controller/action_pack_assertions_test.rb
  16. +9 −0 actionpack/test/controller/integration_test.rb
  17. +19 −13 actionpack/test/controller/mime_responds_test.rb
  18. +15 −2 actionpack/test/controller/params_wrapper_test.rb
  19. +4 −4 actionpack/test/controller/render_test.rb
  20. +24 −0 actionpack/test/dispatch/routing_test.rb
  21. +2 −0 actionpack/test/fixtures/test/hello_world_with_partial.html.erb
  22. +9 −0 actionpack/test/template/form_collections_helper_test.rb
  23. +6 −0 activerecord/CHANGELOG.md
  24. +3 −3 activerecord/lib/active_record/connection_adapters/column.rb
  25. +8 −0 activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
  26. +8 −0 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  27. +7 −2 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  28. +2 −1 activerecord/lib/active_record/core.rb
  29. +1 −1 activerecord/lib/active_record/fixtures.rb
  30. +4 −4 activerecord/lib/active_record/relation/finder_methods.rb
  31. +13 −0 activerecord/test/cases/adapters/mysql/connection_test.rb
  32. +16 −0 activerecord/test/cases/adapters/mysql2/connection_test.rb
  33. +12 −0 activerecord/test/cases/adapters/postgresql/quoting_test.rb
  34. +7 −1 activerecord/test/cases/base_test.rb
  35. +28 −0 activerecord/test/cases/column_test.rb
  36. +4 −0 activerecord/test/cases/finder_test.rb
  37. +9 −1 activerecord/test/cases/relations_test.rb
  38. +4 −1 activerecord/test/schema/schema.rb
  39. +2 −0 activesupport/CHANGELOG.md
  40. +11 −0 activesupport/lib/active_support/core_ext/date_time/calculations.rb
  41. +0 −1 activesupport/lib/active_support/core_ext/hash.rb
  42. +0 −10 activesupport/lib/active_support/core_ext/hash/deep_dup.rb
  43. +1 −0 activesupport/lib/active_support/core_ext/object.rb
  44. +22 −0 activesupport/lib/active_support/core_ext/object/deep_dup.rb
  45. +15 −0 activesupport/lib/active_support/core_ext/time/calculations.rb
  46. +2 −2 activesupport/lib/active_support/multibyte/chars.rb
  47. +1 −1 activesupport/lib/active_support/ordered_options.rb
  48. +3 −3 activesupport/lib/active_support/time_with_zone.rb
  49. +8 −0 activesupport/test/core_ext/date_time_ext_test.rb
  50. +53 −0 activesupport/test/core_ext/deep_dup_test.rb
  51. +0 −15 activesupport/test/core_ext/hash_ext_test.rb
  52. +8 −0 activesupport/test/core_ext/time_ext_test.rb
  53. +23 −8 activesupport/test/core_ext/time_with_zone_test.rb
  54. +9 −0 activesupport/test/multibyte_chars_test.rb
  55. +8 −0 activesupport/test/ordered_options_test.rb
  56. +6 −0 guides/rails_guides/textile_extensions.rb
  57. +50 −14 guides/source/active_record_querying.textile
  58. +75 −0 guides/source/active_support_core_extensions.textile
  59. +1 −1 guides/source/index.html.erb
  60. +1 −2 railties/lib/rails/commands.rb
  61. +28 −10 railties/lib/rails/commands/dbconsole.rb
  62. +1 −1 railties/lib/rails/configuration.rb
  63. +4 −0 railties/lib/rails/engine/commands.rb
  64. +2 −0 railties/test/abstract_unit.rb
  65. +61 −29 railties/test/commands/dbconsole_test.rb
View
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
+* `respond_to` and `respond_with` now raise ActionController::UnknownFormat instead
+ of directly returning head 406. The exception is rescued and converted to 406
+ in the exception handling middleware. *Steven Soroka*
+
* Allows `assert_redirected_to` to match against a regular expression. *Andy Lindeman*
* Add backtrace to development routing error page. *Richard Schneeman*
@@ -12,7 +16,7 @@
* Make current object and counter (when it applies) variables accessible when
rendering templates with :object / :collection. *Carlos Antonio da Silva*
-* JSONP now uses mimetype application/javascript instead of application/json *omjokine*
+* JSONP now uses mimetype application/javascript instead of application/json. *omjokine*
* Allow to lazy load `default_form_builder` by passing a `String` instead of a constant. *Piotr Sarnacki*
@@ -38,4 +38,7 @@ def initialize(message = nil)
class UnknownHttpMethod < ActionControllerError #:nodoc:
end
+
+ class UnknownFormat < ActionControllerError #:nodoc:
+ end
end
@@ -375,8 +375,7 @@ def retrieve_collector_from_mimes(mimes=nil, &block) #:nodoc:
lookup_context.rendered_format = lookup_context.formats.first
collector
else
- head :not_acceptable
- nil
+ raise ActionController::UnknownFormat
end
end
@@ -166,8 +166,9 @@ def _set_wrapper_defaults(options, model=nil)
unless options[:include] || options[:exclude]
model ||= _default_wrap_model
- if model.respond_to?(:accessible_attributes) && model.accessible_attributes.present?
- options[:include] = model.accessible_attributes.to_a
+ role = options.fetch(:as, :default)
+ if model.respond_to?(:accessible_attributes) && model.accessible_attributes(role).present?
+ options[:include] = model.accessible_attributes(role).to_a
elsif model.respond_to?(:attribute_names) && model.attribute_names.present?
options[:include] = model.attribute_names
end
@@ -20,7 +20,12 @@ def setup_subscriptions
ActiveSupport::Notifications.subscribe("render_template.action_view") do |name, start, finish, id, payload|
path = payload[:layout]
- @layouts[path] += 1
+ if path
+ @layouts[path] += 1
+ if path =~ /^layouts\/(.*)/
+ @layouts[$1] += 1
+ end
+ end
end
ActiveSupport::Notifications.subscribe("!render_template.action_view") do |name, start, finish, id, payload|
@@ -59,6 +64,15 @@ def process(*args)
# # assert that the exact template "admin/posts/new" was rendered
# assert_template %r{\Aadmin/posts/new\Z}
#
+ # # assert that the layout 'admin' was rendered
+ # assert_template :layout => 'admin'
+ # assert_template :layout => 'layouts/admin'
+ # assert_template :layout => :admin
+ #
+ # # assert that no layout was rendered
+ # assert_template :layout => nil
+ # assert_template :layout => false
+ #
# # assert that the "_customer" partial was rendered twice
# assert_template :partial => '_customer', :count => 2
#
@@ -90,16 +104,17 @@ def assert_template(options = {}, message = nil)
end
end
when Hash
- if expected_layout = options[:layout]
+ if options.key?(:layout)
+ expected_layout = options[:layout]
msg = message || sprintf("expecting layout <%s> but action rendered <%s>",
expected_layout, @layouts.keys)
case expected_layout
- when String
- assert_includes @layouts.keys, expected_layout, msg
+ when String, Symbol
+ assert_includes @layouts.keys, expected_layout.to_s, msg
when Regexp
assert(@layouts.keys.any? {|l| l =~ expected_layout }, msg)
- when nil
+ when nil, false
assert(@layouts.empty?, msg)
end
end
@@ -120,7 +135,7 @@ def assert_template(options = {}, message = nil)
options[:partial], @partials.keys)
assert_includes @partials, expected_partial, msg
end
- else
+ elsif options.key?(:partial)
assert @partials.empty?,
"Expected no partials to be rendered"
end
@@ -2,7 +2,7 @@
require 'active_support/core_ext/hash/keys'
module ActionDispatch
- class Request
+ class Request < Rack::Request
def cookie_jar
env['action_dispatch.cookies'] ||= Cookies::CookieJar.build(self)
end
@@ -26,9 +26,9 @@ def cookie_jar
# # Sets a cookie that expires in 1 hour.
# cookies[:login] = { :value => "XJ-122", :expires => 1.hour.from_now }
#
- # # Sets a signed cookie, which prevents a user from tampering with its value.
+ # # Sets a signed cookie, which prevents users from tampering with its value.
# # The cookie is signed by your app's <tt>config.secret_token</tt> value.
- # # Rails generates this value by default when you create a new Rails app.
+ # # It can be read using the signed method <tt>cookies.signed[:key]</tt>
# cookies.signed[:user_id] = current_user.id
#
# # Sets a "permanent" cookie (which expires in 20 years from now).
@@ -39,9 +39,10 @@ def cookie_jar
#
# Examples for reading:
#
- # cookies[:user_name] # => "david"
- # cookies.size # => 2
- # cookies[:lat_lon] # => [47.68, -122.37]
+ # cookies[:user_name] # => "david"
+ # cookies.size # => 2
+ # cookies[:lat_lon] # => [47.68, -122.37]
+ # cookies.signed[:login] # => "XJ-122"
#
# Example for deleting:
#
@@ -10,6 +10,7 @@ class ExceptionWrapper
'AbstractController::ActionNotFound' => :not_found,
'ActionController::MethodNotAllowed' => :method_not_allowed,
'ActionController::NotImplemented' => :not_implemented,
+ 'ActionController::UnknownFormat' => :not_acceptable,
'ActionController::InvalidAuthenticityToken' => :unprocessable_entity
)
@@ -1,5 +1,5 @@
module ActionDispatch
- class Request
+ class Request < Rack::Request
# Access the contents of the flash. Use <tt>flash["notice"]</tt> to
# read a notice you put there or <tt>flash["notice"] = "hello"</tt>
# to put a new one.
@@ -12,8 +12,8 @@
request_dump = clean_params.empty? ? 'None' : clean_params.inspect.gsub(',', ",\n")
- def debug_hash(hash)
- hash.sort_by { |k, v| k.to_s }.map { |k, v| "#{k}: #{v.inspect rescue $!.message}" }.join("\n")
+ def debug_hash(object)
+ object.to_hash.sort_by { |k, v| k.to_s }.map { |k, v| "#{k}: #{v.inspect rescue $!.message}" }.join("\n")
end unless self.class.method_defined?(:debug_hash)
%>
@@ -37,7 +37,7 @@ def self.find(env)
def initialize(by, env, default_options)
@by = by
@env = env
- @delegate = default_options
+ @delegate = default_options.dup
end
def [](key)
@@ -188,7 +188,8 @@ def define_url_helper(route, name, options)
remove_possible_method :#{selector}
def #{selector}(*args)
if #{optimize_helper?(route)} && args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && optimize_routes_generation?
- options = #{options.inspect}.merge!(url_options)
+ options = #{options.inspect}
+ options.merge!(url_options) if respond_to?(:url_options)
options[:path] = "#{optimized_helper(route)}"
ActionDispatch::Http::URL.url_for(options)
else
@@ -66,12 +66,12 @@ module DateHelper
# distance_of_time_in_words(Time.now, Time.now) # => less than a minute
#
def distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {})
- unless include_seconds_or_options.is_a?(Hash)
+ if include_seconds_or_options.is_a?(Hash)
+ options = include_seconds_or_options
+ else
ActiveSupport::Deprecation.warn "distance_of_time_in_words and time_ago_in_words now accept :include_seconds " +
"as a part of options hash, not a boolean argument", caller
options[:include_seconds] ||= !!include_seconds_or_options
- else
- options = include_seconds_or_options
end
from_time = from_time.to_time if from_time.respond_to?(:to_time)
@@ -408,7 +408,7 @@ def radio_button_tag(name, value, checked = false, options = {})
# # => <input class="form_submit" name="commit" type="submit" />
#
# submit_tag "Edit", :disable_with => "Editing...", :class => "edit_button"
- # # => <input class="edit_button" data-disable_with="Editing..." name="commit" type="submit" value="Edit" />
+ # # => <input class="edit_button" data-disable-with="Editing..." name="commit" type="submit" value="Edit" />
#
# submit_tag "Save", :confirm => "Are you sure?"
# # => <input name='commit' type='submit' value='Save' data-confirm="Are you sure?" />
@@ -49,7 +49,7 @@ def default_html_options_for_collection(item, value) #:nodoc:
accept = if current_value.respond_to?(:call)
current_value.call(item)
else
- Array(current_value).include?(value)
+ Array(current_value).map(&:to_s).include?(value.to_s)
end
if accept
@@ -76,6 +76,11 @@ def render_with_layout
render "test/hello_world", :layout => "layouts/standard"
end
+ def render_with_layout_and_partial
+ @variable_for_layout = nil
+ render "test/hello_world_with_partial", :layout => "layouts/standard"
+ end
+
def session_stuffing
session['xmas'] = 'turkey'
render :text => "ho ho ho"
@@ -473,11 +478,43 @@ def test_fails_with_wrong_layout
end
end
+ def test_fails_expecting_no_layout
+ get :render_with_layout
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_template :layout => nil
+ end
+ end
+
def test_passes_with_correct_layout
get :render_with_layout
assert_template :layout => "layouts/standard"
end
+ def test_passes_with_layout_and_partial
+ get :render_with_layout_and_partial
+ assert_template :layout => "layouts/standard"
+ end
+
+ def test_passed_with_no_layout
+ get :hello_world
+ assert_template :layout => nil
+ end
+
+ def test_passed_with_no_layout_false
+ get :hello_world
+ assert_template :layout => false
+ end
+
+ def test_passes_with_correct_layout_without_layouts_prefix
+ get :render_with_layout
+ assert_template :layout => "standard"
+ end
+
+ def test_passes_with_correct_layout_symbol
+ get :render_with_layout
+ assert_template :layout => :standard
+ end
+
def test_assert_template_reset_between_requests
get :hello_world
assert_template 'test/hello_world'
@@ -405,6 +405,15 @@ def test_xml_http_request_get
end
end
+ def test_request_with_bad_format
+ with_test_route_set do
+ xhr :get, '/get.php'
+ assert_equal 406, status
+ assert_response 406
+ assert_response :not_acceptable
+ end
+ end
+
def test_get_with_query_string
with_test_route_set do
get '/get_with_params?foo=bar'
@@ -207,8 +207,9 @@ def test_html
get :html_or_xml
assert_equal 'HTML', @response.body
- get :just_xml
- assert_response 406
+ assert_raises(ActionController::UnknownFormat) do
+ get :just_xml
+ end
end
def test_all
@@ -239,8 +240,10 @@ def test_js_or_html
assert_equal 'HTML', @response.body
@request.accept = "text/javascript, text/html"
- xhr :get, :just_xml
- assert_response 406
+
+ assert_raises(ActionController::UnknownFormat) do
+ xhr :get, :just_xml
+ end
end
def test_json_or_yaml_with_leading_star_star
@@ -495,9 +498,9 @@ def test_format_with_custom_response_type_and_request_headers
end
def test_invalid_format
- get :using_defaults, :format => "invalidformat"
- assert_equal " ", @response.body
- assert_equal "text/html", @response.content_type
+ assert_raises(ActionController::UnknownFormat) do
+ get :using_defaults, :format => "invalidformat"
+ end
end
end
@@ -701,12 +704,14 @@ def test_using_resource_with_overwrite_block
def test_not_acceptable
@request.accept = "application/xml"
- get :using_resource_with_block
- assert_equal 406, @response.status
+ assert_raises(ActionController::UnknownFormat) do
+ get :using_resource_with_block
+ end
@request.accept = "text/javascript"
- get :using_resource_with_overwrite_block
- assert_equal 406, @response.status
+ assert_raises(ActionController::UnknownFormat) do
+ get :using_resource_with_overwrite_block
+ end
end
def test_using_resource_for_post_with_html_redirects_on_success
@@ -984,8 +989,9 @@ def test_respond_as_responder_entry_point
def test_clear_respond_to
@controller = InheritedRespondWithController.new
@request.accept = "text/html"
- get :index
- assert_equal 406, @response.status
+ assert_raises(ActionController::UnknownFormat) do
+ get :index
+ end
end
def test_first_in_respond_to_has_higher_priority
Oops, something went wrong.

0 comments on commit 5e58fd8

Please sign in to comment.