aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionmailer/test/base_test.rb4
-rw-r--r--activemodel/lib/active_model/observing.rb2
-rw-r--r--activerecord/lib/active_record/relation.rb13
-rw-r--r--activerecord/test/cases/relations_test.rb15
-rw-r--r--activesupport/lib/active_support/cache.rb25
-rw-r--r--activesupport/test/caching_test.rb6
6 files changed, 44 insertions, 21 deletions
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index 1b793d255e..6a7931da8c 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -153,8 +153,8 @@ class BaseTest < ActiveSupport::TestCase
assert_equal(2, email.parts.length)
assert_equal("multipart/related", email.mime_type)
assert_equal("multipart/alternative", email.parts[0].mime_type)
- assert_equal("text/plain", email.parts[0].parts[0].mime_type)
- assert_equal("text/html", email.parts[0].parts[1].mime_type)
+ assert_equal("text/plain", email.parts[0].parts[0].mime_type)
+ assert_equal("text/html", email.parts[0].parts[1].mime_type)
assert_equal("logo.png", email.parts[1].filename)
end
diff --git a/activemodel/lib/active_model/observing.rb b/activemodel/lib/active_model/observing.rb
index af036b560e..ef36f80bec 100644
--- a/activemodel/lib/active_model/observing.rb
+++ b/activemodel/lib/active_model/observing.rb
@@ -72,7 +72,7 @@ module ActiveModel
def instantiate_observer(observer) #:nodoc:
# string/symbol
if observer.respond_to?(:to_sym)
- observer = observer.to_s.camelize.constantize.instance
+ observer.to_s.camelize.constantize.instance
elsif observer.respond_to?(:instance)
observer.instance
else
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index f939bedc81..5af20bf38b 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -407,8 +407,19 @@ module ActiveRecord
private
def references_eager_loaded_tables?
+ joined_tables = arel.join_sources.map do |join|
+ if join.is_a?(Arel::Nodes::StringJoin)
+ tables_in_string(join.left)
+ else
+ [join.left.table_name, join.left.table_alias]
+ end
+ end
+
+ joined_tables += [table.name, table.table_alias]
+
# always convert table names to downcase as in Oracle quoted table names are in uppercase
- joined_tables = (tables_in_string(arel.join_sql) + [table.name, table.table_alias]).compact.map{ |t| t.downcase }.uniq
+ joined_tables = joined_tables.flatten.compact.map { |t| t.downcase }.uniq
+
(tables_in_string(to_sql) - joined_tables).any?
end
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 37bbb17e74..948fcf7012 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -850,4 +850,19 @@ class RelationTest < ActiveRecord::TestCase
def test_primary_key
assert_equal "id", Post.scoped.primary_key
end
+
+ def test_eager_loading_with_conditions_on_joins
+ scope = Post.includes(:comments)
+
+ # This references the comments table, and so it should cause the comments to be eager
+ # loaded via a JOIN, rather than by subsequent queries.
+ scope = scope.joins(
+ Post.arel_table.create_join(
+ Post.arel_table,
+ Post.arel_table.create_on(Comment.arel_table[:id].eq(3))
+ )
+ )
+
+ assert scope.eager_loading?
+ end
end
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index b4f0c42e37..10c457bb1d 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -484,19 +484,20 @@ module ActiveSupport
# object responds to +cache_key+. Otherwise, to_param method will be
# called. If the key is a Hash, then keys will be sorted alphabetically.
def expanded_key(key) # :nodoc:
- if key.respond_to?(:cache_key)
- key = key.cache_key.to_s
- elsif key.is_a?(Array)
+ return key.cache_key.to_s if key.respond_to?(:cache_key)
+
+ case key
+ when Array
if key.size > 1
- key.collect{|element| expanded_key(element)}.to_param
+ key = key.collect{|element| expanded_key(element)}
else
- key.first.to_param
+ key = key.first
end
- elsif key.is_a?(Hash)
- key = key.to_a.sort{|a,b| a.first.to_s <=> b.first.to_s}.collect{|k,v| "#{k}=#{v}"}.to_param
- else
- key = key.to_param
+ when Hash
+ key = key.sort_by { |k,_| k.to_s }.collect{|k,v| "#{k}=#{v}"}
end
+
+ key.to_param
end
# Prefix a key with the namespace. Namespace and key will be delimited with a colon.
@@ -589,11 +590,7 @@ module ActiveSupport
# Check if the entry is expired. The +expires_in+ parameter can override the
# value set when the entry was created.
def expired?
- if @expires_in && @created_at + @expires_in <= Time.now.to_f
- true
- else
- false
- end
+ @expires_in && @created_at + @expires_in <= Time.now.to_f
end
# Set a new time when the entry will expire.
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index 579d5dad24..e5668e29d7 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -679,12 +679,12 @@ class CacheEntryTest < ActiveSupport::TestCase
def test_expired
entry = ActiveSupport::Cache::Entry.new("value")
- assert_equal false, entry.expired?
+ assert !entry.expired?, 'entry not expired'
entry = ActiveSupport::Cache::Entry.new("value", :expires_in => 60)
- assert_equal false, entry.expired?
+ assert !entry.expired?, 'entry not expired'
time = Time.now + 61
Time.stubs(:now).returns(time)
- assert_equal true, entry.expired?
+ assert entry.expired?, 'entry is expired'
end
def test_compress_values