|
57 | 57 |
|
58 | 58 | context 'POST create' do |
59 | 59 | context 'when the file does not exist yet' do |
| 60 | + let(:filename) { 'v1/x/y/test.txt' } |
| 61 | + let(:content) { 'This is a test file' } |
| 62 | + let(:mime_type) { 'text/plain' } |
| 63 | + |
60 | 64 | before do |
61 | | - post :create, params: { assignment_id: assignment.id, group_id: group.id, filename: 'v1/x/y/test.txt', |
62 | | - mime_type: 'text', file_content: 'This is a test file', course_id: course.id } |
| 65 | + post :create, params: { assignment_id: assignment.id, group_id: group.id, filename: filename, |
| 66 | + mime_type: mime_type, file_content: content, course_id: course.id } |
63 | 67 | end |
64 | 68 |
|
65 | | - it 'should create a file in the corresponding directory' do |
66 | | - path = Pathname.new('v1/x/y') |
67 | | - success, _messages = group.access_repo do |repo| |
68 | | - file_path = Pathname.new(assignment.repository_folder).join path |
69 | | - files = repo.get_latest_revision.files_at_path(file_path.to_s) |
70 | | - files.key? 'test.txt' |
| 69 | + context 'when the file is plaintext' do |
| 70 | + it 'should create the file in the corresponding directory' do |
| 71 | + path = Pathname.new('v1/x/y') |
| 72 | + success, _messages = group.access_repo do |repo| |
| 73 | + file_path = Pathname.new(assignment.repository_folder).join path |
| 74 | + files = repo.get_latest_revision.files_at_path(file_path.to_s) |
| 75 | + files.key? File.basename(filename) |
| 76 | + end |
| 77 | + expect(success).to be_truthy |
| 78 | + end |
| 79 | + end |
| 80 | + |
| 81 | + context 'when the file is binary' do |
| 82 | + let(:filename) { 'v1/x/y/test.pdf' } |
| 83 | + let(:content) { file_fixture('submission_files/pdf.pdf') } |
| 84 | + let(:mime_type) { 'application/pdf' } |
| 85 | + |
| 86 | + it 'should create the file in the corresponding directory' do |
| 87 | + path = Pathname.new('v1/x/y') |
| 88 | + success, _messages = group.access_repo do |repo| |
| 89 | + file_path = Pathname.new(assignment.repository_folder).join path |
| 90 | + files = repo.get_latest_revision.files_at_path(file_path.to_s) |
| 91 | + files.key? File.basename(filename) |
| 92 | + end |
| 93 | + expect(success).to be_truthy |
71 | 94 | end |
72 | | - expect(success).to be_truthy |
73 | 95 | end |
74 | 96 |
|
75 | 97 | it_behaves_like 'for a different course' |
|
0 commit comments