require 'spec_helper' describe Rubydora::Repository do before(:each) do @repository = Rubydora::Repository.new end describe "initialize" do it "should symbolize config keys" do repository = Rubydora::Repository.new "validateChecksum"=> true repository.config[:validateChecksum].should be_true end end describe "client" do it "should return a RestClient resource" do client = @repository.client 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 "profile" do it "should map the fedora repository description to a hash" do @mock_response = mock() @mock_client = mock(RestClient::Resource) @mock_response.should_receive(:get).and_return <<-XML Fedora Repositoryhttp://localhost:8983/fedora3.3 changeme : changeme:100 * example.org : oai:example.org:changeme:100http://localhost:8983/fedora/searchhttp://localhost:8983/fedora/get/demo:5http://localhost:8983/fedora/oai?verb=Identifybob@example.orgsally@example.org XML @mock_client.should_receive(:[]).with('describe?xml=true').and_return(@mock_response) @repository.should_receive(:client).and_return(@mock_client) profile = @repository.profile profile['repositoryVersion'].should == '3.3' end end describe "ping" do it "should raise an error if a connection cannot be established" do @repository.should_receive(:profile).and_return nil lambda { @repository.ping }.should raise_error end it "should return true if a connection is established" do @repository.should_receive(:profile).and_return true @repository.ping.should == true end end describe "load_api_abstraction" do it "should load an abstraction layer for relationships for older versions of the fedora rest api" do Rubydora::Repository.any_instance.stub(:version).and_return(3.3) expect { Rubydora::Repository.new }.to raise_error 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