Sha256: e09ea58a5137133e28f4382f245249cf5696e7f99f53427de0b09eaacfd6c12d

Contents?: true

Size: 973 Bytes

Versions: 8

Compression:

Stored size: 973 Bytes

Contents

require 'test_helper'

class Doc < Dolly::Document
  property :name
end

class BulkDocumentTest < Test::Unit::TestCase
  setup do
    @doc = Dolly::Document.bulk_document
    @req = "http://localhost:5984/test/_bulk_docs"
  end

  teardown do
    @doc.clear
  end

  test 'bulk document intialize with empty payload' do
    assert_equal [], @doc.docs
  end

  test 'adding document to bulk_doc' do
    d = Doc.new
    @doc << d
    assert @doc.docs.include?(d)
  end

  test 'save document will remove docs from payload' do
    docs = 3.times.map{ Doc.new name: "a" }
    docs.each do |d|
      d.id = "doc/#{SecureRandom.uuid}"
      @doc << d
    end

    res = docs.map{|d| {ok: true, id: d.id, rev: "2-#{SecureRandom.uuid}"} }.to_json

    stub_request(:post, @req).
      to_return(body: res)

    assert_equal docs, @doc.payload[:docs]

    @doc.save

    assert_equal [], @doc.errors
    assert_equal [], @doc.docs
    assert_equal [], @doc.payload[:docs]
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dolly-3.1.5 test/bulk_document_test.rb
dolly-3.1.4 test/bulk_document_test.rb
dolly-3.1.3 test/bulk_document_test.rb
dolly-3.1.2 test/bulk_document_test.rb
dolly-3.1.1 test/bulk_document_test.rb
dolly-3.1.0 test/bulk_document_test.rb
dolly-3.0.1 test/bulk_document_test.rb
dolly-3.0.0 test/bulk_document_test.rb