Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #869 from psu-libraries/i#656
Browse files Browse the repository at this point in the history
allowing work type to have any case
  • Loading branch information
awead committed Mar 13, 2019
2 parents c852864 + d5b5fcc commit c6231ce
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ RSpec/NestedGroups:
- 'spec/cho/schema/metadata_field_change_set_spec.rb'
- 'spec/cho/shared/item_factory_spec.rb'
- 'spec/cho/work/submissions/change_set_spec.rb'
- 'spec/cho/work/import/work_hash_validator_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
Expand Down
1 change: 1 addition & 0 deletions app/cho/work/import/work_hash_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def clean_hash
def work_type
@work_type ||= begin
label = resource_hash.fetch('work_type', nil)
label = label.downcase.titleize if label.present?
Work::Type.find_using(label: label).first
end
end
Expand Down
58 changes: 58 additions & 0 deletions spec/cho/work/import/work_hash_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

let(:collection) { create :library_collection }
let(:generic_work_type) { Work::Type.find_using(label: 'Generic').first }
let(:still_image_work_type) { Work::Type.find_using(label: 'Still Image').first }

describe '#change_set' do
subject(:change_set) { reader.change_set }
Expand All @@ -32,6 +33,63 @@
expect(change_set.work_type_id).to eq(generic_work_type.id)
expect(change_set.member_of_collection_ids).to eq(collection.id)
end

context 'with a work type properly cased' do
let(:work_hash) do
{
'member_of_collection_ids' => [collection.id],
'work_type' => 'Still Image',
'title' => 'my awesome work',
'description' => ''
}
end

it 'is valid and has a work type set' do
expect(change_set).to be_a(Work::SubmissionChangeSet)
expect(change_set).to be_valid
expect(change_set.model).to be_a(Work::Submission)
expect(change_set.work_type_id).to eq(still_image_work_type.id)
expect(change_set.member_of_collection_ids).to eq(collection.id)
end
end

context 'with a work type improperly upper cased' do
let(:work_hash) do
{
'member_of_collection_ids' => [collection.id],
'work_type' => 'GENERIC',
'title' => 'my awesome work',
'description' => ''
}
end

it 'is valid and has a work type set' do
expect(change_set).to be_a(Work::SubmissionChangeSet)
expect(change_set).to be_valid
expect(change_set.model).to be_a(Work::Submission)
expect(change_set.work_type_id).to eq(generic_work_type.id)
expect(change_set.member_of_collection_ids).to eq(collection.id)
end
end

context 'with a work type improperly lower cased' do
let(:work_hash) do
{
'member_of_collection_ids' => [collection.id],
'work_type' => 'geNeric',
'title' => 'my awesome work',
'description' => ''
}
end

it 'is valid and has a work type set' do
expect(change_set).to be_a(Work::SubmissionChangeSet)
expect(change_set).to be_valid
expect(change_set.model).to be_a(Work::Submission)
expect(change_set.work_type_id).to eq(generic_work_type.id)
expect(change_set.member_of_collection_ids).to eq(collection.id)
end
end
end

context 'invalid new work' do
Expand Down

0 comments on commit c6231ce

Please sign in to comment.