Sha256: abf617988951c87c073c9c783a5028808bd20c6ebb49665ac923f47ce73fc3a6

Contents?: true

Size: 1.82 KB

Versions: 7

Compression:

Stored size: 1.82 KB

Contents

require_relative "spec_helper"

describe "null_dataset extension" do
  before do
    @db = Sequel::mock(:fetch=>{:id=>1}, :autoid=>1, :numrows=>1, :columns=>[:id]).extension(:null_dataset)
    @ds = @db[:table].nullify
    @i = 0
    @pr = proc{|*a| @i += 1}
  end
  after do
    @db.sqls.must_equal [] unless @skip_check
  end

  it "should make each be a noop" do
    @ds.each(&@pr).must_be_same_as(@ds)
    @i.must_equal 0
  end

  it "should make fetch_rows be a noop" do
    @ds.fetch_rows("SELECT 1", &@pr).must_be_nil
    @i.must_equal 0
  end

  it "should make insert be a noop" do
    @ds.insert(1).must_be_nil
  end

  it "should make update be a noop" do
    @ds.update(:a=>1).must_equal 0
  end

  it "should make delete be a noop" do
    @ds.delete.must_equal 0
  end

  it "should make truncate be a noop" do
    @ds.truncate.must_be_nil
  end

  it "should make execute_* be a noop" do
    @ds.send(:execute_ddl,'FOO').must_be_nil
    @ds.send(:execute_insert,'FOO').must_be_nil
    @ds.send(:execute_dui,'FOO').must_be_nil
    @ds.send(:execute,'FOO').must_be_nil
  end

  it "should have working columns" do
    @skip_check = true
    2.times do
      @ds.columns.must_equal [:id]
    end
    @db.sqls.must_equal ['SELECT * FROM table LIMIT 1']
  end

  it "should have count return 0" do
    @ds.count.must_equal 0
  end

  it "should have empty return true" do
    @ds.empty?.must_equal true
  end

  it "should make import a noop" do
    @ds.import([:id], [[1], [2], [3]]).must_be_nil
  end

  it "should have nullify method returned modified receiver" do
    @skip_check = true
    ds = @db[:table]
    ds.nullify.wont_be_same_as(ds)
    ds.each(&@pr)
    @db.sqls.must_equal ['SELECT * FROM table']
    @i.must_equal 1
  end

  it "should work with method chaining" do
    @ds.where(:a=>1).select(:b).each(&@pr)
    @i.must_equal 0
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/sequel-5.3.0/spec/extensions/null_dataset_spec.rb
tdiary-5.0.7 vendor/bundle/gems/sequel-5.3.0/spec/extensions/null_dataset_spec.rb
sequel-5.3.0 spec/extensions/null_dataset_spec.rb
sequel-5.2.0 spec/extensions/null_dataset_spec.rb
sequel-5.1.0 spec/extensions/null_dataset_spec.rb
tdiary-5.0.6 vendor/bundle/gems/sequel-5.0.0/spec/extensions/null_dataset_spec.rb
sequel-5.0.0 spec/extensions/null_dataset_spec.rb