Skip to content

Commit

Permalink
Return values for inherited attributes the same way we do for properties
Browse files Browse the repository at this point in the history
  • Loading branch information
awead committed Oct 23, 2015
1 parent f85b4ea commit 573edc2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/active_fedora/attributes.rb
Expand Up @@ -44,7 +44,7 @@ def [](key)
if assoc = self.association(key.to_sym)
# This is for id attributes stored in the rdf graph.
assoc.reader
elsif self.class.properties.key?(key.to_s)
elsif self.class.properties.key?(key.to_s) || self.class.attributes_with_defaults.include?(key.to_s)
# Use the generated method so that single value assetions are single
self.send(key)
else
Expand Down Expand Up @@ -126,6 +126,11 @@ def system_attributes
['has_model', 'create_date', 'modified_date']
end

# From ActiveFedora::FedoraAttributes
def attributes_with_defaults
['type', 'rdf_label']
end

# Attributes that represent associations to other repository objects
def association_attributes
outgoing_reflections.values.map { |reflection| reflection.foreign_key.to_s }
Expand Down
14 changes: 14 additions & 0 deletions spec/integration/base_spec.rb
Expand Up @@ -82,6 +82,7 @@ class MockAFBaseRelationship < ActiveFedora::Base
describe "a saved object" do
before do
class Book < ActiveFedora::Base
type [::RDF::URI("http://www.example.com/Book")]
property :title, predicate: ::RDF::DC.title
end
end
Expand Down Expand Up @@ -133,6 +134,19 @@ class Book < ActiveFedora::Base
}.to change { ActiveFedora::Base.exists?(obj.id) }.from(true).to(false)
end
end

describe "#type" do
subject { obj.type }
it { is_expected.to include(::RDF::URI("http://www.example.com/Book")) }
context "when adding additional types" do
before do
t = obj.get_values(:type)
t << ::RDF::URI("http://www.example.com/Novel")
obj.set_value(:type, t)
end
it { is_expected.to include(::RDF::URI("http://www.example.com/Novel")) }
end
end
end

describe "#apply_schema" do
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/attributes_spec.rb
Expand Up @@ -513,6 +513,13 @@ class BarHistory4 < ActiveFedora::Base
expect(subject[:title]).to eq ['test1']
end
end

context "on Fedora attributes" do
it "should return values" do
expect(subject[:type]).to be_empty
expect(subject[:rdf_label]).to contain_exactly("test1")
end
end
end
end

Expand Down

0 comments on commit 573edc2

Please sign in to comment.