diff options
Diffstat (limited to 'activerecord/test/cases/relation_test.rb')
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 693b36f35c..f99801c437 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -9,6 +9,9 @@ module ActiveRecord fixtures :posts, :comments, :authors class FakeKlass < Struct.new(:table_name, :name) + def self.connection + Post.connection + end end def test_construction @@ -108,6 +111,12 @@ module ActiveRecord assert_equal({}, relation.scope_for_create) end + def test_bad_constants_raise_errors + assert_raises(NameError) do + ActiveRecord::Relation::HelloWorld + end + end + def test_empty_eager_loading? relation = Relation.new FakeKlass, :b assert !relation.eager_loading? @@ -201,8 +210,12 @@ module ActiveRecord class RelationMutationTest < ActiveSupport::TestCase class FakeKlass < Struct.new(:table_name, :name) - def quoted_table_name - %{"#{table_name}"} + def arel_table + Post.arel_table + end + + def connection + Post.connection end end @@ -224,7 +237,17 @@ module ActiveRecord test "#order! with symbol prepends the table name" do assert relation.order!(:name).equal?(relation) - assert_equal ['"posts".name ASC'], relation.order_values + node = relation.order_values.first + assert node.ascending? + assert_equal :name, node.expr.name + assert_equal "posts", node.expr.relation.name + end + + test "#order! on non-string does not attempt regexp match for references" do + obj = Object.new + obj.expects(:=~).never + assert relation.order!(obj) + assert_equal [obj], relation.order_values end test '#references!' do @@ -285,7 +308,7 @@ module ActiveRecord assert_equal({foo: 'bar'}, relation.create_with_value) end - test 'merge!' do + def test_merge! assert relation.merge!(where: :foo).equal?(relation) assert_equal [:foo], relation.where_values end |