1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- module TimeHelperCache
- %w[travel travel_to freeze_time travel_back].each do |method_name|
- define_method method_name do |*args, **kwargs, &blk|
- super(*args, **kwargs, &blk).tap do
- Rails.cache.clear
- rescue Errno::EISDIR
-
- ensure
- Setting.class_variable_set :@@last_changed_at, 1.second.ago
- end
- end
- end
-
-
- def browser_travel_to(time)
- execute_script "window.clock = sinon.useFakeTimers({now: new Date(#{time.to_i * 1_000}), toFake: ['Date']})"
- end
-
-
- def frontend_relative_month(obj, month, date = nil, year: nil)
-
- t = obj
-
- m = month.to_i
-
- if date.present?
- dt = date.to_i
- end
-
- raise InvalidDate if !t.is_a?(Time)
-
- t = t.in_time_zone
-
- if date.nil?
- dt = t.day
- end
-
- new_year = t.year
- new_month = t.month + m
- if new_month > 12
- new_year += 1
- new_month -= 12
- end
- new_year += year if year
- Time.zone.local(new_year, new_month, dt, t.hour, t.min, t.sec)
-
-
-
-
- end
- end
- RSpec.configure do |config|
-
- config.include ActiveSupport::Testing::TimeHelpers
- config.include TimeHelperCache
- end
|