diff --git a/lib/rdf/spec/queryable.rb b/lib/rdf/spec/queryable.rb index 0b23bf8..76954fc 100644 --- a/lib/rdf/spec/queryable.rb +++ b/lib/rdf/spec/queryable.rb @@ -85,26 +85,31 @@ expect(solutions.size).to eq @statements.size end - it "returns statements from unnamed graphss with false graph_name" do + it "returns statements from unnamed graphs with false graph_name" do pattern = RDF::Query::Pattern.new(nil, nil, nil, graph_name: false) solutions = [] subject.send(method, pattern) {|s| solutions << s} - named_statements = subject.statements.reject {|st| st.has_name?}.length - expect(solutions.size).to eq named_statements + + named_statements = subject.statements + named_statements.reject! {|st| st.has_name?} unless + subject.respond_to?(:graph_name) && !subject.graph_name.nil? + + expect(solutions.size).to eq named_statements.size end - it "returns statements from named graphss with variable graph_name" do + it "returns statements from named graphs with variable graph_name" do unless subject.graph_names.to_a.empty? pattern = RDF::Query::Pattern.new(nil, nil, nil, graph_name: :c) solutions = [] subject.send(method, pattern) {|s| solutions << s} - named_statements = subject.statements.select {|st| st.has_name?}.length - expect(solutions.size).to eq named_statements + named_statements = subject.statements.select {|st| st.has_name?} + expect(solutions.size).to eq named_statements.size end end it "returns statements from specific graph with URI graph_name" do - unless subject.graph_names.to_a.empty? + unless subject.graph_names.to_a.empty? || + (subject.respond_to?(:graph_name) && !subject.graph_name.nil?) pattern = RDF::Query::Pattern.new(nil, nil, nil, graph_name: RDF::URI("http://ar.to/#self")) solutions = [] subject.send(method, pattern) {|s| solutions << s} diff --git a/lib/rdf/spec/transaction.rb b/lib/rdf/spec/transaction.rb index 5685c3a..65a7d8c 100644 --- a/lib/rdf/spec/transaction.rb +++ b/lib/rdf/spec/transaction.rb @@ -20,9 +20,29 @@ require 'rdf/spec/queryable' let(:queryable) do repository.insert(*RDF::Spec.quads) - q = klass.new(repository, mutable: true) + klass.new(repository) end it_behaves_like 'an RDF::Queryable' + + context 'with a graph_name' do + let(:queryable) do + graph_name = RDF::URI('g') + graph = RDF::Graph.new(graph_name: graph_name, data: repository) + graph.insert(*RDF::Spec.quads) + klass.new(repository, graph_name: graph_name) + end + it_behaves_like 'an RDF::Queryable' + end + + context 'with a false graph_name' do + let(:queryable) do + graph = RDF::Graph.new(data: repository) + graph.insert(*RDF::Spec.quads) + graph_name = false + klass.new(repository, graph_name: graph_name) + end + it_behaves_like 'an RDF::Queryable' + end end describe "#initialize" do @@ -128,17 +148,17 @@ expect(subject.repository).to have_statement(st) end - it 'retains existing graph names' do + it 'overwrites existing graph names' do st.graph_name = RDF::URI('g') repository.insert(st) expect do subject.delete(st) subject.execute - end.to change { subject.repository.statements }.to be_empty + end.not_to change { subject.repository.statements } end - it 'retains existing default graph name' do + it 'overwrites existing default graph name' do st.graph_name = false repository.insert(st) @@ -146,7 +166,7 @@ expect do subject.delete(st) subject.execute - end.to change { subject.repository.statements }.to be_empty + end.not_to change { subject.repository.statements } end end end @@ -200,26 +220,32 @@ expect(subject.repository).to have_statement(with_name) end - it 'retains existing graph names' do + it 'overwrites existing graph names' do st.graph_name = RDF::URI('g') - + with_name = st.dup + with_name.graph_name = graph_uri + expect do subject.insert(st) subject.execute end.to change { subject.repository.statements } - expect(subject.repository).to have_statement(st) + expect(subject.repository).not_to have_statement(st) + expect(subject.repository).to have_statement(with_name) end - it 'retains existing default graph name' do + it 'overwrites existing default graph name' do st.graph_name = false - - expect do + with_name = st.dup + with_name.graph_name = graph_uri + + expect do subject.insert(st) subject.execute end.to change { subject.repository.statements } - - expect(subject.repository).to have_statement(st) + + expect(subject.repository).not_to have_statement(st) + expect(subject.repository).to have_statement(with_name) end end end