diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-05-17 05:30:33 -0700 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-05-17 05:30:33 -0700 |
commit | 77a40722f74a30b5b3d028a3d20129a2aad8722a (patch) | |
tree | 62ab835a46c816fe3aed7a3b53f4f70888851faa /activerecord/test | |
parent | 03f8a574872f1206c16720af034e4bb91930d237 (diff) | |
parent | 64872d1e34d929ee30041b37900591aade2a5eaf (diff) | |
download | rails-77a40722f74a30b5b3d028a3d20129a2aad8722a.tar.gz rails-77a40722f74a30b5b3d028a3d20129a2aad8722a.tar.bz2 rails-77a40722f74a30b5b3d028a3d20129a2aad8722a.zip |
Merge pull request #6058 from RStankov/relation-from-to-accept-other-relation-objects
Relation#from to accept other Relation objects
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 7 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 7 |
2 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 8a7a2441d4..89f818a689 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -203,13 +203,18 @@ module ActiveRecord assert_equal [], relation.extending_values end - (Relation::SINGLE_VALUE_METHODS - [:lock, :reordering, :reverse_order, :create_with]).each do |method| + (Relation::SINGLE_VALUE_METHODS - [:from, :lock, :reordering, :reverse_order, :create_with]).each do |method| test "##{method}!" do assert relation.public_send("#{method}!", :foo).equal?(relation) assert_equal :foo, relation.public_send("#{method}_value") end end + test '#from!' do + assert relation.from!('foo').equal?(relation) + assert_equal ['foo', nil], relation.from_value + end + test '#lock!' do assert relation.lock!('foo').equal?(relation) assert_equal 'foo', relation.lock_value diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 76b868c7b4..dee31f4772 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -133,6 +133,13 @@ class RelationTest < ActiveRecord::TestCase assert topics.loaded? end + def test_finiding_with_subquery + relation = Topic.where(:approved => true) + assert_equal relation.to_a, Topic.select('*').from(relation).to_a + assert_equal relation.to_a, Topic.select('subquery.*').from(relation).to_a + assert_equal relation.to_a, Topic.select('a.*').from(relation, :a).to_a + end + def test_finding_with_conditions assert_equal ["David"], Author.where(:name => 'David').map(&:name) assert_equal ['Mary'], Author.where(["name = ?", 'Mary']).map(&:name) |