diff --git a/app/models/dunlop/source_file_model.rb b/app/models/dunlop/source_file_model.rb index 2852b17..52edda6 100644 --- a/app/models/dunlop/source_file_model.rb +++ b/app/models/dunlop/source_file_model.rb @@ -34,7 +34,7 @@ module Dunlop::SourceFileModel event(:failed) { transition any => :failed } end - after_commit { autoload! } + after_commit(on: :create) { autoload! } self::Job = Class.new "#{name.deconstantize}::ApplicationJob".constantize do def perform(source_file_id) diff --git a/spec/dummy/app/jobs/application_job.rb b/spec/dummy/app/jobs/application_job.rb new file mode 100644 index 0000000..bddb5bc --- /dev/null +++ b/spec/dummy/app/jobs/application_job.rb @@ -0,0 +1,3 @@ +class ApplicationJob < ActiveJob::Base + +end diff --git a/spec/models/dunlop/source_file_model_spec.rb b/spec/models/dunlop/source_file_model_spec.rb index 87a5247..a6c0a37 100644 --- a/spec/models/dunlop/source_file_model_spec.rb +++ b/spec/models/dunlop/source_file_model_spec.rb @@ -4,6 +4,14 @@ describe SourceFile::MySource do subject { create('source_file/my_source', original_file: fixture_file("source_files/my_source_1.csv") ) } let(:model) { SourceRecord::MySource } + describe '#autoload!' do + it 'calls on create, not on update' do + expect_any_instance_of(described_class).to receive(:autoload!).once + subject # create + subject.update(state: 'loading') + subject.update(state: 'pending') + end + end describe "#first_line" do it "returns the first line" do subject.first_line(subject.original_file.path).should eq "my_date,my_var,My count,my_num,my_truth"