Sha256: d7107edda3c2981f240872ac2c447aca80da3041003fae87988e5b420777f238
Contents?: true
Size: 1.33 KB
Versions: 5
Compression:
Stored size: 1.33 KB
Contents
require File.join(File.dirname(File.expand_path(__FILE__)), "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
Version data entries
5 entries across 5 versions & 2 rubygems