Skip to content

Commit fb1740d

Browse files
author
Anna
committed
moved arel test helpers
1 parent 4c2be6b commit fb1740d

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

test/cases/arel_helper.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
AREL_TEST_ROOT = File.expand_path(File.join(Gem.loaded_specs['arel'].full_gem_path,'test'))
2+
$LOAD_PATH.unshift AREL_TEST_ROOT
3+
4+
# TODO: Find A better way to run Arel tests without failing on
5+
# SQL Server brackets instead of quotes
6+
class Object
7+
def must_be_like other
8+
actual = gsub(/\s+/, ' ').gsub(/\[|\]/,'"').gsub(/N\'/,'\'').strip
9+
expected = other.gsub(/\s+/, ' ').strip
10+
actual.must_equal expected
11+
end
12+
end
13+
14+
15+
# Useful for debugging Arel.
16+
# You can call it like arel_to_png(User.where(name: "foo").arel)
17+
def arel_to_png(arel)
18+
graph = GraphViz.parse_string(arel.to_dot)
19+
graph.output(:png => "query.png")
20+
end

test/cases/sqlserver_helper.rb

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,16 @@
44
SQLSERVER_MIGRATIONS_ROOT = File.expand_path(File.join(SQLSERVER_TEST_ROOT,'migrations'))
55
SQLSERVER_SCHEMA_ROOT = File.expand_path(File.join(SQLSERVER_TEST_ROOT,'schema'))
66
ACTIVERECORD_TEST_ROOT = File.expand_path(File.join(Gem.loaded_specs['activerecord'].full_gem_path,'test'))
7-
AREL_TEST_ROOT = File.expand_path(File.join(Gem.loaded_specs['arel'].full_gem_path,'test'))
87

98
ENV['ARCONFIG'] = File.expand_path(File.join(SQLSERVER_TEST_ROOT,'config.yml'))
109

11-
$:.unshift ACTIVERECORD_TEST_ROOT
12-
$LOAD_PATH.unshift AREL_TEST_ROOT
10+
$LOAD_PATH.unshift ACTIVERECORD_TEST_ROOT
1311

1412
require 'rubygems'
1513
require 'bundler'
1614
Bundler.setup
1715
require 'simplecov'
18-
SimpleCov.start do
19-
add_filter "/test/"
20-
end
21-
require 'turn'
22-
Turn.config do |c|
23-
c.format = :dot
24-
#c.trace = 10
25-
# c.natural = true
26-
c.verbose = true
27-
end
28-
2916
require 'graphviz'
30-
3117
require 'mocha/api'
3218
require 'active_support/dependencies'
3319
require 'active_record'
@@ -37,6 +23,12 @@
3723
require 'minitest-spec-rails/init/mini_shoulda'
3824
require 'cases/helper'
3925
require 'models/topic'
26+
require 'cases/arel_helper'
27+
28+
SimpleCov.start do
29+
add_filter "/test/"
30+
end
31+
4032
GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly?)
4133

4234
ActiveRecord::Migration.verbose = false
@@ -120,17 +112,10 @@ def with_auto_connect(boolean)
120112
end
121113
end
122114

123-
#useful for debugging Arel.
124-
# You can call it like arel_to_png(User.where(name: "foo").arel)
125-
def arel_to_png(arel)
126-
graph = GraphViz.parse_string(arel.to_dot)
127-
graph.output(:png => "query.png")
128-
end
115+
# Core AR.
116+
schema_file = "#{ACTIVERECORD_TEST_ROOT}/schema/schema.rb"
117+
eval(File.read(schema_file))
129118

130-
# Core AR.
131-
schema_file = "#{ACTIVERECORD_TEST_ROOT}/schema/schema.rb"
132-
eval(File.read(schema_file))
133-
134-
# SQL Server.
135-
sqlserver_specific_schema_file = "#{SQLSERVER_SCHEMA_ROOT}/sqlserver_specific_schema.rb"
136-
eval(File.read(sqlserver_specific_schema_file))
119+
# SQL Server.
120+
sqlserver_specific_schema_file = "#{SQLSERVER_SCHEMA_ROOT}/sqlserver_specific_schema.rb"
121+
eval(File.read(sqlserver_specific_schema_file))

0 commit comments

Comments
 (0)