Sha256: 1388982929b02ed182b5a5c974f4cfa8e1c8f082a88e296532cfc27926d8c055

Contents?: true

Size: 1.88 KB

Versions: 19

Compression:

Stored size: 1.88 KB

Contents

require 'spec_helper'

describe ActiveFedora::Base do

  describe "deletgating multiple terms to one datastream" do
    class BarnyardDocument < ActiveFedora::NokogiriDatastream
      set_terminology do |t|
        t.root(:path=>"animals", :xmlns=>"urn:zoobar")
        t.waterfowl do
          t.ducks do
            t.duck
          end
        end
        t.donkey()
        t.cow()
        t.horse()
        t.chicken()
        t.pig()
        t.duck(:ref=>[:waterfowl,:ducks,:duck])
      end

      def self.xml_template
            Nokogiri::XML::Document.parse '<animals xmlns="urn:zoobar">
              <waterfowl>
                <ducks>
                  <duck/>
                </ducks>
              </waterfowl>
              <donkey></donkey>
              <cow></cow>
              <horse></horse>
              <chicken></chicken>
              <pig></pig>
            </animals>'
      end
    end

    class Barnyard < ActiveFedora::Base
      has_metadata :type=>BarnyardDocument, :name=>"xmlish"
      delegate_to :xmlish, [:cow, :chicken, :pig, :duck]
      delegate_to :xmlish, [:donkey, :horse], :unique=>true
      #delegate :donkey, :to=>'xmlish', :unique=>true
    end
    before :each do
      @n = Barnyard.new()
    end
    it "should save a delegated property uniquely" do
      @n.donkey="Bray"
      @n.donkey.should == "Bray"
      @n.xmlish.term_values(:donkey).first.should == 'Bray'
      @n.horse="Winee"
      @n.horse.should == "Winee"
      @n.xmlish.term_values(:horse).first.should == 'Winee'
    end
    it "should return an array if not marked as unique" do
      ### Metadata datastream does not appear to support multiple value setting
      @n.cow=["one", "two"]
      @n.cow.should == ["one", "two"]
    end

    it "should be able to delegate deeply into the terminology" do
      @n.duck=["Quack", "Peep"]
      @n.duck.should == ["Quack", "Peep"]
    end

  end
end


Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
active-fedora-5.2.0 spec/unit/base_delegate_to_spec.rb
active-fedora-5.1.0 spec/unit/base_delegate_to_spec.rb
active-fedora-5.0.0 spec/unit/base_delegate_to_spec.rb
active-fedora-5.0.0.rc5 spec/unit/base_delegate_to_spec.rb
active-fedora-5.0.0.rc4 spec/unit/base_delegate_to_spec.rb
active-fedora-5.0.0.rc3 spec/unit/base_delegate_to_spec.rb
active-fedora-5.0.0.rc2 spec/unit/base_delegate_to_spec.rb
active-fedora-5.0.0.rc1 spec/unit/base_delegate_to_spec.rb
active-fedora-4.6.0.rc4 spec/unit/base_delegate_to_spec.rb
active-fedora-4.6.0.rc3 spec/unit/base_delegate_to_spec.rb
active-fedora-4.6.0.rc2 spec/unit/base_delegate_to_spec.rb
active-fedora-4.6.0.rc1 spec/unit/base_delegate_to_spec.rb
active-fedora-4.5.3 spec/unit/base_delegate_to_spec.rb
active-fedora-4.5.2 spec/unit/base_delegate_to_spec.rb
active-fedora-4.5.1 spec/unit/base_delegate_to_spec.rb
active-fedora-4.5.0 spec/unit/base_delegate_to_spec.rb
active-fedora-4.4.1 spec/unit/base_delegate_to_spec.rb
active-fedora-4.4.0 spec/unit/base_delegate_to_spec.rb
active-fedora-4.3.0 spec/unit/base_delegate_to_spec.rb