Permalink
Browse files

fix rails 3.0 edge-case that would otherwise cache sql with order/gro…

…up-by etc
  • Loading branch information...
1 parent d2fb1f7 commit a02ea9fb286e3d939fe47283fc7e2303a2437af7 @grosser grosser committed Dec 11, 2012
Showing with 12 additions and 5 deletions.
  1. +1 −1 gemfiles/activerecord_3.0.gemfile.lock
  2. +7 −4 lib/kasket/query_parser.rb
  3. +4 −0 test/parser_test.rb
@@ -1,5 +1,5 @@
PATH
- remote: /Users/staugaard/code/kasket
+ remote: /Users/mgrosser/code/tools/kasket
specs:
kasket (2.2.0)
activerecord (>= 2.3.6, < 3.3)
View
@@ -23,10 +23,13 @@ def initialize(model_class)
def parse(sql)
if match = @supported_query_pattern.match(sql)
where, limit = match[1], match[2]
- if AR30 && where =~ /limit \d+\s*$/i
- # limit is harder to find in rails 3.0 since where does not use surrounding braces
- return unless where =~ /(.*?)(\s+limit 1)\s*$/i
- where, limit = $1, $2
+ if AR30
+ return if where =~ / (order by|group by|join|having) /i
+ if where =~ /limit \d+\s*$/i
+ # limit is harder to find in rails 3.0 since where does not use surrounding braces
+ return unless where =~ /(.*?)(\s+limit 1)\s*$/i
+ where, limit = $1, $2
+ end
end
query = Hash.new
View
@@ -34,6 +34,10 @@ def parse(options)
assert !parse(:conditions => "(0 = 1)")
end
+ should "not support :order" do
+ assert !parse(:conditions => "id = 1", :order => "xxx")
+ end
+
should 'not support IN queries in combination with other conditions' do
assert !parse(:conditions => {:id => [1,2,3], :is_active => true})
end

0 comments on commit a02ea9f

Please sign in to comment.