Permalink
Browse files

finished Registration.process_import, which does the actual processin…

…g of registration data
  • Loading branch information...
1 parent 4179b9d commit 4e4e697a6c7dc646a5b3a877b365260374ace122 Kang Chen committed Nov 26, 2011
Showing with 49 additions and 14 deletions.
  1. +37 −5 app/models/registration.rb
  2. +12 −9 spec/models/registration_spec.rb
@@ -16,11 +16,43 @@ def self.scoped_by_params( params={} )
def self.process_import( courses_data )
result = {
- :success => 0,
- :failed => 0,
- :noop => 0,
- :failures => [],
- :noops => []
+ :success => 0,
+ :failed => 0,
+ :noop => 0,
+ :successes => [],
+ :failures => [],
+ :noops => []
}
+
+ courses_data.each do |imported_course|
+ course = Course.find_by_id(imported_course.number)
+
+ if course.nil?
+ result[:failed] += imported_course.students.size
+ result[:failures] << { imported_course.number => imported_course.students.map(&:user_id) }
+ else
+ imported_course.students.each do |imported_student|
+ student = Person.find_by_webiso_account(imported_student.user_id)
+ result_hash = { imported_course.number => imported_student.user_id }
+
+
+ if student.nil?
+ result[:failed] += 1
+ result[:failures] << result_hash
+ else
+ if course.students.include?(student)
+ result[:noop] += 1
+ result[:noops] << result_hash
+ else
+ result[:success] += 1
+ result[:successes] << result_hash
+ course.students << student
+ end
+ end
+ end
+ end
+ end
+
+ result
end
end
@@ -1,25 +1,28 @@
require 'spec_helper'
describe Registration do
+ let(:course) { HubStudentImporter::Course.new }
+
describe "#process_import" do
it "should succeed if given empty array" do
-
+ import_course_data = []
+ expect { Registration.process_import( import_course_data ) }.should_not raise_exception
end
it "should succeed with one course" do
-
- end
-
- it "should succeed with many courses" do
-
+ import_course_data = [course]
+ expect { Registration.process_import( import_course_data ) }.should_not raise_exception
end
- it "should process with duplicate courses" do
-
+ it "should process duplicate courses" do
+ import_course_data = [course] * 2
+ expect { Registration.process_import( import_course_data ) }.should_not raise_exception
end
it "should return relevant stats" do
-
+ import_course_data = [course] * 2
+ results = Registration.process_import( import_course_data )
+ results[:failures].size.should == 2
end
end
end

0 comments on commit 4e4e697

Please sign in to comment.