aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_dispatch/testing/test_request.rb2
-rw-r--r--actionpack/test/dispatch/test_request_test.rb7
-rw-r--r--activerecord/CHANGELOG.md7
-rw-r--r--activerecord/lib/active_record/persistence.rb3
-rw-r--r--activerecord/test/cases/persistence_test.rb6
-rw-r--r--activesupport/lib/active_support/cache.rb5
-rw-r--r--activesupport/lib/active_support/callbacks.rb8
-rw-r--r--activesupport/test/caching_test.rb6
8 files changed, 35 insertions, 9 deletions
diff --git a/actionpack/lib/action_dispatch/testing/test_request.rb b/actionpack/lib/action_dispatch/testing/test_request.rb
index d0beb72a41..91b25ec155 100644
--- a/actionpack/lib/action_dispatch/testing/test_request.rb
+++ b/actionpack/lib/action_dispatch/testing/test_request.rb
@@ -22,7 +22,7 @@ module ActionDispatch
private_class_method :default_env
def request_method=(method)
- set_header("REQUEST_METHOD", method.to_s.upcase)
+ super(method.to_s.upcase)
end
def host=(host)
diff --git a/actionpack/test/dispatch/test_request_test.rb b/actionpack/test/dispatch/test_request_test.rb
index 35af3076ba..b479af781d 100644
--- a/actionpack/test/dispatch/test_request_test.rb
+++ b/actionpack/test/dispatch/test_request_test.rb
@@ -88,6 +88,13 @@ class TestRequestTest < ActiveSupport::TestCase
assert_equal "GoogleBot", req.user_agent
end
+ test "request_method getter and setter" do
+ req = ActionDispatch::TestRequest.create
+ req.request_method # to reproduce bug caused by memoization
+ req.request_method = "POST"
+ assert_equal "POST", req.request_method
+ end
+
test "setter methods" do
req = ActionDispatch::TestRequest.create({})
get = "GET"
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 6cc667b754..41e05dd8c1 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,10 @@
+* Return `true` from `update_attribute` when the value of the attribute
+ to be updated is unchanged.
+
+ Fixes #26593.
+
+ *Prathamesh Sonpatki*
+
* Always store errors details information with symbols.
When the association is autosaved we were storing the details with
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 978fb27cab..65248f3a32 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -252,7 +252,8 @@ module ActiveRecord
name = name.to_s
verify_readonly_attribute(name)
public_send("#{name}=", value)
- save(validate: false) if changed?
+
+ changed? ? save(validate: false) : true
end
# Updates the attributes of the model from the passed-in hash and saves the
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb
index d83360e327..688c3ed2b1 100644
--- a/activerecord/test/cases/persistence_test.rb
+++ b/activerecord/test/cases/persistence_test.rb
@@ -391,14 +391,14 @@ class PersistenceTest < ActiveRecord::TestCase
end
topic = klass.create(title: "Another New Topic")
assert_queries(0) do
- topic.update_attribute(:title, "Another New Topic")
+ assert topic.update_attribute(:title, "Another New Topic")
end
end
def test_update_does_not_run_sql_if_record_has_not_changed
topic = Topic.create(title: "Another New Topic")
- assert_queries(0) { topic.update(title: "Another New Topic") }
- assert_queries(0) { topic.update_attributes(title: "Another New Topic") }
+ assert_queries(0) { assert topic.update(title: "Another New Topic") }
+ assert_queries(0) { assert topic.update_attributes(title: "Another New Topic") }
end
def test_delete
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index e71f2673ab..e65e472d08 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -361,6 +361,9 @@ module ActiveSupport
# the cache with the given keys, then that data is returned. Otherwise,
# the supplied block is called for each key for which there was no data,
# and the result will be written to the cache and returned.
+ # Therefore, you need to pass a block that returns the data to be written
+ # to the cache. If you do not want to write the cache when the cache is
+ # not found, use #read_multi.
#
# Options are passed to the underlying cache implementation.
#
@@ -374,6 +377,8 @@ module ActiveSupport
# # "unknown_key" => "Fallback value for key: unknown_key" }
#
def fetch_multi(*names)
+ raise ArgumentError, "Missing block: `Cache#fetch_multi` requires a block." unless block_given?
+
options = names.extract_options!
options = merged_options(options)
results = read_multi(*names, options)
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 3a2c7b0e74..6d39be1c1f 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -738,11 +738,11 @@ module ActiveSupport
#
# ===== Notes
#
- # +names+ passed to `define_callbacks` must not end with
- # `!`, `?` or `=`.
+ # +names+ passed to +define_callbacks+ must not end with
+ # <tt>!</tt>, <tt>?</tt> or <tt>=</tt>.
#
- # Calling `define_callbacks` multiple times with the same +names+ will
- # overwrite previous callbacks registered with `set_callback`.
+ # Calling +define_callbacks+ multiple times with the same +names+ will
+ # overwrite previous callbacks registered with +set_callback+.
def define_callbacks(*names)
options = names.extract_options!
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index a669d666be..0df4173a1a 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -363,6 +363,12 @@ module CacheStoreBehavior
assert_equal({ foo => "FOO!", bar => "BAM!" }, values)
end
+ def test_fetch_multi_without_block
+ assert_raises(ArgumentError) do
+ @cache.fetch_multi("foo")
+ end
+ end
+
def test_read_and_write_compressed_small_data
@cache.write("foo", "bar", compress: true)
assert_equal "bar", @cache.read("foo")