spec/unit/datastreams_spec.rb in active-fedora-3.3.1 vs spec/unit/datastreams_spec.rb in active-fedora-3.3.2

- old
+ new

@@ -7,10 +7,20 @@ it "should respond_to has_metadata" do ActiveFedora::Base.respond_to?(:has_metadata).should be_true end + describe "datastream_from_spec" do + it "should accept versionable" do + ds = @test_object.datastream_from_spec({:type=>ActiveFedora::Datastream, :versionable=>false}, 'test') + ds.versionable.should be_false + ds = @test_object.datastream_from_spec({:type=>ActiveFedora::Datastream, :versionable=>true}, 'test') + ds.versionable.should be_true + end + + end + describe "has_metadata" do @@last_pid = 0 def increment_pid @@last_pid += 1 end @@ -96,79 +106,105 @@ context ":control_group => 'E'" do before do stub_get(@this_pid) stub_add_ds(@this_pid, ['RELS-EXT', 'externalDisseminator', 'externalUrl']) end - before :all do - class MoreFooHistory < ActiveFedora::Base - has_metadata :type=>ActiveFedora::NokogiriDatastream, :name=>"externalDisseminator", :control_group => "E" - end - end - after(:all) do + after :each do # clean up test class Object.send(:remove_const, :MoreFooHistory) end - it "should raise an error without :disseminator or :url option" do - lambda { @n = MoreFooHistory.new }.should raise_exception - end it "should allow :control_group => 'E' with a :url option" do class MoreFooHistory < ActiveFedora::Base has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "E", :url => "http://exampl.com/mypic.jpg" end stub_ingest(@this_pid) @n = MoreFooHistory.new @n.save + @n.datastreams['externalDisseminator'].dsLocation.should == "http://exampl.com/mypic.jpg" end - it "should raise an error if :url is malformed" do + + it "should allow :control_group => 'E' without a :url option" do class MoreFooHistory < ActiveFedora::Base - has_metadata :type => ActiveFedora::NokogiriDatastream, :name=>"externalUrl", :url=>"my_rul", :control_group => "E" + has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "E" end - client = mock_client.stubs(:[]).with do |params| - /objects\/#{@this_pid}\/datastreams\/externalUrl/.match(params) + stub_ingest(@this_pid) + @n = MoreFooHistory.new + @n.datastreams['externalDisseminator'].dsLocation.present?.should == false + @n.save + end + + it "should fail validation if a :url is not added before save" do + class MoreFooHistory < ActiveFedora::Base + has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "E" end - client.raises(RuntimeError, "Error adding datastream externalUrl for object changeme:4020. See logger for details") + stub_ingest(@this_pid) @n = MoreFooHistory.new - lambda {@n.save }.should raise_exception + @n.datastreams['externalDisseminator'].validate_content_present.should == false + @n.save end + + it "should pass validation if a :url is added before save" do + class MoreFooHistory < ActiveFedora::Base + has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "E" + end + stub_ingest(@this_pid) + @n = MoreFooHistory.new + @n.datastreams['externalDisseminator'].dsLocation = "http://exampl.com/mypic.jpg" + @n.datastreams['externalDisseminator'].validate_content_present.should == true + @n.save + end end context ":control_group => 'R'" do before do stub_get(@this_pid) stub_add_ds(@this_pid, ['RELS-EXT', 'externalDisseminator' ]) end - it "should raise an error without :url option" do - class MoreFooHistory < ActiveFedora::Base - has_metadata :type=>ActiveFedora::NokogiriDatastream, :name=>"externalDisseminator", :control_group => "R" - end - lambda { @n = MoreFooHistory.new }.should raise_exception + + after :each do + Object.send(:remove_const, :MoreFooHistory) end - it "should work with a valid :url option" do + it "should allow :control_group => 'R' with a :url option" do stub_ingest(@this_pid) class MoreFooHistory < ActiveFedora::Base has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R", :url => "http://exampl.com/mypic.jpg" end @n = MoreFooHistory.new @n.save end - it "should not take a :disseminator option without a :url option" do + + it "should allow :control_group => 'R' without a :url option" do class MoreFooHistory < ActiveFedora::Base - has_metadata :type=>ActiveFedora::NokogiriDatastream, :name=>"externalDisseminator", :control_group => "R", :disseminator => "foo:s-def/hull-cModel:Foo" + has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R" end - lambda { @n = MoreFooHistory.new }.should raise_exception + stub_ingest(@this_pid) + @n = MoreFooHistory.new + @n.datastreams['externalDisseminator'].dsLocation.present?.should == false + @n.save end - it "should raise an error if :url is malformed" do + + it "should fail validation if a :url is not added before save" do class MoreFooHistory < ActiveFedora::Base - has_metadata :type => ActiveFedora::NokogiriDatastream, :name=>"externalUrl", :url=>"my_rul", :control_group => "R" + has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R" end - client = mock_client.stubs(:[]).with do |params| - /objects\/#{@this_pid}\/datastreams\/externalUrl/.match(params) + stub_ingest(@this_pid) + @n = MoreFooHistory.new + @n.datastreams['externalDisseminator'].validate_content_present.should == false + @n.save + end + + it "should pass validation if a :url is added before save" do + class MoreFooHistory < ActiveFedora::Base + has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R" end - client.raises(RuntimeError, "Error adding datastream externalUrl for object changeme:4020. See logger for details") - lambda {MoreFooHistory.new }.should raise_exception + stub_ingest(@this_pid) + @n = MoreFooHistory.new + @n.datastreams['externalDisseminator'].dsLocation = "http://exampl.com/mypic.jpg" + @n.datastreams['externalDisseminator'].validate_content_present.should == true + @n.save end end end describe "#create_datastream" do