Fix for Article.type always returning an empty string.#805
Merged
JPToroDev merged 1 commit intotwostraws:mainfrom Apr 25, 2025
Merged
Fix for Article.type always returning an empty string.#805JPToroDev merged 1 commit intotwostraws:mainfrom
JPToroDev merged 1 commit intotwostraws:mainfrom
Conversation
Collaborator
|
Nice one! Could you add some tests to verify this behavior so we don't miss this again in the future? 🙏 |
Contributor
Author
|
Hmm, to my shame, I don't know how to do tests. I missed Paul's event on that. Is there any documentation, notes, etc. on adding tests to Ignite? |
Collaborator
|
Nothing to be ashamed about! Many recent test makers had no prior experience. This would be a pretty sophisticated first test to write, so I'm happy to merge this in and provide the test. But to ignite your test-writing journey, I'd love to see you contribute a test that's smaller and more contained! There are no formal instructions about adding tests to Ignite, but if you look at existing tests, starting with the simplest ones first, I think you'll very quickly understand how they work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently the
Article typevariable always returns an empty string. It uses the following code to extract thetypestring from theArticle's metadata:However, the cast
type as? String ?? ""will always fail and return the default empty string. Themetadata["type"]is stored inArticle'sinit()using the following code:The problem here is
path.split(separator: "/")returns a[Substring]not a[String], sotypeis stored as aSubstringnot aString, meaning the casttype as? String ?? ""will always return an empty string.A side effect of this is the
ArticleLoaderfunctyped(_ type: String)will always return an empty[Article]. This is how I noticed the bug :)The fix takes the result of
path.split(separator: "/")and maps it to a[String]to ensure themetadata["type"]is stored as aString.