docbrown/spec/services/edge_cache/bust_organization_spec.rb
Alex d109b6824e
Refactor cache purging (#12811)
* Refactor caching

* Bring back old bust class

* Refactor with PR feedback

* Remove useless return values
2021-03-02 10:09:05 -05:00

27 lines
843 B
Ruby

require "rails_helper"
RSpec.describe EdgeCache::BustOrganization, type: :service do
let(:organization) { create(:organization) }
let(:article) { create(:article, organization: organization) }
let(:slug) { "slug" }
let(:cache_bust) { instance_double(EdgeCache::Bust) }
before do
allow(EdgeCache::Bust).to receive(:new).and_return(cache_bust)
allow(cache_bust).to receive(:call)
end
it "busts the cache" do
described_class.call(organization, slug)
expect(cache_bust).to have_received(:call).with("/#{slug}").once
expect(cache_bust).to have_received(:call).with(article.path).once
end
it "logs an error" do
allow(cache_bust).to receive(:call).with("/5").once
allow(Rails.logger).to receive(:error)
described_class.call(4, 5)
expect(Rails.logger).to have_received(:error).once
end
end