-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract Transactable behavior to module
- Loading branch information
Tom Johnson
committed
Feb 13, 2016
1 parent
cc0c7da
commit 1201f12
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'rdf/spec' | ||
|
||
RSpec.shared_examples 'an RDF::Transactable' do | ||
include RDF::Spec::Matchers | ||
|
||
let(:statements) { RDF::Spec.quads } | ||
|
||
before do | ||
raise '`transactable` must be set with `let(:transactable)`' unless | ||
defined? transactable | ||
end | ||
|
||
subject { transactable } | ||
|
||
describe "#transaction" do | ||
it 'gives an immutable transaction' do | ||
expect { subject.transaction { insert([]) } }.to raise_error TypeError | ||
end | ||
|
||
it 'commits a successful transaction' do | ||
statement = RDF::Statement(:s, RDF.type, :o) | ||
expect(subject).to receive(:commit_transaction).and_call_original | ||
|
||
expect do | ||
subject.transaction(mutable: true) { insert(statement) } | ||
end.to change { subject.statements }.to include(statement) | ||
end | ||
|
||
it 'rolls back a failed transaction' do | ||
original_contents = subject.statements | ||
expect(subject).to receive(:rollback_transaction).and_call_original | ||
|
||
expect do | ||
subject.transaction(mutable: true) do | ||
delete(*@statements) | ||
raise 'my error' | ||
end | ||
end.to raise_error RuntimeError | ||
|
||
expect(subject.statements).to contain_exactly(*original_contents) | ||
end | ||
end | ||
|
||
|
||
|
||
it '' do | ||
end | ||
end |