Skip to content

Commit 38aa198

Browse files
committed
Fixing table_name_test_sqlserver.rb to not leave it's droppings all over the Order model (e.g. repair the table name with what it used to be)
Should we create / use a repair_table_name macro for this?
1 parent 2340222 commit 38aa198

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed
Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
require "cases/helper"
22
require 'active_record/schema'
3+
require 'models/order'
34

4-
if ActiveRecord::Base.connection.supports_migrations?
5-
class Order < ActiveRecord::Base
6-
self.table_name = '[orders]'
7-
end
5+
class TableNameTest < ActiveRecord::TestCase
6+
self.use_transactional_fixtures = false
87

9-
class TableNameTest < ActiveRecord::TestCase
10-
self.use_transactional_fixtures = false
8+
setup do
9+
@old_name = Order.table_name
10+
Order.table_name = '[orders]'
11+
end
12+
13+
teardown do
14+
Order.table_name = @old_name
15+
end
1116

12-
# Ensures Model.columns works when using SQLServer escape characters.
13-
# Enables legacy schemas using SQL reserved words as table names.
14-
# Should work with table names with spaces as well ('table name').
15-
def test_escaped_table_name
16-
assert_nothing_raised do
17-
ActiveRecord::Base.connection.select_all 'SELECT * FROM [orders]'
18-
end
19-
assert_equal '[orders]', Order.table_name
20-
assert_equal 4, Order.columns.length
17+
# Ensures Model.columns works when using SQLServer escape characters.
18+
# Enables legacy schemas using SQL reserved words as table names.
19+
# Should work with table names with spaces as well ('table name').
20+
def test_escaped_table_name
21+
assert_nothing_raised do
22+
ActiveRecord::Base.connection.select_all 'SELECT * FROM [orders]'
2123
end
24+
assert_equal '[orders]', Order.table_name
25+
assert_equal 4, Order.columns.length
2226
end
23-
end
27+
end

0 commit comments

Comments
 (0)