Sha256: 20f82e158d9209faed08fe074113562d3a3f2778f689cd6e34ddf14aeb9c5398
Contents?: true
Size: 1.48 KB
Versions: 29
Compression:
Stored size: 1.48 KB
Contents
require "spec_helper" describe "Simple::SQL::Result counts" do let!(:users) { 1.upto(USER_COUNT).map { create(:user) } } let(:min_user_id) { SQL.ask "SELECT min(id) FROM users" } let(:scope) { SQL.scope("SELECT * FROM users") } let(:paginated_scope) { scope.paginate(per: 1, page: 1) } describe "exact counting" do it "counts" do result = SQL.all(paginated_scope) expect(result.total_count).to eq(USER_COUNT) expect(result.current_page).to eq(1) end end describe "fast counting" do it "counts fast" do result = SQL.all(paginated_scope) expect(result.total_count_estimate).to eq(USER_COUNT) expect(result.current_page).to eq(1) end end context 'when running with a non-paginated paginated_scope' do it "raises errors" do result = SQL.all(scope) expect { result.total_count }.to raise_error(RuntimeError) expect { result.current_page }.to raise_error(RuntimeError) expect { result.total_count_estimate }.to raise_error(RuntimeError) end end context 'when running with an empty, paginated paginated_scope' do let(:scope) { SQL.scope("SELECT * FROM users WHERE FALSE") } let(:paginated_scope) { scope.paginate(per: 1, page: 1) } it "returns correct results" do result = SQL.all(paginated_scope) expect(result.total_count).to eq(0) expect(result.total_count_estimate).to eq(0) expect(result.current_page).to eq(1) end end end
Version data entries
29 entries across 29 versions & 1 rubygems