This is a Ruby on Rails API project designed to manage pay rates and calculate payments based on client counts. Below are instructions on how to run the project locally and how to interact with the API.
To get started with running the project locally, follow these steps:
-
Clone the repository:
git clone [email protected]:LksNuns/yoga-studio-challenge.git cd yoga-studio-challenge
-
Install dependencies: Make sure you have Bundler installed, then run:
bundle install
-
Set up the database: Since we are using SQLite, you can set up the database with:
rails db:create rails db:migrate
-
Run the server: Start the Rails server with:
rails server
The server will be running at
http://localhost:3000
.
A custom RSpec matcher has been created to facilitate JSON response comparisons in this project.
To use the custom matcher, you can do the following in your specs:
expect(actual_response).to match_response(expected_response)
If you need to specify a serializer, you can do so like this:
expect(actual_response).to match_response(expected_response).with_serializer(MySerializer)
This project includes a GitHub Actions workflow that runs RSpec tests for each pull request and push to the master branch. The workflow is defined in the .github/workflows/rspec.yml
file. It ensures that all tests pass before any changes are merged into the master branch, maintaining the integrity of the codebase.
To view or modify the workflow, navigate to the .github/workflows/rspec.yml
file in the repository.
The API provides the following routes:
- Description: Create a new pay rate, and bonus if desired.
- Attributes:
rate_name
(string, required): The name of the pay rate.base_rate_per_client
(decimal, required): The base rate per client.pay_rate_bonus_attributes
(nested attributes, optional):rate_per_client
(decimal, required): The bonus rate per client.min_client_count
(integer, optional): The minimum client count for the bonus.max_client_count
(integer, optional): The maximum client count for the bonus.
- Description: Update an existing pay rate.
- Attributes:
id
(integer, required): The ID of the pay rate to update.rate_name
(string, optional): The new name of the pay rate.base_rate_per_client
(decimal, optional): The new base rate per client.pay_rate_bonus_attributes
(nested attributes, optional):id
(integer, required if updating): The ID of the bonus to update.rate_per_client
(decimal, optional): The new bonus rate per client.min_client_count
(integer, optional): The new minimum client count for the bonus.max_client_count
(integer, optional): The new maximum client count for the bonus._destroy
(boolean, optional): Set totrue
to remove the bonus.
-
Description: Calculate the payment for a given pay rate and client count.
-
Attributes:
pay_rate_id
(integer, required): The ID of the pay rate.clients
(integer, required): The number of clients to calculate the payment for.
-
Response: Returns the calculated payment in JSON format.
- Ensure you have Ruby 3.x and Rails 7.x installed.
- Use Insomnia or a similar tool to test the API endpoints.