File: any_not_empty_spec.rb

package info (click to toggle)
ruby-sequel 5.63.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,408 kB
  • sloc: ruby: 113,747; makefile: 3
file content (23 lines) | stat: -rw-r--r-- 829 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require_relative "spec_helper"

describe "any_not_empty extension" do
  before do
    @ds = Sequel.mock[:t].extension(:any_not_empty)
  end

  it "should use a limited query if no block is given" do
    @ds.with_fetch(:one=>1).any?.must_equal true
    @ds.db.sqls.must_equal ["SELECT 1 AS one FROM t LIMIT 1"]
    @ds.with_fetch([]).any?.must_equal false
    @ds.db.sqls.must_equal ["SELECT 1 AS one FROM t LIMIT 1"]
  end

  it "should use default behavior if block is given" do
    @ds.with_fetch(:one=>1).any?{|x| x[:one] == 1}.must_equal true
    @ds.db.sqls.must_equal ["SELECT * FROM t"]
    @ds.with_fetch(:one=>1).any?{|x| x[:one] != 1}.must_equal false
    @ds.db.sqls.must_equal ["SELECT * FROM t"]
    @ds.with_fetch([]).any?{|x| x[:one] == 1}.must_equal false
    @ds.db.sqls.must_equal ["SELECT * FROM t"]
  end
end