- Rails Engine is a Rails application that works within a service-oriented architecture to expose data through an API that the front-end team can consume.
- Additional Functionality:
- Uses serializers to format JSON responses
- Tests API exposure
- Uses SQL and ActiveRecord to gather data
Table of Contents
- Ruby 2.7.4
- Rails 5.2.6
- RSpec-Rails 4.0.1
- JSON API Serializer
- Factory Bot
- Faker
- SimpleCov
- Postman
Installation instructions found in ➤ Getting Started
- app/controllers/api/v1
- Contains several controllers responsible for rendering JSON responses and status codes.
- app/serializers
- Serializers for Item and Merchant objects.
- Uses the JSON API Serializer Gem to format responses.
- app/models
- Contains models for with added associations and validations
- spec/factories
- Defines FactoryBot objects instantiated in test suite
- app/requests
- Testing suite for API calls to endpoints
- app/models
- Model tests for database objects invoked in API calls
- app/coverage
- Shows SimpleCov coverage report
Note: Only Items, Merchants, Invoices, Invoice Items, and Customers were utilized for this project.
1. Create a new directory on your computer where you'd like the program to live.
$ mkdir /your_folder/rails-engine
2. Navigate into the recently created directory.
$ cd /your_folder/rails-engine
3. Copy the repository by clicking on the code button on Github repo page (using SSH).
4. Clone the recently copied repository information into your currenty directory.
$ git clone git@github.com:JohnSantosuosso/rails-engine.git
5. Open the repository in your preferred IDE. If you are using VSCode, use the code command shown below:
$ code .
6. Download Tests for Postman.
- Click on each link below to load a test collection in your browser, then hit Cmd-S to save it to your system.
- Postman Testing Suite 1
- Postman Testing Suite 2
7. Import Postman tests.
- In Postman, in the top left corner, click on the Import button, and use the file selector to locate the two files on your operating system.
- Next, you’ll confirm the import. The test suite should display as a Postman Collection v2.1 and import as a Collection. Click the Import button to continue.
- Within your collections in Postman, you should see two collections– Rails Engine Lite, Part 1, and Rails Engine Lite, Part 2.
8. In your IDE, install dependencies found in Gemfile using your terminal.
$ bundle install
9. Run migrations and dump schema
$ rake db:{drop,create,migrate,seed}
$ rails db:schema:dump
View the tests for API endpoints inside spec/requests.
Test all functionality by running:.
$ bundle exec rspec spec
API endpoints can be tested both individually and collectively.
- Testing an endpoint
- Start the application on your local server
$ rails s
- Open the Postman Test Collections
- Find the appropriate endpoint within the Postman collection you imported.
- For example, Get All Merchants. When you select Get All Merchants from the list, you should see a Postman tab open, pre-populated with everything you need to connect to the endpoint in your code and see if it works correctly.
- Click the Send button in the top right corner.
- In the lower portion of the Postman interface, you should see Body, Cookies, Headers and a spot that says something like Test Results (7/7). This would indicate that 7 tests passed out of 7. If you see, for example, 3/7 then 3 tests passed and 4 did not.
Project inspired and guided by Turing School of Software and Design's Rails Engine Lite.