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

2429 allow transcribers to delete subjects #3678

Merged
merged 14 commits into from
Sep 5, 2023

Conversation

symmetrically
Copy link
Contributor

No description provided.

@symmetrically symmetrically requested a review from benwbrum June 20, 2023 16:44
Copy link
Owner

@benwbrum benwbrum left a comment

Choose a reason for hiding this comment

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

There are a couple of changes in functionality relating to project owners versus subject creators

app/controllers/article_controller.rb Outdated Show resolved Hide resolved
app/models/xml_source_processor.rb Outdated Show resolved Hide resolved
config/locales/article/article-en.yml Outdated Show resolved Hide resolved
@benwbrum
Copy link
Owner

The test suite is failing with a foreign key check which seems related to the work done here. I'm re-starting it to see if this is just an artifact of TravisCI or a real regression.

@benwbrum
Copy link
Owner

We are consistently getting this exception in the test suite:

  1) XmlSourceProcessor#wiki_to_xml subject linking not disabled (default) builds the xml document
     Failure/Error: article.save! unless preview_mode
     
     ActiveRecord::InvalidForeignKey:
       Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails (`diary_test`.`articles`, CONSTRAINT `fk_rails_35e2f292e3` FOREIGN KEY (`created_by_id`) REFERENCES `users` (`id`))
     # ./app/models/xml_source_processor.rb:373:in `block in update_links_and_xml'
     # ./app/models/xml_source_processor.rb:353:in `update_links_and_xml'
     # ./app/models/xml_source_processor.rb:114:in `wiki_to_xml'
     # ./spec/models/xml_source_processor_spec.rb:41:in `block (4 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # Mysql2::Error:
     #   Cannot add or update a child row: a foreign key constraint fails (`diary_test`.`articles`, CONSTRAINT `fk_rails_35e2f292e3` FOREIGN KEY (`created_by_id`) REFERENCES `users` (`id`))
     #   ./app/models/xml_source_processor.rb:373:in `block in update_links_and_xml'

The failure happens on line 39 of the XML Source processor spec, which is before the actual test runs, indicating that the problem may be with the fixture or factory data. Could it be that we need to include a user reference in the article factory constructor?

@benwbrum
Copy link
Owner

benwbrum commented Sep 2, 2023

The test failure here seems to be due to code in xml_source_processor.rb which sets the article's user relation to the value of User.current_user. When the test fails, the value of User.current_user.id is 4, but there is no record in the users table with an ID of 4 -- only 1 and 2 exist.

DB foreign keys were introduced in later versions of Rails than those current when the most of the xml_source_processor.rb functionality was written -- as a result, models like Page and PageVersion can have their users set to values which may not be present in the database and tests don't fail.

I think we have a couple of options here:

  • Remove the foreign key from the Article table. (I'm not a fan of this, but it would parallel the other tests and older models.
  • Research foreign key constraints and the tools we're using for creating test data in this test. (Mocks? Factories?) Surely we are not the first developers to run into this problem, and there might just be a configuration option or something we can change.

@benwbrum benwbrum merged commit 2da789f into development Sep 5, 2023
@benwbrum benwbrum deleted the 2429-allow-transcribers-to-delete-subjects branch September 5, 2023 11:43
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