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

Refactor and improve tests #17386

Merged
merged 2 commits into from
Jan 27, 2022

Conversation

ClearlyClaire
Copy link
Contributor

@ClearlyClaire ClearlyClaire commented Jan 27, 2022

Currently, our tests are a mess as far as Account and User models are Fabricated, there's lots of boilerplate, a lot of cargo-cult, multiple ways of expressing stuff, as well as a lot of cases where local accounts have no associated records and some cases when remote accounts do, neither of which is representative of the state of objects in production.

To remedy this, this PR changes the :account and :user fabricators so that:

  • Fabricate(:account) implicitly fabricates an associated user if no domain attribute is given (user: nil can be passed to avoid that).
  • Fabricate(:account, user: Fabricate(:user)) should still be possible but is discouraged.

Tests were then fixed:

  • Fix the few tests failing because they were expecting a local account to have no associated user record
  • Fix the few tests failing because they Fabricated users and accounts in different steps (causing lingering records that were not expected)
  • Fix the few tests that explicitly associated user records to remote accounts (this did not cause any error, but it was not representative of the production code)

And refactored:

  • avoid passing unneeded attributes to Fabricate(:user) and Fabricate(:account) (this includes passing unneeded embedded calls to Fabricate(:user) and Fabricate(:account))
  • prefer Fabricate(:user, account_attributes: …) to Fabricate(:user, account: Fabricate(:account, …)
  • avoid embedding Fabricate(:user) into a Fabricate(:account) or the other
  • prefer Fabricate(:account) over Fabricate(:user).account

- `Fabricate(:account)` implicitly fabricates an associated `user` if
  no `domain` attribute is given (an account with `domain: nil` is
  considered a local account, but no user record was created), unless
  `user: nil` is passed
- `Fabricate(:account, user: Fabricate(:user))` should still be possible
  but is discouraged.
@ClearlyClaire ClearlyClaire marked this pull request as ready for review January 27, 2022 19:54
- avoid passing unneeded attributes to `Fabricate(:user)` or
  `Fabricate(:account)`
- avoid embedding `Fabricate(:user)` into a `Fabricate(:account)` or the other
  way around
- prefer `Fabricate(:user, account_attributes: …)` to
  `Fabricate(:user, account: Fabricate(:account, …)`
- also, some tests were using remote accounts with local user records, which is
  not representative of production code.
@Gargron Gargron merged commit e38fc31 into mastodon:main Jan 27, 2022
jesseplusplus pushed a commit to jesseplusplus/decodon that referenced this pull request Feb 10, 2022
* Change account and user fabricators to simplify and improve tests

- `Fabricate(:account)` implicitly fabricates an associated `user` if
  no `domain` attribute is given (an account with `domain: nil` is
  considered a local account, but no user record was created), unless
  `user: nil` is passed
- `Fabricate(:account, user: Fabricate(:user))` should still be possible
  but is discouraged.

* Fix and refactor tests

- avoid passing unneeded attributes to `Fabricate(:user)` or
  `Fabricate(:account)`
- avoid embedding `Fabricate(:user)` into a `Fabricate(:account)` or the other
  way around
- prefer `Fabricate(:user, account_attributes: …)` to
  `Fabricate(:user, account: Fabricate(:account, …)`
- also, some tests were using remote accounts with local user records, which is
  not representative of production code.
jesseplusplus pushed a commit to jesseplusplus/decodon that referenced this pull request May 18, 2022
* Change account and user fabricators to simplify and improve tests

- `Fabricate(:account)` implicitly fabricates an associated `user` if
  no `domain` attribute is given (an account with `domain: nil` is
  considered a local account, but no user record was created), unless
  `user: nil` is passed
- `Fabricate(:account, user: Fabricate(:user))` should still be possible
  but is discouraged.

* Fix and refactor tests

- avoid passing unneeded attributes to `Fabricate(:user)` or
  `Fabricate(:account)`
- avoid embedding `Fabricate(:user)` into a `Fabricate(:account)` or the other
  way around
- prefer `Fabricate(:user, account_attributes: …)` to
  `Fabricate(:user, account: Fabricate(:account, …)`
- also, some tests were using remote accounts with local user records, which is
  not representative of production code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants