|
108 | 108 | let(:assignment) { create(:assignment_with_criteria_and_test_results) } |
109 | 109 |
|
110 | 110 | it 'responds with the appropriate status' do |
111 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'json' |
| 111 | + get_as user, :download_test_results, params: { |
| 112 | + course_id: user.course.id, |
| 113 | + id: assignment.id, |
| 114 | + latest: true, |
| 115 | + student_run: true, |
| 116 | + instructor_run: false |
| 117 | + }, format: 'json' |
112 | 118 | expect(response).to have_http_status :success |
113 | 119 | end |
114 | 120 |
|
115 | 121 | it 'responds with the appropriate header' do |
116 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'json' |
| 122 | + get_as user, :download_test_results, params: { |
| 123 | + course_id: user.course.id, |
| 124 | + id: assignment.id, |
| 125 | + latest: true, |
| 126 | + student_run: true, |
| 127 | + instructor_run: false |
| 128 | + }, format: 'json' |
117 | 129 | expect(response.header['Content-Type']).to eq('application/json') |
118 | 130 | end |
119 | 131 |
|
120 | 132 | it 'sets disposition as attachment' do |
121 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'json' |
| 133 | + get_as user, :download_test_results, params: { |
| 134 | + course_id: user.course.id, |
| 135 | + id: assignment.id, |
| 136 | + latest: true, |
| 137 | + student_run: true, |
| 138 | + instructor_run: false |
| 139 | + }, format: 'json' |
122 | 140 | d = response.header['Content-Disposition'].split.first |
123 | 141 | expect(d).to eq 'attachment;' |
124 | 142 | end |
125 | 143 |
|
126 | 144 | it 'responds with the appropriate filename' do |
127 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'json' |
| 145 | + get_as user, :download_test_results, params: { |
| 146 | + course_id: user.course.id, |
| 147 | + id: assignment.id, |
| 148 | + latest: true, |
| 149 | + student_run: true, |
| 150 | + instructor_run: false |
| 151 | + }, format: 'json' |
128 | 152 | filename = response.header['Content-Disposition'].split[1].split('"').second |
129 | 153 | expect(filename).to eq("#{assignment.short_identifier}_test_results.json") |
130 | 154 | end |
131 | 155 |
|
132 | 156 | it 'returns application/json type' do |
133 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'json' |
| 157 | + get_as user, :download_test_results, params: { |
| 158 | + course_id: user.course.id, |
| 159 | + id: assignment.id, |
| 160 | + latest: true, |
| 161 | + student_run: true, |
| 162 | + instructor_run: false |
| 163 | + }, format: 'json' |
134 | 164 | expect(response.media_type).to eq 'application/json' |
135 | 165 | end |
136 | 166 |
|
137 | 167 | it 'returns the most recent test results' do |
138 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'json' |
| 168 | + get_as user, :download_test_results, params: { |
| 169 | + course_id: user.course.id, |
| 170 | + id: assignment.id, |
| 171 | + latest: true, |
| 172 | + student_run: true, |
| 173 | + instructor_run: false |
| 174 | + }, format: 'json' |
139 | 175 | body = response.parsed_body |
140 | 176 |
|
141 | 177 | # We want to ensure that the test result's group name, test name and status exists |
|
156 | 192 | let(:assignment) { create(:assignment_with_criteria_and_test_results) } |
157 | 193 |
|
158 | 194 | it 'responds with the appropriate status' do |
159 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'csv' |
| 195 | + get_as user, :download_test_results, params: { |
| 196 | + course_id: user.course.id, |
| 197 | + id: assignment.id, |
| 198 | + latest: true, |
| 199 | + student_run: true, |
| 200 | + instructor_run: false |
| 201 | + }, format: 'csv' |
160 | 202 | expect(response).to have_http_status :success |
161 | 203 | end |
162 | 204 |
|
163 | 205 | it 'sets disposition as attachment' do |
164 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'csv' |
| 206 | + get_as user, :download_test_results, params: { |
| 207 | + course_id: user.course.id, |
| 208 | + id: assignment.id, |
| 209 | + latest: true, |
| 210 | + student_run: true, |
| 211 | + instructor_run: false |
| 212 | + }, format: 'csv' |
165 | 213 | d = response.header['Content-Disposition'].split.first |
166 | 214 | expect(d).to eq 'attachment;' |
167 | 215 | end |
168 | 216 |
|
169 | 217 | it 'responds with the appropriate filename' do |
170 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'csv' |
| 218 | + get_as user, :download_test_results, params: { |
| 219 | + course_id: user.course.id, |
| 220 | + id: assignment.id, |
| 221 | + latest: true, |
| 222 | + student_run: true, |
| 223 | + instructor_run: false |
| 224 | + }, format: 'csv' |
171 | 225 | filename = response.header['Content-Disposition'].split[1].split('"').second |
172 | 226 | expect(filename).to eq("#{assignment.short_identifier}_test_results.csv") |
173 | 227 | end |
174 | 228 |
|
175 | 229 | it 'returns text/csv type' do |
176 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'csv' |
| 230 | + get_as user, :download_test_results, params: { |
| 231 | + course_id: user.course.id, |
| 232 | + id: assignment.id, |
| 233 | + latest: true, |
| 234 | + student_run: true, |
| 235 | + instructor_run: false |
| 236 | + }, format: 'csv' |
177 | 237 | expect(response.media_type).to eq 'text/csv' |
178 | 238 | end |
179 | 239 |
|
180 | 240 | it 'returns the most recent test results of the correct size' do |
181 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'csv' |
| 241 | + get_as user, :download_test_results, params: { |
| 242 | + course_id: user.course.id, |
| 243 | + id: assignment.id, |
| 244 | + latest: true, |
| 245 | + student_run: true, |
| 246 | + instructor_run: false |
| 247 | + }, format: 'csv' |
182 | 248 |
|
183 | 249 | test_results = CSV.parse(response.body, headers: true) |
184 | 250 |
|
|
187 | 253 | end |
188 | 254 |
|
189 | 255 | it 'returns the correct csv headers' do |
190 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'csv' |
| 256 | + get_as user, :download_test_results, params: { |
| 257 | + course_id: user.course.id, |
| 258 | + id: assignment.id, |
| 259 | + latest: true, |
| 260 | + student_run: true, |
| 261 | + instructor_run: false |
| 262 | + }, format: 'csv' |
191 | 263 | test_results = CSV.parse(response.body, headers: true) |
192 | 264 |
|
193 | | - assignment_results = assignment.summary_test_results |
| 265 | + assignment_results = SummaryTestResultsHelper::SummaryTestResults.fetch( |
| 266 | + test_groups: assignment.test_groups, |
| 267 | + latest: true, |
| 268 | + student_run: true, |
| 269 | + instructor_run: false |
| 270 | + ).instance_variable_get(:@test_results) |
194 | 271 |
|
195 | 272 | headers = Set.new(test_results.headers.drop(1)).sort |
196 | 273 | assignment_results.each do |result| |
|
199 | 276 | end |
200 | 277 |
|
201 | 278 | it 'returns the correct csv headers in the correct order' do |
202 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'csv' |
| 279 | + get_as user, :download_test_results, params: { |
| 280 | + course_id: user.course.id, |
| 281 | + id: assignment.id, |
| 282 | + latest: true, |
| 283 | + student_run: true, |
| 284 | + instructor_run: false |
| 285 | + }, format: 'csv' |
203 | 286 | test_results = CSV.parse(response.body, headers: true) |
204 | 287 |
|
205 | 288 | headers = test_results.headers.drop(1) |
|
210 | 293 | end |
211 | 294 |
|
212 | 295 | it 'returns the correct amount of passed tests per group' do |
213 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'csv' |
| 296 | + get_as user, :download_test_results, params: { |
| 297 | + course_id: user.course.id, |
| 298 | + id: assignment.id, |
| 299 | + latest: true, |
| 300 | + student_run: true, |
| 301 | + instructor_run: false |
| 302 | + }, format: 'csv' |
214 | 303 | test_results = CSV.parse(response.body, headers: true).to_a.drop(1) |
215 | 304 | test_results.to_a.each do |row| |
216 | 305 | count = 0 |
|
230 | 319 | let(:csv_results) { CSV.parse(response.body, headers: true) } |
231 | 320 |
|
232 | 321 | before do |
233 | | - get_as user, :download_test_results, params: { course_id: user.course.id, id: assignment.id }, format: 'csv' |
| 322 | + get_as user, :download_test_results, params: { |
| 323 | + course_id: user.course.id, |
| 324 | + id: assignment.id, |
| 325 | + latest: true, |
| 326 | + student_run: true, |
| 327 | + instructor_run: false |
| 328 | + }, format: 'csv' |
234 | 329 | end |
235 | 330 |
|
236 | 331 | it 'returns the correct headers' do |
|
2351 | 2446 | expect(response).to redirect_to(edit_course_assignment_path(course.id, assignment.id)) |
2352 | 2447 | end |
2353 | 2448 | end |
| 2449 | + |
| 2450 | + describe '#download_test_results' do |
| 2451 | + let(:course) { assignment.course } |
| 2452 | + let(:assignment) { create(:assignment_with_criteria_and_test_results) } |
| 2453 | + let(:instructor) { create(:instructor) } |
| 2454 | + |
| 2455 | + context 'when latest is false and format is json' do |
| 2456 | + it 'should send a zip file' do |
| 2457 | + get_as instructor, :download_test_results, |
| 2458 | + params: { course_id: course.id, id: assignment.id, latest: 'false' }, |
| 2459 | + format: :json |
| 2460 | + |
| 2461 | + expect(response).to have_http_status(:ok) |
| 2462 | + expect(response.headers['Content-Type']).to eq('application/zip') |
| 2463 | + expect(response.headers['Content-Disposition']).to include('attachment') |
| 2464 | + expect(response.headers['Content-Disposition']).to include("#{assignment.short_identifier}_test_results.zip") |
| 2465 | + end |
| 2466 | + end |
| 2467 | + end |
2354 | 2468 | end |
0 commit comments