Class: RR::Committers::NeverCommitter
- Inherits:
-
DefaultCommitter
- Object
- DefaultCommitter
- RR::Committers::NeverCommitter
- Defined in:
- lib/rubyrep/committers/committers.rb
Overview
Starts a transaction but does never commit it. Useful during testing.
Constant Summary collapse
- @@current_session =
nil
Instance Attribute Summary
Attributes inherited from DefaultCommitter
Class Method Summary collapse
-
.current_session ⇒ Object
Returns the last active data session.
-
.current_session=(session) ⇒ Object
Saves the provided database session as class variable.
-
.rollback_current_session ⇒ Object
Rolls back transactions of current session (if there is one).
Instance Method Summary collapse
-
#initialize(session) ⇒ NeverCommitter
constructor
Refer to DefaultCommitter#initialize for details.
Methods inherited from DefaultCommitter
#delete_record, #finalize, #insert_record, #update_record
Constructor Details
#initialize(session) ⇒ NeverCommitter
Refer to DefaultCommitter#initialize for details. Starts new transactions on left and right database connectin of session. Additionally rolls back transactions started in previous NeverCommitter instances.
136 137 138 139 140 141 142 |
# File 'lib/rubyrep/committers/committers.rb', line 136 def initialize(session) super self.class.rollback_current_session self.class.current_session = session session.left.begin_db_transaction session.right.begin_db_transaction end |
Class Method Details
.current_session ⇒ Object
Returns the last active data session
109 110 111 |
# File 'lib/rubyrep/committers/committers.rb', line 109 def self.current_session @@current_session end |
.current_session=(session) ⇒ Object
Saves the provided database session as class variable. Purpose: the last database session stays available after the NeverCommitter is destroyed so that also later the transaction rollback can still be executed.
117 118 119 |
# File 'lib/rubyrep/committers/committers.rb', line 117 def self.current_session=(session) @@current_session = session end |
.rollback_current_session ⇒ Object
Rolls back transactions of current session (if there is one). This would be called e. g. in rspec’s after(:each) to ensure that the next test case finds the original test data.
124 125 126 127 128 129 130 |
# File 'lib/rubyrep/committers/committers.rb', line 124 def self.rollback_current_session if self.current_session self.current_session.left.rollback_db_transaction self.current_session.right.rollback_db_transaction self.current_session = nil end end |