Add Timeless helper module to prevent updated_at from being updated

This commit is contained in:
Douwe Maan 2016-06-20 18:52:54 +02:00
parent a9fa45f09e
commit 17ab745e40
2 changed files with 17 additions and 6 deletions

View File

@ -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

16
lib/gitlab/timeless.rb Normal file
View File

@ -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