Sha256: b71966bc6de0262d4887eff58b22b71b05d85c9cf994d8bd88d6dfd7197e20e8

Contents?: true

Size: 1.76 KB

Versions: 39

Compression:

Stored size: 1.76 KB

Contents

require 'spec_helper'

describe Rubydora::ExtensionParameters do
  describe "extension parameters" do
    class MockExtensionParametersClass
      include Rubydora::Callbacks
      register_callback :after_initialize
      include Rubydora::ExtensionParameters
    end

    it "should have extension parameters at the class level" do
      MockExtensionParametersClass.extension_parameters[:a] = 1 

      MockExtensionParametersClass.extension_parameters.should == { :a => 1 }

    end
  end

  describe "DigitalObject" do
    module FakeExtension
    end

    module OtherFakeExtension

    end
    before(:each) do
      @mock_repository = mock()
    end

    after(:each) do
      Rubydora::DigitalObject.registered_extensions = []
    end

    it "should be extendable" do
      Rubydora::DigitalObject.use_extension FakeExtension
      @object = Rubydora::DigitalObject.new 'pid', @mock_repository
      @object.is_a?(FakeExtension).should == true
    end

    it "should be extendable conditionally" do
      Rubydora::DigitalObject.use_extension(FakeExtension) { |x| true }
      Rubydora::DigitalObject.use_extension(OtherFakeExtension) { |x| false }
      @object = Rubydora::DigitalObject.new 'pid', @mock_repository
      @object.is_a?(FakeExtension).should == true
      @object.is_a?(OtherFakeExtension).should == false
    end

    it "should be able to introspect object profiles" do
      @mock_repository.should_receive(:object).any_number_of_times.with({:pid => 'pid'}).and_return <<-XML
      <objectProfile>
        <a>1</a>
      </objectProfile>
      XML
      Rubydora::DigitalObject.use_extension(FakeExtension) { |x| x.profile['a'] == '1' }
      @object = Rubydora::DigitalObject.new 'pid', @mock_repository
      @object.is_a?(FakeExtension).should == true
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
rubydora-0.5.13 spec/lib/extension_parameters_spec.rb
rubydora-0.5.12 spec/lib/extension_parameters_spec.rb
rubydora-0.5.11 spec/lib/extension_parameters_spec.rb
rubydora-0.5.10 spec/lib/extension_parameters_spec.rb
rubydora-0.5.9 spec/lib/extension_parameters_spec.rb
rubydora-0.5.8 spec/lib/extension_parameters_spec.rb
rubydora-0.5.7 spec/lib/extension_parameters_spec.rb
rubydora-0.5.6 spec/lib/extension_parameters_spec.rb
rubydora-0.5.5 spec/lib/extension_parameters_spec.rb
rubydora-0.5.4 spec/lib/extension_parameters_spec.rb
rubydora-0.5.3 spec/lib/extension_parameters_spec.rb
rubydora-0.5.2 spec/lib/extension_parameters_spec.rb
rubydora-0.5.1 spec/lib/extension_parameters_spec.rb
rubydora-0.5.0 spec/lib/extension_parameters_spec.rb
rubydora-0.4.1 spec/lib/extension_parameters_spec.rb
rubydora-0.4.0 spec/lib/extension_parameters_spec.rb
rubydora-0.4.0pre1 spec/lib/extension_parameters_spec.rb
rubydora-0.3.1 spec/lib/extension_parameters_spec.rb
rubydora-0.3.0 spec/lib/extension_parameters_spec.rb
rubydora-0.2.6 spec/lib/extension_parameters_spec.rb