diff options
author | Radoslav Stankov <rstankov@gmail.com> | 2012-04-29 21:17:57 +0300 |
---|---|---|
committer | Radoslav Stankov <rstankov@gmail.com> | 2012-05-17 02:36:13 +0300 |
commit | 64872d1e34d929ee30041b37900591aade2a5eaf (patch) | |
tree | 65288d3fdd80559ecbe655c15b83ce19e49c8906 /activerecord/test/cases | |
parent | 78b6fdd89f541dfedd369da9957ee6eab9a8a586 (diff) | |
download | rails-64872d1e34d929ee30041b37900591aade2a5eaf.tar.gz rails-64872d1e34d929ee30041b37900591aade2a5eaf.tar.bz2 rails-64872d1e34d929ee30041b37900591aade2a5eaf.zip |
Relation#from to accept other Relation objects
Record.from("(#{sub_query.to_sql})") -> Record.from(sub_query)
Record.from("(#{sub_query.to_sql}) a") -> Record.from(sub_query, :a)
Diffstat (limited to 'activerecord/test/cases')
-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) |