Skip to content
Browse files

hit the database in `paginate_by_sql` tests

exposes the issue introduced in 6dc60a9
  • Loading branch information...
1 parent 5fb4061 commit f5be4f6926189596bc07ac21c5c863d07f886d5f @mislav mislav committed
Showing with 6 additions and 9 deletions.
  1. +6 −9 test/finder_test.rb
View
15 test/finder_test.rb
@@ -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

0 comments on commit f5be4f6

Please sign in to comment.
Something went wrong with that request. Please try again.