Skip to content

Commit

Permalink
edit PracticeResourcesController spec
Browse files Browse the repository at this point in the history
adds tests for additional file types
  • Loading branch information
PhilipDeFraties committed Nov 15, 2023
1 parent f6bfd4a commit 5db8c8b
Showing 1 changed file with 60 additions and 6 deletions.
66 changes: 60 additions & 6 deletions spec/requests/practice_resources_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,76 @@

RSpec.describe PracticeResourcesController, type: :controller do
describe 'GET #download' do
let(:practice_resource) { create(:practice_resource) } # Assumes a PracticeResource factory is defined

context 'when accessing the download action' do
let(:practice_resource) { create(:practice_resource) }
it 'redirects to a URL that includes the attachment path' do
get :download, params: { practice_id: practice_resource.practice.id, id: practice_resource.id }
get :download, params: {
practice_id: practice_resource.practice.id,
id: practice_resource.id,
resource_type: practice_resource.class.to_s
}

expect(response).to redirect_to(
/\/system\/practice_resources\/attachments\/.*\/original\/dummy.pdf\?.*/
)
end

it 'redirects for a PracticeProblemResource' do
problem_resource = create(:practice_problem_resource)
get :download, params: {
practice_id: problem_resource.practice.id,
id: problem_resource.id,
resource_type: problem_resource.class.to_s
}

expect(response).to redirect_to(
/\/system\/practice_problem_resources\/attachments\/.*\/original\/dummy.pdf\?.*/
)
end

expect(response).to redirect_to(/\/system\/practice_resources\/attachments\/.*\/original\/dummy.pdf\?.*/)
it 'redirects for a PracticeResultsResource' do
results_resource = create(:practice_results_resource)
get :download, params: {
practice_id: results_resource.practice.id,
id: results_resource.id,
resource_type: results_resource.class.to_s
}

expect(response).to redirect_to(
/\/system\/practice_results_resources\/attachments\/.*\/original\/dummy.pdf\?.*/
)
end

it 'redirects for a PracticeSolutionResource' do
solution_resource = create(:practice_solution_resource)
get :download, params: {
practice_id: solution_resource.practice.id,
id: solution_resource.id,
resource_type: solution_resource.class.to_s
}

expect(response).to redirect_to(
/\/system\/practice_solution_resources\/attachments\/.*\/original\/dummy.pdf\?.*/
)
end

it 'returns a 404 status if the practice is not found' do
get :download, params: { practice_id: 'nonexistent', id: practice_resource.id }
get :download, params: {
practice_id: 'nonexistent',
id: practice_resource.id,
resource_type: practice_resource.class.to_s
}

expect(response).to have_http_status(:not_found)
end

it 'returns a 404 status if the resource is not found' do
get :download, params: { practice_id: practice_resource.practice.id, id: 'nonexistent' }
get :download, params: {
practice_id: practice_resource.practice.id,
id: 'nonexistent',
resource_type: practice_resource.class.to_s
}

expect(response).to have_http_status(:not_found)
end
end
Expand Down

0 comments on commit 5db8c8b

Please sign in to comment.