diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 81db709b..3e8d9a6c 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -43,7 +43,7 @@ def add_imported_course import_service = CourseImportService.new(organization: current_organization, course_id: params['course_id'].to_i) new_course = import_service.import! - success_message = 'Congrats! You have just imported a PLA course.
Please set your desired Course Category, Access Level and Publication Status.'.html_safe + success_message = 'Congrats! You have just imported a PLA course.' redirect_to edit_admin_course_path(new_course), notice: success_message rescue ActiveRecord::RecordInvalid => e diff --git a/app/services/course_import_service.rb b/app/services/course_import_service.rb index 904f2a72..3195a499 100644 --- a/app/services/course_import_service.rb +++ b/app/services/course_import_service.rb @@ -12,6 +12,7 @@ def import! save_new_course! copy_parent_lessons! copy_topics! + copy_attachments! end @new_course @@ -54,4 +55,14 @@ def copy_topics! new_topic.save! end end + + def copy_attachments! + # Create copies of the attachments + @parent_course.additional_resource_attachments.each do |attachment| + new_attachment = attachment.dup + new_attachment.document = attachment.document + new_attachment.course_id = @new_course.id + new_attachment.save! + end + end end diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb index d1d91d43..986493fd 100644 --- a/spec/controllers/admin/dashboard_controller_spec.rb +++ b/spec/controllers/admin/dashboard_controller_spec.rb @@ -89,7 +89,7 @@ it 'should assign correct flash' do post :add_imported_course, params: { course_id: importable_course1.id } - expect(flash[:notice]).to eq('Congrats! You have just imported a PLA course.
Please set your desired Course Category, Access Level and Publication Status.') + expect(flash[:notice]).to eq('Congrats! You have just imported a PLA course.') end it 'should create new subdomain course with new category with same name as imported course' do diff --git a/spec/services/course_import_service_spec.rb b/spec/services/course_import_service_spec.rb index b4d08f2f..5d03ddb5 100644 --- a/spec/services/course_import_service_spec.rb +++ b/spec/services/course_import_service_spec.rb @@ -9,7 +9,8 @@ let(:pla_course) { FactoryBot.create(:course_with_lessons, organization: pla, topics: [topic], category: category) } let(:document) { fixture_file_upload(Rails.root.join('spec', 'fixtures', 'testfile.pdf'), 'application/pdf') } - let!(:attachment) { FactoryBot.create(:attachment, document: document, course: pla_course) } + let!(:text_copy_attachment) { FactoryBot.create(:attachment, doc_type: 'text-copy', document: document, course: pla_course) } + let!(:additional_resource_attachment) { FactoryBot.create(:attachment, doc_type: 'additional-resource', document: document, course: pla_course) } let(:subsite) { FactoryBot.create(:organization) } @@ -45,10 +46,16 @@ end.to change { subsite.lessons.count }.by(3) end - it 'should not copy attachments' do + it 'should copy additional-content attachments' do expect do subject.import! - end.to_not change(Attachment, :count) + end.to change { Attachment.where(doc_type: 'additional-resource').count }.by(1) + end + + it 'should not copy text-copy attachments' do + expect do + subject.import! + end.to_not(change { Attachment.where(doc_type: 'text-copy').count }) end it 'should create new course topic' do