Class: RR::Committers::NeverCommitter

Inherits:
DefaultCommitter show all
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

#connections, #session

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DefaultCommitter

#delete_record, #finalize, #insert_record, #new_transaction?, #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.



142
143
144
145
146
147
148
# File 'lib/rubyrep/committers/committers.rb', line 142

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_sessionObject

Returns the last active data session



115
116
117
# File 'lib/rubyrep/committers/committers.rb', line 115

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.



123
124
125
# File 'lib/rubyrep/committers/committers.rb', line 123

def self.current_session=(session)
  @@current_session = session
end

.rollback_current_sessionObject

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.



130
131
132
133
134
135
136
# File 'lib/rubyrep/committers/committers.rb', line 130

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