Skip to content
This repository has been archived by the owner on Jan 10, 2018. It is now read-only.

Commit

Permalink
hit the database in paginate_by_sql tests
Browse files Browse the repository at this point in the history
exposes the issue introduced in 6dc60a9
  • Loading branch information
mislav committed May 21, 2009
1 parent 5fb4061 commit f5be4f6
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions test/finder_test.rb
Expand Up @@ -361,18 +361,15 @@ def test_should_use_scoped_finders_if_present
end

def test_paginate_by_sql
assert_respond_to Developer, :paginate_by_sql
Developer.expects(:find_by_sql).with(regexp_matches(/sql LIMIT 3(,| OFFSET) 3/)).returns([])
Developer.expects(:count_by_sql).with('SELECT COUNT(*) FROM (sql) AS count_table').returns(0)

entries = Developer.paginate_by_sql 'sql', :page => 2, :per_page => 3
sql = "SELECT * FROM users WHERE type = 'Developer' ORDER BY id"
entries = Developer.paginate_by_sql(sql, :page => 2, :per_page => 3)
assert_equal 11, entries.total_entries
assert_equal [users(:dev_4), users(:dev_5), users(:dev_6)], entries
end

def test_paginate_by_sql_respects_total_entries_setting
Developer.expects(:find_by_sql).returns([])
Developer.expects(:count_by_sql).never

entries = Developer.paginate_by_sql 'sql', :page => 1, :total_entries => 999
sql = "SELECT * FROM users"
entries = Developer.paginate_by_sql(sql, :page => 1, :total_entries => 999)
assert_equal 999, entries.total_entries
end

Expand Down

0 comments on commit f5be4f6

Please sign in to comment.