Skip to content

Commit

Permalink
Merge remote-tracking branch 'tapalilov/worker_specs' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	core/app/workers/gaku/core/importers/students/roster_worker.rb
  • Loading branch information
Kagetsuki committed Jun 13, 2013
2 parents 15f8941 + 657dbeb commit 6235b06
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/app/controllers/gaku/students/importer_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def create
def import_roster(file)
if file.data_file.content_type == 'application/vnd.ms-excel' ||
file.data_file.content_type == 'application/vnd.oasis.opendocument.spreadsheet'
Gaku::Core::Importers::Students::Roster.import(file)
Gaku::Core::Importers::Students::RosterWorker.perform_async(file.id)
render text: "Importing"
else
redirect_to importer_index_path, alert: I18n.t('errors.messages.file_type_unsupported')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ module Importers
module Students
class RosterWorker
include Sidekiq::Worker
sidekiq_options retry: true, queue: 'roster_worker'

def perform(file)
if file.data_file
def perform(file_id)
file = Gaku::ImportFile.find file_id
if file
Gaku::Core::Importers::Students::Roster.new(file)
else
raise "NO FILE"
Expand Down
3 changes: 2 additions & 1 deletion core/lib/gaku/core/importers/students/roster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module Students
class Roster

def initialize(file)
@book = Roo::Spreadsheet.open(file.data_file.path)
open_file = File.open(file.data_file.path)
@book = Roo::Spreadsheet.open open_file
end

def start
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryGirl.define do
factory :import_file, :class => Gaku::ImportFile do
context 'students'
data_file File.open(Rails.root + "../support/sample_roster.xls")
end
end
7 changes: 5 additions & 2 deletions core/spec/workers/roster_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

it { should be_retryable true }

it 'opa' do
expect( subject.perform('opa') ).to have_enqueued_jobs(1)
it 'add new job to worker' do
file_f = create(:import_file)
worker = Gaku::Core::Importers::Students::RosterWorker
worker.perform_async(file_f.id)
expect(worker).to have(1).enqueued.jobs
end

end

0 comments on commit 6235b06

Please sign in to comment.