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

Fix Sipity::Role#destroy spec #7007

Open
randalldfloyd opened this issue Feb 7, 2025 · 0 comments
Open

Fix Sipity::Role#destroy spec #7007

randalldfloyd opened this issue Feb 7, 2025 · 0 comments

Comments

@randalldfloyd
Copy link
Contributor

The spec Sipity::Role#destroy almost always fails in the context of the entire test suite, but will succeed when ran again individually. The failure is always the same:

./spec/models/sipity/role_spec.rb
 
 Sipity::Role#destroy will not allow registered role names to be destroyed
 
 PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_sipity_roles_on_name" DETAIL:  Key (name)=(managing) already exists.
Failure/Error: role = described_class.create!(name: Hyrax::RoleRegistry::MANAGING)
...
/app/bundle/ruby/3.3.0/gems/activerecord-7.2.2.1/lib/active_record/persistence.rb:55:in `create!'
./spec/models/sipity/role_spec.rb:32:in `block (3 levels) in <module:Sipity>'

There is likely a race condition where a previous database operation hasn't finished cleaning up before this test starts. Here are a couple of ideas from @dmolesUC :

In terms of just getting this spec to pass, it seems like the easiest fix would be to replace the create! with find_or_create_by

I notice we're using different DatabaseCleaner strategies for different tests :

hyrax/spec/spec_helper.rb

Lines 199 to 205 in 5b03f59

config.before do |example|
if example.metadata[:type] == :feature && Capybara.current_driver != :rack_test
DatabaseCleaner.strategy = :truncation
else
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.start
end
— maybe sometimes a Capybara test hasn't finished cleaning up when the Role test starts?

It might be worth trying just using truncation for everything, I know it's supposed to be slower but IDK if it's enough slower that we need to care

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

No branches or pull requests

1 participant