Back-End Engineering Intern Assessment #202
Open
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.
This pull request introduces several changes to the Article model and its corresponding database table. The main goal of these changes was to add new attributes to the Article model and ensure that our unit tests pass successfully.
I started with adding the content attribute to the Article model: My initial approach was addressing each test failure as it came up in each unit test, and working my way down. The first test failure that was caused by the Article model not having a content attribute.
To fix this, I generated a migration to add a content column to the articles table in the database. The content attribute is of type text, which allows me to store large amounts of text.
Next was adding the author attribute to the Article model. The second test failure that I encountered was due to the Article model not having an author attribute. I generated another migration to add an author column to the articles table. The author attribute is of type string.
Next, I had to add the search method to the Article model. I learned this when I encountered a test failure because the Article model did not have a search method. I added a search class method to the Article model. This method takes a query parameter and returns all articles where the title or content contains the query string.
Finally, I had to add the date attribute to the Article model. I learned this when I encountered a test failure due to the Article model not having a date attribute. I generated a migration to add a date column to the articles table. The date attribute is of type datetime.
After each migration, I ran rails
db:migrate
to apply the changes to the database, and railsdb:test:prepare
to ensure that the test database was up to date with the development database.Conclusion
With these changes, we have extended the Article model with new attributes and ensured that our unit tests pass successfully. These additions will allow us to store more detailed information about each article and provide better functionality in our application.