Sha256: 33603ce84be708907f6b4ccc99c3acaf13b7df8c5ede445b9c062cb6edba01c5
Contents?: true
Size: 1.21 KB
Versions: 3
Compression:
Stored size: 1.21 KB
Contents
require 'spec_helper' describe Jamnagar::Storage::SourceStore do context 'Finding Sources' do before do @adapter = double(Jamnagar::Adapters::MongoAdapter, :store => 123) @sut = Jamnagar::Storage::SourceStore.new(@adapter) end context 'When the source exists' do before do @item = {"_id" => 2} @existing = {"_id" => 123, "contributions" => [1]} allow(@adapter).to receive(:find_first).and_return(@existing) end it 'should return the source' do expect(@sut.find_source({}, {"id" => 123})).to eq(@existing) end it 'should update contributions on the source' do expect(@adapter).to receive(:update).with({"_id" => 123}, {"$set" => {"contributions" => [1,2]}, "$inc" => {"contributions_count" => 1}}) @sut.find_source(@item, {"id" => 123}) end end context 'When the source does not exist' do it 'should insert and return the record' do allow(@adapter).to receive(:find_first).and_return(nil) expect(@adapter).to receive(:store).with(123, {"id" => 123, "_id" => 123, "contributions" => [42], "contributions_count" => 1}) @sut.find_source({"_id" => 42}, {"id" => 123}) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
jamnagar-1.3.9.1 | spec/source_store_spec.rb |
jamnagar-1.3.9 | spec/source_store_spec.rb |
jamnagar-1.3.8 | spec/source_store_spec.rb |