diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-30 14:29:35 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-30 14:29:35 -0800 |
commit | 6c32290bac460ce53ea2d29b50047248f9f0de92 (patch) | |
tree | f7741afdcf63579c0d13fc05b9b683db55bf216e | |
parent | bfc398cb7083c41becf6e4938c0a80a6659a1caa (diff) | |
download | rails-6c32290bac460ce53ea2d29b50047248f9f0de92.tar.gz rails-6c32290bac460ce53ea2d29b50047248f9f0de92.tar.bz2 rails-6c32290bac460ce53ea2d29b50047248f9f0de92.zip |
testing Relation#table_name
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 21 |
2 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 1ed42ffb95..098a03b39b 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -356,6 +356,10 @@ module ActiveRecord to_a.inspect end + def table_name + @klass.table_name + end + protected def method_missing(method, *args, &block) diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 96856ac22b..3629f6f806 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -2,6 +2,9 @@ require "cases/helper" module ActiveRecord class RelationTest < ActiveRecord::TestCase + class FakeTable < Struct.new(:table_name) + end + def test_construction relation = nil assert_nothing_raised do @@ -52,5 +55,23 @@ module ActiveRecord relation = Relation.new :a, :b assert_equal [], relation.extensions end + + def test_where_values_hash + relation = Relation.new :a, :b + assert_equal({}, relation.where_values_hash) + + relation.where_values << :hello + assert_equal({}, relation.where_values_hash) + end + + def test_table_name_delegates_to_klass + relation = Relation.new FakeTable.new('foo'), :b + assert_equal 'foo', relation.table_name + end + + def test_scope_for_create + relation = Relation.new :a, :b + assert_equal({}, relation.scope_for_create) + end end end |