diff options
-rw-r--r-- | app/models/info_request.rb | 9 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 10 |
2 files changed, 16 insertions, 3 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 78121f5ea..e570150bb 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1050,9 +1050,12 @@ public if !MySociety::Config.get('VARNISH_HOST').nil? && !self.id.nil? # we only do this for existing info_requests (new ones have a nil id) path = url_for(:controller => 'request', :action => 'show', :url_title => self.url_title, :only_path => true, :locale => :none) - req = PurgeRequest.new(:url => path, - :model => self.class.base_class.to_s, - :model_id => self.id) + req = PurgeRequest.find_by_url(path) + if req.nil? + req = PurgeRequest.new(:url => path, + :model => self.class.base_class.to_s, + :model_id => self.id) + end req.save() end end diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index c79ddab36..cfd11a2ca 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -166,6 +166,16 @@ describe RequestController, "when changing things that appear on the request pag ir.save! PurgeRequest.all().first.model_id.should == ir.id end + it "should not create more than one entry for any given resourcce" do + ir = info_requests(:fancy_dog_request) + ir.prominence = 'hidden' + ir.save! + PurgeRequest.all().count.should == 1 + ir = info_requests(:fancy_dog_request) + ir.prominence = 'hidden' + ir.save! + PurgeRequest.all().count.should == 1 + end end describe RequestController, "when showing one request" do |