Skip to content

Commit

Permalink
fix(Stub): align #destroyed with #new_record/#persisted
Browse files Browse the repository at this point in the history
  • Loading branch information
bf4 authored and mike-burns committed Sep 1, 2023
1 parent e17be4a commit 6486fce
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# News

## Unreleased

* Changed: Explicitly define `#destroyed?` within the `Stub` strategy to return `false` to be consistent
with `#new_record?` and `#persisted?`.

## 6.2.1 (March 8, 2022)
* Added: CI testing against truffleruby
* Changed: Documentation improvements for sequences and traits
Expand Down
2 changes: 1 addition & 1 deletion docs/src/ref/build-strategies.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ data as appropriate:
- all [ActiveModel::Dirty] change tracking is cleared
- `persisted?` is true
- `new_record?` is false
- `destroyed?` is nil
- `destroyed?` is false
- persistence methods raise a `RuntimeError` (`#connection`, `#delete`, `#save`, `#update`, etc.)

[ActiveModel::Dirty]: https://api.rubyonrails.org/classes/ActiveModel/Dirty.html
Expand Down
2 changes: 1 addition & 1 deletion lib/factory_bot/strategy/stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def new_record?
end

def destroyed?
nil
false
end

DISABLED_PERSISTENCE_METHODS.each do |write_method|
Expand Down

0 comments on commit 6486fce

Please sign in to comment.