Sha256: ea4910719217df1d5cc9977a24b3e84c0b6ebb0819dd1f5b8c2c567b52354faf

Contents?: true

Size: 1.86 KB

Versions: 45

Compression:

Stored size: 1.86 KB

Contents

require_relative "spec_helper"

describe "subset_conditions plugin" do
  before do
    @c = Class.new(Sequel::Model(:a))
    @c.plugin :subset_conditions
  end

  it "should provide *_conditions method return the arguments passed" do
    @c.dataset_module{subset(:published, :published => true)}
    @c.where(@c.published_conditions).sql.must_equal @c.published.sql

    @c.dataset_module{where(:active, :active)}
    @c.where(@c.active_conditions).sql.must_equal @c.active.sql

    @c.dataset_module{subset(:active_published, Sequel.&(:active, :published => true))}
    @c.where(@c.active_published_conditions).sql.must_equal @c.active_published.sql
    @c.where(Sequel.&(@c.active_conditions, @c.published_conditions)).sql.must_equal @c.active_published.sql
    @c.where(Sequel.|(@c.active_conditions, @c.published_conditions)).sql.must_equal "SELECT * FROM a WHERE (active OR (published IS TRUE))"
    @c.where(Sequel.|(@c.active_published_conditions, :foo)).sql.must_equal "SELECT * FROM a WHERE ((active AND (published IS TRUE)) OR foo)"
  end

  it "should work with blocks" do
    p1 = proc{{:published=>true}}
    @c.dataset_module{subset(:published, &p1)}
    @c.where(@c.published_conditions).sql.must_equal @c.published.sql

    p2 = :active
    @c.dataset_module{subset(:active, p2)}
    @c.where(@c.active_conditions).sql.must_equal @c.active.sql

    @c.dataset_module{subset(:active_published, p2, &p1)}
    @c.where(@c.active_published_conditions).sql.must_equal @c.active_published.sql
    @c.where(Sequel.&(@c.active_conditions, @c.published_conditions)).sql.must_equal @c.active_published.sql
    @c.where(Sequel.|(@c.active_conditions, @c.published_conditions)).sql.must_equal "SELECT * FROM a WHERE (active OR (published IS TRUE))"
    @c.where(Sequel.|(@c.active_published_conditions, :foo)).sql.must_equal "SELECT * FROM a WHERE ((active AND (published IS TRUE)) OR foo)"
  end
end

Version data entries

45 entries across 41 versions & 2 rubygems

Version Path
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/sequel-5.26.0/spec/extensions/subset_conditions_spec.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/sequel-5.26.0/spec/extensions/subset_conditions_spec.rb
tdiary-5.1.1 vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/spec/extensions/subset_conditions_spec.rb
sequel-5.29.0 spec/extensions/subset_conditions_spec.rb
sequel-5.28.0 spec/extensions/subset_conditions_spec.rb
sequel-5.27.0 spec/extensions/subset_conditions_spec.rb
tdiary-5.1.0 vendor/bundle/gems/sequel-5.26.0/spec/extensions/subset_conditions_spec.rb
sequel-5.26.0 spec/extensions/subset_conditions_spec.rb
sequel-5.25.0 spec/extensions/subset_conditions_spec.rb
sequel-5.24.0 spec/extensions/subset_conditions_spec.rb
sequel-5.23.0 spec/extensions/subset_conditions_spec.rb
sequel-5.22.0 spec/extensions/subset_conditions_spec.rb
sequel-5.21.0 spec/extensions/subset_conditions_spec.rb
sequel-5.20.0 spec/extensions/subset_conditions_spec.rb
tdiary-5.0.13 vendor/bundle/gems/sequel-5.18.0/spec/extensions/subset_conditions_spec.rb
sequel-5.19.0 spec/extensions/subset_conditions_spec.rb
tdiary-5.0.12.1 vendor/bundle/gems/sequel-5.18.0/spec/extensions/subset_conditions_spec.rb
sequel-5.18.0 spec/extensions/subset_conditions_spec.rb
sequel-5.17.0 spec/extensions/subset_conditions_spec.rb
sequel-5.16.0 spec/extensions/subset_conditions_spec.rb