aboutsummaryrefslogtreecommitdiffstats
path: root/spec/views/request/_describe_state.rhtml_spec.rb
blob: 18778d5d281cd0efc36b20a7054775dd002a885b (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__)

describe 'when showing the form for describing the state of a request' do 
    
    def expect_radio_button(value)
        do_render
        response.should have_tag("input[type=radio][value=#{value}]")
    end
    
    def expect_no_radio_button(value)
        do_render
        response.should_not have_tag("input[type=radio][value=#{value}]")
    end

    def do_render
        render :partial => 'request/describe_state', :locals => {:id_suffix => '1'}
    end
    
    before do 
        @mock_user = mock_model(User, :name => 'test user', :url_name => 'test_user')
        @mock_request = mock_model(InfoRequest,
            :described_state => '',
            :user => @mock_user,
            :user_name => @mock_user.name, 
            :is_external? => false
        )
        assigns[:info_request] = @mock_request
    end
    
    describe 'if the user is a regular user (not the request owner)' do
        
        before do 
            assigns[:is_owning_user] = false
        end
        
        describe 'if the request is not old and unclassified' do 
            
            it 'should not show the form' do 
                do_render
                response.should_not have_tag('h2', :text => 'What best describes the status of this request now?')
            end
        
            it 'should give a link to login' do 
                do_render
                response.should have_tag('a', :text => 'sign in')
            end
            
        end
       
        describe 'if the request is old and unclassified' do 
            
            before do
                assigns[:old_unclassified] = true
            end
            
            it 'should not show the form' do 
                do_render
                response.should_not have_tag('h2', :text => 'What best describes the status of this request now?')
            end
            
            it 'should show the form for someone else to classify the request' do 
                do_render
                response.should have_tag('h2', :text => /We need your help/)
            end
            
            it 'should not give a link to login' do 
                do_render
                response.should_not have_tag('a', :text => 'sign in')
            end
        end
            
    end
    
    describe 'if showing the form to the user owning the request' do 
    
        before do 
            assigns[:is_owning_user] = true
        end
    
        describe 'when the request is not in internal review' do 
        
            before do 
                @mock_request.stub!(:described_state).and_return('waiting response')
            end    
    
            it 'should show a radio button to set the status to "waiting response"' do 
                expect_radio_button('waiting_response')
            end
        
            it 'should show a radio button to set the status to "waiting clarification"' do 
                expect_radio_button('waiting_clarification')
            end
            
            it 'should not show a radio button to set the status to "internal_review"' do 
                expect_no_radio_button('internal_review')
            end
        
        end
        
        describe 'when the user has asked to update the status of the request' do 
            
            before do 
                assigns[:update_status] = true
            end
            
            it 'should show a radio button to set the status to "internal_review"' do 
                expect_radio_button('internal_review')
            end

            it 'should show a radio button to set the status to "requires_admin"' do 
                expect_radio_button('requires_admin')
            end

            it 'should show a radio button to set the status to "user_withdrawn"' do 
                expect_radio_button('user_withdrawn')
            end
            
        end
    
        describe 'when the request is in internal review' do 

            before do 
                @mock_request.stub!(:described_state).and_return('internal_review')
            end
    
            it 'should show a radio button to set the status to "internal review"' do 
                expect_radio_button('internal_review')
            end
        
            it 'should show the text "The review has finished and overall:"' do 
                do_render
                response.should have_tag('p', :text => 'The review has finished and overall:')
            end
    
        end
        
        describe 'when request is awaiting a description and the user has not asked to update the status' do 
        end
    
        it 'should show a radio button to set the status to "gone postal"' do 
            expect_radio_button('gone_postal') 
        end
    
        it 'should show a radio button to set the status to "not held"' do 
            expect_radio_button('not_held') 
        end
    
        it 'should show a radio button to set the status to "partially successful"' do 
            expect_radio_button('partially_successful') 
        end
    
        it 'should show a radio button to set the status to "successful"' do 
            expect_radio_button('successful') 
        end
    
        it 'should show a radio button to set the status to "rejected"' do 
            expect_radio_button('rejected') 
        end
    
        it 'should show a radio button to set the status to "error_message"' do 
            expect_radio_button('error_message') 
        end
    
        it 'should not show a radio button to set the status to "requires_admin"' do 
            expect_no_radio_button('requires_admin') 
        end
        
        it 'should not show a radio button to set the status to "user_withdrawn"' do 
            expect_no_radio_button('user_withdrawn')
        end
        
    end
end