aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-07-17 17:37:39 -0400
committerGitHub <noreply@github.com>2017-07-17 17:37:39 -0400
commit589adea81c2f6ff04178a09986a455f6b7062dcc (patch)
treeeafb27c1e5f3ce3b13f3d3431e6504b2452e5ba9 /activerecord/test
parentf0b16afa581fd0ba51583bc026a3e300add2287a (diff)
parentea09bf5419ec752dd020d26b03533afa457d09d6 (diff)
downloadrails-589adea81c2f6ff04178a09986a455f6b7062dcc.tar.gz
rails-589adea81c2f6ff04178a09986a455f6b7062dcc.tar.bz2
rails-589adea81c2f6ff04178a09986a455f6b7062dcc.zip
Merge pull request #29828 from kamipo/fix_using_custom_table_with_joins
Fix `JoinDependency` with using a custom table
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/relations_test.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 82e1077e87..316ea75e36 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1785,15 +1785,15 @@ class RelationTest < ActiveRecord::TestCase
end
test "using a custom table affects the wheres" do
- table_alias = Post.arel_table.alias("omg_posts")
+ post = posts(:welcome)
- table_metadata = ActiveRecord::TableMetadata.new(Post, table_alias)
- predicate_builder = ActiveRecord::PredicateBuilder.new(table_metadata)
- relation = ActiveRecord::Relation.create(Post, table_alias, predicate_builder)
+ assert_equal post, custom_post_relation.where!(title: post.title).take
+ end
+ test "using a custom table with joins affects the joins" do
post = posts(:welcome)
- assert_equal post, relation.where!(title: post.title).take
+ assert_equal post, custom_post_relation.joins(:author).where!(title: post.title).take
end
test "#load" do
@@ -1950,4 +1950,13 @@ class RelationTest < ActiveRecord::TestCase
end
end
end
+
+ private
+ def custom_post_relation
+ table_alias = Post.arel_table.alias("omg_posts")
+ table_metadata = ActiveRecord::TableMetadata.new(Post, table_alias)
+ predicate_builder = ActiveRecord::PredicateBuilder.new(table_metadata)
+
+ ActiveRecord::Relation.create(Post, table_alias, predicate_builder)
+ end
end