-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2340 from projecthydra/scm_2133
Adding a surveyor to create survey items for an id list
- Loading branch information
Showing
5 changed files
with
94 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Class that will survey Fedora based on a list of ids | ||
module Sufia | ||
module Migration | ||
module Survey | ||
class Surveyor | ||
class << self | ||
# call causes the surveyor to create a survey item for each id in the list | ||
# | ||
# @param [Array] id_list a list of ids to be surveyed | ||
def call(id_list) | ||
ActiveFedora::Base.find(id_list).each do |object| | ||
Item.create(object_id: object.id, object_class: object.class, object_title: object.title, migration_status: :initial_state) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'spec_helper' | ||
|
||
describe Sufia::Migration::Survey::Surveyor, type: :model do | ||
let(:collection) do | ||
Collection.create(title: "title1", creator: ["creator1"], description: "description1") do |col| | ||
col.apply_depositor_metadata("jilluser") | ||
end | ||
end | ||
let(:file) { create :generic_file, title: ["my title"] } | ||
|
||
subject { described_class } | ||
it { is_expected.to respond_to(:call) } | ||
|
||
describe "#call" do | ||
let(:ids) { [object.id] } | ||
subject { Sufia::Migration::Survey::Item.where(object_id: object.id).first } | ||
|
||
before do | ||
described_class.call(ids) | ||
end | ||
|
||
context "when object is a file" do | ||
let(:object) { file } | ||
|
||
it "creates a survey item for a file" do | ||
is_expected.not_to be_nil | ||
expect(subject.object_id).to eq file.id | ||
expect(subject.object_class).to eq "GenericFile" | ||
expect(subject.object_title).to eq file.title.to_s | ||
expect(subject.initial_state?).to be_truthy | ||
end | ||
end | ||
|
||
context "when object is a collection" do | ||
let(:object) { collection } | ||
|
||
it "creates a survey item for a file" do | ||
is_expected.not_to be_nil | ||
expect(subject.object_id).to eq collection.id | ||
expect(subject.object_class).to eq "Collection" | ||
expect(subject.object_title).to eq collection.title.to_s | ||
expect(subject.initial_state?).to be_truthy | ||
end | ||
end | ||
|
||
context "when multiple types of objects are passed" do | ||
let(:ids) { [file.id, collection.id] } | ||
let(:file_survey) { Sufia::Migration::Survey::Item.where(object_id: file.id).first } | ||
let(:collection_survey) { Sufia::Migration::Survey::Item.where(object_id: collection.id).first } | ||
|
||
it "creates a survey item for each" do | ||
expect(file_survey).not_to be_nil | ||
expect(collection_survey).not_to be_nil | ||
end | ||
end | ||
end | ||
|
||
context "when one of the objects does not exist" do | ||
let(:ids) { [file.id, "abc123"] } | ||
|
||
it "Errors with out creating any survey items" do | ||
expect { described_class.call(ids) }.to raise_error(ActiveFedora::ObjectNotFoundError) | ||
expect(Sufia::Migration::Survey::Item.find_by(object_id: file.id)).to be_nil | ||
end | ||
end | ||
end |