Skip to content

Commit

Permalink
pulls in some missing presenter and form classes from Sufia
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingzumwalt committed Jul 8, 2015
1 parent f14951a commit f64db2f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 4 deletions.
9 changes: 9 additions & 0 deletions app/forms/curation_concerns/forms/generic_work_edit_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module CurationConcerns
module Forms
class GenericWorkEditForm < GenericWorkPresenter
include HydraEditor::Form
include HydraEditor::Form::Permissions
self.required_fields = [:title, :creator, :tag, :rights]
end
end
end
13 changes: 13 additions & 0 deletions app/presenters/curation_concerns/generic_work_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module CurationConcerns
class GenericWorkPresenter
include Hydra::Presenter
self.model_class = GenericWork
# Terms is the list of fields displayed
self.terms = [:resource_type, :title, :creator, :contributor, :description, :tag, :rights,
:publisher, :date_created, :subject, :language, :identifier, :based_near, :related_url]

# Depositor and permissions are not displayed
# so don't include them in `terms'.
delegate :depositor, :permissions, to: :model
end
end
33 changes: 33 additions & 0 deletions spec/forms/generic_file_edit_form_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'

describe CurationConcerns::Forms::GenericFileEditForm do
subject { described_class.new(GenericFile.new) }

describe "#terms" do
it "should return a list" do
expect(subject.terms).to eq([:resource_type, :title, :creator, :contributor, :description, :tag,
:rights, :publisher, :date_created, :subject, :language, :identifier, :based_near, :related_url])
end

it "doesn't contain fields that users shouldn't be allowed to edit" do
# date_uploaded is reserved for the original creation date of the record.
expect(subject.terms).not_to include(:date_uploaded)
end
end

it "should initialize multivalued fields" do
expect(subject.title).to eq ['']
end

describe ".model_attributes" do
let(:params) { ActionController::Parameters.new(title: ['foo'], description: [''], "permissions_attributes"=>{"2"=>{"access"=>"edit", "_destroy"=>"true", "id"=>"a987551e-b87f-427a-8721-3e5942273125"}})}
subject { described_class.model_attributes(params) }

it "should only change title" do
expect(subject['title']).to eq ["foo"]
expect(subject['description']).to be_empty
expect(subject['permissions_attributes']).to eq("2" => {"access"=>"edit", "id"=>"a987551e-b87f-427a-8721-3e5942273125", "_destroy"=>"true"})
end
end

end
4 changes: 2 additions & 2 deletions spec/jobs/import_url_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# allow(CharacterizeJob).to receive(:new).with(generic_file.id).and_return(s2)
# expect(CurationConcerns.queue).to receive(:push).with(s2).once
#
# expect(Sufia::GenericFile::Actor).to receive(:virus_check).and_return(false)
# expect(CurationConcerns::GenericFileActor).to receive(:virus_check).and_return(false)
# end
#
# xit "should create a content datastream" do
Expand All @@ -59,7 +59,7 @@
# allow(CharacterizeJob).to receive(:new).with(generic_file.id).never
# end
# xit "should abort if virus check fails" do
# allow(Sufia::GenericFile::Actor).to receive(:virus_check).and_raise(Sufia::VirusFoundError.new('A virus was found'))
# allow(CurationConcerns::GenericFileActor).to receive(:virus_check).and_raise(Sufia::VirusFoundError.new('A virus was found'))
# job.run
# expect(user.mailbox.inbox.first.subject).to eq("File Import Error")
# end
Expand Down
4 changes: 2 additions & 2 deletions spec/jobs/ingest_local_file_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#
# describe "virus checking" do
# it "should run virus check" do
# expect(Sufia::GenericFile::Actor).to receive(:virus_check).and_return(0)
# expect(CurationConcerns::GenericFileActor).to receive(:virus_check).and_return(0)
# job.run
# end
# it "should abort if virus check fails" do
# allow(Sufia::GenericFile::Actor).to receive(:virus_check).and_raise(Sufia::VirusFoundError.new('A virus was found'))
# allow(CurationConcerns::GenericFileActor).to receive(:virus_check).and_raise(Sufia::VirusFoundError.new('A virus was found'))
# job.run
# expect(user.mailbox.inbox.first.subject).to eq("Local file ingest error")
# end
Expand Down
16 changes: 16 additions & 0 deletions spec/presenters/curation_concerns/generic_file_presenter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe CurationConcerns::GenericFilePresenter do

describe ".terms" do
it "should return a list" do
expect(described_class.terms).to eq([:resource_type, :title,
:creator, :contributor, :description, :tag, :rights, :publisher,
:date_created, :subject, :language, :identifier, :based_near,
:related_url])
end
end

let(:presenter) { CurationConcerns::GenericFilePresenter.new(file) }

end

0 comments on commit f64db2f

Please sign in to comment.