aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/public_body_controller_spec.rb2
-rw-r--r--spec/models/info_request_spec.rb66
2 files changed, 67 insertions, 1 deletions
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 000d1cf80..87544b96a 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -233,7 +233,7 @@ describe PublicBodyController, "when showing public body statistics" do
graph['y_values'].should == [0, 50, 100, 100]
end
# Check that at least every confidence interval value is
- # numeric:
+ # a Float (rather than NilClass, say):
graph['cis_below'].each { |v| v.should be_instance_of(Float) }
graph['cis_above'].each { |v| v.should be_instance_of(Float) }
end
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 3451e018f..3f2e02189 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -857,4 +857,70 @@ describe InfoRequest do
end
end
end
+
+ describe 'when saving an info_request' do
+
+ before do
+ @info_request = InfoRequest.new(:external_url => 'http://www.example.com',
+ :external_user_name => 'Example User',
+ :title => 'Some request or other',
+ :public_body => public_bodies(:geraldine_public_body))
+ end
+
+ it "should call purge_in_cache and update_counter_cache" do
+ @info_request.should_receive(:purge_in_cache)
+ # Twice - once for save, once for destroy:
+ @info_request.should_receive(:update_counter_cache).twice
+ @info_request.save!
+ @info_request.destroy
+ end
+
+ end
+
+ describe 'when destroying an info_request' do
+
+ before do
+ @info_request = InfoRequest.new(:external_url => 'http://www.example.com',
+ :external_user_name => 'Example User',
+ :title => 'Some request or other',
+ :public_body => public_bodies(:geraldine_public_body))
+ end
+
+ it "should call update_counter_cache" do
+ @info_request.save!
+ @info_request.should_receive(:update_counter_cache)
+ @info_request.destroy
+ end
+
+ end
+
+ describe 'when changing a described_state' do
+
+ it "should change the counts on its PublicBody" do
+ pb = public_bodies(:geraldine_public_body)
+ 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',
+ :external_user_name => 'Example User',
+ :title => 'Some request or other',
+ :described_state => 'partially_successful',
+ :public_body => pb)
+ ir.save!
+ pb.info_requests_successful_count.should == (old_successful_count + 1)
+ ir.described_state = 'not_held'
+ ir.save!
+ 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.info_requests_successful_count.should == (old_successful_count + 1)
+ pb.info_requests_not_held_count.should == old_not_held_count
+ ir.destroy
+ pb.info_requests_successful_count.should == old_successful_count
+ pb.info_requests_successful_count.should == old_not_held_count
+ end
+
+ end
+
+
end