spec/processor_spec.rb in pupa-0.0.13 vs spec/processor_spec.rb in pupa-0.1.0
- old
+ new
@@ -9,11 +9,11 @@
def make_person_valid
@person = Pupa::Person.new(name: 'foo')
end
def make_person_invalid
- @person = Pupa::Person.new
+ @person = Pupa::Person.new(name: ['foo'])
end
def scrape_people
dispatch(person)
end
@@ -26,15 +26,15 @@
let :io do
StringIO.new
end
let :processor do
- PersonProcessor.new('/tmp', level: 'WARN', logdev: io)
+ PersonProcessor.new('/tmp', database_url: 'mongodb://localhost:27017/pupa_test', level: 'WARN', logdev: io)
end
let :novalidate do
- PersonProcessor.new('/tmp', level: 'WARN', logdev: io, validate: false)
+ PersonProcessor.new('/tmp', database_url: 'mongodb://localhost:27017/pupa_test', level: 'WARN', logdev: io, validate: false)
end
describe '#get' do
it 'should send a GET request' do
processor.get('http://httpbin.org/get', 'foo=bar')['args'].should == {'foo' => 'bar'}
@@ -96,12 +96,11 @@
end
end
describe '#import' do
before :each do
- Pupa.session = Moped::Session.new(['localhost:27017'], database: 'pupa_test')
- Pupa.session.collections.each(&:drop)
+ processor.connection.raw_connection[:organizations].drop
end
let :_type do
if testing_python_compatibility?
'organization'
@@ -174,11 +173,11 @@
it 'should remove duplicate objects and re-assign foreign keys' do
processor.should_receive(:load_scraped_objects).and_return(graphable)
processor.import
- documents = Pupa.session[:organizations].find.entries
+ documents = processor.connection.raw_connection[:organizations].find.entries
documents.size.should == 2
documents[0].slice('_id', '_type', 'name', 'parent_id').should == {'_id' => '2', '_type' => _type, 'name' => 'Parent'}
documents[1].slice('_id', '_type', 'name', 'parent_id').should == {'_id' => '1', '_type' => _type, 'name' => 'Child', 'parent_id' => '2'}
end
@@ -191,21 +190,21 @@
it 'should remove duplicate objects and resolve foreign objects' do
processor.should_receive(:load_scraped_objects).and_return(ungraphable)
processor.import
- documents = Pupa.session[:organizations].find.entries
+ documents = processor.connection.raw_connection[:organizations].find.entries
documents.size.should == 2
documents[0].slice('_id', '_type', 'name', 'parent_id').should == {'_id' => '5', '_type' => _type, 'name' => 'Parent'}
documents[1].slice('_id', '_type', 'name', 'parent_id').should == {'_id' => '4', '_type' => _type, 'name' => 'Child', 'parent_id' => '5'}
end
it 'should resolve foreign keys on foreign objects' do
processor.should_receive(:load_scraped_objects).and_return(foreign_keys_on_foreign_objects)
processor.import
- documents = Pupa.session[:organizations].find.entries
+ documents = processor.connection.raw_connection[:organizations].find.entries
documents.size.should == 3
documents[0].slice('_id', '_type', 'name', 'parent_id').should == {'_id' => '9', '_type' => _type, 'name' => 'Parent'}
documents[1].slice('_id', '_type', 'name', 'parent_id').should == {'_id' => '7', '_type' => _type, 'name' => 'Child', 'parent_id' => '9'}
documents[2].slice('_id', '_type', 'name', 'parent_id').should == {'_id' => '8', '_type' => _type, 'name' => 'Grandchild', 'parent_id' => '7'}
end
@@ -313,11 +312,11 @@
it 'should resolve foreign keys' do
processor.should_receive(:load_scraped_objects).and_return(resolvable_foreign_key)
processor.import
- documents = Pupa.session[:organizations].find.entries
+ documents = processor.connection.raw_connection[:organizations].find.entries
documents.size.should == 2
documents[0].slice('_id', '_type', 'name', 'parent_id').should == {'_id' => '2', '_type' => _type, 'name' => 'Parent'}
documents[1].slice('_id', '_type', 'name', 'parent_id').should == {'_id' => '1', '_type' => _type, 'name' => 'Child', 'parent_id' => '2'}
end
@@ -338,10 +337,10 @@
it 'should resolve foreign keys on foreign objects' do
processor.should_receive(:load_scraped_objects).and_return(resolvable_foreign_keys_on_foreign_objects)
processor.import
- documents = Pupa.session[:organizations].find.entries
+ documents = processor.connection.raw_connection[:organizations].find.entries
documents.size.should == 3
documents[0].slice('_id', '_type', 'name', 'parent_id').should == {'_id' => '2', '_type' => _type, 'name' => 'Parent'}
documents[1].slice('_id', '_type', 'name', 'parent_id').should == {'_id' => '1', '_type' => _type, 'name' => 'Child', 'parent_id' => '2'}
documents[2].slice('_id', '_type', 'name', 'parent_id').should == {'_id' => 'b', '_type' => _type, 'name' => 'Grandchild', 'parent_id' => '1'}
end