Sha256: 5d809a89a3235aec42bd49e841a8cb028cf46baff9670a9fe678bced67b2cce0
Contents?: true
Size: 1.84 KB
Versions: 6
Compression:
Stored size: 1.84 KB
Contents
require 'spec_helper' module Hikki module Adapters describe MongoAdapter, :integration do context 'when actually using Mongo' do subject(:adapter) { MongoAdapter.new } let(:data) { { id: id, field1: 'test', field2: 123 } } let(:expected) { { 'id' => id, '_id' => id, 'field1' => 'test', 'field2' => 123 } } let(:id) { '1' } let(:collection) { 'collection1' } it 'can store and retreive data' do adapter.remove_all(collection) adapter.index(collection, :field1) adapter.save(collection, data) expect(adapter.find(collection, id)).to eq expected expect(adapter.find(collection, '2')).to eq Hash.new expect(adapter.all(collection)).to eq [expected] expect(adapter.find_by(collection, :field1, 'test')).to eq [expected] expect(adapter.find_by(collection, :field2, 123)).to eq [expected] expect(adapter.find_by(collection, :field1, 'foo')).to eq [] expect(adapter.find_by(collection, :field2, 1)).to eq [] adapter.remove(collection, id) expect(adapter.find(collection, id)).to eq Hash.new expect(adapter.all(collection)).to eq [] 10.times do |i| adapter.save(collection, { id: i, field1: "test-#{i%2}" }) end expect(adapter.all(collection, {limit: 2, offset: 6})).to eq [{'id' => '6', '_id' => '6', 'field1' => 'test-0'}, {'id' => '7', '_id' => '7', 'field1' => 'test-1'}] expect(adapter.find_by(collection, :field1, 'test-0', {limit: 2})).to eq [{'id' => '0', '_id' => '0', 'field1' => 'test-0'}, {'id' => '2', '_id' => '2', 'field1' => 'test-0'}] adapter.remove_all(collection) expect(adapter.find(collection, id)).to eq Hash.new expect(adapter.all(collection)).to eq [] end end end end end
Version data entries
6 entries across 6 versions & 2 rubygems