Sha256: 513ba67b21b3061505fdc7af2cf5cc09901355b6a9224cc00e30619148d20930

Contents?: true

Size: 1.91 KB

Versions: 19

Compression:

Stored size: 1.91 KB

Contents

require 'spec_helper'

describe ActiveFedora::SimpleDatastream do

  before do
    @sample_xml =  "<fields><coverage>coverage1</coverage><coverage>coverage2</coverage><creation_date>2012-01-15</creation_date><mydate>fake-date</mydate><publisher>publisher1</publisher></fields>"
    @test_ds = ActiveFedora::SimpleDatastream.from_xml(@sample_xml )
    @test_ds.field :coverage
    @test_ds.field :creation_date, :date
    @test_ds.field :mydate
    @test_ds.field :publisher

  end
  it "from_xml should parse everything correctly" do
    @test_ds.ng_xml.should be_equivalent_to @sample_xml
  end

  
  describe '#new' do
    describe "model methods" do 

      [:coverage, :mydate, :publisher].each do |el|
        it "should respond to getters and setters for the string typed #{el} element" do
          value = "Hey #{el}"
          @test_ds.send("#{el.to_s}=", value) 
          @test_ds.send(el).first.should == value  #Looking at first because creator has 2 nodes
        end
      end

      it "should set date elements" do
        d = Date.parse('1939-05-23')
        @test_ds.creation_date = d
        @test_ds.creation_date.first.should == d
      end
    end
  end
  
  describe '.to_xml' do
    it 'should output the fields hash as Qualified Dublin Core XML' do
      @test_ds.publisher= "charlie"
      @test_ds.coverage= ["80%", "20%"]

      @test_ds.to_xml.should be_equivalent_to('
        <fields>
          <coverage>80%</coverage>
          <coverage>20%</coverage>
          <creation_date>2012-01-15</creation_date>
          <mydate>fake-date</mydate>
          <publisher>charlie</publisher>
        </fields>')
    end
  end

  describe "#to_solr" do
    it "should have title" do
      solr = @test_ds.to_solr
      solr[ActiveFedora::SolrService.solr_name('publisher', type: :string)].should == ["publisher1"]
      solr[ActiveFedora::SolrService.solr_name('creation_date', type: :date)].should == ["2012-01-15"]
    end
  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
active-fedora-6.1.0 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.rc7 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.rc6 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.rc5 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.rc4 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.rc3 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.rc2 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.rc1 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.pre10 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.pre9 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.pre8 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.pre7 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.pre6 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.pre5 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.pre4 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.pre3 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.pre2 spec/unit/simple_datastream_spec.rb
active-fedora-6.0.0.pre1 spec/unit/simple_datastream_spec.rb