aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorkennyj <kennyj@gmail.com>2012-10-31 02:21:52 +0900
committerkennyj <kennyj@gmail.com>2012-10-31 10:04:10 +0900
commita7c3c9025009cef98cd91ff27707f678cb8fb3c3 (patch)
tree2d3cb829b8fcbcf4cc9aba6eedb6d2757e527a66 /activerecord
parent7e17b0baec4ea811c1a7e3bd491eaedf95b1feb4 (diff)
downloadrails-a7c3c9025009cef98cd91ff27707f678cb8fb3c3.tar.gz
rails-a7c3c9025009cef98cd91ff27707f678cb8fb3c3.tar.bz2
rails-a7c3c9025009cef98cd91ff27707f678cb8fb3c3.zip
Fix #6951. Use query cache/uncache, when using not only database.yml but also DATABASE_URL.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md5
-rw-r--r--activerecord/lib/active_record/query_cache.rb12
-rw-r--r--activerecord/test/cases/query_cache_test.rb11
3 files changed, 22 insertions, 6 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index f7aed090a4..7d318808de 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* Use query cache/uncache when using DATABASE_URL.
+ Fix #6951.
+
+ *kennyj*
+
* Added `#none!` method for mutating `ActiveRecord::Relation` objects to a NullRelation.
It acts like `#none` but modifies relation in place.
diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb
index 2bd8ecda20..38e18b32a4 100644
--- a/activerecord/lib/active_record/query_cache.rb
+++ b/activerecord/lib/active_record/query_cache.rb
@@ -5,19 +5,19 @@ module ActiveRecord
module ClassMethods
# Enable the query cache within the block if Active Record is configured.
def cache(&block)
- if ActiveRecord::Base.configurations.blank?
- yield
- else
+ if ActiveRecord::Base.connected?
connection.cache(&block)
+ else
+ yield
end
end
# Disable the query cache within the block if Active Record is configured.
def uncached(&block)
- if ActiveRecord::Base.configurations.blank?
- yield
- else
+ if ActiveRecord::Base.connected?
connection.uncached(&block)
+ else
+ yield
end
end
end
diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb
index 51a285a2b4..4ff481e6a5 100644
--- a/activerecord/test/cases/query_cache_test.rb
+++ b/activerecord/test/cases/query_cache_test.rb
@@ -184,6 +184,17 @@ class QueryCacheTest < ActiveRecord::TestCase
assert_queries(2) { task.lock!; task.lock! }
end
end
+
+ def test_cache_is_available_when_connection_is_connected
+ conf = ActiveRecord::Base.configurations
+
+ ActiveRecord::Base.configurations = {}
+ Task.cache do
+ assert_queries(1) { Task.find(1); Task.find(1) }
+ end
+ ensure
+ ActiveRecord::Base.configurations = conf
+ end
end
class QueryCacheExpiryTest < ActiveRecord::TestCase