Skip to content

Commit 1c94e3a

Browse files
author
Thomas Johnson
committed
Merge pull request #51 from mcritchlow/add-mutable-update-coverage
add test coverage for #update
2 parents ddcb4f5 + 4468927 commit 1c94e3a

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

lib/rdf/spec/mutable.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,63 @@
8484
end
8585
end
8686

87+
context "when updating statements" do
88+
let(:s1) { RDF::Statement(resource, RDF::URI.new("urn:predicate:1"), RDF::URI.new("urn:object:1")) }
89+
let(:s2) { RDF::Statement(resource, RDF::URI.new("urn:predicate:2"), RDF::URI.new("urn:object:2")) }
90+
91+
before :each do
92+
subject.insert(*[s1,s2])
93+
end
94+
95+
after :each do
96+
subject.delete(*[s1,s2])
97+
end
98+
99+
it "should not raise errors" do
100+
s1_updated = RDF::Statement(resource, RDF::URI.new("urn:predicate:1"), RDF::URI.new("urn:object:2"))
101+
expect { subject.update(s1_updated) }.not_to raise_error if subject.mutable?
102+
end
103+
104+
it "should support updating one statement at a time with an object" do
105+
if subject.mutable?
106+
s1_updated = RDF::Statement(resource, RDF::URI.new("urn:predicate:1"), RDF::URI.new("urn:object:2"))
107+
subject.update(s1_updated)
108+
expect(subject.has_statement?(s1_updated)).to be true
109+
expect(subject.has_statement?(s1)).to be false
110+
end
111+
end
112+
113+
it "should support updating one statement at a time without an object" do
114+
if subject.mutable?
115+
s1_deleted = RDF::Statement(resource, RDF::URI.new("urn:predicate:1"), nil)
116+
subject.update(s1_deleted)
117+
expect(subject.has_statement?(s1)).to be false
118+
end
119+
end
120+
121+
it "should support updating an array of statements at a time" do
122+
s1_updated = RDF::Statement(resource, RDF::URI.new("urn:predicate:1"), RDF::URI.new("urn:object:2"))
123+
s2_updated = RDF::Statement(resource, RDF::URI.new("urn:predicate:2"), RDF::URI.new("urn:object:3"))
124+
subject.update(*[s1_updated, s2_updated])
125+
expect(subject.has_statement?(s1_updated)).to be true
126+
expect(subject.has_statement?(s2_updated)).to be true
127+
expect(subject.has_statement?(s1)).to be false
128+
expect(subject.has_statement?(s2)).to be false
129+
end
130+
131+
it "should support updating an enumerable of statements at a time" do
132+
s1_updated = RDF::Statement(resource, RDF::URI.new("urn:predicate:1"), RDF::URI.new("urn:object:2"))
133+
s2_updated = RDF::Statement(resource, RDF::URI.new("urn:predicate:2"), RDF::URI.new("urn:object:3"))
134+
updates = [s1_updated, s2_updated]
135+
updates.extend(RDF::Enumerable)
136+
subject.update(updates)
137+
expect(subject.has_statement?(s1_updated)).to be true
138+
expect(subject.has_statement?(s2_updated)).to be true
139+
expect(subject.has_statement?(s1)).to be false
140+
expect(subject.has_statement?(s2)).to be false
141+
end
142+
end
143+
87144
context "when deleting statements" do
88145
before :each do
89146
subject.insert(*@statements)

0 commit comments

Comments
 (0)