File: inverted_subsets_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 (33 lines) | stat: -rw-r--r-- 1,319 bytes parent folder | download | duplicates (4)
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
require_relative "spec_helper"

describe "Sequel::Plugins::InvertedSubsets" do
  it "should add an inverted subset method which inverts the condition" do
    c = Class.new(Sequel::Model(:a))
    c.plugin :inverted_subsets
    c.dataset_module{subset(:published, :published => true)}
    c.not_published.sql.must_equal 'SELECT * FROM a WHERE (published IS NOT TRUE)'
  end

  it "should support a configuration block to customise the inverted method name" do
    c = Class.new(Sequel::Model(:a))
    c.plugin(:inverted_subsets){|name| "exclude_#{name}"}
    c.dataset_module{where(:published, :published => true)}
    c.exclude_published.sql.must_equal 'SELECT * FROM a WHERE (published IS NOT TRUE)'
  end

  it "should chain to existing dataset" do
    c = Class.new(Sequel::Model(:a))
    c.plugin :inverted_subsets
    c.dataset_module{where(:published, :published => true)}
    c.where(1=>0).not_published.sql.must_equal 'SELECT * FROM a WHERE ((1 = 0) AND (published IS NOT TRUE))'
  end

  it "should work in subclasses" do
    c = Class.new(Sequel::Model)
    c.plugin(:inverted_subsets){|name| "exclude_#{name}"}
    c = Class.new(c)
    c.dataset = :a
    c.dataset_module{subset(:published, :published => true)}
    c.exclude_published.sql.must_equal 'SELECT * FROM a WHERE (published IS NOT TRUE)'
  end
end