Skip to content

Instantly share code, notes, and snippets.

@hotchpotch
Forked from miyagawa/gist:3057813
Created July 6, 2012 03:13
Show Gist options
  • Save hotchpotch/3057860 to your computer and use it in GitHub Desktop.
Save hotchpotch/3057860 to your computer and use it in GitHub Desktop.
require 'timecop'
module ActiveRecordDetectTimeInScopes
extend ActiveSupport::Concern
module ClassMethods
def scope(*args)
scope_caller = caller
Timecop.travel(Time.now) do
Timecop.top_stack_item.define_singleton_method :time do
Rails.logger.warn "WARNING: You have a scope with Time evaluated immediately in its args. " +
"You might want to use lambda.\n" +
Rails.backtrace_cleaner.clean(scope_caller).map { |trace| "\t#{trace}" }.join("\n")
super()
end
super
end
end
end
end
ActiveRecord::Base.send(:include, ActiveRecordDetectTimeInScopes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment