From aeaa0c3d15ee58eeefc5963bb4055ac9733c2a18 Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Fri, 7 Jan 2022 09:49:33 +1100 Subject: [PATCH 1/2] prevent auto_reload from reloading factories --- CHANGELOG.md | 5 +++++ lib/cypress_on_rails/smart_factory_wrapper.rb | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3556606..fc57726 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Unreleased + +### Fixed +* keep track of factory manual reloads to prevent auto_reload from reloading again + ## [1.12.0] [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.11.0...v1.12.0 diff --git a/lib/cypress_on_rails/smart_factory_wrapper.rb b/lib/cypress_on_rails/smart_factory_wrapper.rb index cbaab29..b8fb882 100644 --- a/lib/cypress_on_rails/smart_factory_wrapper.rb +++ b/lib/cypress_on_rails/smart_factory_wrapper.rb @@ -80,6 +80,7 @@ def build_list(*args) end def reload + @latest_mtime = current_latest_mtime logger.info 'Loading Factories' factory.reload files.each do |file| @@ -105,14 +106,16 @@ def logger CypressOnRails.configuration.logger end + def current_latest_mtime + files.map{|file| @file_system.mtime(file) }.max + end + def auto_reload - current_latest_mtime = files.map{|file| @file_system.mtime(file) }.max - return unless should_reload?(current_latest_mtime) - @latest_mtime = current_latest_mtime + return unless should_reload? reload end - def should_reload?(current_latest_mtime) + def should_reload? @always_reload || @latest_mtime.nil? || @latest_mtime < current_latest_mtime end end From 6ee4d5a74ad6c1acc630b9d87c9768f432de6372 Mon Sep 17 00:00:00 2001 From: Grant Petersen-Speelman Date: Fri, 7 Jan 2022 09:54:28 +1100 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc57726..2d9f9aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## Unreleased ### Fixed -* keep track of factory manual reloads to prevent auto_reload from reloading again +* keep track of factory manual reloads to prevent auto_reload from reloading again [PR 98](https://github.com/shakacode/cypress-on-rails/pull/98) ## [1.12.0] [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.11.0...v1.12.0