Permalink
Browse files

add test for eager loading fully-qualified table names with oracle

This test addresses improper detection of valid table names by the
Relation#tables_in_string method on Oracle.  To make the test fail,
setup test/config.yml use an oracle database with a username like
'ops$user', or any valid variation that has non-word characters
in it.  It should pass otherwise.
  • Loading branch information...
1 parent 37b77c6 commit d1f75d1123a5f353d3724b93b340e0d52b779b4e Simon Chiang committed Aug 9, 2011
@@ -22,12 +22,15 @@
require 'models/club'
require 'models/categorization'
require 'models/sponsor'
+require 'models/emp'
+require 'models/dept'
class EagerAssociationTest < ActiveRecord::TestCase
fixtures :posts, :comments, :authors, :author_addresses, :categories, :categories_posts,
:companies, :accounts, :tags, :taggings, :people, :readers, :categorizations,
:owners, :pets, :author_favorites, :jobs, :references, :subscribers, :subscriptions, :books,
- :developers, :projects, :developers_projects, :members, :memberships, :clubs, :sponsors
+ :developers, :projects, :developers_projects, :members, :memberships, :clubs, :sponsors,
+ :emps, :depts
def setup
# preheat table existence caches
@@ -80,6 +83,11 @@ def test_with_two_tables_in_from_without_getting_double_quoted
assert_equal 2, posts.first.comments.size
end
+ def test_with_full_qualified_table_name
+ assert_equal "Research", Emp.find(1, :include => :dept).dept.nombre
+ assert_equal "Research", Emp.find(:first, :include => :dept).dept.nombre
+ end
+
def test_loading_with_multiple_associations
posts = Post.find(:all, :include => [ :comments, :author, :categories ], :order => "posts.id")
assert_equal 2, posts.first.comments.size
@@ -0,0 +1,3 @@
+research:
+ id: 1
+ name: Research
@@ -0,0 +1,4 @@
+doej:
+ id: 1
+ name: John Doe
+ dept_id: 1
@@ -0,0 +1,5 @@
+class Dept < ActiveRecord::Base
+ if connection.class.to_s == "ActiveRecord::ConnectionAdapters::OracleAdapter"
+ set_table_name "#{connection.current_user.downcase}.depts"
+ end
+end
@@ -0,0 +1,6 @@
+class Emp < ActiveRecord::Base
+ if connection.class.to_s == "ActiveRecord::ConnectionAdapters::OracleAdapter"
+ set_table_name "#{connection.current_user.downcase}.emps"
+ end
+ belongs_to :dept, :select => "id, name nombre"
+end
@@ -712,6 +712,14 @@ def create_table(*args, &block)
t.string 'a$b'
end
+ create_table :emps, :force => true do |t|
+ t.string :name
+ t.integer :dept_id
+ end
+ create_table :depts, :force => true do |t|
+ t.string :name
+ end
+
except 'SQLite' do
# fk_test_has_fk should be before fk_test_has_pk
create_table :fk_test_has_fk, :force => true do |t|

0 comments on commit d1f75d1

Please sign in to comment.