require 'spec_helper' require 'active_fedora' require "nokogiri" describe ActiveFedora::Datastream do before(:each) do @test_object = ActiveFedora::Base.new @test_datastream = ActiveFedora::Datastream.new(@test_object.inner_object, 'abcd') @test_datastream.content = "hi there" end its(:metadata?) { should be_false} it "should escape dots in to_param" do @test_datastream.stub(:dsid).and_return('foo.bar') @test_datastream.to_param.should == 'foo%2ebar' end it "should be inspectable" do @test_datastream.inspect.should match /#/ end describe '#validate_content_present' do before :each do @test_datastream.content = nil @test_datastream.dsLocation = nil end it "should expect content on an Inline (X) datastream" do @test_datastream.controlGroup = 'X' @test_datastream.dsLocation = "http://example.com/test/content/abcd" @test_datastream.validate_content_present.should be_false @test_datastream.content = "" @test_datastream.validate_content_present.should be_true end it "should expect content on a Managed (M) datastream" do @test_datastream.controlGroup = 'M' @test_datastream.dsLocation = "http://example.com/test/content/abcd" @test_datastream.validate_content_present.should be_false @test_datastream.content = "" @test_datastream.validate_content_present.should be_true @test_datastream.should_not be_external end it "should expect a dsLocation on an External (E) datastream" do @test_datastream.controlGroup = 'E' @test_datastream.content = "" @test_datastream.validate_content_present.should be_false @test_datastream.dsLocation = "http://example.com/test/content/abcd" @test_datastream.validate_content_present.should be_true @test_datastream.should be_external end it "should expect a dsLocation on a Redirect (R) datastream" do @test_datastream.controlGroup = 'R' @test_datastream.content = "" @test_datastream.validate_content_present.should be_false @test_datastream.dsLocation = "http://example.com/test/content/abcd" @test_datastream.validate_content_present.should be_true end end it "should have mimeType accessors" do ds1 = ActiveFedora::Datastream.new ds1.mimeType = "text/foo" ds1.mimeType.should == "text/foo" ds2 = ActiveFedora::Datastream.new ds2.mimeType = "text/bar" ds2.mimeType.should == "text/bar" end describe ".size" do it "should lazily load the datastream size attribute from the fedora repository" do ds_profile = <<-EOS #{@test_datastream.dsid}.1 2011-07-11T16:48:13.536Z A text/xml X 9999 true #{@test_object.pid}+#{@test_datastream.dsid}+#{@test_datastream.dsid}.1 DISABLED none " EOS mock_repo = Rubydora::Repository.new @test_object.inner_object.stub(:repository).and_return(mock_repo) mock_repo.api.should_receive(:datastream).with(:dsid => 'abcd', :pid => @test_object.pid).and_return(ds_profile) @test_datastream.size.should == 9999 end it "should default to an empty string if ds has not been saved" do @test_datastream.size.should be_nil end end end