Sha256: c9a45bf6e4e3fb033d029ca09a8f39998c95ed5f59ef6bf415b201ef09d1786e

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")

describe "boolean_subsets plugin" do
  before do
    @db = Sequel::Database.new
    def @db.supports_schema_parsing?() true end
    def @db.schema(*args)
      [[:asdaf9898as, {}], [:active, {:type=>:boolean}]]
    end

    @c = Class.new(Sequel::Model(@db[:items]))
    @p = proc do
      @columns = [:asdaf9898as, :active]
      def columns; @columns; end
    end
    @c.instance_eval(&@p)
  end 

  it "should create subsets only for boolean attributes" do
    @c.plugin(:boolean_subsets)
    @c.active.sql.must_equal "SELECT * FROM items WHERE (active IS TRUE)"
    @c.respond_to?(:asdaf9898as).must_equal false
  end

  it "should handle a block passed to the plugin" do
    @c.plugin(:boolean_subsets){|c| ["where_#{c}", c]}
    @c.where_active.sql.must_equal "SELECT * FROM items WHERE active"
    @c.respond_to?(:active).must_equal false
  end

  it "should create boolean subsets when set_dataset is called" do
    c = Class.new(Sequel::Model(@db))
    c.instance_eval(&@p)
    c.plugin(:boolean_subsets)
    c.respond_to?(:active).must_equal false

    c.set_dataset(@db[:items])
    c.active.sql.must_equal "SELECT * FROM items WHERE (active IS TRUE)"
    c.respond_to?(:asdaf9898as).must_equal false
  end

  it "should handle cases where getting the columns raises an error" do
    @c.meta_def(:columns){raise Sequel::Error}
    @c.plugin(:boolean_subsets)
    @c.respond_to?(:active).must_equal false
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sequel-4.32.0 spec/extensions/boolean_subsets_spec.rb
sequel-4.31.0 spec/extensions/boolean_subsets_spec.rb
sequel-4.30.0 spec/extensions/boolean_subsets_spec.rb
sequel-4.29.0 spec/extensions/boolean_subsets_spec.rb
sequel-4.28.0 spec/extensions/boolean_subsets_spec.rb