aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/info_request.rb6
-rw-r--r--spec/controllers/request_controller_spec.rb2
-rw-r--r--spec/models/info_request_spec.rb7
3 files changed, 13 insertions, 2 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 91bd37d9f..c0b8e2fca 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -1128,12 +1128,18 @@ public
after_save :update_counter_cache
after_destroy :update_counter_cache
def update_counter_cache
+ PublicBody.skip_callback(:save, :after, :purge_in_cache)
self.public_body.info_requests_not_held_count = InfoRequest.where(
:public_body_id => self.public_body.id,
:described_state => 'not_held').count
self.public_body.info_requests_successful_count = InfoRequest.where(
:public_body_id => self.public_body.id,
:described_state => ['successful', 'partially_successful']).count
+ self.public_body.without_revision do
+ public_body.no_xapian_reindex = true
+ public_body.save
+ end
+ PublicBody.set_callback(:save, :after, :purge_in_cache)
end
def for_admin_column
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 2c605a139..9c4e16c67 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -174,7 +174,7 @@ 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
+ it "should not create more than one entry for any given resource" do
ir = info_requests(:fancy_dog_request)
ir.prominence = 'hidden'
ir.save!
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 3f2e02189..ab36a201c 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -896,8 +896,9 @@ describe InfoRequest do
describe 'when changing a described_state' do
- it "should change the counts on its PublicBody" do
+ it "should change the counts on its PublicBody without saving a new version" do
pb = public_bodies(:geraldine_public_body)
+ old_version_count = pb.versions.count
old_successful_count = pb.info_requests_successful_count
old_not_held_count = pb.info_requests_not_held_count
ir = InfoRequest.new(:external_url => 'http://www.example.com',
@@ -909,15 +910,19 @@ describe InfoRequest do
pb.info_requests_successful_count.should == (old_successful_count + 1)
ir.described_state = 'not_held'
ir.save!
+ pb.reload
pb.info_requests_successful_count.should == old_successful_count
pb.info_requests_not_held_count.should == (old_not_held_count + 1)
ir.described_state = 'successful'
ir.save!
+ pb.reload
pb.info_requests_successful_count.should == (old_successful_count + 1)
pb.info_requests_not_held_count.should == old_not_held_count
ir.destroy
+ pb.reload
pb.info_requests_successful_count.should == old_successful_count
pb.info_requests_successful_count.should == old_not_held_count
+ pb.versions.count.should == old_version_count
end
end