Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test models #30

Merged
merged 14 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ group :development do
gem 'rails-controller-testing'
end

gem 'database_cleaner'
gem 'devise-jwt'
gem 'factory_bot_rails'
gem 'paranoia', '~> 2.5'
gem 'rack-cors'
gem 'rswag'
gem 'shoulda-matchers'
16 changes: 16 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ GEM
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
crass (1.0.6)
database_cleaner (2.0.2)
database_cleaner-active_record (>= 2, < 3)
database_cleaner-active_record (2.1.0)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.3.4)
debug (1.8.0)
irb (>= 1.5.0)
Expand All @@ -112,6 +118,11 @@ GEM
concurrent-ruby (~> 1.0)
zeitwerk (~> 2.6)
erubi (1.12.0)
factory_bot (6.4.2)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.2)
factory_bot (~> 6.4)
railties (>= 5.0.0)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.14.1)
Expand Down Expand Up @@ -245,6 +256,8 @@ GEM
actionpack (>= 3.1, < 7.2)
railties (>= 3.1, < 7.2)
ruby2_keywords (0.0.5)
shoulda-matchers (5.3.0)
activesupport (>= 5.2.0)
stringio (3.1.0)
thor (1.3.0)
timeout (0.4.1)
Expand All @@ -271,9 +284,11 @@ PLATFORMS

DEPENDENCIES
bootsnap
database_cleaner
debug
devise (~> 4.9)
devise-jwt
factory_bot_rails
paranoia (~> 2.5)
pg (~> 1.1)
psych (~> 4.0.1)
Expand All @@ -283,6 +298,7 @@ DEPENDENCIES
rails-controller-testing
rspec-rails
rswag
shoulda-matchers
tzinfo-data

RUBY VERSION
Expand Down
171 changes: 158 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,169 @@
# README
<a name="readme-top"></a>

This README would normally document whatever steps are necessary to get the
application up and running.
<div align="center">

Things you may want to cover:
</div>

* Ruby version

* System dependencies
# 📗 Table of Contents

* Configuration
- [📖 About the Project](#about-project)
- [🛠 Built With](#built-with)
- [Tech Stack](#tech-stack)
- [Key Features](#key-features)
- [💻 Getting Started](#getting-started)
- [Setup](#setup)
- [Prerequisites](#prerequisites)
- [Install](#install)
- [Usage](#usage)
- [Run tests](#run-tests)
- [Frontend Repository](#frontend-repository)
- [ERD Image](#erd-image)
- [API Documentation](#api-documentation)
- [👥 Authors](#authors)
- [🔭 Future Features](#future-features)
- [🤝 Contributing](#contributing)
- [⭐️ Show your support](#support)
- [🙏 Acknowledgements](#acknowledgements)
- [❓ FAQ (OPTIONAL)](#faq)
- [📝 License](#license)

* Database creation
# 📖 vehicle booking app <a name="about-project"></a>

* Database initialization
**vehicle booking app** is a Booking app made connectively with Ruby in Rails and React for front-end [vehicle booking app](https://github.com/tan12082001/Vehicle-Booking-App-Backend.git) React frontend App in JSON format through an API endpoint.

* How to run the test suite
## 🛠 Built With <a name="built-with"></a>

* Services (job queues, cache servers, search engines, etc.)
### Tech Stack <a name="tech-stack"></a>
<details>
<summary>Client</summary>
<ul>
<li><a href="https://react.dev/">React</a></li>
<li><a href="https://react-redux.js.org/">React-Redux</a></li>
<li><a href="https://redux-toolkit.js.org/">Redux Toolkit</a></li>
</ul>
</details>

* Deployment instructions
<details>
- <summary>Server</summary>
<ul>
<li><a href="https://guides.rubyonrails.org/">Ruby on Rails</a></li>
<li><a href="https://www.postgresql.org/docs/">PostgreSQL</a></li>
</ul>
</details>

* ...
### Key Features <a name="key-features"></a>

- Rails API backend
- React Front-end
- Redux Toolkit used to consume the backend api

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## 💻 Getting Started <a name="getting-started"></a>

To get a local copy up and running, follow these steps:

### Prerequisites

In order to run this project you need:
- A text editor of your choice ([VS Code](https://code.visualstudio.com/download) works well).
- [Ruby and Rails](https://gorails.com/setup/windows/10)
- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)

### Setup

Use the following URL to clone this project:

https://github.com/tan12082001/Vehicle-Booking-App-Backend.git

### Install
Open the terminal in the root directory of the project and run the following command to install all dependencies.

bundle install

### Frontend Repository
Reference the [Frontend Repository](https://github.com/tan12082001/Vehicle-Booking-App-Frontend.git) for the corresponding frontend.

### ERD Image
Add an ERD image to visualize the database schema.
## follow the below link to access
(https://drawsql.app/teams/wineshuga/diagrams/book-appointment)

### API Documentation
Reference the API documentation for details on how to interact with the API.

### Usage
To start the development server, run the following command then navigate to `localhost:3000` in your browser.

rails s

Open [http://localhost:3000](http://localhost:3000/api/random_greeting) to view it in your browser.


### Run tests
There are no tests to run.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

Comment on lines +103 to +107
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add rspec as we just added the test suites.


## 👥 Authors <a name="authors"></a>


👤 **Suleiman Gacheru**

- GitHub: [@hetrox8](https://github.com/hetrox8)
- Twitter: [@suleimangacheru](https://twitter.com/suleimangacheru)


👤 **Tanmayi manku**

- GitHub: [@tan12082001](https://github.com/tan12082001)


👤 **Winnie uzochukwu**

- GitHub: [@winnie](https://github.com/Wineshuga)

👤 **Winnie uzochukwu**

- GitHub: [@toyybi bolaji](https://github.com/Simpleshaikh1)


<p align="right">(<a href="#readme-top">back to top</a>)</p>


## 🔭 Future Features <a name="future-features"></a>

- None planned


Comment on lines +135 to +139
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to add at least two future features.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## 🤝 Contributing <a name="contributing"></a>

Contributions, issues, and feature requests are welcome!

Feel free to check the [issues page](../../issues/).

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## ⭐️ Show your support <a name="support"></a>


If you like this project, please give it a star ⭐️ and share it with your friends.

<p align="right">(<a href="#readme-top">back to top</a>)</p>


## 🙏 Acknowledgments <a name="acknowledgements"></a>

I would like to thank <a href="https://www.microverse.org/">Microverse</a> for providing the resources and guidelines that enabled me to complete this project.

<p align="right">(<a href="#readme-top">back to top</a>)</p>



## 📝 License <a name="license"></a>

This project is [MIT](./LICENSE) licensed.
2 changes: 1 addition & 1 deletion app/models/car.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Car < ApplicationRecord
acts_as_paranoid
has_many :users, through: :my_reservations
has_many :my_reservations

validates :name, presence: true, length: { minimum: 2, maximum: 150 }
validates :image, presence: true
validates :description, presence: true
validates :pricePerHr, presence: true
validates :seating_capacity, presence: true
Expand Down
4 changes: 1 addition & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
include Devise::JWT::RevocationStrategies::JTIMatcher

devise :database_authenticatable, :registerable, :validatable,
:jwt_authenticatable, jwt_revocation_strategy: self

has_many :cars, through: :my_reservations
has_many :my_reservations
has_many :cars, through: :my_reservations

validates :username, presence: true, uniqueness: true
validates :email, presence: true
Expand Down
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fAtn19uLyNhgX/ZDtLX9gOmxM3j7ftyeD5FGXTr5TurQX1rvjgBdnm0UHa7hQW9zKTgW/8u36rGIsHkv7FXQNdQ973rqx622S76o7TTuxZ1ihrhKKDBZhb9L4tIxMOHhLxGvuUf8ztIP2LkuF6s4KhJxf5yQop+zKbasaxcdTHwAzNmx1E6gxiaQiRGSDqIkMKHllGjmc3rNT44N7z9I+h9Zm+J+mgrIcKU8lZ+tGbVNkE9dJoGGrWLFDeuP54liacjmiZACmMEq1E9QA7pyvDaL60PD678SLktthGbVbgySU2xg+TawbHTt9mkr458+padCCi3CV5JAcdKfG2uH8XgDdzKiXKXuFIkPNfhFL8msOhe0R0FiHlchWOelXYgMNAAbfR7Oxv2Rez08OCWn8DJFdmFf--1bfvO5+kKjsedmRn--3ahtbfXpTxPynTpxpi2WXg==
Ub4GwFY64RuGmN4tF3T5NYa41bAEZFrbj2pAVHLkK0ERfIr8/I5mUxuJ2xQKuF2JRL2spC1jOhWTKyTS+7KphFxc25b4CuYsaBm5mI2Q4WGq+RdYKBr1F5fISRWFuEKVw0uSTg3Iu7wLvU0kBsyvrb4lvV15Q4ZrRLH74GDeZFGZMwbilbVX1Pjxv08GO/hHUksjZahlouqiYNtdVQU5ddM/TKScWeBiBt6VVl3r4u5Mmu9K2cIABpmGTaWWS1t8C+G9Afx93+8E4en9c+Vefn0jl0iP38ab9UrnzD5sV9jds/xSg5I1m/txc/OozZCypJRnIgifnEvas1U7thoZIkqMxNgqgtJ3wWM99gZPHMQ5APnMrwKamctsE9wjSNg9a6s9aj33EMBx+g2WdUkL2fLWM9LK--RXyuCv1yyZ786dyc--t1D0aqw6YPSrnsMMF+/oRA==
10 changes: 10 additions & 0 deletions spec/models/car_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'rails_helper'

RSpec.describe Car, type: :model do
describe 'associations' do
it { is_expected.to have_many(:my_reservations) }
it { is_expected.to have_many(:users).through(:my_reservations) }
end

# Add tests for other validations here
end
10 changes: 10 additions & 0 deletions spec/models/my_reservation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'rails_helper'

RSpec.describe MyReservation, type: :model do
describe 'associations' do
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:car) }
end

# Add tests for other validations here
end
10 changes: 10 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'rails_helper'

RSpec.describe User, type: :model do
describe 'associations' do
it { is_expected.to have_many(:my_reservations) }
it { is_expected.to have_many(:cars).through(:my_reservations) }
end

# Add tests for other validations here
end
77 changes: 77 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# spec/rails_helper.rb

# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
require 'rspec/rails'
require 'shoulda/matchers'
require 'database_cleaner'

# Prevent database truncation if the environment is production
abort('The Rails environment is running in production mode!') if Rails.env.production?

# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
abort e.to_s.strip
end

RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_paths = [
Rails.root.join('spec/fixtures')
]

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true

# You can uncomment this line to turn off ActiveRecord support entirely.
# config.use_active_record = false

# Configure shoulda-matchers
Shoulda::Matchers.configure do |shoulda_config|
shoulda_config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end

# Configure DatabaseCleaner
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end

config.before(:each) do
DatabaseCleaner.start
end

config.after(:each) do
DatabaseCleaner.clean
end

# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, type: :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://rspec.info/features/6-0/rspec-rails
config.infer_spec_type_from_file_location!

# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
end
Loading
Loading