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

- old
+ new

@@ -27,11 +27,12 @@ before(:each) do @this_pid = increment_pid.to_s stub_get(@this_pid) Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client) - ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(@this_pid) + ActiveFedora::Base.stubs(:assign_pid).returns(@this_pid) + #ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(@this_pid) end describe "creates datastreams" do before do class FooHistory < ActiveFedora::Base @@ -50,10 +51,11 @@ end stub_ingest(@this_pid) stub_add_ds(@this_pid, ['RELS-EXT', 'someData', 'withText', 'withText2']) @n = FooHistory.new() + FooHistory.stubs(:assign_pid).returns(@this_pid) @n.datastreams['RELS-EXT'].expects(:changed?).returns(true).at_least_once @n.expects(:update_index) @n.save end @@ -69,11 +71,11 @@ end end it "should create specified datastreams with appropriate control group" do - ActiveFedora.fedora_config.stubs(:[]).returns({:url=>'sub_url'}) + ActiveFedora.stubs(:config_for_environment).returns(:url=>'sub_url') stub_ingest(@this_pid) stub_add_ds(@this_pid, ['RELS-EXT', 'DC', 'rightsMetadata', 'properties', 'descMetadata', 'UKETD_DC']) stub_get(@this_pid, ['RELS-EXT', 'DC', 'rightsMetadata', 'properties', 'descMetadata', 'UKETD_DC']) class UketdObject < ActiveFedora::Base has_metadata :name => "rightsMetadata", :label=>"Rights metadata", :type => ActiveFedora::NokogiriDatastream @@ -92,10 +94,11 @@ m.field 'depositor', :string end end @n = UketdObject.new() + UketdObject.stubs(:assign_pid).returns(@this_pid) @n.save @n.datastreams["DC"].controlGroup.should eql("X") @n.datastreams["rightsMetadata"].controlGroup.should eql("X") @n.datastreams["properties"].controlGroup.should eql("X") @n.datastreams["descMetadata"].controlGroup.should eql("M") @@ -118,43 +121,39 @@ 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 + MoreFooHistory.stubs(:assign_pid).returns(@this_pid) @n.save @n.datastreams['externalDisseminator'].dsLocation.should == "http://exampl.com/mypic.jpg" end - it "should allow :control_group => 'E' without a :url option" do - class MoreFooHistory < ActiveFedora::Base - has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "E" + describe "control_group E without a url" do + before do + class MoreFooHistory < ActiveFedora::Base + has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "E" + end + stub_ingest(@this_pid) + @n = MoreFooHistory.new + MoreFooHistory.stubs(:assign_pid).returns(@this_pid) end - 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" + it "should allow :control_group => 'E' without a :url option" do + @n.datastreams['externalDisseminator'].dsLocation.present?.should == false + @n.save end - 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 => "E" + + it "should fail validation if a :url is not added before save" do + @n.datastreams['externalDisseminator'].validate_content_present.should == false + @n.save 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 + + it "should pass validation if a :url is added before save" do + @n.datastreams['externalDisseminator'].dsLocation = "http://exampl.com/mypic.jpg" + @n.datastreams['externalDisseminator'].validate_content_present.should == true + @n.save + end end end context ":control_group => 'R'" do before do @@ -170,41 +169,37 @@ 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 + MoreFooHistory.stubs(:assign_pid).returns(@this_pid) @n.save end - it "should allow :control_group => 'R' without a :url option" do - class MoreFooHistory < ActiveFedora::Base - has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R" + describe "control_group R without url" do + before do + class MoreFooHistory < ActiveFedora::Base + has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R" + end + MoreFooHistory.stubs(:assign_pid).returns(@this_pid) + stub_ingest(@this_pid) + @n = MoreFooHistory.new end - 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 => "R" + it "should allow :control_group => 'R' without a :url option" do + @n.datastreams['externalDisseminator'].dsLocation.present?.should == false + @n.save end - 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" + + it "should fail validation if a :url is not added before save" do + @n.datastreams['externalDisseminator'].validate_content_present.should == false + @n.save 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 + + it "should pass validation if a :url is added before save" do + @n.datastreams['externalDisseminator'].dsLocation = "http://exampl.com/mypic.jpg" + @n.datastreams['externalDisseminator'].validate_content_present.should == true + @n.save + end end end end describe "#create_datastream" do