spec/lib/batch_spec.rb in assimilate-0.0.1 vs spec/lib/batch_spec.rb in assimilate-0.0.2
- old
+ new
@@ -12,11 +12,11 @@
@catalog.catalog.remove
@catalog.batches.remove
end
def import_data(datestamp, filename = "batch_input.csv")
- @batcher = @catalog.start_batch(domain: 'testdata', datestamp: datestamp, idfield: 'ID')
+ @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|
@batcher << rec
end
@@ -30,12 +30,13 @@
end
it "should return correct import stats" do
@batcher.stats.should == {
:baseline_count => 0,
- :final_count => 5,
- :adds_count => 5,
+ :final_count => 6,
+ :adds_count => 6,
+ :new_ids => ["1", "2", "3", "4", "5", "6"],
:deletes_count => 0,
:updates_count => 0,
:unchanged_count => 0,
:updated_fields => {}
}
@@ -49,19 +50,24 @@
it "should refuse to do a duplicate import" do
lambda {import_data("123")}.should raise_error(Assimilate::DuplicateImportError)
end
+ it "should refuse to re-import same file" do
+ lambda {import_data("234")}.should raise_error(Assimilate::DuplicateImportError)
+ end
+
it "should do all no-ops when importing identical data" do
- lambda {import_data("234")}.should_not raise_error
+ lambda {import_data("234", "duplicate_input.csv")}.should_not raise_error
@batcher.stats.should == {
- :baseline_count => 5,
- :final_count => 5,
+ :baseline_count => 6,
+ :final_count => 6,
:adds_count => 0,
+ :new_ids => [],
:deletes_count => 0,
:updates_count => 0,
- :unchanged_count => 5,
+ :unchanged_count => 6,
:updated_fields => {}
}
@catalog.catalog.count.should == @records.count
end
end
@@ -76,13 +82,14 @@
import_data("345", "updates.csv")
end
it "should recognize changes" do
@batcher.stats.should == {
- :baseline_count => 5,
- :final_count => 6,
+ :baseline_count => 6,
+ :final_count => 7,
:adds_count => 1,
- :deletes_count => 1,
+ :new_ids => ["7"],
+ :deletes_count => 2,
:updates_count => 1,
:unchanged_count => 3,
:updated_fields => {'title' => 1}
}
@catalog.active_count.should == @records.count