File: split_array_nil_spec.rb

package info (click to toggle)
ruby-sequel 5.101.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,312 kB
  • sloc: ruby: 124,594; makefile: 3
file content (37 lines) | stat: -rw-r--r-- 1,555 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require_relative "spec_helper"

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

  it "should split IN with nil in array into separate OR IS NULL clause" do
    @ds.filter(:a=>[1, nil]).sql.must_equal "SELECT * FROM table WHERE ((a IN (1)) OR (a IS NULL))"
  end

  it "should split NOT IN with nil in array into separate AND IS NOT NULL clause" do
    @ds.exclude(:a=>[1, nil]).sql.must_equal "SELECT * FROM table WHERE ((a NOT IN (1)) AND (a IS NOT NULL))"
  end

  it "should not affect other IN/NOT in clauses with arrays" do
    @ds.filter(:a=>[1, 2]).sql.must_equal "SELECT * FROM table WHERE (a IN (1, 2))"
    @ds.exclude(:a=>[1, 2]).sql.must_equal "SELECT * FROM table WHERE (a NOT IN (1, 2))"
  end

  it "should split IN with nil in set into separate OR IS NULL clause" do
    @ds.filter(:a=>Set[1, nil]).sql.must_equal "SELECT * FROM table WHERE ((a IN (1)) OR (a IS NULL))"
  end

  it "should split NOT IN with nil in set into separate AND IS NOT NULL clause" do
    @ds.exclude(:a=>Set[1, nil]).sql.must_equal "SELECT * FROM table WHERE ((a NOT IN (1)) AND (a IS NOT NULL))"
  end

  it "should not affect other IN/NOT in clauses with sets" do
    @ds.filter(:a=>Set[1, 2]).sql.must_equal "SELECT * FROM table WHERE (a IN (1, 2))"
    @ds.exclude(:a=>Set[1, 2]).sql.must_equal "SELECT * FROM table WHERE (a NOT IN (1, 2))"
  end

  it "should not affect other types of filters clauses" do
    @ds.filter(:a=>1).sql.must_equal "SELECT * FROM table WHERE (a = 1)"
  end
end