Week 14 Building an API Part 2 - Code-the-Dream-School/rails-guidebook GitHub Wiki
Week | Topic | Learning Objectives | Key Resources |
---|---|---|---|
14 | Building an API Part 2 |
|
Lesson Materials - See Coding Assignment Coding Assignment |
In this lesson, students will:
-
Set Up Testing and Documentation Tools
- Install and configure RSpec and Swagger for API testing and documentation.
- Add necessary gems to the Gemfile and install them using
bundle install
. - Generate RSpec and RSwag configuration files.
-
Create FactoryBot Factories
- Define factories for
User
,Member
, andFact
models usingFactoryBot
.
- Define factories for
-
Write RSpec Tests for API Endpoints
- Create RSpec tests for user registration, session management, member, and fact controllers.
- Use Swagger specifications to document the API within the tests.
-
Generate Swagger Documentation
- Configure Swagger to generate API documentation.
- Verify and test the generated Swagger UI.
-
Submit and Propose Final Project
- Ensure all tests pass and submit the work on GitHub.
- Start planning the final project and submit a proposal using the provided rubric.
-
Branch Creation
- Create and switch to the
lesson13
branch from thelesson12
branch.
- Create and switch to the
-
Gem Installation
- Add
rspec-rails
,rexml
, andrswag
gems to the Gemfile. - Add
factory_bot_rails
,faker
, andrails-controller-testing
to the:test
group in the Gemfile. - Run
bundle install
. - Generate RSpec and RSwag configuration with
bin/rails generate rspec:install
andbin/rails generate rswag:install
.
- Add
-
FactoryBot Factories
- Create
spec/factories/users.rb
with user factory. - Create
spec/factories/members.rb
with member factory. - Create
spec/factories/facts.rb
with fact factory.
- Create
-
RSpec Tests
- Update
spec/rails_helper.rb
to include Devise test helpers. - Create
spec/requests/registrations_spec.rb
for user registration. - Create
spec/requests/sessions_spec.rb
for session management. - Create
spec/requests/api/v1/members_spec.rb
for member API. - Create
spec/requests/api/v1/facts_spec.rb
for fact API.
- Update
-
Swagger Configuration
- Edit
spec/swagger_helper.rb
to set up Swagger with correct URL and authentication. - Run
bundle exec rake rswag:specs:swaggerize
to generate Swagger documentation.
- Edit
-
Testing and Verification
- Verify that all RSpec tests pass.
- Access Swagger UI at
http://localhost:3000/api-docs
and test the API endpoints. - Handle CSRF token issues for POST, PUT, and DELETE requests in Swagger UI.
-
Submission
- Add, commit, and push changes to the
lesson13
branch. - Create a pull request on GitHub.
- Add, commit, and push changes to the
-
Final Project Proposal
- Review the final project rubric.
- Develop and submit a final project proposal using the Homework Assignment Submission Form.
- Communicate with the mentor via Slack if needed.