From 7b556774db68387a1eb1ae2eaa78d4cb61df9888 Mon Sep 17 00:00:00 2001 From: Hector Correa Date: Tue, 13 Jan 2015 15:48:20 -0500 Subject: [PATCH] Warn user when initial connection to Fedora fails and the URL does not end with /rest --- lib/active_fedora/fedora.rb | 3 +++ spec/unit/active_fedora_spec.rb | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/active_fedora/fedora.rb b/lib/active_fedora/fedora.rb index 2e660ff26..4f8b52cdc 100644 --- a/lib/active_fedora/fedora.rb +++ b/lib/active_fedora/fedora.rb @@ -26,6 +26,9 @@ def init_base_path ActiveFedora::Base.logger.info "Attempted to init base path `#{root_resource_path}`, but it already exists" if ActiveFedora::Base.logger return false rescue Ldp::NotFound + if !host.downcase.end_with?("/rest") + ActiveFedora::Base.logger.warn "Fedora URL (#{host}) does not end with /rest. This could be the problem. Check your fedora.yml config" + end connection.put(root_resource_path, BLANK).success? end diff --git a/spec/unit/active_fedora_spec.rb b/spec/unit/active_fedora_spec.rb index 4b5e6ecd8..fb592e460 100644 --- a/spec/unit/active_fedora_spec.rb +++ b/spec/unit/active_fedora_spec.rb @@ -15,6 +15,24 @@ restore_spec_configuration end + describe "validate Fedora URL" do + + let(:good_url) { ActiveFedora.fedora_config.credentials[:url] } + let(:bad_url) { good_url.gsub('/rest', '/') } + + it "should connect OK" do + expect(ActiveFedora::Base.logger).to_not receive(:warn) + ActiveFedora::Fedora.new(:url => good_url, :base_path => '/test') + end + + it "should not connect and warn" do + expect { + expect(ActiveFedora::Base.logger).to receive(:warn) + ActiveFedora::Fedora.new(:url => bad_url, :base_path => '/test') + }.to raise_error Ldp::HttpError + end + end + describe "initialization methods" do describe "environment" do it "should use config_options[:environment] if set" do