From ea03685aa9d09d7cd29e0ef875d3afa7758b29ea Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Thu, 31 Jan 2013 13:23:19 +1100 Subject: There's really no need to test the internals of Rails --- spec/integration/errors_spec.rb | 9 --------- 1 file changed, 9 deletions(-) (limited to 'spec/integration/errors_spec.rb') diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb index a44ed7051..0e3157ca8 100644 --- a/spec/integration/errors_spec.rb +++ b/spec/integration/errors_spec.rb @@ -4,26 +4,18 @@ describe "When rendering errors" do before(:each) do load_raw_emails_data - ActionController::Base.consider_all_requests_local = false - end - - after(:each) do - ActionController::Base.consider_all_requests_local = true end it "should render a 404 for unrouteable URLs" do get("/frobsnasm") - response.body.should include("The page doesn't exist") response.code.should == "404" end it "should render a 404 for users that don't exist" do get("/user/wobsnasm") - response.body.should include("The page doesn't exist") response.code.should == "404" end it "should render a 404 for bodies that don't exist" do get("/body/wobsnasm") - response.body.should include("The page doesn't exist") response.code.should == "404" end it "should render a 500 for general errors" do @@ -46,7 +38,6 @@ describe "When rendering errors" do end it "should render a 404 for non-existent 'details' pages for requests" do get("/details/request/wobble" ) - response.body.should include("The page doesn't exist") response.code.should == "404" end end -- cgit v1.2.3 From 905c9495a9005d71488e1737ebc28f697b8a9f2e Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 19 Mar 2013 05:59:10 +1100 Subject: Remove test of rails internals that is somehow interfering with other tests --- spec/integration/errors_spec.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'spec/integration/errors_spec.rb') diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb index 0e3157ca8..edf570182 100644 --- a/spec/integration/errors_spec.rb +++ b/spec/integration/errors_spec.rb @@ -6,10 +6,6 @@ describe "When rendering errors" do load_raw_emails_data end - it "should render a 404 for unrouteable URLs" do - get("/frobsnasm") - response.code.should == "404" - end it "should render a 404 for users that don't exist" do get("/user/wobsnasm") response.code.should == "404" -- cgit v1.2.3 From 2b1ec0102078aef523736eb1b24311e458a403a0 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Wed, 1 May 2013 16:27:23 +0100 Subject: Rewrite specs to more clearly represent expected behaviour - exceptions and 404s on non-local requests are to be rendered with our custom template (such that this template can be overriden by themes in the usual way). Note that requests to the admin interface are considered local. --- spec/integration/errors_spec.rb | 123 ++++++++++++++++++++++++++++++---------- 1 file changed, 94 insertions(+), 29 deletions(-) (limited to 'spec/integration/errors_spec.rb') diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb index edf570182..6069a69b8 100644 --- a/spec/integration/errors_spec.rb +++ b/spec/integration/errors_spec.rb @@ -1,40 +1,105 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -describe "When rendering errors" do +describe "When errors occur" do - before(:each) do - load_raw_emails_data + def set_consider_all_requests_local(value) + # Reload application controller so it picks up new config value + @requests_local = Rails.application.config.consider_all_requests_local + Rails.application.config.consider_all_requests_local = value + load 'application_controller.rb' end - it "should render a 404 for users that don't exist" do - get("/user/wobsnasm") - response.code.should == "404" + def restore_consider_all_requests_local + Rails.application.config.consider_all_requests_local = @requests_local + load "application_controller.rb" end - it "should render a 404 for bodies that don't exist" do - get("/body/wobsnasm") - response.code.should == "404" + + before(:each) do + # This should happen automatically before each test but doesn't with these integration + # tests for some reason. + ActionMailer::Base.deliveries = [] end - it "should render a 500 for general errors" do - ir = info_requests(:naughty_chicken_request) - # Set an invalid state for the request. Note that update_attribute doesn't run the validations - ir.update_attribute(:described_state, "crotchety") - get("/request/#{ir.url_title}") - response.code.should == "500" + + after(:each) do + restore_consider_all_requests_local end - it "should render a 403 for attempts at directory listing for attachments" do - # make a fake cache - foi_cache_path = File.expand_path(File.join(File.dirname(__FILE__), '../../cache')) - FileUtils.mkdir_p(File.join(foi_cache_path, "views/en/request/101/101/response/1/attach/html/1")) - get("/request/101/response/1/attach/html/1/" ) - response.body.should include("Directory listing not allowed") - response.code.should == "403" - get("/request/101/response/1/attach/html" ) - response.body.should include("Directory listing not allowed") - response.code.should == "403" + + context 'when considering all requests local (by default all in development)' do + + before(:each) { set_consider_all_requests_local(true) } + + it 'should show a full trace for general errors' do + InfoRequest.stub!(:find_by_url_title!).and_raise("An example error") + get("/request/example") + response.body.should have_selector('div[id=traces]') + response.body.should match('An example error') + end + end - it "should render a 404 for non-existent 'details' pages for requests" do - get("/details/request/wobble" ) - response.code.should == "404" + + context 'when not considering all requests local' do + + before(:each) { set_consider_all_requests_local(false) } + + it "should render a 404 for unrouteable URLs using the general/exception_caught template" do + get("/frobsnasm") + response.should render_template('general/exception_caught') + response.code.should == "404" + end + + it "should render a 404 for users or bodies that don't exist using the general/exception_caught + template" do + ['/user/wobsnasm', '/body/wobsnasm'].each do |non_existent_url| + get(non_existent_url) + response.should render_template('general/exception_caught') + response.code.should == "404" + end + end + + it "should render a 500 for general errors using the general/exception_caught template" do + InfoRequest.stub!(:find_by_url_title!).and_raise("An example error") + get("/request/example") + response.should render_template('general/exception_caught') + response.body.should match('An example error') + response.code.should == "500" + end + + it 'should notify of a general error' do + InfoRequest.stub!(:find_by_url_title!).and_raise("An example error") + get("/request/example") + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.body.should =~ /An example error/ + end + + it 'should assign the locale for the general/exception_caught template' do + InfoRequest.stub!(:find_by_url_title!).and_raise("An example error") + get("/es/request/example") + response.should render_template('general/exception_caught') + response.body.should match('Lo sentimos, hubo un problema procesando esta página') + response.body.should match('An example error') + end + + it "should render a 403 with text body for attempts at directory listing for attachments" do + # make a fake cache + foi_cache_path = File.expand_path(File.join(File.dirname(__FILE__), '../../cache')) + FileUtils.mkdir_p(File.join(foi_cache_path, "views/en/request/101/101/response/1/attach/html/1")) + get("/request/101/response/1/attach/html/1/" ) + response.body.should include("Directory listing not allowed") + response.code.should == "403" + get("/request/101/response/1/attach/html" ) + response.body.should include("Directory listing not allowed") + response.code.should == "403" + end + + context "in the admin interface" do + it 'should show a full trace for general errors' do + InfoRequest.stub!(:find).and_raise("An example error") + get("/admin/request/show/333") + response.body.should have_selector('div[id=traces]') + response.body.should match('An example error') + end + end end end - -- cgit v1.2.3 From 6acce073443fbd700f346b1bf99ee72be3e4f387 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 2 May 2013 10:23:26 +0100 Subject: Clearer setting of status code, addition of notification. --- spec/integration/errors_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'spec/integration/errors_spec.rb') diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb index 6069a69b8..ccf3c4379 100644 --- a/spec/integration/errors_spec.rb +++ b/spec/integration/errors_spec.rb @@ -3,15 +3,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "When errors occur" do def set_consider_all_requests_local(value) - # Reload application controller so it picks up new config value @requests_local = Rails.application.config.consider_all_requests_local Rails.application.config.consider_all_requests_local = value - load 'application_controller.rb' end def restore_consider_all_requests_local Rails.application.config.consider_all_requests_local = @requests_local - load "application_controller.rb" end before(:each) do @@ -56,6 +53,7 @@ describe "When errors occur" do end end + it "should render a 500 for general errors using the general/exception_caught template" do InfoRequest.stub!(:find_by_url_title!).and_raise("An example error") get("/request/example") @@ -94,12 +92,16 @@ describe "When errors occur" do end context "in the admin interface" do + it 'should show a full trace for general errors' do InfoRequest.stub!(:find).and_raise("An example error") get("/admin/request/show/333") response.body.should have_selector('div[id=traces]') response.body.should match('An example error') end + end + end + end -- cgit v1.2.3 From c35b3973726e338857695ab371749db14f4aa5fb Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 2 May 2013 15:16:42 +0100 Subject: Add logging of any errors. --- spec/integration/errors_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'spec/integration/errors_spec.rb') diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb index ccf3c4379..f85186b3d 100644 --- a/spec/integration/errors_spec.rb +++ b/spec/integration/errors_spec.rb @@ -53,7 +53,6 @@ describe "When errors occur" do end end - it "should render a 500 for general errors using the general/exception_caught template" do InfoRequest.stub!(:find_by_url_title!).and_raise("An example error") get("/request/example") @@ -71,6 +70,12 @@ describe "When errors occur" do mail.body.should =~ /An example error/ end + it 'should log a general error' do + Rails.logger.should_receive(:fatal) + InfoRequest.stub!(:find_by_url_title!).and_raise("An example error") + get("/request/example") + end + it 'should assign the locale for the general/exception_caught template' do InfoRequest.stub!(:find_by_url_title!).and_raise("An example error") get("/es/request/example") -- cgit v1.2.3 From 1b84df5e1392413822719ef1d4a716665357a2b3 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 2 May 2013 15:55:42 +0100 Subject: Add encoding line as we use utf-8 in the tests. --- spec/integration/errors_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/integration/errors_spec.rb') diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb index f85186b3d..ed0d7bfec 100644 --- a/spec/integration/errors_spec.rb +++ b/spec/integration/errors_spec.rb @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "When errors occur" do -- cgit v1.2.3 From 832da034a6855b94eb5eefd3b3dc4fb8fc9f78a6 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 3 Jun 2013 16:07:18 +0100 Subject: For non-HTML requests, just return the response code for now. --- spec/integration/errors_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'spec/integration/errors_spec.rb') diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb index ed0d7bfec..17a0153c2 100644 --- a/spec/integration/errors_spec.rb +++ b/spec/integration/errors_spec.rb @@ -62,6 +62,17 @@ describe "When errors occur" do response.code.should == "500" end + it 'should render a 500 for json errors' do + InfoRequest.stub!(:find_by_url_title!).and_raise("An example error") + get("/request/example.json") + response.code.should == '500' + end + + it 'should render a 404 for a non-found xml request' do + get("/frobsnasm.xml") + response.code.should == '404' + end + it 'should notify of a general error' do InfoRequest.stub!(:find_by_url_title!).and_raise("An example error") get("/request/example") @@ -97,6 +108,12 @@ describe "When errors occur" do response.code.should == "403" end + it "return a 403 for a JSON PermissionDenied error" do + InfoRequest.stub!(:find_by_url_title!).and_raise(ApplicationController::PermissionDenied) + get("/request/example.json") + response.code.should == '403' + end + context "in the admin interface" do it 'should show a full trace for general errors' do -- cgit v1.2.3