Skip to content

Commit

Permalink
prevent auto_reload from reloading factories that has just been reloa…
Browse files Browse the repository at this point in the history
…ded (#98)
  • Loading branch information
grantspeelman authored Jan 12, 2022
1 parent 6e0b9b3 commit 4dfd46d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
### Tasks
* Documenting how to setup Factory Associations [PR 100](https://github.com/shakacode/cypress-on-rails/pull/100)

### Fixed
* 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

Expand Down
11 changes: 7 additions & 4 deletions lib/cypress_on_rails/smart_factory_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
Expand Down

0 comments on commit 4dfd46d

Please sign in to comment.