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: remove more test order dependence #4273

Merged
merged 3 commits into from
Apr 25, 2024

Conversation

elasticspoon
Copy link
Collaborator

@elasticspoon elasticspoon commented Apr 13, 2024

As discussed here #4264, some tests modify global variables and expect them to be reset before each test. This makes it more difficult to move forward with removal of pre-seeding.

This PR refactors certain tests to be less brittle to changes in global state and to rely less on assumptions on global state. Ex: not assuming that there are 0 records of a certain type when a test starts, etc.

Also spec files starting with describe have been changed to start with Rspec.describe. This makes future greping much simpler.

@elasticspoon elasticspoon force-pushed the fix-more-order-dependent-tests branch from 662fe00 to f8b008f Compare April 13, 2024 22:08
As discussed here rubyforgood#4264,
some tests modify global variables and expect them to
be reset before each test. This makes it more difficult
to move forward with removal of pre-seeding.

This commit refactors certain tests to be less brittle to
changes in global state and to rely less on assumptions
on global state. Ex: not assuming that there are 0 records
of a certain type when a test starts, etc.
@elasticspoon elasticspoon force-pushed the fix-more-order-dependent-tests branch from f8b008f to 5e64fbb Compare April 13, 2024 22:18
@elasticspoon elasticspoon marked this pull request as ready for review April 13, 2024 22:31
@elasticspoon elasticspoon added the BLOCKER This issue blocks others and should be prioritized label Apr 15, 2024
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

I LOVE THIS in general 😁

let!(:today) { create(described_class.to_s.underscore.to_sym, date_field.to_sym => Time.zone.local(2019, 7, 31)) }
let!(:very_old) { create(described_class.to_s.underscore.to_sym, date_field.to_sym => Time.zone.local(2000, 7, 31), :organization => @organization) }
let!(:recent) { create(described_class.to_s.underscore.to_sym, date_field.to_sym => Time.zone.local(2019, 7, 24), :organization => @organization) }
let!(:today) { create(described_class.to_s.underscore.to_sym, date_field.to_sym => Time.zone.local(2019, 7, 31), :organization => @organization) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we adding instance variables here when we're removing them everywhere else?

let(:item2) { create(:item, name: "Crap item") }
let(:partner1) { create(:partner, name: "This Guy", email: "thisguy@example.com") }
let(:partner2) { create(:partner, name: "Not This Guy", email: "ntg@example.com") }
let(:item1) { create(:item, name: "Good item", item_category: item_category, organization: @organization) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

spec/system/distribution_system_spec.rb Outdated Show resolved Hide resolved
item = Item.alphabetized.first
select @storage_location.name, from: "purchase_storage_location_id"
expect(page).to have_content(@item.name)
select @item.name, from: "purchase_line_items_attributes_0_item_id"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same. In general I'm confused here why some tests are removing instance variables and others are adding them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Basically I wanted to make minimal changes. A lot of the order dependence issues stemmed from needing to set organization: on things. Thus, where possible I set it with the instance variable organization but since the db is not getting reset within a spec file some of the specs modify @organization and cause other ones to fail.

In general I could remove all the changes to @organization with a created organization but I think that will expand the PR a decent amount. They are also really to find and replace later.

EX: with some of the shared examples, I have to change all the parts that use it if I move off instance variables.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I basically went:

  • does this work? If yes leave
  • does this work if I add instance variables to it? If yes add them
  • otherwise replace instance variables with created ones.

Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

I think this is good to merge!

@dorner
Copy link
Collaborator

dorner commented Apr 22, 2024

...dangit - @elasticspoon there's a conflict now 😁

@elasticspoon
Copy link
Collaborator Author

@dorner fixed. I'll rebase the other PR and mark it as ready for review whenever this is merged.

@dorner dorner merged commit b896c7c into rubyforgood:main Apr 25, 2024
19 checks passed
@dorner
Copy link
Collaborator

dorner commented Apr 25, 2024

Great, thanks!

@elasticspoon elasticspoon deleted the fix-more-order-dependent-tests branch April 25, 2024 18:02
Copy link
Contributor

@elasticspoon: Your PR refactor: remove more test order dependence is part of today's Human Essentials production release: 2024.04.28.
Thank you very much for your contribution!

@elasticspoon elasticspoon mentioned this pull request May 2, 2024
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BLOCKER This issue blocks others and should be prioritized
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants