Sha256: 727930db93af5f99f2e9da210f92bfdc8077f6586de87ceed0c20fac4e555091

Contents?: true

Size: 1.52 KB

Versions: 45

Compression:

Stored size: 1.52 KB

Contents

def mock_client
  return @mock_client if @mock_client
  @mock_client = mock("client")
  @getter = mock("getter")
  @getter.stub(:get).and_return('')
  @mock_client.stub(:[]).with("describe?xml=true").and_return('')
  @mock_client 
end
  
def stub_get(pid, datastreams=nil, record_exists=false)
  pid.gsub!(/:/, '%3A')
  if record_exists
    mock_client.stub(:[]).with("objects/#{pid}?format=xml").and_return(stub('get getter', :get=>'foobar'))
  else
    mock_client.stub(:[]).with("objects/#{pid}?format=xml").and_raise(RestClient::ResourceNotFound)
  end
  mock_client.stub(:[]).with("objects/#{pid}/datastreams?format=xml").and_return(@getter)
  datastreams ||= ['someData', 'withText', 'withText2', 'RELS-EXT']
  datastreams.each do |dsid|
    mock_client.stub(:[]).with("objects/#{pid}/datastreams/#{dsid}?format=xml").and_return(@getter)
  end
end

def stub_ingest(pid=nil)
  n = pid ? pid.gsub(/:/, '%3A') : nil
  mock_client.should_receive(:[]).with("objects/#{n || 'new'}").and_return(stub("ingester", :post=>pid))
end

def stub_add_ds(pid, dsids)
  pid.gsub!(/:/, '%3A')
  dsids.each do |dsid|
    client = mock_client.stub(:[]).with do |params|
      /objects\/#{pid}\/datastreams\/#{dsid}/.match(params)
    end
    client.and_return(stub("ds_adder", :post=>pid, :get=>''))
  end
end

def stub_get_content(pid, dsids)
  pid.gsub!(/:/, '%3A')
  dsids.each do |dsid|
    mock_client.stub(:[]).with { |params| /objects\/#{pid}\/datastreams\/#{dsid}\/content/.match(params)}.and_return(stub("content_accessor", :post=>pid, :get=>''))
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
active-fedora-5.7.1 spec/support/mock_fedora.rb
active-fedora-5.7.0 spec/support/mock_fedora.rb
active-fedora-6.4.2 spec/support/mock_fedora.rb
active-fedora-6.4.1 spec/support/mock_fedora.rb
active-fedora-6.4.0 spec/support/mock_fedora.rb
active-fedora-6.4.0.rc4 spec/support/mock_fedora.rb
active-fedora-6.4.0.rc3 spec/support/mock_fedora.rb
active-fedora-6.4.0.rc2 spec/support/mock_fedora.rb
active-fedora-6.4.0.rc1 spec/support/mock_fedora.rb
active-fedora-6.3.0 spec/support/mock_fedora.rb
active-fedora-6.2.0 spec/support/mock_fedora.rb
active-fedora-6.1.1 spec/support/mock_fedora.rb
active-fedora-6.1.0 spec/support/mock_fedora.rb
active-fedora-5.6.3 spec/support/mock_fedora.rb
active-fedora-6.0.0 spec/support/mock_fedora.rb
active-fedora-6.0.0.rc7 spec/support/mock_fedora.rb
active-fedora-6.0.0.rc6 spec/support/mock_fedora.rb
active-fedora-6.0.0.rc5 spec/support/mock_fedora.rb
active-fedora-6.0.0.rc4 spec/support/mock_fedora.rb
active-fedora-6.0.0.rc3 spec/support/mock_fedora.rb