require 'spec_helper' describe Daengine::TeamsiteMetadataParser do before { Daengine.configure(:assets_path => Dir.pwd+'/spec/mock_data', :daengine_yml_file => Dir.pwd+'/spec/mock_data/daengine.yml', :digital_assets_file_directory => Dir.pwd + '/spec/mock_data/' ) } subject { Daengine::TeamsiteMetadataParser } context "#parse_tuple_file" do it 'reads xml' do # subject.logger= Logger.new(STDOUT) file = File.expand_path('./spec/mock_data/selective_new_package.xml') expect { subject.parse_tuple_file(open(file),'2011-09-04 11:59:47 -0600') }.to change(DigitalAsset, :count).by(2) entered = DigitalAsset.first entered.id.should == '163742d3-fbc2-4c99-8396-6eabe7464b8f' entered.path.should == '/digitalAssets/SSC_Developer_Installation_Guide-163742d3-fbc2-4c99-8396-6eabe7464b8f.doc' entered.summary.should == 'first foo bar...' entered.title.should == 'fake title' entered.size.should == '12 kB' entered.pages.should == 1 # DigitalAsset.first.documents.count.should eq(2) # returns the associated FINRA url entered.finra_path.should == "/digitalAssets/TEST_FINRA_DOC.doc" end it 'can read a whole bulk deploy xml file quickly' do # subject.logger= Logger.new(STDOUT) file = File.expand_path('./spec/mock_data/bulk-ssc_deploy.xml') open_file = open(file, 'rb') expect { subject.parse_tuple_file(open_file,'2011-09-04 11:59:47 -0600') }.to change(DigitalAsset, :count).by(6) end it "takes the most-recent-non-finra DOC as the content document" do end end # no longer have this use-case as we only allow a single doc in each package # context 'deleting paths' do # before do # file = File.expand_path('./spec/mock_data/selective_new_package.xml') # subject.parse_tuple_file(open(file),'2011-09-04 11:59:47 -0600') # end # it 'deletes paths that are no-longer in the tuples for a package' do # file = File.expand_path('./spec/mock_data/selective_path_delete_from_package.xml') # DigitalAsset.find('163742d3-fbc2-4c99-8396-6eabe7464b8f').documents.should have(2).items # expect { # subject.parse_tuple_file(open(file),'2011-09-04 11:59:47 -0600') # }.to change(DigitalAsset, :count).by(0) # DigitalAsset.find('163742d3-fbc2-4c99-8396-6eabe7464b8f').documents.should have(1).item # end # end context 'remove unpublished documents from mongo' do before do file = File.expand_path('./spec/mock_data/selective-ssc_2012_05_18_13_48_03_publish.xml') subject.parse_tuple_file(open(file),'2011-09-04 11:59:47 -0600') end it 'removes package records from mongo that are in unpublished state' do # DigitalAsset.find('11570991-9887-46df-8c47-d0870e6b5008').documents.should have(1).item file = File.expand_path('./spec/mock_data/selective-ssc_2012_05_18_13_56_18_unpublish.xml') expect { subject.parse_tuple_file(open(file),'2011-09-04 11:59:47 -0600') }.to change(DigitalAsset, :count).by(-1) end end end