aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin_censor_rule_controller_spec.rb2
-rw-r--r--spec/controllers/request_controller_spec.rb21
-rw-r--r--spec/models/purge_request_spec.rb32
-rw-r--r--spec/spec_helper.rb2
4 files changed, 42 insertions, 15 deletions
diff --git a/spec/controllers/admin_censor_rule_controller_spec.rb b/spec/controllers/admin_censor_rule_controller_spec.rb
index 952830f02..8893a858b 100644
--- a/spec/controllers/admin_censor_rule_controller_spec.rb
+++ b/spec/controllers/admin_censor_rule_controller_spec.rb
@@ -6,13 +6,13 @@ describe AdminCensorRuleController, "when making censor rules from the admin int
it "should create a censor rule and purge the corresponding request from varnish" do
ir = info_requests(:fancy_dog_request)
- ir.should_receive(:purge_in_cache)
post :create, :censor_rule => {
:text => "meat",
:replacement => "tofu",
:last_edit_comment => "none",
:info_request => ir
}
+ PurgeRequest.all().first.model_id.should == ir.id
end
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 89d165587..9090bc26f 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -121,55 +121,50 @@ describe RequestController, "when changing things that appear on the request pag
integrate_views
- before(:each) do
- FakeWeb.last_request = nil
- end
-
it "should purge the downstream cache when mail is received" do
ir = info_requests(:fancy_dog_request)
receive_incoming_mail('incoming-request-plain.email', ir.incoming_email)
- FakeWeb.last_request.path.should include(ir.url_title)
+ PurgeRequest.all().first.model_id.should == ir.id
end
it "should purge the downstream cache when a comment is added" do
ir = info_requests(:fancy_dog_request)
- ir.should_receive(:purge_in_cache)
new_comment = info_requests(:fancy_dog_request).add_comment('I also love making annotations.', users(:bob_smith_user))
+ PurgeRequest.all().first.model_id.should == ir.id
end
it "should purge the downstream cache when a followup is made" do
session[:user_id] = users(:bob_smith_user).id
ir = info_requests(:fancy_dog_request)
post :show_response, :outgoing_message => { :body => "What a useless response! You suck.", :what_doing => 'normal_sort' }, :id => ir.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_followup => 1
- FakeWeb.last_request.path.should include(ir.url_title)
+ PurgeRequest.all().first.model_id.should == ir.id
end
it "should purge the downstream cache when the request is categorised" do
ir = info_requests(:fancy_dog_request)
- ir.should_receive(:purge_in_cache)
ir.set_described_state('waiting_clarification')
+ PurgeRequest.all().first.model_id.should == ir.id
end
it "should purge the downstream cache when the authority data is changed" do
ir = info_requests(:fancy_dog_request)
ir.public_body.name = "Something new"
ir.public_body.save!
- FakeWeb.last_request.path.should include(ir.url_title)
+ PurgeRequest.all().map{|x| x.model_id}.should =~ ir.public_body.info_requests.map{|x| x.id}
end
it "should purge the downstream cache when the user details are changed" do
ir = info_requests(:fancy_dog_request)
ir.user.name = "Something new"
- FakeWeb.last_request.should == nil
ir.user.save!
- FakeWeb.last_request.path.should include(ir.url_title)
+ PurgeRequest.all().map{|x| x.model_id}.should =~ ir.user.info_requests.map{|x| x.id}
end
it "should purge the downstream cache when censor rules have changed" do
# XXX really, CensorRules should execute expiry logic as part
# of the after_save of the model. Currently this is part of
- # the AdminController logic, so must be tested from
+ # the AdminCensorRuleController logic, so must be tested from
# there. Leaving this stub test in place as a reminder
end
it "should purge the downstream cache when something is hidden by an admin" do
ir = info_requests(:fancy_dog_request)
- ir.should_receive(:purge_in_cache)
ir.prominence = 'hidden'
ir.save!
+ PurgeRequest.all().first.model_id.should == ir.id
end
end
diff --git a/spec/models/purge_request_spec.rb b/spec/models/purge_request_spec.rb
new file mode 100644
index 000000000..f7d01f784
--- /dev/null
+++ b/spec/models/purge_request_spec.rb
@@ -0,0 +1,32 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+require 'fakeweb'
+
+describe PurgeRequest, "purging things" do
+ before do
+ FakeWeb.last_request = nil
+ end
+
+ it 'should issue purge requests to the server' do
+ req = PurgeRequest.new(:url => "/begone_from_here",
+ :model => "don't care",
+ :model_id => "don't care")
+ req.save()
+ PurgeRequest.all().count.should == 1
+ PurgeRequest.purge_all()
+ PurgeRequest.all().count.should == 0
+ end
+
+ it 'should fail silently for a misconfigured server' do
+ FakeWeb.register_uri(:get, %r|brokenv|, :body => "BROKEN")
+ config = MySociety::Config.load_default()
+ config['VARNISH_HOST'] = "brokencache"
+ req = PurgeRequest.new(:url => "/begone_from_here",
+ :model => "don't care",
+ :model_id => "don't care")
+ req.save()
+ PurgeRequest.all().count.should == 1
+ PurgeRequest.purge_all()
+ PurgeRequest.all().count.should == 1
+ end
+end
+
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 5ca4b6de9..a98a5113d 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -15,7 +15,7 @@ config['REPLY_LATE_AFTER_DAYS'] = 20
# register a fake Varnish server
require 'fakeweb'
-FakeWeb.register_uri(:get, %r|varnish|, :body => "OK")
+FakeWeb.register_uri(:purge, %r|varnish.localdomain|, :body => "OK")
# Uncomment the next line to use webrat's matchers
#require 'webrat/integrations/rspec-rails'