Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media type not required #947

Draft
wants to merge 15 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion app/forms/hyrax/physical_instantiation_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PhysicalInstantiationForm < Hyrax::Forms::WorkForm
:keyword, :license, :rights_statement, :publisher, :subject, :identifier, :based_near, :related_url,
:bibliographic_citation, :source]
self.required_fields -= [:creator, :keyword, :rights_statement]
self.required_fields += [:format, :location, :media_type, :holding_organization]
self.required_fields += [:format, :location, :holding_organization]

self.single_valued_fields = [:title]

Expand Down
2 changes: 1 addition & 1 deletion app/forms/physical_instantiation_resource_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PhysicalInstantiationResourceForm < Hyrax::Forms::ResourceForm(PhysicalIns

attr_accessor :controller, :current_ability

self.required_fields += [:format, :location, :media_type, :holding_organization]
self.required_fields += [:format, :location, :holding_organization]

self.single_valued_fields = [:title]

Expand Down
1 change: 0 additions & 1 deletion app/models/digital_instantiation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class DigitalInstantiation < ActiveFedora::Base

validates :location, presence: { message: 'Your work must have a Location.' }
validates :digital_format, presence: { message: 'Your work must have a Digital Format.' }
validates :media_type, presence: { message: 'Your work must have a Media Type.' }
validates :duration, format: { with: AMS::TimeCodeService.regex, allow_blank: true, message: "Invalid format for duration. Use HH:MM:SS, H:MM:SS, MM:SS, or M:SS" }
validates :time_start, format: { with: AMS::TimeCodeService.regex, allow_blank: true, message: "Invalid format for time start. Use HH:MM:SS, H:MM:SS, MM:SS, or M:SS" }

Expand Down
1 change: 0 additions & 1 deletion app/models/digital_instantiation_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def aapb_invalid_message
msg = []
msg << "#{self.id} title is required" unless title.present?
msg << "#{self.id} location is required" unless location.present?
msg << "#{self.id} media_type is required" unless media_type.present?
msg << "#{self.id} holding_organization is required" unless holding_organization.present?
msg.to_sentence if msg.present?
end
Expand Down
1 change: 0 additions & 1 deletion app/models/physical_instantiation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class PhysicalInstantiation < ActiveFedora::Base

validates :format, presence: { message: 'Your work must have a format.' }
validates :location, presence: { message: 'Your work must have a location.' }
validates :media_type, presence: { message: 'Your work must have a media type.' }
validates :duration, format: { with: AMS::TimeCodeService.regex, allow_blank: true, message: "Invalid format for duration. Use HH:MM:SS, H:MM:SS, MM:SS, or M:SS" }
# Custom validation block for time_start multi-valued field.
validate do |physical_instantiation|
Expand Down
1 change: 0 additions & 1 deletion app/models/physical_instantiation_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def aapb_invalid_message
msg = []
msg << "#{self.id} format is required" unless format.present?
msg << "#{self.id} location is required" unless location.present?
msg << "#{self.id} media_type is required" unless media_type.present?
msg << "#{self.id} holding_organization is required" unless holding_organization.present?
msg.to_sentence if msg.present?
end
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/digital_instantiation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
media_type { "Sound" }
end

trait :without_media_type do
media_type { nil }
end

transient do
# Pass in InstantiationAdminData.gid or it will create one for you!
with_instantiation_admin_data { false }
Expand Down
8 changes: 8 additions & 0 deletions spec/factories/physical_instantiation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
local_instantiation_identifier { [ "1234" ] }
location { "Test location" }
media_type { "Test media_type" }

trait :without_media_type do
media_type { nil }
end
end

factory :minimal_physical_instantiation, class: PhysicalInstantiation do
Expand All @@ -16,5 +20,9 @@
annotation { ["Minimal annotation"] }
location { "Minimal location" }
media_type { "Minimal media_type" }

trait :without_media_type do
media_type { nil }
end
end
end
8 changes: 7 additions & 1 deletion spec/models/digital_instantiation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@
expect(digital_instantiation.resource.dump(:ttl)).to match(/terms\/type/)
expect(digital_instantiation.media_type.include?("Test media_type")).to be true
end

it "handles absence of media_type gracefully" do
digital_instantiation.media_type = nil
expect(digital_instantiation.resource.dump(:ttl)).not_to match(/terms\/type/)
expect(digital_instantiation.media_type).to be_nil
end
end

context "generations" do
let(:digital_instantiation) { FactoryBot.build(:digital_instantiation) }
it "has generations" do
Expand Down
6 changes: 6 additions & 0 deletions spec/models/physical_instantiation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
expect(physical_instantiation.resource.dump(:ttl)).to match(/terms\/type/)
expect(physical_instantiation.media_type.include?("Test media_type")).to be true
end

it "handles absence of media_type gracefully" do
physical_instantiation.media_type = nil
expect(physical_instantiation.resource.dump(:ttl)).not_to match(/terms\/type/)
expect(physical_instantiation.media_type).to be_nil
end
end

context "generations" do
Expand Down
Loading