Add Timeless helper module to prevent updated_at from being updated
This commit is contained in:
		
							parent
							
								
									a9fa45f09e
								
							
						
					
					
						commit
						17ab745e40
					
				| 
						 | 
				
			
			@ -85,12 +85,7 @@ class MergeRequest < ActiveRecord::Base
 | 
			
		|||
    state :cannot_be_merged
 | 
			
		||||
 | 
			
		||||
    around_transition do |merge_request, transition, block|
 | 
			
		||||
      merge_request.record_timestamps = false
 | 
			
		||||
      begin
 | 
			
		||||
        block.call
 | 
			
		||||
      ensure
 | 
			
		||||
        merge_request.record_timestamps = true
 | 
			
		||||
      end
 | 
			
		||||
      Gitlab::Timeless.timeless(merge_request, &block)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
module Gitlab
 | 
			
		||||
  module Timeless
 | 
			
		||||
    def self.timeless(model, &block)
 | 
			
		||||
      original_record_timestamps = model.record_timestamps
 | 
			
		||||
      model.record_timestamps = false
 | 
			
		||||
 | 
			
		||||
      if block.arity.abs == 1
 | 
			
		||||
        block.call(model)
 | 
			
		||||
      else
 | 
			
		||||
        block.call
 | 
			
		||||
      end
 | 
			
		||||
    ensure
 | 
			
		||||
      model.record_timestamps = original_record_timestamps
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
		Reference in New Issue