diff --git a/lib/fastly-rails.rb b/lib/fastly-rails.rb index a50c5c2..231ca8e 100644 --- a/lib/fastly-rails.rb +++ b/lib/fastly-rails.rb @@ -26,6 +26,10 @@ def self.purge_by_key(*args) client.purge_by_key(*args) if purging_enabled? end + def self.purge_by_url(url, soft = false) + client.purge(url, soft) if purging_enabled? + end + def self.client raise NoAPIKeyProvidedError unless configuration.authenticatable? diff --git a/test/fastly-rails_test.rb b/test/fastly-rails_test.rb index 9e9a4c0..b4bbb21 100644 --- a/test/fastly-rails_test.rb +++ b/test/fastly-rails_test.rb @@ -86,4 +86,36 @@ end end end + + describe 'purge_by_url' do + let(:client) { MiniTest::Mock.new } + let(:url) { "http://test.com" } + + it 'delegates to the client when purging is enabled' do + FastlyRails.stub(:client, client) do + FastlyRails.stub(:purging_enabled?, true) do + client.expect(:purge, nil, [url, false]) + FastlyRails.purge_by_url(url) + client.verify + end + end + end + + it 'allows soft purging' do + FastlyRails.stub(:client, client) do + FastlyRails.stub(:purging_enabled?, true) do + client.expect(:purge, nil, [url, true]) + FastlyRails.purge_by_url(url, true) + client.verify + end + end + end + + it 'does nothing when purging is disabled' do + configuration.purging_enabled = false + FastlyRails.stub(:client, client) do + FastlyRails.purge_by_url(url) + end + end + end end