Skip to content

Commit

Permalink
[WIP] don't change child nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Johnson committed Jan 21, 2016
1 parent 6c821af commit 5526422
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/active_triples/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ def value_to_node(val)
def add_child_node(resource, object = nil)
parent.insert [rdf_subject, predicate, resource.rdf_subject]

resource = resource.dup
unless resource.frozen? ||
resource == parent ||
resource.persistence_strategy.is_a?(ParentStrategy) ||
(parent.persistence_strategy.is_a?(ParentStrategy) &&
parent.persistence_strategy.ancestors.include?(resource))
parent.persistence_strategy.ancestors.find { |a| a.eql? resource })
resource.set_persistence_strategy(ParentStrategy)
resource.parent = parent
end
Expand Down
17 changes: 11 additions & 6 deletions spec/active_triples/rdf_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -500,18 +500,23 @@ class SourceWithCreator
describe 'capturing child nodes' do
let(:other) { source_class.new }

it 'captures a child node' do
it 'adds child node data to own graph' do
other << RDF::Statement(:s, RDF::URI('p'), 'o')
expect { subject.set_value(RDF::OWL.sameAs, other) }
.to change { other.persistence_strategy }
.to(ActiveTriples::ParentStrategy)
expect(other.persistence_strategy.parent).to eq subject
.to change { subject.statements.to_a }.to include(*other.statements.to_a)
end

it 'does not change persistence strategy of added node' do
expect { subject.set_value(RDF::OWL.sameAs, other) }
.not_to change { other.persistence_strategy }
end

it 'does not capture a child node when it already persists to a parent' do
third = source_class.new
third.set_value(RDF::OWL.sameAs, other)

expect { subject.set_value(RDF::OWL.sameAs, other) }

child_other = third.get_values(RDF::OWL.sameAs).first
expect { subject.set_value(RDF::OWL.sameAs, child_other) }
.not_to change { other.persistence_strategy.parent }
end
end
Expand Down

0 comments on commit 5526422

Please sign in to comment.