Permalink
Browse files

Merge branch 'master' into adequaterecord

* master: (108 commits)
  make tests pass on Ruby 2.2
  Use Sqlite3 adapter in examples
  use the body proxy to freeze headers
  just ask the response for the commit status, we do not need to ask the jar
  only write the jar if the response isn't committed
  Fix a grammatical error in the i18n guide [ci skip]
  use method_defined? to check whether or not a method is defined
  Enhance docs for update_attribute [ci-skip]
  Change usec to 0 on tests that compare seconds
  Unit test for mysql quote time usec
  Changelog entry for mysql56 microseconds
  Test microsecond on mysql 5.6
  MySQL 5.6 and later supports microsecond precision in datetime.
  [ci skip] Add documentation for original_fullpath.
  Remove mocking on save, when not necessary
  comment why we are modifying global state. [ci skip]
  `change_table` supports `citext`. Follow up to #12523.
  Removed unnecessary command "application"
  register OID for PostgreSQL citex datatype [Troy Kruthoff & Lachlan Sylvester]
  Fixes STI when 2+ levels deep.
  ...
  • Loading branch information...
2 parents 37ca1b4 + e88da37 commit 66e032117fa5c6953a7b1d791dcdc1ee029e4cef @tenderlove tenderlove committed Mar 13, 2014
Showing with 2,119 additions and 895 deletions.
  1. +1 −1 Rakefile
  2. +1 −1 actionmailer/README.rdoc
  3. +1 −1 actionmailer/lib/action_mailer/base.rb
  4. +15 −0 actionmailer/lib/action_mailer/gem_version.rb
  5. +4 −7 actionmailer/lib/action_mailer/version.rb
  6. +1 −0 actionmailer/test/base_test.rb
  7. +6 −0 actionpack/CHANGELOG.md
  8. +3 −3 actionpack/lib/action_controller/log_subscriber.rb
  9. +33 −8 actionpack/lib/action_controller/metal/live.rb
  10. +2 −2 actionpack/lib/action_controller/metal/rack_delegation.rb
  11. +1 −3 actionpack/lib/action_controller/metal/rendering.rb
  12. +7 −1 actionpack/lib/action_controller/metal/request_forgery_protection.rb
  13. +37 −7 actionpack/lib/action_controller/test_case.rb
  14. +7 −0 actionpack/lib/action_dispatch/http/request.rb
  15. +35 −15 actionpack/lib/action_dispatch/http/response.rb
  16. +2 −2 actionpack/lib/action_dispatch/journey/formatter.rb
  17. +3 −3 actionpack/lib/action_dispatch/journey/gtg/builder.rb
  18. +1 −1 actionpack/lib/action_dispatch/journey/gtg/simulator.rb
  19. +7 −7 actionpack/lib/action_dispatch/journey/gtg/transition_table.rb
  20. +2 −2 actionpack/lib/action_dispatch/journey/nfa/dot.rb
  21. +1 −1 actionpack/lib/action_dispatch/journey/nfa/simulator.rb
  22. +5 −5 actionpack/lib/action_dispatch/journey/nfa/transition_table.rb
  23. +2 −2 actionpack/lib/action_dispatch/journey/path/pattern.rb
  24. +17 −6 actionpack/lib/action_dispatch/middleware/cookies.rb
  25. +42 −31 actionpack/lib/action_dispatch/routing/mapper.rb
  26. +15 −0 actionpack/lib/action_pack/gem_version.rb
  27. +4 −7 actionpack/lib/action_pack/version.rb
  28. +2 −2 actionpack/test/controller/caching_test.rb
  29. +42 −28 actionpack/test/controller/live_stream_test.rb
  30. +12 −17 actionpack/test/controller/new_base/render_body_test.rb
  31. +16 −0 actionpack/test/controller/request_forgery_protection_test.rb
  32. +13 −2 actionpack/test/dispatch/live_response_test.rb
  33. +0 −191 actionpack/test/dispatch/rack_test.rb
  34. +386 −179 actionpack/test/dispatch/request_test.rb
  35. +0 −8 actionpack/test/dispatch/response_test.rb
  36. +238 −0 actionpack/test/dispatch/routing_test.rb
  37. +16 −0 actionview/CHANGELOG.md
  38. +51 −13 actionview/lib/action_view/digestor.rb
  39. +15 −0 actionview/lib/action_view/gem_version.rb
  40. +1 −1 actionview/lib/action_view/helpers/cache_helper.rb
  41. +8 −4 actionview/lib/action_view/helpers/date_helper.rb
  42. +2 −2 actionview/lib/action_view/helpers/form_helper.rb
  43. +12 −6 actionview/lib/action_view/helpers/form_tag_helper.rb
  44. +3 −2 actionview/lib/action_view/helpers/rendering_helper.rb
  45. +8 −2 actionview/lib/action_view/helpers/tag_helper.rb
  46. +0 −5 actionview/lib/action_view/rendering.rb
  47. +4 −7 actionview/lib/action_view/version.rb
  48. +15 −0 actionview/test/fixtures/digestor/messages/new.html+iphone.erb
  49. +27 −8 actionview/test/template/digestor_test.rb
  50. +5 −0 actionview/test/template/form_tag_helper_test.rb
  51. +49 −30 activemodel/README.rdoc
  52. +15 −0 activemodel/lib/active_model/gem_version.rb
  53. +4 −7 activemodel/lib/active_model/version.rb
  54. +52 −24 activemodel/test/cases/attribute_methods_test.rb
  55. +7 −0 activemodel/test/cases/errors_test.rb
  56. +14 −7 activemodel/test/cases/secure_password_test.rb
  57. +27 −21 activemodel/test/cases/serializers/json_serialization_test.rb
  58. +33 −33 activemodel/test/cases/serializers/xml_serialization_test.rb
  59. +4 −0 activemodel/test/cases/translation_test.rb
  60. +19 −16 activemodel/test/cases/validations/confirmation_validation_test.rb
  61. +1 −0 activemodel/test/cases/validations/i18n_validation_test.rb
  62. +2 −0 activemodel/test/cases/validations/numericality_validation_test.rb
  63. +2 −0 activemodel/test/cases/validations_test.rb
  64. +54 −8 activerecord/CHANGELOG.md
  65. +2 −2 activerecord/lib/active_record/associations.rb
  66. +3 −1 activerecord/lib/active_record/associations/collection_association.rb
  67. +4 −4 activerecord/lib/active_record/associations/has_many_association.rb
  68. +1 −1 activerecord/lib/active_record/associations/preloader/through_association.rb
  69. +3 −3 activerecord/lib/active_record/attribute_methods.rb
  70. +3 −2 activerecord/lib/active_record/autosave_association.rb
  71. +5 −0 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
  72. +10 −2 activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
  73. +8 −0 activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
  74. +7 −0 activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
  75. +19 −2 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  76. +2 −2 activerecord/lib/active_record/connection_handling.rb
  77. +15 −0 activerecord/lib/active_record/gem_version.rb
  78. +2 −0 activerecord/lib/active_record/persistence.rb
  79. +10 −1 activerecord/lib/active_record/relation.rb
  80. +6 −1 activerecord/lib/active_record/relation/finder_methods.rb
  81. +22 −17 activerecord/lib/active_record/relation/query_methods.rb
  82. +5 −4 activerecord/lib/active_record/scoping/default.rb
  83. +8 −2 activerecord/lib/active_record/validations/uniqueness.rb
  84. +4 −7 activerecord/lib/active_record/version.rb
  85. +22 −2 activerecord/test/cases/adapters/mysql/case_sensitivity_test.rb
  86. +22 −2 activerecord/test/cases/adapters/mysql2/case_sensitivity_test.rb
  87. +7 −0 activerecord/test/cases/adapters/mysql2/connection_test.rb
  88. +77 −0 activerecord/test/cases/adapters/postgresql/citext_test.rb
  89. +26 −0 activerecord/test/cases/adapters/postgresql/enum_test.rb
  90. +1 −1 activerecord/test/cases/adapters/postgresql/range_test.rb
  91. +1 −1 activerecord/test/cases/associations/callbacks_test.rb
  92. +9 −0 activerecord/test/cases/associations/eager_test.rb
  93. +10 −0 activerecord/test/cases/associations/has_many_associations_test.rb
  94. +13 −0 activerecord/test/cases/attribute_methods_test.rb
  95. +18 −9 activerecord/test/cases/autosave_association_test.rb
  96. +1 −1 activerecord/test/cases/base_test.rb
  97. +27 −0 activerecord/test/cases/enum_test.rb
  98. +17 −7 activerecord/test/cases/finder_test.rb
  99. +5 −0 activerecord/test/cases/helper.rb
  100. +3 −3 activerecord/test/cases/persistence_test.rb
  101. +26 −2 activerecord/test/cases/relations_test.rb
  102. +9 −2 activerecord/test/cases/schema_dumper_test.rb
  103. +10 −1 activerecord/test/schema/postgresql_specific_schema.rb
  104. +5 −1 activerecord/test/schema/schema.rb
  105. +15 −0 activesupport/lib/active_support/gem_version.rb
  106. +4 −0 activesupport/lib/active_support/ordered_hash.rb
  107. +1 −1 activesupport/lib/active_support/testing/declarative.rb
  108. +1 −1 activesupport/lib/active_support/values/time_zone.rb
  109. +4 −7 activesupport/lib/active_support/version.rb
  110. +1 −1 activesupport/test/inflector_test_cases.rb
  111. +4 −1 activesupport/test/ordered_hash_test.rb
  112. +10 −9 guides/source/4_1_release_notes.md
  113. +18 −3 guides/source/action_controller_overview.md
  114. +14 −3 guides/source/action_view_overview.md
  115. +17 −8 guides/source/active_support_core_extensions.md
  116. +20 −0 guides/source/caching_with_rails.md
  117. +3 −3 guides/source/configuring.md
  118. +0 −1 guides/source/documents.yaml
  119. +1 −1 guides/source/i18n.md
  120. +5 −2 guides/source/layouts_and_rendering.md
  121. +10 −3 guides/source/security.md
  122. +20 −0 guides/source/upgrading_ruby_on_rails.md
  123. +3 −1 guides/source/working_with_javascript_in_rails.md
  124. +34 −0 railties/CHANGELOG.md
  125. +0 −4 railties/lib/rails.rb
  126. +1 −6 railties/lib/rails/commands/commands_tasks.rb
  127. +1 −1 railties/lib/rails/commands/plugin.rb
  128. +15 −0 railties/lib/rails/gem_version.rb
  129. +1 −1 railties/lib/rails/generators/actions.rb
  130. +2 −2 railties/lib/rails/generators/erb.rb
  131. +1 −1 railties/lib/rails/generators/erb/controller/controller_generator.rb
  132. +1 −1 railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb
  133. +2 −2 railties/lib/rails/generators/rails/controller/controller_generator.rb
  134. +1 −1 railties/lib/rails/paths.rb
  135. +1 −1 railties/lib/rails/source_annotation_extractor.rb
  136. +1 −1 railties/lib/rails/tasks/framework.rake
  137. +5 −7 railties/lib/rails/version.rb
  138. +11 −0 railties/test/application/rake_test.rb
  139. +12 −0 railties/test/generators/plugin_generator_test.rb
  140. +12 −0 railties/test/version_test.rb
  141. +5 −0 version.rb
View
@@ -66,7 +66,7 @@ task :update_versions do
version_file = File.read("version.rb")
PROJECTS.each do |project|
- Dir["#{project}/lib/*/version.rb"].each do |file|
+ Dir["#{project}/lib/*/gem_version.rb"].each do |file|
File.open(file, "w") do |f|
f.write version_file.gsub(/Rails/, constants[project])
end
View
@@ -102,7 +102,7 @@ Example:
)
if email.has_attachments?
- email.attachments.each do |attachment|
+ email.attachments.each do |attachment|
page.attachments.create({
file: attachment, description: email.subject
})
@@ -94,7 +94,7 @@ module ActionMailer
# Hi <%= @account.name %>,
# Thanks for joining our service! Please check back often.
#
- # You can even use Action Pack helpers in these views. For example:
+ # You can even use Action View helpers in these views. For example:
#
# You got a new note!
# <%= truncate(@note.body, length: 25) %>
@@ -0,0 +1,15 @@
+module ActionMailer
+ # Returns the version of the currently loaded ActionMailer as a <tt>Gem::Version</tt>
+ def self.gem_version
+ Gem::Version.new VERSION::STRING
+ end
+
+ module VERSION
+ MAJOR = 4
+ MINOR = 2
+ TINY = 0
+ PRE = "alpha"
+
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
+ end
+end
@@ -1,11 +1,8 @@
+require_relative 'gem_version'
+
module ActionMailer
- # Returns the version of the currently loaded ActionMailer as a Gem::Version
+ # Returns the version of the currently loaded ActionMailer as a <tt>Gem::Version</tt>
def self.version
- Gem::Version.new "4.2.0.alpha"
- end
-
- module VERSION #:nodoc:
- MAJOR, MINOR, TINY, PRE = ActionMailer.version.segments
- STRING = ActionMailer.version.to_s
+ gem_version
end
end
@@ -13,6 +13,7 @@ class BaseTest < ActiveSupport::TestCase
def teardown
ActionMailer::Base.asset_host = nil
ActionMailer::Base.assets_dir = nil
+ ActionMailer::Base.preview_interceptors.clear
end
test "method call to mail does not raise error" do
View
@@ -1,3 +1,9 @@
+* Make logging of CSRF failures optional (but on by default) with the
+ `log_warning_on_csrf_failure` configuration setting in
+ `ActionController::RequestForgeryProtection`.
+
+ *John Barton*
+
* Fix URL generation in controller tests with request-dependent
`default_url_options` methods.
@@ -54,9 +54,9 @@ def unpermitted_parameters(event)
end
def deep_munge(event)
- message = "Value for params[:#{event.payload[:keys].join('][:')}] was set"\
- "to nil, because it was one of [], [null] or [null, null, ...]."\
- "Go to http://guides.rubyonrails.org/security.html#unsafe-query-generation"\
+ message = "Value for params[:#{event.payload[:keys].join('][:')}] was set "\
+ "to nil, because it was one of [], [null] or [null, null, ...]. "\
+ "Go to http://guides.rubyonrails.org/security.html#unsafe-query-generation "\
"for more information."\
debug(message)
@@ -107,8 +107,11 @@ def perform_write(json, options)
end
class Buffer < ActionDispatch::Response::Buffer #:nodoc:
+ include MonitorMixin
+
def initialize(response)
- @error_callback = nil
+ @error_callback = lambda { true }
+ @cv = new_cond
super(response, SizedQueue.new(10))
end
@@ -122,14 +125,25 @@ def write(string)
end
def each
+ @response.sending!
while str = @buf.pop
yield str
end
+ @response.sent!
end
def close
- super
- @buf.push nil
+ synchronize do
+ super
+ @buf.push nil
+ @cv.broadcast
+ end
+ end
+
+ def await_close
+ synchronize do
+ @cv.wait_until { @closed }
+ end
end
def on_error(&block)
@@ -165,12 +179,20 @@ def to_hash
end
end
- def commit!
- headers.freeze
+ private
+
+ def before_committed
super
+ jar = request.cookie_jar
+ # The response can be committed multiple times
+ jar.write self unless committed?
end
- private
+ def before_sending
+ super
+ request.cookie_jar.commit!
+ headers.freeze
+ end
def build_buffer(response, body)
buf = Live::Buffer.new response
@@ -191,6 +213,7 @@ def process(name)
t1 = Thread.current
locals = t1.keys.map { |key| [key, t1[key]] }
+ error = nil
# This processes the action in a child thread. It lets us return the
# response code and headers back up the rack stack, and still process
# the body in parallel with sending data to the client
@@ -205,8 +228,9 @@ def process(name)
begin
super(name)
rescue => e
- @_response.status = 500 unless @_response.committed?
- @_response.status = 400 if e.class == ActionController::BadRequest
+ unless @_response.committed?
+ error = e
+ end
begin
@_response.stream.write(ActionView::Base.streaming_completion_on_exception) if request.format == :html
@_response.stream.call_on_error
@@ -222,6 +246,7 @@ def process(name)
}
@_response.await_commit
+ raise error if error
end
def log_error(exception)
@@ -5,8 +5,8 @@ module ActionController
module RackDelegation
extend ActiveSupport::Concern
- delegate :headers, :status=, :location=, :content_type=, :no_content_type=,
- :status, :location, :content_type, :no_content_type, :to => "@_response"
+ delegate :headers, :status=, :location=, :content_type=,
+ :status, :location, :content_type, :to => "@_response"
def dispatch(action, request)
set_response!(request)
@@ -45,9 +45,7 @@ def _render_in_priorities(options)
def _process_format(format, options = {})
super
- if options[:body]
- self.headers.delete "Content-Type"
- elsif options[:plain]
+ if options[:plain]
self.content_type = Mime::TEXT
else
self.content_type ||= format.to_s
@@ -68,6 +68,10 @@ module RequestForgeryProtection
config_accessor :allow_forgery_protection
self.allow_forgery_protection = true if allow_forgery_protection.nil?
+ # Controls whether a CSRF failure logs a warning. On by default.
+ config_accessor :log_warning_on_csrf_failure
+ self.log_warning_on_csrf_failure = true
+
helper_method :form_authenticity_token
helper_method :protect_against_forgery?
end
@@ -193,7 +197,9 @@ def verify_authenticity_token
mark_for_same_origin_verification!
if !verified_request?
- logger.warn "Can't verify CSRF token authenticity" if logger
+ if logger && log_warning_on_csrf_failure
+ logger.warn "Can't verify CSRF token authenticity"
+ end
handle_unverified_request
end
end
@@ -258,6 +258,29 @@ def recycle!
end
end
+ class LiveTestResponse < Live::Response
+ def recycle!
+ @body = nil
+ initialize
+ end
+
+ def body
+ @body ||= super
+ end
+
+ # Was the response successful?
+ alias_method :success?, :successful?
+
+ # Was the URL not found?
+ alias_method :missing?, :not_found?
+
+ # Were we redirected?
+ alias_method :redirect?, :redirection?
+
+ # Was there a server-side error?
+ alias_method :error?, :server_error?
+ end
+
# Methods #destroy and #load! are overridden to avoid calling methods on the
# @store object, which does not exist for the TestSession class.
class TestSession < Rack::Session::Abstract::SessionHash #:nodoc:
@@ -572,7 +595,9 @@ def process(action, http_method = 'GET', *args)
@controller.process(name)
if cookies = @request.env['action_dispatch.cookies']
- cookies.write(@response)
+ unless @response.committed?
+ cookies.write(@response)
+ end
end
@response.prepare!
@@ -583,13 +608,14 @@ def process(action, http_method = 'GET', *args)
end
def setup_controller_request_and_response
- @request = build_request
- @response = build_response
- @response.request = @request
-
@controller = nil unless defined? @controller
+ response_klass = TestResponse
+
if klass = self.class.controller_class
+ if klass < ActionController::Live
+ response_klass = LiveTestResponse
+ end
unless @controller
begin
@controller = klass.new
@@ -599,6 +625,10 @@ def setup_controller_request_and_response
end
end
+ @request = build_request
+ @response = build_response response_klass
+ @response.request = @request
+
if @controller
@controller.request = @request
@controller.params = {}
@@ -609,8 +639,8 @@ def build_request
TestRequest.new
end
- def build_response
- TestResponse.new
+ def build_response(klass)
+ klass.new
end
included do
@@ -152,6 +152,13 @@ def headers
Http::Headers.new(@env)
end
+ # Returns a +String+ with the last requested path including their params.
+ #
+ # # get '/foo'
+ # request.original_fullpath # => '/foo'
+ #
+ # # get '/foo?bar'
+ # request.original_fullpath # => '/foo?bar'
def original_fullpath
@original_fullpath ||= (env["ORIGINAL_FULLPATH"] || fullpath)
end
Oops, something went wrong.

0 comments on commit 66e0321

Please sign in to comment.