Creating ActiveRecord Models
Explore how to create ActiveRecord models in Rails and integrate them into your test-driven development workflow. Understand how to use Rails generators to set up models, migrations, and routes, while maintaining control over your test files. Learn to update model attributes and associations, run migrations, and ensure tests pass using RSpec and Minitest. This lesson helps you build efficient, maintainable Rails applications with a solid TDD foundation.
We'll cover the following...
We can see the first error by running the test:
rsync -avr --progress /usercode/* /usr/local/educative/gatherer --exclude Gemfile --exclude Gemfile.lock --exclude execute_.sh --exclude execute.sh cd /usr/local/educative/gatherer clear bundle exec rspec
Since Project isn’t yet a standard ActiveRecord resource with routes, the test (unsurprisingly) can’t find new_project_path.
ActiveRecord models
If we read the previous chapter and wondered when we would create ActiveRecord models, our time has come. We need to save to the database for the end-to-end test to pass. We’ll use the Rails resource generator, which creates a controller, migration, and route, but doesn’t put any code in the generated controller.
Note: This creates a bunch of files that we’re unlikely to use, but we’ll let that part slide for now.
When we execute the rails generate command, Rails will interactively ...