diff --git a/app/controllers/concerns/sufia/works_controller_behavior.rb b/app/controllers/concerns/sufia/works_controller_behavior.rb index 1fb547a4d9..88b07bf473 100644 --- a/app/controllers/concerns/sufia/works_controller_behavior.rb +++ b/app/controllers/concerns/sufia/works_controller_behavior.rb @@ -9,8 +9,8 @@ module WorksControllerBehavior end module ClassMethods - # We don't want the breadcrumb action to occur until after the concern has - # been loaded and authorized + # We don't want the actions to occur until after the concern has been loaded and authorized + # @note this is a terribly side-effecty kludge def curation_concern_type=(curation_concern_type) super before_action :build_breadcrumbs, only: [:edit, :show] diff --git a/app/jobs/batch_create_job.rb b/app/jobs/batch_create_job.rb index e01f7ee905..22c3de5ce6 100644 --- a/app/jobs/batch_create_job.rb +++ b/app/jobs/batch_create_job.rb @@ -24,9 +24,9 @@ def perform(user, titles, resource_types, uploaded_files, attributes, log) private def create(user, titles, resource_types, uploaded_files, attributes, log) + model = attributes.delete(:model) || attributes.delete('model') + raise ArgumentError, 'attributes must include "model" => ClassName.to_s' unless model uploaded_files.each do |upload_id| - model = attributes.delete(:model) || attributes.delete('model') - raise ArgumentError, 'attributes must include "model" => ClassName.to_s' unless model title = [titles[upload_id]] if titles[upload_id] resource_type = [resource_types[upload_id]] if resource_types[upload_id] attributes = attributes.merge(uploaded_files: [upload_id], diff --git a/spec/features/edit_work_spec.rb b/spec/features/edit_work_spec.rb index a48a5436e2..92ffc8e301 100644 --- a/spec/features/edit_work_spec.rb +++ b/spec/features/edit_work_spec.rb @@ -11,6 +11,7 @@ context 'when the user changes permissions' do it 'confirms copying permissions to files using Sufia layout' do + # e.g. /concern/generic_works/jq085k20z/edit visit edit_curation_concerns_generic_work_path(work) choose('generic_work_visibility_open') check('agreement') diff --git a/spec/jobs/batch_create_job_spec.rb b/spec/jobs/batch_create_job_spec.rb index a85bf2cc2c..76c5bbd811 100644 --- a/spec/jobs/batch_create_job_spec.rb +++ b/spec/jobs/batch_create_job_spec.rb @@ -5,25 +5,19 @@ before do allow(CharacterizeJob).to receive(:perform_later) allow(CurationConcerns.config.callback).to receive(:run) - allow(CurationConcerns.config.callback).to receive(:set?) - .with(:after_batch_create_success) - .and_return(true) - allow(CurationConcerns.config.callback).to receive(:set?) - .with(:after_batch_create_failure) - .and_return(true) + allow(CurationConcerns.config.callback).to receive(:set?).with(:after_batch_create_success).and_return(true) + allow(CurationConcerns.config.callback).to receive(:set?).with(:after_batch_create_failure).and_return(true) end describe "#perform" do - let(:file1) { File.open(fixture_path + '/world.png') } - let(:file2) { File.open(fixture_path + '/image.jp2') } - let(:upload1) { Sufia::UploadedFile.create(user: user, file: file1) } - let(:upload2) { Sufia::UploadedFile.create(user: user, file: file2) } + let(:upload1) { Sufia::UploadedFile.create(user: user, file: File.open(fixture_path + '/world.png')) } + let(:upload2) { Sufia::UploadedFile.create(user: user, file: File.open(fixture_path + '/image.jp2')) } let(:title) { { upload1.id.to_s => 'File One', upload2.id.to_s => 'File Two' } } let(:resource_types) { { upload1.id.to_s => 'Article', upload2.id.to_s => 'Image' } } let(:metadata) { { keyword: [], model: 'GenericWork' } } let(:uploaded_files) { [upload1.id.to_s, upload2.id.to_s] } - let(:errors) { double(full_messages: "It's broke!") } - let(:work) { double(errors: errors) } + # let(:errors) { double(full_messages: "It's broke!") } + let(:work) { build(:generic_work) } let(:actor) { double(curation_concern: work) } subject do @@ -36,7 +30,7 @@ end it "updates work metadata" do - expect(CurationConcerns::CurationConcern).to receive(:actor).and_return(actor).twice + expect(CurationConcerns::CurationConcern).to receive(:actor).with(an_instance_of(GenericWork), user).and_return(actor).twice expect(actor).to receive(:create).with(keyword: [], title: ['File One'], resource_type: ["Article"], uploaded_files: ['1']).and_return(true) expect(actor).to receive(:create).with(keyword: [], title: ['File Two'], resource_type: ["Image"], uploaded_files: ['2']).and_return(true) expect(CurationConcerns.config.callback).to receive(:run).with(:after_batch_create_success, user) @@ -46,24 +40,19 @@ end context "when permissions_attributes are passed" do - let(:metadata) do - { "permissions_attributes" => [{ "type" => "group", "name" => "public", "access" => "read" }] } - end + let(:permissions) { { 'permissions_attributes' => [{ 'type' => 'group', 'name' => 'public', 'access' => 'read' }] } } + let(:metadata) { super().merge(permissions) } it "sets the groups" do subject - work = GenericWork.last - expect(work.read_groups).to include "public" + expect(GenericWork.last.read_groups).to include "public" end end context "when visibility is passed" do - let(:metadata) do - { "visibility" => 'open' } - end + let(:metadata) { super().merge('visibility' => 'open') } it "sets public read access" do subject - work = GenericWork.last - expect(work.reload.read_groups).to eq ['public'] + expect(GenericWork.last.reload.read_groups).to eq ['public'] end end