Sha256: 431df47c90ed4b5ab8917c391777559c5336e9c1564ec45cc42838013de98d85

Contents?: true

Size: 1.42 KB

Versions: 8

Compression:

Stored size: 1.42 KB

Contents

def mock_client
  return @mock_client if @mock_client
  @mock_client = mock("client")
  @getter = mock("getter")
  @getter.stubs(:get).returns('')
  @mock_client 
end
  
def stub_get(pid, datastreams=nil, record_exists=false)
  pid.gsub!(/:/, '%3A')
  mock_client.stubs(:[]).with("objects/#{pid}?format=xml").returns(stub('get getter', :get=>'foobar')) if record_exists
 # @mock_client.expects(:[]).with("objects/#{pid}?format=xml").raises(RestClient::ResourceNotFound) unless record_exists
  mock_client.stubs(:[]).with("objects/#{pid}/datastreams?format=xml").returns(@getter)
  datastreams ||= ['someData', 'withText', 'withText2', 'RELS-EXT']
  datastreams.each do |dsid|
    mock_client.stubs(:[]).with("objects/#{pid}/datastreams/#{dsid}?format=xml").returns(@getter)
  end
end
def stub_ingest(pid)
  n = pid.gsub(/:/, '%3A')
  mock_client.stubs(:[]).with("objects/#{n || 'new'}").returns(stub("ingester", :post=>pid))
end

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
active-fedora-3.1.6 spec/support/mock_fedora.rb
active-fedora-3.2.0.pre2 spec/support/mock_fedora.rb
active-fedora-3.2.0.pre1 spec/support/mock_fedora.rb
active-fedora-3.1.5 spec/support/mock_fedora.rb
active-fedora-3.1.4 spec/support/mock_fedora.rb
active-fedora-3.1.3 spec/support/mock_fedora.rb
active-fedora-3.1.2 spec/support/mock_fedora.rb
active-fedora-3.1.1 spec/support/mock_fedora.rb