File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323 require 'rdf/spec/dataset'
2424 it_behaves_like 'an RDF::Dataset'
2525 end
26+
27+ context 'as transactable' do
28+ require 'rdf/spec/transactable'
29+ let ( :transactable ) { repository }
30+ it_behaves_like 'an RDF::Transactable'
31+ end
2632
2733 context "when updating" do
2834 require 'rdf/spec/mutable'
Original file line number Diff line number Diff line change 1+ require 'rdf/spec'
2+
3+ RSpec . shared_examples 'an RDF::Transactable' do
4+ include RDF ::Spec ::Matchers
5+
6+ let ( :statements ) { RDF ::Spec . quads }
7+
8+ before do
9+ raise '`transactable` must be set with `let(:transactable)`' unless
10+ defined? transactable
11+ end
12+
13+ subject { transactable }
14+
15+ describe "#transaction" do
16+ it 'gives an immutable transaction' do
17+ expect { subject . transaction { insert ( [ ] ) } } . to raise_error TypeError
18+ end
19+
20+ it 'commits a successful transaction' do
21+ statement = RDF ::Statement ( :s , RDF . type , :o )
22+ expect ( subject ) . to receive ( :commit_transaction ) . and_call_original
23+
24+ expect do
25+ subject . transaction ( mutable : true ) { insert ( statement ) }
26+ end . to change { subject . statements } . to include ( statement )
27+ end
28+
29+ it 'rolls back a failed transaction' do
30+ original_contents = subject . statements
31+ expect ( subject ) . to receive ( :rollback_transaction ) . and_call_original
32+
33+ expect do
34+ subject . transaction ( mutable : true ) do
35+ delete ( *@statements )
36+ raise 'my error'
37+ end
38+ end . to raise_error RuntimeError
39+
40+ expect ( subject . statements ) . to contain_exactly ( *original_contents )
41+ end
42+ end
43+ end
You can’t perform that action at this time.
0 commit comments