diff options
14 files changed, 57 insertions, 11 deletions
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 9a76b68ae1..c8ad8cee68 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -327,6 +327,12 @@ module ActionDispatch # Performs the actual request. def process(method, path, params: nil, headers: nil, env: nil, xhr: false, as: nil) request_encoder = RequestEncoder.encoder(as) + headers ||= {} + + if method == :get && as == :json && params + headers['X-Http-Method-Override'] = 'GET' + method = :post + end if path =~ %r{://} path = build_expanded_path(path, request_encoder) do |location| @@ -361,7 +367,6 @@ module ActionDispatch } if xhr - headers ||= {} headers['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' headers['HTTP_ACCEPT'] ||= [Mime[:js], Mime[:html], Mime[:xml], 'text/xml', '*/*'].join(', ') end diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index c8a45a0851..2d189f9f27 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -104,6 +104,7 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase middleware.use ActionDispatch::Callbacks middleware.use ActionDispatch::Cookies middleware.use ActionDispatch::Flash + middleware.use Rack::MethodOverride middleware.use Rack::Head yield(middleware) if block_given? end diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index e02b0b267d..7ad8dbb2bd 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -1238,6 +1238,22 @@ class IntegrationRequestEncodersTest < ActionDispatch::IntegrationTest end end + def test_get_request_with_json_uses_method_override_and_sends_a_post_request + with_routing do |routes| + routes.draw do + ActiveSupport::Deprecation.silence do + get ':action' => FooController + end + end + + get '/foos_json', params: { foo: 'heyo' }, as: :json + + assert_equal 'POST', request.method + assert_equal 'GET', request.headers['X-Http-Method-Override'] + assert_equal({ 'foo' => 'heyo' }, response.parsed_body) + end + end + private def post_to_foos(as:) with_routing do |routes| diff --git a/activejob/lib/rails/generators/job/templates/application_job.rb b/activejob/lib/rails/generators/job/templates/application_job.rb index 0b113b950e..f93745a31a 100644 --- a/activejob/lib/rails/generators/job/templates/application_job.rb +++ b/activejob/lib/rails/generators/job/templates/application_job.rb @@ -1,4 +1,9 @@ <% module_namespacing do -%> class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError end <% end -%> diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 14a6c3c9f7..dfd9a07997 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,10 @@ +* Hashes can once again be passed to setters of `composed_of`, if all of the + mapping methods are methods implemented on `Hash`. + + Fixes #25978. + + *Sean Griffin* + * Fix the SELECT statement in `#table_comment` for MySQL. *Takeshi Akima* diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb index 8bed5bca28..9f965052c5 100644 --- a/activerecord/lib/active_record/aggregations.rb +++ b/activerecord/lib/active_record/aggregations.rb @@ -261,8 +261,10 @@ module ActiveRecord part = converter.respond_to?(:call) ? converter.call(part) : klass.send(converter, part) end - if part.is_a?(Hash) - raise ArgumentError unless part.size == part.keys.max + hash_from_multiparameter_assignment = part.is_a?(Hash) && + part.each_key.all? { |k| k.is_a?(Integer) } + if hash_from_multiparameter_assignment + raise ArgumentError unless part.size == part.each_key.max part = klass.new(*part.sort.map(&:last)) end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index acc21866f1..5e9705e02f 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -753,7 +753,7 @@ module ActiveRecord when ER_DATA_TOO_LONG ValueTooLong.new(message) when ER_LOCK_DEADLOCK - DeadlockDetected.new(message) + Deadlocked.new(message) else super end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index e213c991c8..8a1fdc9f92 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -422,7 +422,7 @@ module ActiveRecord when SERIALIZATION_FAILURE SerializationFailure.new(message) when DEADLOCK_DETECTED - DeadlockDetected.new(message) + Deadlocked.new(message) else super end diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index 3f75ce4099..03e6e1eee3 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -300,9 +300,9 @@ module ActiveRecord class SerializationFailure < TransactionRollbackError end - # DeadlockDetected will be raised when a transaction is rolled + # Deadlocked will be raised when a transaction is rolled # back by the database when a deadlock is encountered. - class DeadlockDetected < TransactionRollbackError + class Deadlocked < TransactionRollbackError end # IrreversibleOrderError is raised when a relation's order is too complex for diff --git a/activerecord/test/cases/adapters/mysql2/transaction_test.rb b/activerecord/test/cases/adapters/mysql2/transaction_test.rb index 1a88b9cbca..5d8765d63a 100644 --- a/activerecord/test/cases/adapters/mysql2/transaction_test.rb +++ b/activerecord/test/cases/adapters/mysql2/transaction_test.rb @@ -27,8 +27,8 @@ module ActiveRecord @connection.drop_table 'samples', if_exists: true end - test "raises DeadlockDetected when a deadlock is encountered" do - assert_raises(ActiveRecord::DeadlockDetected) do + test "raises Deadlocked when a deadlock is encountered" do + assert_raises(ActiveRecord::Deadlocked) do s1 = Sample.create value: 1 s2 = Sample.create value: 2 diff --git a/activerecord/test/cases/adapters/postgresql/transaction_test.rb b/activerecord/test/cases/adapters/postgresql/transaction_test.rb index 87d1fffe19..8dea92c785 100644 --- a/activerecord/test/cases/adapters/postgresql/transaction_test.rb +++ b/activerecord/test/cases/adapters/postgresql/transaction_test.rb @@ -58,9 +58,9 @@ module ActiveRecord end end - test "raises DeadlockDetected when a deadlock is encountered" do + test "raises Deadlocked when a deadlock is encountered" do with_warning_suppression do - assert_raises(ActiveRecord::DeadlockDetected) do + assert_raises(ActiveRecord::Deadlocked) do s1 = Sample.create value: 1 s2 = Sample.create value: 2 diff --git a/activerecord/test/cases/aggregations_test.rb b/activerecord/test/cases/aggregations_test.rb index 8a728902a8..4e865264c7 100644 --- a/activerecord/test/cases/aggregations_test.rb +++ b/activerecord/test/cases/aggregations_test.rb @@ -143,6 +143,11 @@ class AggregationsTest < ActiveRecord::TestCase customers(:barney).fullname = { first: "Barney", last: "Stinson" } assert_equal "Barney STINSON", customers(:barney).name end + + def test_assigning_hash_without_custom_converter + customers(:barney).fullname_no_converter = { first: "Barney", last: "Stinson" } + assert_equal({ first: "Barney", last: "Stinson" }.to_s, customers(:barney).name) + end end class OverridingAggregationsTest < ActiveRecord::TestCase diff --git a/activerecord/test/models/customer.rb b/activerecord/test/models/customer.rb index 3338aaf7e1..d464759430 100644 --- a/activerecord/test/models/customer.rb +++ b/activerecord/test/models/customer.rb @@ -7,6 +7,7 @@ class Customer < ActiveRecord::Base composed_of :non_blank_gps_location, :class_name => "GpsLocation", :allow_nil => true, :mapping => %w(gps_location gps_location), :converter => lambda { |gps| self.gps_conversion_was_run = true; gps.blank? ? nil : GpsLocation.new(gps)} composed_of :fullname, :mapping => %w(name to_s), :constructor => Proc.new { |name| Fullname.parse(name) }, :converter => :parse + composed_of :fullname_no_converter, :mapping => %w(name to_s), class_name: "Fullname" end class Address diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md index 73dbb2bc40..89b1d3ca03 100644 --- a/guides/source/getting_started.md +++ b/guides/source/getting_started.md @@ -148,6 +148,10 @@ This will create a Rails application called Blog in a `blog` directory and install the gem dependencies that are already mentioned in `Gemfile` using `bundle install`. +NOTE: If you're using Windows Subsystem for Linux then there are currently some +limitations on file system notifications that mean you should disable the `spring` +and `listen` gems which you can do by running `rails new blog --skip-spring --skip-listen`. + TIP: You can see all of the command line options that the Rails application builder accepts by running `rails new -h`. |
