require 'spec_helper' # These tests require a fedora repository with the resource index enabled (and with syncUpdates = true) describe "Integration testing against a live Fedora repository" do REPOSITORY_CONFIG = { :url => 'http://localhost:8983/fedora', :user => 'fedoraAdmin', :password => 'fedoraAdmin' } before(:all) do @repository = Rubydora.connect REPOSITORY_CONFIG @repository.find('test:1').delete rescue nil @repository.find('test:2').delete rescue nil @repository.find('test:3').delete rescue nil end it "should connect" do @repository.ping.should == true end it "should create an object" do obj = @repository.find('test:1') obj.new?.should == true obj.save obj.new?.should == false end it "new should not return true until the profile is read" do obj = @repository.find('test:1') obj.save new_obj = Rubydora::DigitalObject.new('test:1', @repository) new_obj.new?.should == false end it "should have default datastreams" do obj = @repository.find('test:1') obj.datastreams.keys.should include("DC") end it "should list object models" do obj = @repository.find('test:1') obj.models.should include("info:fedora/fedora-system:FedoraObject-3.0") end it "should create another object" do obj = @repository.find('test:2') obj.save obj.new?.should == false end it "should create and update object labels" do obj = @repository.find('test:3') obj.label = 'asdf' obj.save obj = @repository.find('test:3') obj.label.should == 'asdf' obj.label = 'qwerty' obj.save obj = @repository.find('test:3') obj.label.should == 'qwerty' end it "should persist parts" do obj = @repository.find('test:1') end it "should create a managed datastream" do obj = @repository.find('test:1') obj.save ds = obj.datastreams["Test"] ds.content = open(__FILE__).read ds.mimeType = 'text/plain' ds.save end it "should create a redirect datastream" do obj = @repository.find('test:1') ds = obj.datastreams["Redirect"] ds.controlGroup = "R" ds.dsLocation = "http://example.org" ds.save end it "should have datastreams" do obj = @repository.find('test:1') obj.datastreams.keys.should include("Test") obj.datastreams.keys.should include("Redirect") end it "should have datastream content" do obj = @repository.find('test:1') obj.datastreams["Test"].content.should match( "Integration testing against a live Fedora repository") end it "should delete datastreams" do obj = @repository.find('test:1') ds = obj.datastreams["Test"].delete obj.datastreams.keys.should_not include("Test") end it "should save changed datastreams when the object is saved" do obj = @repository.find('test:1') obj.datastreams["new_ds"].content = "XXX" obj.datastreams["empty_ds"].new? obj.save obj.datastreams["new_ds"].new?.should == false obj.datastreams["empty_ds"].new?.should == true end it "should update datastream attributes without changing the content (or mime type)" do obj = @repository.find('test:1') obj.datastreams["my_ds"].content = "XXX" obj.datastreams["my_ds"].mimeType = "application/x-text" obj.save obj = @repository.find('test:1') obj.datastreams["my_ds"].dsLabel = "New Label" obj.save obj = @repository.find('test:1') obj.datastreams["my_ds"].content.should == "XXX" obj.datastreams["my_ds"].dsLabel.should == "New Label" obj.datastreams["my_ds"].mimeType.should == "application/x-text" end context "mime types" do before(:each) do obj = @repository.find('test:1') obj.datastreams["my_ds"].delete rescue nil end it "should default to application/octet-stream" do obj = @repository.find('test:1') obj.datastreams["my_ds"].content = "XXX" obj.save obj = @repository.find('test:1') obj.datastreams["my_ds"].mimeType.should == "application/octet-stream" end it "should allow the user to specify a mimetype" do obj = @repository.find('test:1') obj.datastreams["my_ds"].content = "XXX" obj.datastreams["my_ds"].mimeType = "text/plain" obj.save obj = @repository.find('test:1') obj.datastreams["my_ds"].mimeType.should == "text/plain" end it "should preserve the mimetype on update" do obj = @repository.find('test:1') obj.datastreams["my_ds"].content = "XXX" obj.datastreams["my_ds"].mimeType = "text/plain" obj.save obj = @repository.find('test:1') obj.datastreams["my_ds"].content = "ZZZ" obj.save obj = @repository.find('test:1') obj.datastreams["my_ds"].mimeType.should == "text/plain" end it "should allow the mimetype to be changed" do obj = @repository.find('test:1') obj.datastreams["my_ds"].content = "XXX" obj.datastreams["my_ds"].mimeType = "text/plain" obj.save obj = @repository.find('test:1') obj.datastreams["my_ds"].mimeType = "application/json" obj.save obj = @repository.find('test:1') obj.datastreams["my_ds"].mimeType.should == "application/json" end end after(:all) do @repository.find('test:1').delete rescue nil @repository.find('test:2').delete rescue nil end end