Skip to content

Commit

Permalink
Remove use of deprecated method load_instance_from_solr
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Aug 10, 2016
1 parent ce08c8b commit adf36d5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def show
wants.html { presenter && parent_presenter }
wants.json do
# load and authorize @curation_concern manually because it's skipped for html
# This has to use #find instead of #load_instance_from_solr because
# we want to return values like file_set_ids in the json
@curation_concern = _curation_concern_type.find(params[:id]) unless curation_concern
authorize! :show, @curation_concern
render :show, status: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def show
wants.html { presenter }
wants.json do
# load and authorize @curation_concern manually because it's skipped for html
self.curation_concern ||= curation_concern_type.load_instance_from_solr(params[:id])
# TODO: is there any reason we couldn't use `presenter' here?
self.curation_concern ||= curation_concern_type.find(params[:id])
authorize! :show, curation_concern
render :show, status: :ok
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def authorize_user!
end

def asset
@asset ||= ActiveFedora::Base.load_instance_from_solr(params[:id])
@asset ||= ActiveFedora::Base.find(params[:id])
end
end
end
27 changes: 23 additions & 4 deletions app/models/concerns/curation_concerns/solr_document_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,35 @@ def to_s
title_or_label
end

class ModelWrapper
def initialize(model, id)
@model = model
@id = id
end

def persisted?
true
end

def to_param
@id
end

def model_name
@model.model_name
end

def to_partial_path
@model._to_partial_path
end
end
##
# Offer the source (ActiveFedora-based) model to Rails for some of the
# Rails methods (e.g. link_to).
# @example
# link_to '...', SolrDocument(:id => 'bXXXXXX5').new => <a href="/dams_object/bXXXXXX5">...</a>
def to_model
@model ||= begin
m = ActiveFedora::Base.load_instance_from_solr(id, self)
m.class == ActiveFedora::Base ? self : m
end
@model ||= ModelWrapper.new(hydra_model, id)
end

def collection?
Expand Down
4 changes: 2 additions & 2 deletions spec/actors/curation_concerns/file_set_actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@
end

it "removes representative, thumbnail, and the proxy association" do
gw = GenericWork.load_instance_from_solr(work.id)
gw = GenericWork.find(work.id)
expect(gw.representative_id).to eq(file_set.id)
expect(gw.thumbnail_id).to eq(file_set.id)
expect { actor.destroy }.to change { ActiveFedora::Aggregation::Proxy.count }.by(-1)
gw = GenericWork.load_instance_from_solr(work.id)
gw = GenericWork.find(work.id)
expect(gw.representative_id).to be_nil
expect(gw.thumbnail_id).to be_nil
end
Expand Down
7 changes: 5 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@
end

config.include FactoryGirl::Syntax::Methods
config.include Devise::TestHelpers, type: :controller
config.include Devise::TestHelpers, type: :view
if defined? Devise::Test::ControllerHelpers
config.include Devise::Test::ControllerHelpers, type: :controller
else
config.include Devise::TestHelpers, type: :controller
end
config.include Warden::Test::Helpers, type: :feature
config.after(:each, type: :feature) { Warden.test_reset! }
config.include Controllers::EngineHelpers, type: :controller
Expand Down
3 changes: 0 additions & 3 deletions spec/views/catalog/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
allow(resp).to receive(:limit_value).and_return(10)
allow(resp).to receive(:empty?).and_return(false)

# This stubs out the SolrDocument#to_model
allow(ActiveFedora::Base).to receive(:load_instance_from_solr).with('abc123', doc).and_return(collection)

assign(:document_list, [doc])
end

Expand Down

0 comments on commit adf36d5

Please sign in to comment.