Skip to content

Commit

Permalink
Setting type should not wipe out properties. Fixes #737
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Mar 27, 2015
1 parent b038a4f commit a2780cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/active_fedora/fedora_attributes.rb
Expand Up @@ -65,9 +65,12 @@ def resource
module ClassMethods
# We make a unique class, because properties belong to a class.
# This keeps properties from different objects separate.
# Since the copy of properties can only happen once, we don't want to invoke it
# until all properties have been defined.
def resource_class
@generated_resource_class ||= begin
klass = self.const_set(:GeneratedResourceSchema, Class.new(ActiveTriples::Resource))
klass.configure type: @type if @type
klass.properties.merge(self.properties).each do |property, config|
klass.property(config.term,
predicate: config.predicate,
Expand All @@ -77,8 +80,9 @@ def resource_class
end
end

# Set the rdf type for this class
def type(uri)
resource_class.configure type: uri
@type = uri
end
end
end
Expand Down
10 changes: 9 additions & 1 deletion spec/unit/base_spec.rb
Expand Up @@ -32,15 +32,23 @@ class FooHistory < ActiveFedora::Base
before do
class FooHistory < ActiveFedora::Base
type ::RDF::URI.new('http://example.com/foo')
property :title, predicate: ::RDF::DC.title
end
end
after do
Object.send(:remove_const, :FooHistory)
end

subject { FooHistory.new().type }
subject { FooHistory.new.type }

it { is_expected.to eq [RDF::URI('http://example.com/foo')] }

context "when type is called before propertes" do
subject { FooHistory.resource_class.reflect_on_property(:title) }
it "should not wipe out the properties" do
expect(subject).to be_kind_of ActiveTriples::NodeConfig
end
end
end

describe 'descendants' do
Expand Down

0 comments on commit a2780cd

Please sign in to comment.