From b3abd90218249a9ca2af12ffbb812667662f7341 Mon Sep 17 00:00:00 2001 From: suleiman gacheru Date: Mon, 11 Dec 2023 16:41:55 +0300 Subject: [PATCH 01/14] create tests for models --- .rspec | 1 + config/credentials.yml.enc | 2 +- spec/models/car_spec.rb | 26 ++++++++ spec/models/my_reservation_spec.rb | 13 ++++ spec/models/user_spec.rb | 44 ++++++++++++++ spec/rails_helper.rb | 65 ++++++++++++++++++++ spec/spec_helper.rb | 98 ++++++++++++++++++++++++++++++ 7 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 .rspec create mode 100644 spec/models/car_spec.rb create mode 100644 spec/models/my_reservation_spec.rb create mode 100644 spec/models/user_spec.rb create mode 100644 spec/rails_helper.rb create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..c99d2e7 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index 5a26316..7929e80 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -fAtn19uLyNhgX/ZDtLX9gOmxM3j7ftyeD5FGXTr5TurQX1rvjgBdnm0UHa7hQW9zKTgW/8u36rGIsHkv7FXQNdQ973rqx622S76o7TTuxZ1ihrhKKDBZhb9L4tIxMOHhLxGvuUf8ztIP2LkuF6s4KhJxf5yQop+zKbasaxcdTHwAzNmx1E6gxiaQiRGSDqIkMKHllGjmc3rNT44N7z9I+h9Zm+J+mgrIcKU8lZ+tGbVNkE9dJoGGrWLFDeuP54liacjmiZACmMEq1E9QA7pyvDaL60PD678SLktthGbVbgySU2xg+TawbHTt9mkr458+padCCi3CV5JAcdKfG2uH8XgDdzKiXKXuFIkPNfhFL8msOhe0R0FiHlchWOelXYgMNAAbfR7Oxv2Rez08OCWn8DJFdmFf--1bfvO5+kKjsedmRn--3ahtbfXpTxPynTpxpi2WXg== \ No newline at end of file +Ub4GwFY64RuGmN4tF3T5NYa41bAEZFrbj2pAVHLkK0ERfIr8/I5mUxuJ2xQKuF2JRL2spC1jOhWTKyTS+7KphFxc25b4CuYsaBm5mI2Q4WGq+RdYKBr1F5fISRWFuEKVw0uSTg3Iu7wLvU0kBsyvrb4lvV15Q4ZrRLH74GDeZFGZMwbilbVX1Pjxv08GO/hHUksjZahlouqiYNtdVQU5ddM/TKScWeBiBt6VVl3r4u5Mmu9K2cIABpmGTaWWS1t8C+G9Afx93+8E4en9c+Vefn0jl0iP38ab9UrnzD5sV9jds/xSg5I1m/txc/OozZCypJRnIgifnEvas1U7thoZIkqMxNgqgtJ3wWM99gZPHMQ5APnMrwKamctsE9wjSNg9a6s9aj33EMBx+g2WdUkL2fLWM9LK--RXyuCv1yyZ786dyc--t1D0aqw6YPSrnsMMF+/oRA== \ No newline at end of file diff --git a/spec/models/car_spec.rb b/spec/models/car_spec.rb new file mode 100644 index 0000000..90c8a04 --- /dev/null +++ b/spec/models/car_spec.rb @@ -0,0 +1,26 @@ + +require 'rails_helper' + +RSpec.describe Car, type: :model do + describe 'validations' do + it { should validate_presence_of(:name) } + it { should validate_length_of(:name).is_at_least(2).is_at_most(150) } + + it { should validate_presence_of(:description) } + + it { should validate_presence_of(:pricePerHr) } + + it { should validate_presence_of(:seating_capacity) } + + it { should validate_presence_of(:rental_duration) } + end + + describe 'associations' do + it { should have_many(:my_reservations) } + it { should have_many(:users).through(:my_reservations) } + end + + describe 'acts_as_paranoid' do + it { should act_as_paranoid } + end +end diff --git a/spec/models/my_reservation_spec.rb b/spec/models/my_reservation_spec.rb new file mode 100644 index 0000000..f84d951 --- /dev/null +++ b/spec/models/my_reservation_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' + +RSpec.describe MyReservation, type: :model do + describe 'validations' do + it { should validate_presence_of(:date) } + it { should validate_presence_of(:city) } + end + + describe 'associations' do + it { should belong_to(:user) } + it { should belong_to(:car) } + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..d247940 --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,44 @@ +RSpec.describe User, type: :model do + describe 'validations' do + it 'is valid with valid attributes' do + user = User.new(username: 'testuser', email: 'user@example.com', password: 'password') + + expect(user).to be_valid + end + + it 'is not valid without a username' do + user = User.new(email: 'user@example.com', password: 'password') + + expect(user).not_to be_valid + expect(user.errors[:username]).to include("can't be blank") + end + + it 'is not valid without an email' do + user = User.new(username: 'testuser', password: 'password') + + expect(user).not_to be_valid + expect(user.errors[:email]).to include("can't be blank") + end + + it 'is not valid with a duplicate username' do + User.create(username: 'testuser', email: 'user1@example.com', password: 'password') + user = User.new(username: 'testuser', email: 'user2@example.com', password: 'password') + + expect(user).not_to be_valid + expect(user.errors[:username]).to include('has already been taken') + end + end + + describe 'associations' do + it 'has many cars through my_reservations' do + user = User.reflect_on_association(:cars) + expect(user.macro).to eq(:has_many) + expect(user.options[:through]).to eq(:my_reservations) + end + + it 'has many my_reservations' do + user = User.reflect_on_association(:my_reservations) + expect(user.macro).to eq(:has_many) + end + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..a15455f --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,65 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'spec_helper' +ENV['RAILS_ENV'] ||= 'test' +require_relative '../config/environment' +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f } + +# 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 + + # 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..35de9f0 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,98 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end From 7517f9bf9e54db9692770faa10983a699e9337f3 Mon Sep 17 00:00:00 2001 From: suleiman gacheru Date: Mon, 11 Dec 2023 17:50:48 +0300 Subject: [PATCH 02/14] modify tests, modify order for associations in models --- Gemfile | 3 ++ Gemfile.lock | 16 ++++++++++ app/models/car.rb | 2 +- app/models/user.rb | 4 +-- spec/models/car_spec.rb | 22 ++------------ spec/models/my_reservation_spec.rb | 11 +++---- spec/models/user_spec.rb | 46 ++++------------------------ spec/rails_helper.rb | 48 +++++++++++++++++++----------- 8 files changed, 64 insertions(+), 88 deletions(-) diff --git a/Gemfile b/Gemfile index d5b9d41..8a5b4d3 100644 --- a/Gemfile +++ b/Gemfile @@ -41,3 +41,6 @@ gem 'devise-jwt' gem 'paranoia', '~> 2.5' gem 'rack-cors' gem 'rswag' +gem 'factory_bot_rails' +gem 'shoulda-matchers' +gem 'database_cleaner' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 32bf81a..d71ef4d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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) @@ -283,6 +298,7 @@ DEPENDENCIES rails-controller-testing rspec-rails rswag + shoulda-matchers tzinfo-data RUBY VERSION diff --git a/app/models/car.rb b/app/models/car.rb index 93afe35..194cce6 100644 --- a/app/models/car.rb +++ b/app/models/car.rb @@ -1,7 +1,7 @@ class Car < ApplicationRecord acts_as_paranoid - has_many :users, through: :my_reservations has_many :my_reservations + has_many :users, through: :my_reservations validates :name, presence: true, length: { minimum: 2, maximum: 150 } validates :description, presence: true diff --git a/app/models/user.rb b/app/models/user.rb index 4a40dd0..532da48 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/spec/models/car_spec.rb b/spec/models/car_spec.rb index 90c8a04..970e50a 100644 --- a/spec/models/car_spec.rb +++ b/spec/models/car_spec.rb @@ -1,26 +1,10 @@ - require 'rails_helper' RSpec.describe Car, type: :model do - describe 'validations' do - it { should validate_presence_of(:name) } - it { should validate_length_of(:name).is_at_least(2).is_at_most(150) } - - it { should validate_presence_of(:description) } - - it { should validate_presence_of(:pricePerHr) } - - it { should validate_presence_of(:seating_capacity) } - - it { should validate_presence_of(:rental_duration) } - end - describe 'associations' do - it { should have_many(:my_reservations) } - it { should have_many(:users).through(:my_reservations) } + it { is_expected.to have_many(:my_reservations) } + it { is_expected.to have_many(:users).through(:my_reservations) } end - describe 'acts_as_paranoid' do - it { should act_as_paranoid } - end + # Add tests for other validations here end diff --git a/spec/models/my_reservation_spec.rb b/spec/models/my_reservation_spec.rb index f84d951..de6d3d1 100644 --- a/spec/models/my_reservation_spec.rb +++ b/spec/models/my_reservation_spec.rb @@ -1,13 +1,10 @@ require 'rails_helper' RSpec.describe MyReservation, type: :model do - describe 'validations' do - it { should validate_presence_of(:date) } - it { should validate_presence_of(:city) } - end - describe 'associations' do - it { should belong_to(:user) } - it { should belong_to(:car) } + it { is_expected.to belong_to(:user) } + it { is_expected.to belong_to(:car) } end + + # Add tests for other validations here end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d247940..6689043 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,44 +1,10 @@ -RSpec.describe User, type: :model do - describe 'validations' do - it 'is valid with valid attributes' do - user = User.new(username: 'testuser', email: 'user@example.com', password: 'password') - - expect(user).to be_valid - end - - it 'is not valid without a username' do - user = User.new(email: 'user@example.com', password: 'password') - - expect(user).not_to be_valid - expect(user.errors[:username]).to include("can't be blank") - end - - it 'is not valid without an email' do - user = User.new(username: 'testuser', password: 'password') - - expect(user).not_to be_valid - expect(user.errors[:email]).to include("can't be blank") - end - - it 'is not valid with a duplicate username' do - User.create(username: 'testuser', email: 'user1@example.com', password: 'password') - user = User.new(username: 'testuser', email: 'user2@example.com', password: 'password') - - expect(user).not_to be_valid - expect(user.errors[:username]).to include('has already been taken') - end - end +require 'rails_helper' +RSpec.describe User, type: :model do describe 'associations' do - it 'has many cars through my_reservations' do - user = User.reflect_on_association(:cars) - expect(user.macro).to eq(:has_many) - expect(user.options[:through]).to eq(:my_reservations) - end - - it 'has many my_reservations' do - user = User.reflect_on_association(:my_reservations) - expect(user.macro).to eq(:has_many) - end + 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 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index a15455f..c6ba4e7 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,26 +1,15 @@ +# 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_relative '../config/environment' -# Prevent database truncation if the environment is production -abort("The Rails environment is running in production mode!") if Rails.env.production? +require File.expand_path('../config/environment', __dir__) require 'rspec/rails' -# Add additional requires below this line. Rails is not loaded until this point! +require 'shoulda/matchers' +require 'database_cleaner' -# Requires supporting ruby files with custom matchers and macros, etc, in -# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are -# run as spec files by default. This means that files in spec/support that end -# in _spec.rb will both be required and run as specs, causing the specs to be -# run twice. It is recommended that you do not name files matching this glob to -# end with _spec.rb. You can configure this pattern with the --pattern -# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. -# -# The following line is provided for convenience purposes. It has the downside -# of increasing the boot-up time by auto-requiring all files in the support -# directory. Alternatively, in the individual `*_spec.rb` files, manually -# require only the support files necessary. -# -# Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f } +# 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. @@ -29,6 +18,7 @@ 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 = [ @@ -43,6 +33,28 @@ # 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`. From 849c1ac91e2fb2539b7ed42ec1f301e8b1b68ca3 Mon Sep 17 00:00:00 2001 From: suleiman yusuf <108791588+hetrox8@users.noreply.github.com> Date: Mon, 11 Dec 2023 23:06:04 +0300 Subject: [PATCH 03/14] Update README.md --- README.md | 159 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 146 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7db80e4..c87d809 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,157 @@ -# README + -This README would normally document whatever steps are necessary to get the -application up and running. +
-Things you may want to cover: +
-* 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) +- [👥 Authors](#authors) +- [🔭 Future Features](#future-features) +- [🤝 Contributing](#contributing) +- [⭐️ Show your support](#support) +- [🙏 Acknowledgements](#acknowledgements) +- [❓ FAQ (OPTIONAL)](#faq) +- [📝 License](#license) -* Database creation +# 📖 vehicle booking app -* 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 -* Services (job queues, cache servers, search engines, etc.) +### Tech Stack +
+ Client + +
-* Deployment instructions +
+ - Server + +
-* ... +### Key Features + +- Rails API backend +- React Front-end +- Redux Toolkit used to consume the backend api + +

(back to top)

+ +## 💻 Getting Started + +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 + npm i + + +### 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. + +

(back to top)

+ + +## 👥 Authors + + +👤 **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) + + +

(back to top)

+ + +## 🔭 Future Features + +- None planned + + +

(back to top)

+ +## 🤝 Contributing + +Contributions, issues, and feature requests are welcome! + +Feel free to check the [issues page](../../issues/). + +

(back to top)

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

(back to top)

+ + +## 🙏 Acknowledgments + +I would like to thank Microverse for providing the resources and guidelines that enabled me to complete this project. + +

(back to top)

+ + + +## 📝 License + +This project is [MIT](./LICENSE) licensed. From 0c09917d4953768c1637aa22e45eb00bfbef75c1 Mon Sep 17 00:00:00 2001 From: suleiman yusuf <108791588+hetrox8@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:45:50 +0300 Subject: [PATCH 04/14] Update rails_helper.rb --- spec/rails_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c6ba4e7..40bbe40 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -9,7 +9,7 @@ require 'database_cleaner' # Prevent database truncation if the environment is production -abort("The Rails environment is running in production mode!") if Rails.env.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. From a6cdadc5e75150d958fa1b1a0a245c8d04e7044d Mon Sep 17 00:00:00 2001 From: suleiman yusuf <108791588+hetrox8@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:49:21 +0300 Subject: [PATCH 05/14] Update spec_helper.rb --- spec/spec_helper.rb | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 35de9f0..a9a65f6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -21,10 +21,10 @@ # This option will default to `true` in RSpec 4. It makes the `description` # and `failure_message` of custom matchers include text for helper methods # defined using `chain`, e.g.: - # be_bigger_than(2).and_smaller_than(4).description - # # => "be bigger than 2 and smaller than 4" + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" # ...rather than: - # # => "be bigger than 2" + # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true end @@ -32,29 +32,29 @@ # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| # Prevents you from mocking or stubbing a method that does not exist on - # a real object. This is generally recommended, and will default to + # a real object. This is generally recommended and will default to # `true` in RSpec 4. mocks.verify_partial_doubles = true end # This option will default to `:apply_to_host_groups` in RSpec 4 (and will - # have no way to turn it off -- the option exists only for backwards + # have no way to turn it off -- the option exists only for backward # compatibility in RSpec 3). It causes shared context metadata to be # inherited by the metadata hash of host groups and examples, rather than # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups # you care about by tagging them with `:focus` metadata. When nothing # is tagged with `:focus`, all examples get run. RSpec also provides # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # metadata: `fit`, `fdescribe`, and `fcontext`, respectively. config.filter_run_when_matching :focus - # Allows RSpec to persist some state between runs in order to support + # Allows RSpec to persist some state between runs to support # the `--only-failures` and `--next-failure` CLI options. We recommend # you configure your source control system to ignore this file. config.example_status_persistence_file_path = "spec/examples.txt" @@ -64,7 +64,7 @@ # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ config.disable_monkey_patching! - # This setting enables warnings. It's recommended, but in some cases may + # This setting enables warnings. It's recommended, but in some cases, it may # be too noisy due to issues in dependencies. config.warnings = true @@ -74,12 +74,12 @@ if config.files_to_run.one? # Use the documentation formatter for detailed output, # unless a formatter has already been configured - # (e.g. via a command-line flag). + # (e.g., via a command-line flag). config.default_formatter = "doc" end # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running + # end of the spec run to help surface which specs are running # particularly slow. config.profile_examples = 10 @@ -94,5 +94,4 @@ # test failures related to randomization by passing the same `--seed` value # as the one that triggered the failure. Kernel.srand config.seed -=end end From 993bdddabfe1f27ecbf319e8b95e8290c418f67c Mon Sep 17 00:00:00 2001 From: suleiman yusuf <108791588+hetrox8@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:57:15 +0300 Subject: [PATCH 06/14] Update spec_helper.rb --- spec/spec_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a9a65f6..6bffcec 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -57,7 +57,7 @@ # Allows RSpec to persist some state between runs to support # the `--only-failures` and `--next-failure` CLI options. We recommend # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" + config.example_status_persistence_file_path = 'spec/examples.txt' # Limits the available syntax to the non-monkey patched syntax that is # recommended. For more details, see: @@ -75,7 +75,7 @@ # Use the documentation formatter for detailed output, # unless a formatter has already been configured # (e.g., via a command-line flag). - config.default_formatter = "doc" + config.default_formatter = 'doc' end # Print the 10 slowest examples and example groups at the From 8dcf4574239c2ced5d8b9d9be4105aae02a4d207 Mon Sep 17 00:00:00 2001 From: suleiman yusuf <108791588+hetrox8@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:59:27 +0300 Subject: [PATCH 07/14] Update Gemfile --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 8a5b4d3..eda166c 100644 --- a/Gemfile +++ b/Gemfile @@ -38,9 +38,9 @@ group :development do end gem 'devise-jwt' +gem 'factory_bot_rails' +gem 'database_cleaner' gem 'paranoia', '~> 2.5' gem 'rack-cors' gem 'rswag' -gem 'factory_bot_rails' gem 'shoulda-matchers' -gem 'database_cleaner' \ No newline at end of file From d13dfd210a6ed0ff3d062412eb5066cac1b3d308 Mon Sep 17 00:00:00 2001 From: suleiman yusuf <108791588+hetrox8@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:03:59 +0300 Subject: [PATCH 08/14] Update Gemfile --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index eda166c..d5b5df8 100644 --- a/Gemfile +++ b/Gemfile @@ -38,8 +38,8 @@ group :development do end gem 'devise-jwt' -gem 'factory_bot_rails' gem 'database_cleaner' +gem 'factory_bot_rails' gem 'paranoia', '~> 2.5' gem 'rack-cors' gem 'rswag' From 068b3c5a7dcbdd5b9a348b072ce16bdaf8b38306 Mon Sep 17 00:00:00 2001 From: suleiman yusuf <108791588+hetrox8@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:05:15 +0300 Subject: [PATCH 09/14] Update Gemfile --- Gemfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index d5b5df8..2510f74 100644 --- a/Gemfile +++ b/Gemfile @@ -37,8 +37,9 @@ group :development do gem 'rails-controller-testing' end -gem 'devise-jwt' + gem 'database_cleaner' +gem 'devise-jwt' gem 'factory_bot_rails' gem 'paranoia', '~> 2.5' gem 'rack-cors' From a6da522de44653c8be9c2e17a7b9e840d8bd8d10 Mon Sep 17 00:00:00 2001 From: suleiman yusuf <108791588+hetrox8@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:06:15 +0300 Subject: [PATCH 10/14] Update Gemfile --- Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile b/Gemfile index 2510f74..cd00a22 100644 --- a/Gemfile +++ b/Gemfile @@ -37,7 +37,6 @@ group :development do gem 'rails-controller-testing' end - gem 'database_cleaner' gem 'devise-jwt' gem 'factory_bot_rails' From 391620b4fd026a38bd28d8ccb833070d72327c4c Mon Sep 17 00:00:00 2001 From: suleiman yusuf <108791588+hetrox8@users.noreply.github.com> Date: Tue, 12 Dec 2023 15:14:47 +0300 Subject: [PATCH 11/14] Update README.md --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c87d809..79abad1 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,9 @@ - [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) @@ -78,8 +81,15 @@ Use the following URL to clone this project: Open the terminal in the root directory of the project and run the following command to install all dependencies. bundle install - npm i +### Frontend Repository +Reference the [Frontend Repository](https://github.com/your-frontend-repo) for the corresponding frontend. + +### ERD Image +Add an ERD image to visualize the database schema. + +### 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. From 8a6caf7e21dd385068fed7df7ef5a692373e06db Mon Sep 17 00:00:00 2001 From: suleiman yusuf <108791588+hetrox8@users.noreply.github.com> Date: Tue, 12 Dec 2023 15:16:19 +0300 Subject: [PATCH 12/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 79abad1..dd91e84 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ Open the terminal in the root directory of the project and run the following com bundle install ### Frontend Repository -Reference the [Frontend Repository](https://github.com/your-frontend-repo) for the corresponding frontend. +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. From 2774efce0a366ac713e639803b5350b73686b3f7 Mon Sep 17 00:00:00 2001 From: suleiman yusuf <108791588+hetrox8@users.noreply.github.com> Date: Tue, 12 Dec 2023 15:19:43 +0300 Subject: [PATCH 13/14] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index dd91e84..0a8e642 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,8 @@ Reference the [Frontend Repository](https://github.com/tan12082001/Vehicle-Booki ### 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. From 6458fb3fc1a5ceaa18f5d90a8dc5f180dac1b387 Mon Sep 17 00:00:00 2001 From: suleiman gacheru Date: Tue, 12 Dec 2023 19:20:06 +0300 Subject: [PATCH 14/14] solved failing test for car --- app/models/car.rb | 2 +- spec/examples.txt | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 spec/examples.txt diff --git a/app/models/car.rb b/app/models/car.rb index 93afe35..194cce6 100644 --- a/app/models/car.rb +++ b/app/models/car.rb @@ -1,7 +1,7 @@ class Car < ApplicationRecord acts_as_paranoid - has_many :users, through: :my_reservations has_many :my_reservations + has_many :users, through: :my_reservations validates :name, presence: true, length: { minimum: 2, maximum: 150 } validates :description, presence: true diff --git a/spec/examples.txt b/spec/examples.txt new file mode 100644 index 0000000..0a7cf00 --- /dev/null +++ b/spec/examples.txt @@ -0,0 +1,8 @@ +example_id | status | run_time | +------------------------------------------- | ------ | --------------- | +./spec/models/car_spec.rb[1:1:1] | passed | 0.00187 seconds | +./spec/models/car_spec.rb[1:1:2] | passed | 0.05522 seconds | +./spec/models/my_reservation_spec.rb[1:1:1] | passed | 0.03853 seconds | +./spec/models/my_reservation_spec.rb[1:1:2] | passed | 0.00198 seconds | +./spec/models/user_spec.rb[1:1:1] | passed | 0.00376 seconds | +./spec/models/user_spec.rb[1:1:2] | passed | 0.11558 seconds |