Sha256: 950a8be1f166cde4187db5fca64f0a6e6e2315c4ab26a026dc33f9ffe3f11ad7

Contents?: true

Size: 1.9 KB

Versions: 21

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'

require 'active_fedora'
require "rexml/document"

describe ActiveFedora::Datastream do
  
  before(:each) do
    @test_object = ActiveFedora::Base.new
    @test_object.save
  end
  
  after(:each) do
    @test_object.delete
  end
  
  it "should be able to access Datastreams using datastreams method" do    
    dc = @test_object.datastreams["DC"]
    dc.should be_an_instance_of(ActiveFedora::Datastream)
    dc.dsid.should eql("DC")
    dc.pid.should_not be_nil
    # dc.control_group.should == "X"
  end
  
  it "should be able to access Datastream content using content method" do    
    dc = @test_object.datastreams["DC"].content
    dc.should_not be_nil
  end
  
  it "should be able to update XML Datastream content and save to Fedora" do    
    xml_content = Nokogiri::XML::Document.parse(@test_object.datastreams["DC"].content)
    title = Nokogiri::XML::Element.new "title", xml_content
    title.content = "Test Title"
    title.namespace = xml_content.xpath('//oai_dc:dc/dc:identifier').first.namespace
    xml_content.root.add_child title
    
    @test_object.datastreams["DC"].stubs(:before_save)
    @test_object.datastreams["DC"].content = xml_content.to_s
    @test_object.datastreams["DC"].save
    
    found = Nokogiri::XML::Document.parse(@test_object.class.find(@test_object.pid).datastreams['DC'].content)
    found.xpath('*/dc:title/text()').first.inner_text.should == title.content
  end
  
  it "should be able to update Blob Datastream content and save to Fedora" do    
    dsid = "ds#{Time.now.to_i}"
    ds = ActiveFedora::Datastream.new(@test_object.inner_object, dsid)
    ds.content = fixture('dino.jpg')
    @test_object.add_datastream(ds).should be_true
    @test_object.save
    to = ActiveFedora::Base.find(@test_object.pid) 
    to.should_not be_nil 
    to.datastreams[dsid].should_not be_nil
    to.datastreams[dsid].content.should == fixture('dino.jpg').read
    
  end
  
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
active-fedora-4.1.0 spec/integration/datastream_spec.rb
active-fedora-4.0.0 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc20 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc19 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc18 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc17 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc16 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc15 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc14 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc13 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc12 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc11 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc10 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc9 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc8 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc7 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc6 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc5 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc4 spec/integration/datastream_spec.rb
active-fedora-4.0.0.rc3 spec/integration/datastream_spec.rb