Sha256: a45470ace6627876e3de952dacaa4d6b4033980012fea23c65ac038ed0e697a3

Contents?: true

Size: 1.52 KB

Versions: 6

Compression:

Stored size: 1.52 KB

Contents

require 'test_helper'

class FooBar < BaseDolly
  property :foo, :bar
  property :with_default, default: 1
  property :boolean, class_name: TrueClass, default: true
  property :date, class_name: Date
  property :time, class_name: Time
  property :datetime, class_name: DateTime
  property :is_nil, class_name: NilClass, default: nil

  timestamps!
end

class MangoIndexTest < Test::Unit::TestCase
  DB_BASE_PATH = "http://localhost:5984/test".freeze

  def setup
    stub_request(:get, index_base_path).
      to_return(body: { indexes:[ {
        ddoc: nil,
        name:"_all_docs",
        type:"special",
        def:{ fields:[{ _id:"asc" }] }
      },
      {
        ddoc: "_design/1",
        name:"foo-index-json",
        type:"json",
        def:{ fields:[{ foo:"asc" }] }
      }
    ]}.to_json)
  end

  test '#delete_all' do
    previous_indexes = Dolly::MangoIndex.all

    stub_request(:delete, index_delete_path(previous_indexes.last)).
      to_return(body: { "ok": true }.to_json)

    Dolly::MangoIndex.delete_all

    stub_request(:get, index_base_path).
      to_return(body: { indexes:[ {
        ddoc: nil,
        name:"_all_docs",
        type:"special",
        def:{ fields:[{ _id:"asc" }] }
      }
    ]}.to_json)

    new_indexes = Dolly::MangoIndex.all
    assert_not_equal(new_indexes.length, previous_indexes.length)
    assert_equal(new_indexes.length, 1)
  end

  def index_base_path
    "#{DB_BASE_PATH}/_index"
  end

  def index_delete_path(doc)
    "#{index_base_path}/#{doc[:ddoc]}/json/#{doc[:name]}"
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dolly-3.1.4 test/mango_index_test.rb
dolly-3.1.3 test/mango_index_test.rb
dolly-3.1.2 test/mango_index_test.rb
dolly-3.1.1 test/mango_index_test.rb
dolly-3.1.0 test/mango_index_test.rb
dolly-3.0.1 test/mango_index_test.rb