Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit

  • Loading branch information...
commit f4e79618fde2268ba7ccb3cf6aa278eeb466b62b 0 parents
Chris Beer authored
45 .gitignore
@@ -0,0 +1,45 @@
+# rcov generated
+coverage
+
+# rdoc generated
+rdoc
+
+# yard generated
+doc
+.yardoc
+
+# bundler
+.bundle
+
+# jeweler generated
+pkg
+
+Gemfile.lock
+.rvmrc
+
+# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
+#
+# * Create a file at ~/.gitignore
+# * Include files you want ignored
+# * Run: git config --global core.excludesfile ~/.gitignore
+#
+# After doing this, these files will be ignored in all your git projects,
+# saving you from having to 'pollute' every project you touch with them
+#
+# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
+#
+# For MacOS:
+#
+#.DS_Store
+#
+# For TextMate
+#*.tmproj
+#tmtags
+#
+# For emacs:
+#*~
+#\#*
+#.\#*
+#
+# For vim:
+*.swp
19 Gemfile
@@ -0,0 +1,19 @@
+source "http://rubygems.org"
+
+gem "fastercsv"
+gem "rest-client"
+gem "nokogiri"
+
+# Add dependencies required to use your gem here.
+# Example:
+# gem "activesupport", ">= 2.3.5"
+
+# Add dependencies to develop your gem here.
+# Include everything needed to run rake, tests, features, etc.
+group :development do
+ gem "shoulda", ">= 0"
+ gem "bundler", "~> 1.0.0"
+ gem "jeweler", "~> 1.5.1"
+ gem "rcov", ">= 0"
+ gem "rspec"
+end
20 LICENSE.txt
@@ -0,0 +1,20 @@
+Copyright (c) 2010 Chris Beer
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 README.rdoc
@@ -0,0 +1,19 @@
+= rubydora
+
+Description goes here.
+
+== Contributing to rubydora
+
+* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
+* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
+* Fork the project
+* Start a feature/bugfix branch
+* Commit and push until you are happy with your contribution
+* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
+* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
+
+== Copyright
+
+Copyright (c) 2011 Chris Beer. See LICENSE.txt for
+further details.
+
54 Rakefile
@@ -0,0 +1,54 @@
+require 'rubygems'
+require 'bundler'
+begin
+ Bundler.setup(:default, :development)
+rescue Bundler::BundlerError => e
+ $stderr.puts e.message
+ $stderr.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
+require 'rake'
+
+require 'jeweler'
+Jeweler::Tasks.new do |gem|
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
+ gem.name = "rubydora"
+ gem.homepage = "http://github.com/cbeer/rubydora"
+ gem.license = "MIT"
+ gem.summary = %Q{TODO: one-line summary of your gem}
+ gem.description = %Q{TODO: longer description of your gem}
+ gem.email = "chris@cbeer.info"
+ gem.authors = ["Chris Beer"]
+end
+Jeweler::RubygemsDotOrgTasks.new
+
+# Get your spec rake tasks working in RSpec 2.0
+
+require 'rspec/core/rake_task'
+
+desc 'Default: run specs.'
+task :default => :spec
+
+desc "Run specs"
+RSpec::Core::RakeTask.new do |t|
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
+ # Put spec opts in a file named .rspec in root
+end
+
+desc "Generate code coverage"
+require "rcov/rcovtask"
+RSpec::Core::RakeTask.new(:coverage) do |t|
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
+ t.rcov = true
+ t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems/*']
+end
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "rubydora #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
1  VERSION
@@ -0,0 +1 @@
+0.0.0
26 lib/rubydora.rb
@@ -0,0 +1,26 @@
+module Rubydora
+ autoload :Datastream, "rubydora/datastream"
+ autoload :Repository, "rubydora/repository"
+ autoload :ResourceIndex, "rubydora/resource_index"
+ autoload :RestApiClient, "rubydora/rest_api_client"
+ autoload :DigitalObject, "rubydora/digital_object"
+
+ require 'fastercsv'
+ require 'restclient'
+ require 'nokogiri'
+
+ def self.version
+ @version ||= File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).chomp
+ end
+
+ VERSION = self.version
+
+ def self.connect *args
+ Repository.new *args
+ end
+
+ def self.repository
+ nil
+ end
+
+end
51 lib/rubydora/datastream.rb
@@ -0,0 +1,51 @@
+module Rubydora
+ module Datastream
+ def self.new digital_object, dsid, dsxml = nil
+ ds = Base.new digital_object, dsid
+ ds.profile = dsxml
+ ds
+ end
+
+ class Base
+ attr_reader :dsid
+
+ def initialize digital_object, dsid
+ @digital_object = digital_object
+ @dsid = dsid
+ end
+
+ def new!
+ @new = true
+ end
+
+ def new?
+ @new
+ end
+
+
+ def profile
+ @profile ||= begin
+ profile = nil
+ end
+ end
+
+ def profile= xml
+ @profile = xml
+ end
+
+ def dirty?
+ false
+ end
+
+ def save
+ return create if new?
+ end
+
+ protected
+
+ def client
+ @digital_object.send(:client)["datastreams/%s"%[dsid]]
+ end
+ end
+ end
+end
76 lib/rubydora/digital_object.rb
@@ -0,0 +1,76 @@
+module Rubydora
+ module DigitalObject
+ def self.find pid, repository = nil
+ Base.new pid, repository
+ end
+
+ def self.create pid, options = {}, repository = nil
+ repository ||= Rubydora.repository
+
+ repository.ingest(options.merge(:pid => pid))
+
+ Base.new pid, repository
+ end
+
+ class Base
+ attr_reader :pid
+
+ def initialize pid, repository = nil
+ @pid = pid
+ @repository = repository
+ end
+
+ def delete
+ repository.purge_object(:pid => pid)
+ end
+
+ def profile
+ @profile ||= begin
+ profile_xml = repository.object(:pid => pid)
+ profile_xml.gsub! '<objectProfile', '<objectProfile xmlns="http://www.fedora.info/definitions/1/0/access/"' unless profile_xml =~ /xmlns=/
+ doc = Nokogiri::XML(profile_xml)
+ h = doc.xpath('/access:objectProfile/*', {'access' => "http://www.fedora.info/definitions/1/0/access/"} ).inject({}) do |sum, node|
+ sum[node.name] ||= []
+ sum[node.name] << node.text
+
+ if node.name == "objModels"
+ sum[node.name] = node.xpath('access:model', {'access' => "http://www.fedora.info/definitions/1/0/access/"}).map { |x| x.text }
+ end
+
+ sum
+ end
+ h.select { |key, value| value.length == 1 }.each do |key, value|
+ h[key] = value.first
+ end
+
+ h
+
+ end
+ end
+
+ def datastreams
+ @datastreams ||= begin
+ h = Hash.new { |h,k| h[k] = Datastream.new self, k; h[k].new!; h[k] }
+ datastreams_xml = repository.datastreams(:pid => pid)
+ datastreams_xml.gsub! '<objectDatastreams', '<objectDatastreams xmlns="http://www.fedora.info/definitions/1/0/access/"' unless datastreams_xml =~ /xmlns=/
+ doc = Nokogiri::XML(datastreams_xml)
+ doc.xpath('//access:datastream', {'access' => "http://www.fedora.info/definitions/1/0/access/"}).each { |ds| h[ds['dsid']] = Datastream.new self, ds['dsid'], ds.to_s }
+ h
+ end
+ end
+
+ def save
+ self.datastreams.select(&:dirty?).reject(&:empty?).each(&:save)
+ end
+
+
+ protected
+
+ def repository
+ @repository ||= Rubydora.repository
+ end
+
+ end
+
+ end
+end
17 lib/rubydora/repository.rb
@@ -0,0 +1,17 @@
+module Rubydora
+ class Repository
+ include ResourceIndex
+ include RestApiClient
+ attr_reader :config
+
+ def initialize options = {}
+ @config = options
+ end
+
+ def find pid
+ DigitalObject.find(pid, self)
+ end
+
+
+ end
+end
19 lib/rubydora/resource_index.rb
@@ -0,0 +1,19 @@
+module Rubydora
+ module ResourceIndex
+ def find_by_sparql query, options = { :binding => 'pid' }
+ self.sparql(query).map { |x| self.find(x[options[:binding]]) rescue nil }
+ end
+
+ def sparql query
+ FasterCSV.parse(self.risearch(query), :headers => true)
+ end
+
+ protected
+ def risearch query, options = {}
+ request_params = { :dt => 'on', :format => 'CSV', :lang => 'sparql', :limit => nil, :query => query, type => 'tuples' }.merge(options)
+
+ self.client['risearch'].post request_params
+ end
+
+ end
+end
151 lib/rubydora/rest_api_client.rb
@@ -0,0 +1,151 @@
+module Rubydora
+ module RestApiClient
+ def client config = {}
+ config = @config.merge(config)
+ @client ||= RestClient::Resource.new @config[:url], :user => @config[:user], :password => @config[:password]
+ end
+
+ def next_pid options = {}
+ client[url_for(object_url() + "/nextPID", options)].post nil
+ end
+
+ def find_objects options = {}
+ raise "" if options[:terms] and options[:query]
+
+ client[object_url(nil, options)].get
+ end
+
+ def object options = {}
+ pid = options.delete(:pid)
+ client[object_url(pid, options)].get
+ end
+
+ def ingest options = {}
+ pid = options.delete(:pid) || 'new'
+ file = options.delete(:file)
+ client[object_url(pid, options)].post file, :content_type => 'text/xml'
+ end
+
+ def modify_object options = {}
+ pid = options.delete(:pid)
+ client[object_url(pid, options)].put nil
+ end
+
+ def purge_object options = {}
+ pid = options.delete(:pid)
+ client[object_url(pid, options)].delete
+ end
+
+ def object_versions options = {}
+ pid = options.delete(:pid)
+ raise "" unless pid
+ client[url_for(object_url(pid) + "/versions", options)].get
+ end
+
+ def object_xml options = {}
+ pid = options.delete(:pid)
+ raise "" unless pid
+ client[url_for(object_url(pid) + "/objectXML", options)].get
+ end
+
+ def datastream options = {}
+ pid = options.delete(:pid)
+ dsid = options.delete(:dsid)
+ client[datastream_url(pid, dsid, options)].get
+ end
+
+ alias_method :datastreams, :datastream
+
+ def set_datastream_options options = {}
+ pid = options.delete(:pid)
+ dsid = options.delete(:dsid)
+ client[datastream_url(pid, dsid, options)].put nil
+ end
+
+ def datastream_versions options = {}
+ pid = options.delete(:pid)
+ dsid = options.delete(:dsid)
+ raise "" unless dsid
+ client[url_for(datastream_url(pid, dsid) + "/versions", options)].get
+ end
+
+ def datastream_dissemination options = {}
+ pid = options.delete(:pid)
+ dsid = options.delete(:dsid)
+ options[:format] ||= false
+ raise "" unless dsid
+ client[url_for(datastream_url(pid, dsid) + "/content", options)].get
+ end
+
+ def add_datastream options = {}
+ pid = options.delete(:pid)
+ dsid = options.delete(:dsid)
+ file = options.delete(:file)
+ content_type = options.delete(:content_type) || options[:mimeType] || 'text/plain'
+ client[datastream_url(pid, dsid, options)].post file, :content_type => content_type
+ end
+
+ def modify_datastream options = {}
+ pid = options.delete(:pid)
+ dsid = options.delete(:dsid)
+ file = options.delete(:file)
+ content_type = options.delete(:content_type) || options[:mimeType] || 'text/plain'
+ client[datastream_url(pid, dsid, options)].put file, :content_type => content_type
+ end
+
+ def purge_datastream options = {}
+ pid = options.delete(:pid)
+ dsid = options.delete(:dsid)
+ client[datastream_url(pid, dsid, options)].delete
+ end
+
+ def relationships options = {}
+ pid = options.delete(:pid)
+ raise "" unless pid
+ client[url_for(object_url(pid) + "/relationships", options)].get
+ end
+
+ def add_relationship options = {}
+ pid = options.delete(:pid)
+ client[url_for(object_url(pid) + "/relationships", options)].post nil
+ end
+
+ def purge_relationship options = {}
+ pid = options.delete(:pid)
+ client[url_for(object_url(pid) + "/relationships", options)].delete
+ end
+
+
+ def dissemination options = {}
+ pid = options.delete(:pid)
+ sdef = options.delete(:sdef)
+ method = options.delete(:method)
+ client[dissemination_url(pid,sdef,method,options)].get
+ end
+
+ private
+
+ def url_for base, options = nil
+ return base unless options.is_a? Hash
+
+ options[:format] ||= 'xml' unless options[:format] == false
+ options.delete(:format) unless options[:format]
+ "#{base}" + (("?#{options.map { |key, value| "#{CGI::escape(key.to_s)}=#{CGI::escape(value.to_s)}"}.join("&") }" if options and not options.empty?) || '')
+ end
+
+ def object_url pid = nil, options = nil
+ url_for("objects" + (("/#{CGI::escape(pid)}" if pid) || ''), options)
+ end
+
+ def dissemination_url pid, sdef = nil, method = nil, options = nil
+ raise "" unless pid
+ url_for(object_url(pid) + "/methods" + (("/#{CGI::escape(sdef)}" if sdef) || '') + (("/#{CGI::escape(method)}" if method) || ''), options)
+ end
+
+ def datastream_url pid, dsid = nil, options = nil
+ raise "" unless pid
+ url_for(object_url(pid) + "/datastreams" + (("/#{CGI::escape(dsid)}" if dsid) || ''), options)
+ end
+
+ end
+end
107 spec/digital_object_spec.rb
@@ -0,0 +1,107 @@
+require 'spec_helper'
+
+describe Rubydora::DigitalObject do
+ describe "find" do
+ it "should load a DigitalObject instance" do
+ Rubydora::DigitalObject.find("pid").should be_a_kind_of(Rubydora::DigitalObject::Base)
+ end
+ end
+
+ describe "profile" do
+ before(:each) do
+ @mock_repository = mock(Rubydora::Repository)
+ @object = Rubydora::DigitalObject.find 'pid', @mock_repository
+ end
+
+ it "should convert object profile to a simple hash" do
+ @mock_repository.should_receive(:object).with(:pid => 'pid').and_return("<objectProfile><a>1</a><b>2</b><objModels><model>3</model><model>4</model></objectProfile>")
+ h = @object.profile
+
+ h.should have_key("a")
+ h['a'].should == '1'
+ h.should have_key("b")
+ h['b'].should == '2'
+ h.should have_key("objModels")
+ h['objModels'].should == ['3', '4']
+
+ end
+ end
+
+ describe "create" do
+ it "should call the Fedora REST API to create a new object" do
+ @mock_repository = mock(Rubydora::Repository)
+ @mock_repository.should_receive(:ingest).with(instance_of(Hash)).and_return(nil)
+ obj = Rubydora::DigitalObject.create "pid", { :a => 1, :b => 2}, @mock_repository
+ obj.should be_a_kind_of(Rubydora::DigitalObject::Base)
+ end
+ end
+
+ describe "retreive" do
+ before(:each) do
+ @mock_repository = mock(Rubydora::Repository)
+ @object = Rubydora::DigitalObject.find 'pid', @mock_repository
+ end
+
+ describe "datastreams" do
+ it "should provide a hash populated by the existing datastreams" do
+ @mock_repository.should_receive(:datastreams).with(:pid => 'pid').and_return("<objectDatastreams><datastream dsid='a'></datastream>><datastream dsid='b'></datastream>><datastream dsid='c'></datastream></objectDatastreams>")
+
+ @object.datastreams.should have_key("a")
+ @object.datastreams.should have_key("b")
+ @object.datastreams.should have_key("c")
+ end
+
+ it "should allow other datastreams to be added" do
+ @mock_repository.should_receive(:datastreams).with(:pid => 'pid').and_return("<objectDatastreams><datastream dsid='a'></datastream>><datastream dsid='b'></datastream>><datastream dsid='c'></datastream></objectDatastreams>")
+
+ @object.datastreams.length.should == 3
+
+ ds = @object.datastreams["z"]
+ ds.should be_a_kind_of(Rubydora::Datastream::Base)
+ ds.new?.should == true
+
+ @object.datastreams.length.should == 4
+ end
+
+ end
+
+ end
+
+ describe "save" do
+ before(:each) do
+ @mock_repository = mock(Rubydora::Repository)
+ @object = Rubydora::DigitalObject.find 'pid', @mock_repository
+ end
+
+ it "should save all dirty datastreams" do
+ @ds1 = mock()
+ @ds1.should_receive(:dirty?).and_return(false)
+ @ds1.should_not_receive(:save)
+ @ds2 = mock()
+ @ds2.should_receive(:dirty?).and_return(true)
+ @ds2.should_receive(:empty?).and_return(true)
+ @ds2.should_not_receive(:save)
+ @ds3 = mock()
+ @ds3.should_receive(:dirty?).and_return(true)
+ @ds3.should_receive(:empty?).and_return(false)
+ @ds3.should_receive(:save)
+
+ @object.should_receive(:datastreams).and_return([@ds1, @ds2, @ds3])
+
+ @object.save
+ end
+ end
+
+ describe "delete" do
+ before(:each) do
+ @mock_repository = mock()
+ @object = Rubydora::DigitalObject.find 'pid', @mock_repository
+ end
+
+ it "should call the Fedora REST API" do
+ @mock_repository.should_receive(:purge_object).with({:pid => 'pid'})
+ @object.delete
+ end
+ end
+
+end
53 spec/repository_spec.rb
@@ -0,0 +1,53 @@
+require 'spec_helper'
+
+describe Rubydora::Repository do
+ before(:each) do
+ @repository = Rubydora::Repository.new
+ end
+
+ describe "client" do
+ it "should return a RestClient resource" do
+ client = @repository.client :url => 'http://example.org', :user => 'fedoraAdmin', :password => 'fedoraAdmin'
+
+ client.should be_a_kind_of(RestClient::Resource)
+ end
+ end
+
+ describe "find" do
+
+ it "should load objects by pid" do
+ @mock_object = mock(Rubydora::DigitalObject)
+ Rubydora::DigitalObject.should_receive(:find).with("pid", instance_of(Rubydora::Repository)).and_return @mock_object
+
+ @repository.find('pid')
+ end
+
+ end
+
+ describe "sparql" do
+ it "should return csv results for sparql queries" do
+ resource_index_query = ""
+ @repository.should_receive(:risearch).with(resource_index_query).and_return("pid\na\nb\nc\n")
+
+ csv = @repository.sparql(resource_index_query)
+ end
+
+end
+
+describe "find_by_sparql" do
+ it "should attempt to load objects from the results of a sparql query" do
+
+ resource_index_query = ""
+ @repository.should_receive(:risearch).with(resource_index_query).and_return("pid\na\nb\nc\n")
+
+ @repository.should_receive(:find).with('a').and_return(1)
+ @repository.should_receive(:find).with('b').and_return(1)
+ @repository.should_receive(:find).with('c').and_return(1)
+
+ objects = @repository.find_by_sparql(resource_index_query)
+
+ objects.length.should == 3
+ end
+ end
+
+end
131 spec/rest_api_client_spec.rb
@@ -0,0 +1,131 @@
+require 'spec_helper'
+
+describe Rubydora::RestApiClient do
+ class MockRepository
+ include Rubydora::RestApiClient
+
+ attr_accessor :config
+ end
+
+ before(:each) do
+ @mock_repository = MockRepository.new
+ @mock_repository.config = { :url => 'http://example.org',:user => 'fedoraAdmin', :password => 'fedoraAdmin'}
+ end
+
+ it "should call nextPID" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/nextPID?format=xml"))
+ @mock_repository.next_pid
+ end
+
+ it "should find objects" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects?query=a&format=xml"))
+ @mock_repository.find_objects :query => 'a'
+ end
+
+ it "should show object properties" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/z?format=xml"))
+ @mock_repository.object :pid => 'z'
+ end
+
+ it "ingest" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/new?format=xml"))
+ @mock_repository.ingest
+ end
+
+ it "ingest with pid" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid?format=xml"))
+ @mock_repository.ingest :pid => 'mypid'
+ end
+
+ it "modify_object" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid?format=xml&state=Z"))
+ @mock_repository.modify_object :pid => 'mypid', :state => 'Z'
+ end
+
+ it "purge_object" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid?format=xml"))
+ @mock_repository.purge_object :pid => 'mypid'
+ end
+
+ it "object_versions" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/versions?format=xml"))
+ @mock_repository.object_versions :pid => 'mypid'
+ end
+
+ it "object_xml" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/objectXML?format=xml"))
+ @mock_repository.object_xml :pid => 'mypid'
+ end
+
+ it "datastream" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams?format=xml"))
+ @mock_repository.datastream :pid => 'mypid'
+ end
+
+ it "datastream" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa?format=xml"))
+ @mock_repository.datastream :pid => 'mypid', :dsid => 'aaa'
+ end
+
+ it "datastream_dissemination" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa/content"))
+ @mock_repository.datastream_dissemination :pid => 'mypid', :dsid => 'aaa'
+ end
+
+ it "add_datastream" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa?format=xml"))
+ @mock_repository.add_datastream :pid => 'mypid', :dsid => 'aaa'
+ end
+
+ it "modify_datastream" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa?format=xml"))
+ @mock_repository.modify_datastream :pid => 'mypid', :dsid => 'aaa'
+ end
+
+ it "purge_datastream" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa?format=xml"))
+ @mock_repository.purge_datastream :pid => 'mypid', :dsid => 'aaa'
+ end
+
+ it "set_datastream_options" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa?format=xml&aparam=true"))
+ @mock_repository.set_datastream_options :pid => 'mypid', :dsid => 'aaa', :aparam => true
+ end
+
+ it "datastream_versions" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa/versions?format=xml"))
+ @mock_repository.datastream_versions :pid => 'mypid', :dsid => 'aaa'
+
+ end
+
+ it "relationships" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/relationships?format=xml"))
+ @mock_repository.relationships :pid => 'mypid'
+ end
+
+ it "add_relationship" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/relationships?subject=z&format=xml"))
+ @mock_repository.add_relationship :pid => 'mypid', :subject => 'z'
+ end
+
+ it "purge_relationships" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/relationships?subject=z&format=xml"))
+ @mock_repository.purge_relationship :pid => 'mypid', :subject => 'z'
+ end
+
+ it "dissemination" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/methods?format=xml"))
+ @mock_repository.dissemination :pid => 'mypid'
+ end
+
+ it "dissemination" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/methods/sdef?format=xml"))
+ @mock_repository.dissemination :pid => 'mypid', :sdef => 'sdef'
+ end
+
+ it "dissemination" do
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/methods/sdef/method?format=xml"))
+ @mock_repository.dissemination :pid => 'mypid', :sdef => 'sdef', :method => 'method'
+ end
+
+end
4 spec/spec_helper.rb
@@ -0,0 +1,4 @@
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+require 'rubydora'
+require 'rspec'
Please sign in to comment.
Something went wrong with that request. Please try again.