Sha256: afbb1e0dc879b36e0008f5ea94cf6840c1232afc8cafce087c5f7aefb7dc7fe3

Contents?: true

Size: 894 Bytes

Versions: 30

Compression:

Stored size: 894 Bytes

Contents

require 'test_helper'

class Doc < Dolly::Document
  property :name
end

class BulkDocumentTest < ActiveSupport::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.doc['_id'] = "foo_bar/#{SecureRandom.uuid}"
      @doc << d
    end

    res = docs.map{|d| {ok: true, id: d.id, rev: "2-#{SecureRandom.uuid}"} }.to_json
    FakeWeb.register_uri :post, @req, body: res

    @doc.save

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

end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
dolly-1.1.7 test/bulk_document_test.rb
dolly-1.1.6 test/bulk_document_test.rb
dolly-1.1.5 test/bulk_document_test.rb
dolly-1.1.4 test/bulk_document_test.rb
dolly-1.1.3 test/bulk_document_test.rb
dolly-1.1.2 test/bulk_document_test.rb
dolly-1.1.1 test/bulk_document_test.rb
dolly-1.1.0 test/bulk_document_test.rb
dolly-1.0.1 test/bulk_document_test.rb
dolly-1.0.0 test/bulk_document_test.rb
dolly-0.9.0 test/bulk_document_test.rb
dolly-0.8.1 test/bulk_document_test.rb
dolly-0.8.0 test/bulk_document_test.rb
dolly-0.7.6 test/bulk_document_test.rb
dolly-0.7.5 test/bulk_document_test.rb
dolly-0.7.3 test/bulk_document_test.rb
dolly-0.7.2 test/bulk_document_test.rb
dolly-0.7.1 test/bulk_document_test.rb
dolly-0.7.0 test/bulk_document_test.rb
dolly-0.6.2 test/bulk_document_test.rb