spec/lib/batch_spec.rb in assimilate-0.0.3 vs spec/lib/batch_spec.rb in assimilate-0.0.4
- old
+ new
@@ -14,12 +14,11 @@
end
def import_data(datestamp, filename = "batch_input.csv")
@batcher = @catalog.start_batch(domain: 'testdata', datestamp: datestamp, filename: filename, idfield: 'ID')
- @records = CSV.read(File.dirname(__FILE__) + "/../data/#{filename}", :headers => true)
- @records.each do |rec|
+ Assimilate.slurp(File.dirname(__FILE__) + "/../data/#{filename}") do |rec|
@batcher << rec
end
@batcher.commit
end
@@ -36,19 +35,19 @@
:adds_count => 6,
:new_ids => ["1", "2", "3", "4", "5", "6"],
:deletes_count => 0,
:deleted_ids => [],
:updates_count => 0,
+ :updated_ids => [],
:unchanged_count => 0,
:updated_fields => {}
}
end
it "should load the records verbatim" do
- @catalog.catalog.count.should == @records.count
- example = @records[rand(@records.count)]
- @catalog.where('_resource' => 'testdata', 'ID' => example['ID']).should == example.to_hash
+ @catalog.catalog.count.should == 6
+ @catalog.where('_resource' => 'testdata', 'ID' => '3').should == {'ID' => '3', 'name' => 'Benjamin Franklin', 'title' => 'Sage'}
end
it "should refuse to do a duplicate import" do
lambda {import_data("123")}.should raise_error(Assimilate::DuplicateImportError)
end
@@ -65,14 +64,15 @@
:adds_count => 0,
:new_ids => [],
:deletes_count => 0,
:deleted_ids => [],
:updates_count => 0,
+ :updated_ids => [],
:unchanged_count => 6,
:updated_fields => {}
}
- @catalog.catalog.count.should == @records.count
+ @catalog.catalog.count.should == 6
end
end
describe "into existing catalog" do
before(:all) do
@@ -91,12 +91,13 @@
:adds_count => 1,
:new_ids => ["7"],
:deletes_count => 2,
:deleted_ids => ['4', '6'],
:updates_count => 1,
+ :updated_ids => ['3'],
:unchanged_count => 3,
:updated_fields => {'title' => 1}
}
- @catalog.active_count.should == @records.count
+ @catalog.active_count.should == 5
end
end
end