aboutsummaryrefslogtreecommitdiffstats
path: root/spec/views/request/show.rhtml_spec.rb
blob: a22f29951b093634b195eb6ec4a5913756e42467 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__)

describe 'when viewing an information request' do 
    
    before do 
        @mock_body = mock_model(PublicBody, :name => 'test body',
                                            :url_name => 'test_body',
                                            :is_school? => false)
        @mock_user = mock_model(User, :name => 'test user',
                                      :url_name => 'test_user',
                                      :profile_photo => nil)
        @mock_request = mock_model(InfoRequest, :title => 'test request',
                                                :awaiting_description => false, 
                                                :law_used_with_a => 'A Freedom of Information request',
                                                :law_used_full => 'Freedom of Information',
                                                :public_body => @mock_body,
                                                :user => @mock_user, 
                                                :user_name => @mock_user.name, 
                                                :is_external? => false,
                                                :calculate_status => 'waiting_response', 
                                                :date_response_required_by => Date.today,
                                                :prominence => 'normal')
    end
    
    def request_page
        assigns[:info_request] = @mock_request
        assigns[:info_request_events] = []
        assigns[:status] = @mock_request.calculate_status
        template.stub!(:render_partial)
        render 'request/show'
    end
    
    it 'should show the sidebar' do 
        template.should_receive(:render_partial).with(:partial => 'sidebar', :locals => {})
        request_page
    end
    
    it 'should show the actions people can take' do
        template.should_receive(:render_partial).with(:partial => 'after_actions', :locals => {})
        request_page
    end
    
    describe 'when a status update has been requested' do 
        
        before do 
            assigns[:update_status] = true
        end
        
        it 'should show the first form for describing the state of the request' do
            request_page
            response.should have_tag("div.describe_state_form#describe_state_form_1")
        end    
        
    end
    
    describe 'when it is awaiting a description' do 
    
        before do 
            @mock_request.stub!(:awaiting_description).and_return(true)
        end
        
        it 'should show the first form for describing the state of the request' do
            request_page
            response.should have_tag("div.describe_state_form#describe_state_form_1")
        end
        
        it 'should show the second form for describing the state of the request' do 
            request_page
            response.should have_tag("div.describe_state_form#describe_state_form_2")
        end
    
    end
    
    describe 'when the user is the request owner' do 
    
        before do 
            assigns[:is_owning_user] = true
        end
        
        describe 'when the request status is "waiting clarification"' do 
    
            before do 
                @mock_request.stub!(:calculate_status).and_return('waiting_clarification')
            end
        
            describe 'when there is a last response' do 
            
                before do
                    @mock_response = mock_model(IncomingMessage)
                    @mock_request.stub!(:get_last_response).and_return(@mock_response)
                    @old_filters = ActionController::Routing::Routes.filters
                    ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
                end
                after do
                    ActionController::Routing::Routes.filters = @old_filters
                end

            
                it 'should show a link to follow up the last response with clarification' do 
                    request_page
                    expected_url = "/request/#{@mock_request.id}/response/#{@mock_response.id}#followup"
                    response.should have_tag("a[href=#{expected_url}]", :text => 'send a follow up message')
                end
            
            end
    
            describe 'when there is no last response' do
        
                before do 
                    @mock_request.stub!(:get_last_response).and_return(nil)
                    @old_filters = ActionController::Routing::Routes.filters
                    ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
                end
                after do
                    ActionController::Routing::Routes.filters = @old_filters
                end

            
                it 'should show a link to follow up the request without reference to a specific response' do 
                    request_page
                    expected_url = "/request/#{@mock_request.id}/response#followup"
                    response.should have_tag("a[href=#{expected_url}]", :text => 'send a follow up message')
                end
            end
        end
    
    end
end