Skip to content

Commit

Permalink
Ensure that paginate_by_sql doesn't change the original SQL query. Cl…
Browse files Browse the repository at this point in the history
…oses mislav#235
  • Loading branch information
mislav committed Aug 27, 2008
1 parent 48d409a commit f54bc39
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/will_paginate/finder.rb
Expand Up @@ -127,7 +127,7 @@ def paginated_each(options = {}, &block)
#
def paginate_by_sql(sql, options)
WillPaginate::Collection.create(*wp_parse_options(options)) do |pager|
query = sanitize_sql(sql)
query = sanitize_sql(sql.dup)
original_query = query.dup
# add limit, offset
add_limit! query, :offset => pager.offset, :limit => pager.per_page
Expand Down
9 changes: 9 additions & 0 deletions test/finder_test.rb
Expand Up @@ -397,6 +397,15 @@ def test_paginating_finder_doesnt_mangle_options
Developer.paginate(options)
assert_equal options, options_before
end

def test_paginate_by_sql_doesnt_change_original_query
query = 'SQL QUERY'
original_query = query.dup
Developer.expects(:find_by_sql).returns([])

Developer.paginate_by_sql query, :page => 1
assert_equal original_query, query
end

def test_paginated_each
collection = stub('collection', :size => 5, :empty? => false, :per_page => 5)
Expand Down

0 comments on commit f54bc39

Please sign in to comment.