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

Fix ActiveFedora::Inheritance.base_class for deep File descendants #1211

Merged
merged 1 commit into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/active_fedora/inheritance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module ClassMethods
# If B < A and C < B and if A is an abstract_class then both B.base_class
# and C.base_class would return B as the answer since A is an abstract_class.
def base_class
return File if self == File || superclass == File
return File if self <= File

unless self <= Base
raise ActiveFedoraError, "#{name} doesn't belong in a hierarchy descending from ActiveFedora"
Expand Down
26 changes: 26 additions & 0 deletions spec/unit/inheritance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class MyDS < ActiveFedora::File
class MySample < ActiveFedora::File
end

class MyDeepSample < MySample
end

class Foo < ActiveFedora::Base
has_subresource 'foostream', class_name: 'MyDS'
has_subresource 'dcstream', class_name: 'MySample'
Expand All @@ -16,6 +19,9 @@ class Foo < ActiveFedora::Base
class Bar < ActiveFedora::Base
has_subresource 'barstream', class_name: 'MyDS'
end

class Baz < Bar
end
end

subject(:attached_files) { f.attached_files }
Expand All @@ -25,10 +31,30 @@ class Bar < ActiveFedora::Base
expect(attached_files.values).to match_array [MyDS, MySample]
end

context 'base_class' do
it 'shallow < Base' do
expect(Bar.base_class).to eq(Bar)
end

it 'deep < Base' do
expect(Baz.base_class).to eq(Bar)
end

it 'shallow < File' do
expect(MySample.base_class).to eq(ActiveFedora::File)
end

it 'deep < File' do
expect(MyDeepSample.base_class).to eq(ActiveFedora::File)
end
end

after do
Object.send(:remove_const, :Baz)
Object.send(:remove_const, :Bar)
Object.send(:remove_const, :Foo)
Object.send(:remove_const, :MyDS)
Object.send(:remove_const, :MyDeepSample)
Object.send(:remove_const, :MySample)
end
end