Skip to content

Commit 3725aca

Browse files
author
Tom Johnson
committed
Test Transaction#graph_name
1 parent fb1eadb commit 3725aca

1 file changed

Lines changed: 62 additions & 1 deletion

File tree

lib/rdf/spec/transaction.rb

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Pass in an instance of RDF::Transaction as follows:
44
#
5-
# it_behaves_like "RDF::Transaction", RDF::Transaction
5+
# it_behaves_like "an RDF::Transaction", RDF::Transaction
66
shared_examples "an RDF::Transaction" do |klass|
77
include RDF::Spec::Matchers
88

@@ -40,6 +40,17 @@
4040
it 'allows mutability' do
4141
expect(klass.new(repository, mutable: true)).to be_mutable
4242
end
43+
44+
it 'accepts a graph_name' do
45+
graph_uri = RDF::URI('http://example.com/graph_1')
46+
47+
expect(klass.new(repository, graph_name: graph_uri).graph_name)
48+
.to eq graph_uri
49+
end
50+
51+
it 'defaults graph_name to nil' do
52+
expect(klass.new(repository).graph_name).to be_nil
53+
end
4354
end
4455

4556
it "does not respond to #load" do
@@ -96,6 +107,27 @@
96107
subject.execute
97108
end.to change { subject.repository.empty? }.from(false).to(true)
98109
end
110+
111+
context 'with a graph_name' do
112+
subject { klass.new(repository, mutable: true, graph_name: graph_uri) }
113+
114+
let(:graph_uri) { RDF::URI('http://example.com/graph_1') }
115+
116+
it 'adds the graph_name to statements' do
117+
subject.repository.insert(st)
118+
with_name = st.dup
119+
with_name.graph_name = graph_uri
120+
subject.repository.insert(with_name)
121+
122+
expect do
123+
subject.delete(st)
124+
subject.execute
125+
end.to change { subject.repository.statements }
126+
127+
expect(subject.repository).not_to have_statement(with_name)
128+
expect(subject.repository).to have_statement(st)
129+
end
130+
end
99131
end
100132

101133
describe "#insert" do
@@ -129,6 +161,35 @@
129161
end.to change { subject.repository.statements }
130162
.to contain_exactly(*sts)
131163
end
164+
165+
context 'with a graph_name' do
166+
subject { klass.new(repository, mutable: true, graph_name: graph_uri) }
167+
168+
let(:graph_uri) { RDF::URI('http://example.com/graph_1') }
169+
170+
it 'adds the graph_name to statements' do
171+
with_name = st.dup
172+
with_name.graph_name = graph_uri
173+
174+
expect do
175+
subject.insert(st)
176+
subject.execute
177+
end.to change { subject.repository }
178+
179+
expect(subject.repository).to have_statement(with_name)
180+
end
181+
182+
it 'retains existing graph names' do
183+
st.graph_name = RDF::URI('g')
184+
185+
expect do
186+
subject.insert(st)
187+
subject.execute
188+
end.to change { subject.repository.statements }
189+
190+
expect(subject.repository).to have_statement(st)
191+
end
192+
end
132193
end
133194

134195
describe '#execute' do

0 commit comments

Comments
 (0)