Skip to content

Commit 4f9e9af

Browse files
committed
Allow complex order objects to not be molested by our visitor overrides. Fixes #99
1 parent 7dbc0f9 commit 4f9e9af

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
* 3.1.0 *
33

4+
* Allow complex order objects to not be molested by our visitor overrides. Fixes #99
5+
46
* Default unicode datatypes!
57

68
* New #lowercase_schema_reflection configuration that allows you to downcase all tables and columns.

lib/arel/visitors/sqlserver.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def order(*exprs)
3535
table = Arel::Table.new(x.relation.table_alias || x.relation.name)
3636
expr = table[x.name]
3737
Arel::Nodes::Ordering.new expr
38+
when Arel::Nodes::Ordering
39+
x
3840
when String
3941
x.split(',').map do |s|
4042
expr, direction = s.split

test/cases/adapter_test_sqlserver.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
require 'models/joke'
55
require 'models/subscriber'
66
require 'models/minimalistic'
7+
require 'models/post'
78

89
class AdapterTestSqlserver < ActiveRecord::TestCase
910

10-
fixtures :tasks
11+
fixtures :tasks, :posts
1112

1213
def setup
1314
@connection = ActiveRecord::Base.connection
@@ -18,6 +19,12 @@ def setup
1819

1920
context 'For abstract behavior' do
2021

22+
should 'not mangel complex order clauses' do
23+
xyz_order = "CASE WHEN [title] LIKE N'XYZ%' THEN 0 ELSE 1 END"
24+
xyz_post = Post.create :title => 'XYZ Post', :body => 'Test cased orders.'
25+
assert_equal xyz_post, Post.order(Arel::Nodes::Ordering.new(Arel.sql(xyz_order))).first
26+
end
27+
2128
should 'have a 128 max #table_alias_length' do
2229
assert @connection.table_alias_length <= 128
2330
end

0 commit comments

Comments
 (0)