Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent auto_reload from reloading factories #98

Merged
merged 3 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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