diff options
Diffstat (limited to 'spec/integration')
-rw-r--r-- | spec/integration/admin_spec.rb | 2 | ||||
-rw-r--r-- | spec/integration/errors_spec.rb | 159 | ||||
-rw-r--r-- | spec/integration/localisation_spec.rb | 88 | ||||
-rw-r--r-- | spec/integration/search_request_spec.rb | 6 | ||||
-rw-r--r-- | spec/integration/view_request_spec.rb | 7 |
5 files changed, 216 insertions, 46 deletions
diff --git a/spec/integration/admin_spec.rb b/spec/integration/admin_spec.rb index e148ea3ca..8a5e59ba2 100644 --- a/spec/integration/admin_spec.rb +++ b/spec/integration/admin_spec.rb @@ -13,7 +13,7 @@ describe "When administering the site" do # Now fetch the "log in as" link to log in as Bob get_via_redirect "/admin/user/login_as/#{users(:bob_smith_user).id}", nil, { - "Authorization" => "Basic " + Base64.encode64("#{Configuration::admin_username}:#{Configuration::admin_password}").strip + "Authorization" => "Basic " + Base64.encode64("#{AlaveteliConfiguration::admin_username}:#{AlaveteliConfiguration::admin_password}").strip } response.should be_success session[:user_id].should == users(:bob_smith_user).id diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb index a44ed7051..17a0153c2 100644 --- a/spec/integration/errors_spec.rb +++ b/spec/integration/errors_spec.rb @@ -1,53 +1,130 @@ +# -*- coding: utf-8 -*- 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 - ActionController::Base.consider_all_requests_local = false + def set_consider_all_requests_local(value) + @requests_local = Rails.application.config.consider_all_requests_local + Rails.application.config.consider_all_requests_local = value end - after(:each) do - ActionController::Base.consider_all_requests_local = true + def restore_consider_all_requests_local + Rails.application.config.consider_all_requests_local = @requests_local 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" + 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.body.should include("The page doesn't exist") - 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 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") + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + 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") + 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 + + 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 + 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 +end diff --git a/spec/integration/localisation_spec.rb b/spec/integration/localisation_spec.rb new file mode 100644 index 000000000..4f6b61ae1 --- /dev/null +++ b/spec/integration/localisation_spec.rb @@ -0,0 +1,88 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "when generating urls" do + + before do + @home_link_regex = /href=".*\/en\// + end + + it "should generate URLs that include the locale when using one that includes an underscore" do + get('/en_GB') + response.body.should match /href="\/en_GB\// + end + + it "should fall back to the language if the territory is unknown" do + AlaveteliLocalization.set_locales(available_locales='es en', default_locale='en') + get('/', {}, {'HTTP_ACCEPT_LANGUAGE' => 'en_US'}) + response.body.should match /href="\/en\// + response.body.should_not match /href="\/en_US\// + end + + it "should generate URLs without a locale prepended when there's only one locale set" do + AlaveteliLocalization.set_locales(available_locales='en', default_locale='en') + get('/') + response.should_not contain @home_link_regex + end + + it 'should redirect requests for a public body in a locale to the canonical name in that locale' do + get('/es/body/dfh') + response.should redirect_to "/es/body/edfh" + end + + it 'should remember a filter view when redirecting a public body request to the canonical name' do + get('/es/body/tgq/successful') + response.should redirect_to "/es/body/etgq/successful" + end + + describe 'when there is more than one locale' do + + before do + AlaveteliLocalization.set_locales(available_locales='es en', default_locale='en') + end + + it "should generate URLs with a locale prepended when there's more than one locale set" do + get('/') + response.body.should match @home_link_regex + end + + describe 'when using the default locale' do + + before do + @default_lang_home_link = /href=".*\/en\// + @other_lang_home_link = /href=".*\/es\// + @old_include_default_locale_in_urls = AlaveteliConfiguration::include_default_locale_in_urls + end + + describe 'when the config value INCLUDE_DEFAULT_LOCALE_IN_URLS is false' do + + before do + AlaveteliLocalization.set_default_locale_urls(false) + end + + it 'should generate URLs without a locale prepended' do + get '/' + response.should_not contain @default_lang_home_link + end + + it 'should render the front page in the default language when no locale param + is present and the session locale is not the default' do + get('/', {:locale => 'es'}) + response.should_not contain @other_lang_home_link + end + end + + it 'should generate URLs with a locale prepended when the config value + INCLUDE_DEFAULT_LOCALE_IN_URLS is true' do + AlaveteliLocalization.set_default_locale_urls(true) + get '/' + response.body.should match /#{@default_lang_home_link}/ + end + + after do + AlaveteliLocalization.set_default_locale_urls(@old_include_default_locale_in_urls) + end + + end + end + +end diff --git a/spec/integration/search_request_spec.rb b/spec/integration/search_request_spec.rb index c564032a6..23a62e97b 100644 --- a/spec/integration/search_request_spec.rb +++ b/spec/integration/search_request_spec.rb @@ -13,10 +13,8 @@ describe "When searching" do end it "should redirect requests with search in query string to URL-based page" do - url = '/search/all?query=bob' - request_via_redirect("post", url) - response.request.url.should_not include(url) - response.request.url.should include("/search/bob/all") + post '/search/all?query=bob' + response.should redirect_to "/en/search/bob/all" end it "should correctly execute simple search" do diff --git a/spec/integration/view_request_spec.rb b/spec/integration/view_request_spec.rb index 442721890..3d646cfe7 100644 --- a/spec/integration/view_request_spec.rb +++ b/spec/integration/view_request_spec.rb @@ -13,5 +13,12 @@ describe "When viewing requests" do response.body.should include("dog.json?unfold=1") end + it 'should not raise a routing error when making a json link for a request with an + "action" querystring param' do + @dog_request = info_requests(:fancy_dog_request) + get "request/#{@dog_request.url_title}?action=add" + response.should be_success + end + end |