aboutsummaryrefslogtreecommitdiffstats
path: root/spec/integration/errors_spec.rb
blob: a44ed7051c450256876c944745605d6e33d6a27f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

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
        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"
    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"
    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