require 'spec_helper' describe Jamnagar::Utilities::PopularityIncrementor do it 'should accept a store' do store = {} Jamnagar::Utilities::PopularityIncrementor.new(store) end it 'should increment the popularity of the original record' do store = double(Jamnagar::Storage::BasicStore, :find_and_modify => {}) sut = Jamnagar::Utilities::PopularityIncrementor.new(store) expect(store).to receive(:find_and_modify).with(:query => {"_id" => "123abc"}, :update => {"$inc" => {"popularity" => 1}}) sut.increment("123abc") end it 'should increment the popularity of the original record, based on id' do store = double(Jamnagar::Storage::BasicStore, :find_and_modify => {}) sut = Jamnagar::Utilities::PopularityIncrementor.new(store) expect(store).to receive(:find_and_modify).with(:query => {"_id" => "456efg"}, :update => {"$inc" => {"popularity" => 1}}) sut.increment("456efg") end end