From 549780ef88f61597043cc571dd16970bee899778 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Fri, 12 Feb 2016 10:42:52 -0800 Subject: [PATCH 1/3] Expect an error to be raised if trying `Repository#transaction` when the repository does not support transactions. --- lib/rdf/spec/repository.rb | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/rdf/spec/repository.rb b/lib/rdf/spec/repository.rb index db7ac9f..80dbb03 100644 --- a/lib/rdf/spec/repository.rb +++ b/lib/rdf/spec/repository.rb @@ -42,7 +42,16 @@ end end - describe "#transaction" do + describe '#transaction' do + it 'is not implemented when #supports(:transactions) is false' do + unless subject.supports?(:transactions) + expect { subject.transaction }.to raise_error NotImplementedError + end + end + end + + context "with transaction support" do + before {skip "Does not support Transactions" unless subject.supports?(:transactions)} it 'gives an immutable transaction' do expect { subject.transaction { insert([]) } }.to raise_error TypeError end @@ -73,15 +82,16 @@ end end - context "with snapshot support" do - - describe '#snapshot' do - it 'is not implemented when #supports(:snapshots) is false' do - unless subject.supports?(:snapshots) - expect { subject.snapshot }.to raise_error NotImplementedError - end + describe '#snapshot' do + it 'is not implemented when #supports(:snapshots) is false' do + unless subject.supports?(:snapshots) + expect { subject.snapshot }.to raise_error NotImplementedError end end + end + + context "with snapshot support" do + before {skip "Does not support Snapshots" unless subject.supports?(:snapshots)} it 'returns a queryable #snapshot' do if subject.supports? :snapshots From 67107a232fe377ba4a593bea32270bb7d1b7ad7c Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Fri, 12 Feb 2016 10:58:48 -0800 Subject: [PATCH 2/3] Fix "commits a successful transaction" to clear the repository before checking to see that it is updated properly. --- lib/rdf/spec/repository.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/rdf/spec/repository.rb b/lib/rdf/spec/repository.rb index 80dbb03..3068791 100644 --- a/lib/rdf/spec/repository.rb +++ b/lib/rdf/spec/repository.rb @@ -57,6 +57,7 @@ end it 'commits a successful transaction' do + subject.clear! statement = RDF::Statement(:s, RDF.type, :o) expect(subject).to receive(:commit_transaction).and_call_original From 93e4172e56fb3cd9b0fb9c0f05ea9df51c952459 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Fri, 12 Feb 2016 11:21:50 -0800 Subject: [PATCH 3/3] Change back #transaction tests, but don't try to do updating transaction unless the subject is mutable. --- lib/rdf/spec/repository.rb | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/lib/rdf/spec/repository.rb b/lib/rdf/spec/repository.rb index 3068791..6841b0e 100644 --- a/lib/rdf/spec/repository.rb +++ b/lib/rdf/spec/repository.rb @@ -42,30 +42,23 @@ end end - describe '#transaction' do - it 'is not implemented when #supports(:transactions) is false' do - unless subject.supports?(:transactions) - expect { subject.transaction }.to raise_error NotImplementedError - end - end - end - - context "with transaction support" do - before {skip "Does not support Transactions" unless subject.supports?(:transactions)} + describe "#transaction'" do it 'gives an immutable transaction' do expect { subject.transaction { insert([]) } }.to raise_error TypeError end it 'commits a successful transaction' do - subject.clear! - statement = RDF::Statement(:s, RDF.type, :o) - expect(subject).to receive(:commit_transaction).and_call_original + if subject.mutable? + subject.clear! + statement = RDF::Statement(:s, RDF.type, :o) + expect(subject).to receive(:commit_transaction).and_call_original - expect do - subject.transaction(mutable: true) do - insert(statement) - end - end.to change { subject.statements }.to contain_exactly(statement) + expect do + subject.transaction(mutable: true) do + insert(statement) + end + end.to change { subject.statements }.to contain_exactly(statement) + end end it 'rolls back a failed transaction' do