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

Free specs from seeding #927

Merged
merged 8 commits into from
Apr 9, 2021
Merged

Free specs from seeding #927

merged 8 commits into from
Apr 9, 2021

Conversation

solebared
Copy link
Collaborator

@solebared solebared commented Apr 8, 2021

Why

Our ruby specs currently depend on the test database being seeded, which is non-standard and surprising, particularly for new contributors.

What, How

  • Consolidate logo_url logic into a new helper method and make it defensive in case the DB doesn't have an instance_owner.
    • Moves existing logic out of shared/_organization_logo and NavBar.vue.
  • Extract GenerateLandingPageJson interactor out of PublicPagesController.landing_page to ease testing.
  • Create LocationType in a couple of specs instead of relying on one having been seeded.
  • Thread SystemSetting into SubmissionMailer so it can be injected easily in specs.
  • Thread Organization into EmailNewSubmission and EmailPeer interactors, and the corresponding mailers (SubmissionMailer, PeerToPeerMatchMailer)
  • Drop seeding from CircleCI rspec task.

Testing

Relies on existing specs and some manual testing of nav bar, login and signup pages.

Next Steps

  • Probably worth exploring whether Organization.instance_owner should live in Context, similar to SystemSetting.current_settings.
  • Remove mention of needing to seed in docs.

Outstanding Questions, Concerns and Other Notes

Note this is built on top of #926 which renamed Organization.current_organization to .instance_owner. However the changes here aren't really dependent on that particular change.

Pre-Merge Checklist

  • Security & accessibility have been considered
  • Tests have been added, or an explanation has been given why the features cannot be tested
  • Documentation and comments have been added to the codebase where required
  • Entry to CHANGELOG.md not necessary
  • Outstanding questions and concerns have been resolved
  • Any next steps have been turned into Issues or Discussions as appropriate

@maebeale
Copy link
Collaborator

maebeale commented Apr 8, 2021

Love this: Probably worth exploring whether Organization.instance_owner should live in Context, similar to SystemSetting.current_settings.

Comment on lines +78 to +79
# There should always be a current org, but being defensive here helps simplify tests
Organization.instance_owner&.logo_url.presence || asset_pack_path('media/images/logo.png')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I've tripped up on this many times, and this feels to me like a much better home for this conditional than anywhere else it has lived before

Base automatically changed from org-instance-owner to main April 9, 2021 21:27
1. Move logo defaulting method out of Vue into the backend
2. Accommodate current_organization being nil: intended to support specs
   without having to seed the test db.
3. Extract helper method to consolidate defaulting logic

Note: i don't love adding this to application_helper, particularly since
that module is already quite cluttered. Couldn't come up with a better
option though.
Allows simpler assertions than a request spec would.
Also means the spec doesn't have to rely on a seeded test DB.
Inverting the dependency here allows specs to easily pass in a
SystemSetting instance instead of relying on the test db to have been
seeded.
Allows for organization to be injected in specs instead of having to
mock Organization.instance_owner or relying on it having been seeded.
Allows specs to inject organization instead of having to rely on seeding
or class method mocking.
@solebared solebared merged commit b025937 into main Apr 9, 2021
@solebared solebared deleted the free-specs-from-seeding branch April 9, 2021 22:52
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.

3 participants