Skip to content

Commit

Permalink
Merge pull request #450 from commercekitchen/course_import_fixes
Browse files Browse the repository at this point in the history
Course import fixes
  • Loading branch information
tmichaelreis authored Apr 9, 2020
2 parents 7c1f197 + ba75692 commit 95acfe0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br /> 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
Expand Down
11 changes: 11 additions & 0 deletions app/services/course_import_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def import!
save_new_course!
copy_parent_lessons!
copy_topics!
copy_attachments!
end

@new_course
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/controllers/admin/dashboard_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br /> 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
Expand Down
13 changes: 10 additions & 3 deletions spec/services/course_import_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 95acfe0

Please sign in to comment.