Skip to content

Commit

Permalink
Merge pull request #14 from Fatima-hub333/feature/vehicle-model-update
Browse files Browse the repository at this point in the history
Feature/vehicle model update
  • Loading branch information
kinginthenorthcodez authored Oct 4, 2022
2 parents d795d21 + c6b7ab3 commit eb0a61a
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/vehicles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ def set_vehicle
end

def vehicle_params
params.permit(:brand, :model, :price, :image, :description)
params.permit(:brand, :model, :price, :image, :visible, :description)
end
end
2 changes: 1 addition & 1 deletion app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def create
def destroy
@user = current_user
if @user
render json: { status: 'Success', message: 'signed out', data: @user }, status: :ok
render json: { status: 'Success', message: 'signed out', data: @user }, status: 200
sign_out(@user)
else
render json: { status: 'Failed', message: 'There is no user to sign out' }, status: :unauthorized
Expand Down
2 changes: 1 addition & 1 deletion app/models/vehicle.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Vehicle < ApplicationRecord
validates :brand, :model, :description, :image, presence: true
validates :brand, :model, :description, :image, :visible, presence: true
validates :price, numericality: { greater_than_or_equal_to: 0 }

has_many :reservations, dependent: :destroy
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20221004054904_add_visble_to_vehicle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddVisbleToVehicle < ActiveRecord::Migration[7.0]
def change
add_column :vehicles, :visible, :boolean
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

user1 = User.create!(name: 'John Doe', email: '[email protected]', password: 'test123', roles: ['admin'])
user2 = User.create!(name: 'Jane Doe', email: '[email protected]', password: 'test123', roles: ['admin'])
user1.confirm
user2.confirm
veh1 = Vehicle.create!(brand: 'BWM', model: 'BMW-30', image: 'image-bmw', price: 80, description: 'good and lightspeed with low consumptiom')
veh2 = Vehicle.create!(brand: 'Macendiz', model: 'Benz-30', image: 'image-Benz', price: 90, description: 'good and lightspeed with low consumptiom')
veh3 = Vehicle.create!(brand: 'G-Wagon', model: 'G-wagon-15', image: 'image-wagon', price: 95, description: 'good and lightspeed with low consumptiom')
veh1 = Vehicle.create!(brand: 'BWM', model: 'BMW-30', image: 'image-bmw', price: 80, visible: true, description: 'good and lightspeed with low consumptiom')
veh2 = Vehicle.create!(brand: 'Macendiz', model: 'Benz-30', image: 'image-Benz', price: 90, visible: true,description: 'good and lightspeed with low consumptiom')
veh3 = Vehicle.create!(brand: 'G-Wagon', model: 'G-wagon-15', image: 'image-wagon', price: 95, visible: true, description: 'good and lightspeed with low consumptiom')
res1 = Reservation.create!(user: user1, vehicle: veh1, date: '24-09-2022', city: 'bravos')
res1 = Reservation.create!(user: user2, vehicle: veh1,date: '24-09-2022', city: 'capetown')
res1 = Reservation.create!(user: user2, vehicle: veh3,date: '24-09-2022', city: 'lusaka')
Expand Down
19 changes: 12 additions & 7 deletions spec/requests/api/v1/vehicles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
model: 'Benz-30',
price: '90.0',
image: 'image-Benz',
visible: 'true',
description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T04:51:07.296Z',
updated_at: '2022-10-01T04:51:07.296Z'
Expand All @@ -35,6 +36,7 @@
brand: 'G-Wagon',
model: 'G-wagon-15',
price: '95.0',
visible: 'true',
image: 'image-wagon',
description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T04:51:07.302Z',
Expand All @@ -45,6 +47,7 @@
brand: 'Farari',
model: 'BMW',
price: '450.0',
visible: 'true',
image: 'farari.png',
description: 'Some text here',
created_at: '2022-10-01T12:39:00.705Z',
Expand Down Expand Up @@ -75,6 +78,7 @@
model: { type: :string },
image: { type: :string },
price: { type: :decimal },
visible: { type: :boolean },
description: { type: :text }
},
required: %w[authenticate_token brand model image price description]
Expand All @@ -83,7 +87,7 @@
let(:params) do
{ authentication_token: User.last.authentication_token,
brand: 'Mecedz', model: 'benz-30', image: 'image-bmw',
price: 80, description: 'good and lightspeed with low consumptiom' }
price: 80, visible: true, description: 'good and lightspeed with low consumptiom' }
end
example 'application/json', 'success', {
status: 'Success',
Expand All @@ -93,6 +97,7 @@
brand: 'G-Wagon',
model: 'G-wagon-15',
price: '95.0',
visible: 'true',
image: 'image-wagon',
description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T22:01:18.479Z',
Expand Down Expand Up @@ -121,7 +126,7 @@
let(:params) { { authentication_token: User.first.authentication_token } }
example 'application/json', 'success', {
status: 'Success', message: 'Loaded vehicle',
data: { id: 4, brand: 'BWM', model: 'BMW-30', price: '80.0',
data: { id: 4, brand: 'BWM', model: 'BMW-30', price: '80.0', visible: 'true',
image: 'image-bmw', description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T04:51:07.286Z', updated_at: '2022-10-01T04:51:07.286Z' }
}
Expand All @@ -144,11 +149,11 @@
let(:params) do
{ authentication_token: User.first.authentication_token,
brand: 'Lambo', model: 'lambo-30', image: 'image-bmw',
price: 80, description: 'good and lightspeed with low consumptiom' }
price: 80, visible: true, description: 'good and lightspeed with low consumptiom' }
end
example 'application/json', 'success', {
status: 'Success', message: 'Loaded vehicle',
data: { id: 4, brand: 'BWM', model: 'BMW-30', price: '80.0',
data: { id: 4, brand: 'BWM', model: 'BMW-30', price: '80.0', visible: 'true',
image: 'image-bmw', description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T04:51:07.286Z', updated_at: '2022-10-01T04:51:07.286Z' }
}
Expand All @@ -171,11 +176,11 @@
let(:params) do
{ authentication_token: User.first.authentication_token,
brand: 'Lambo', model: 'lambo-30', image: 'image-bmw',
price: 80, description: 'good and lightspeed with low consumptiom' }
price: 80, visible: true, description: 'good and lightspeed with low consumptiom' }
end
example 'application/json', 'success', {
status: 'Success', message: 'Loaded vehicle',
data: { id: 4, brand: 'BWM', model: 'BMW-30', price: '80.0',
data: { id: 4, brand: 'BWM', model: 'BMW-30', price: '80.0', visible: 'true',
image: 'image-bmw', description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T04:51:07.286Z', updated_at: '2022-10-01T04:51:07.286Z' }
}
Expand All @@ -199,7 +204,7 @@
example 'application/json', 'success', {
status: 'Success', message: 'Loaded vehicle',
data: { id: 4,
brand: 'BWM', model: 'BMW-30', price: '80.0',
brand: 'BWM', model: 'BMW-30', price: '80.0', visible: 'true',
image: 'image-bmw', description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T04:51:07.286Z', updated_at: '2022-10-01T04:51:07.286Z' }
}
Expand Down
6 changes: 2 additions & 4 deletions spec/requests/login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
RSpec.describe 'users/sign_in', type: :request do
context 'sign_in' do
before(:each) do
Rails.application.load_seed
User.find_by(email: '[email protected]').confirm
post user_session_path, params: { email: '[email protected]', password: 'test123' }
post user_session_path, params: { email: '[email protected]', password: 'test123' }
end
it 'Responds with ok status' do
puts response
Expand All @@ -18,7 +16,7 @@
end
it 'Responds data has the email of the user signed in' do
data = JSON.parse(response.body)['data']
expect(data['email']).to eq('john@gmail.com')
expect(data['email']).to eq('john123@gmail.com')
end
end
end
4 changes: 0 additions & 4 deletions spec/requests/reservation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
RSpec.describe '/api/v1/reservation', type: :request do
context 'Create Reservation ' do
before(:each) do
Rails.application.load_seed
User.first.confirm
get api_v1_reservations_path, params: { authentication_token: User.first.authentication_token }
end

Expand All @@ -29,8 +27,6 @@
end
context 'Unauthorized access' do
before(:each) do
Rails.application.load_seed
User.first.confirm
get api_v1_reservations_path
end
it 'Respnse unauthrozed' do
Expand Down
6 changes: 2 additions & 4 deletions spec/requests/sign_out_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
RSpec.describe 'users/sign_out', type: :request do
context 'sign-out existing session' do
before do
Rails.application.load_seed
User.find_by(email: '[email protected]').confirm
post user_session_path, params: { email: '[email protected]', password: 'test123' }
post user_session_path, params: { email: '[email protected]', password: 'test123' }
delete destroy_user_session_path
end
it 'Responds with ok status' do
Expand All @@ -17,7 +15,7 @@
end
it 'Responds data has email of the user signed out' do
data = JSON.parse(response.body)['data']
expect(data['email']).to eq('john@gmail.com')
expect(data['email']).to eq('john123@gmail.com')
end
end

Expand Down
18 changes: 16 additions & 2 deletions spec/requests/users/sessions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
}

response(200, 'successful') do
@user = User.last
@user.confirm
let(:params) { { email: '[email protected]', password: 'test123' } }
example 'application/json', :successfull_login, {
status: 'Success',
Expand Down Expand Up @@ -47,5 +45,21 @@
end
end
end

path '/users/sign_out' do
delete('delete session') do
tags 'Sign-out'
description ' Signs out user in session'
produces 'application/json'

response(401, 'unauthorized') do
example 'application/json', :unauthorized, {
status: 'Failed',
message: 'There is no user to sign out'
}
run_test!
end
end
end
end
# rubocop:enable Metrics/BlockLength
10 changes: 2 additions & 8 deletions spec/requests/vehicles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
RSpec.describe '/api/v1/vehicles', type: :request do
context 'Get vehicles ' do
before(:each) do
Rails.application.load_seed
User.first.confirm
get api_v1_vehicles_path, params: { authentication_token: User.first.authentication_token }
end

Expand All @@ -19,7 +17,6 @@
data = JSON.parse(response.body)
expect(data['message']).to eq('Loaded vehicle')
end

it 'List brand Vehicle' do
get api_v1_vehicle_path(Vehicle.first.id), params: { authentication_token: User.first.authentication_token }
data = JSON.parse(response.body)['data']['brand']
Expand All @@ -29,19 +26,18 @@
post api_v1_vehicles_path,
params: { authentication_token: User.first.authentication_token,
brand: 'Mecedz', model: 'benz-30', image: 'image-bmw',
price: 80, description: 'good and lightspeed with low consumptiom' }
price: 80, visible: true, description: 'good and lightspeed with low consumptiom' }
data = JSON.parse(response.body)
expect(data['message']).to eq('Created Vehicle')
end
it 'Update a vehicle' do
patch api_v1_vehicle_path(Vehicle.last.id),
params: { authentication_token: User.first.authentication_token,
brand: 'Lambo', model: 'lambo-30', image: 'image-bmw',
price: 80, description: 'good and lightspeed with low consumptiom' }
price: 80, visible: true, description: 'good and lightspeed with low consumptiom' }
data = JSON.parse(response.body)
expect(data['message']).to eq('Updeted Vehicle Succesfully')
end

it 'Deletes a vehicle' do
delete api_v1_vehicle_path(Vehicle.last.id), params: { authentication_token: User.first.authentication_token }
data = JSON.parse(response.body)
Expand All @@ -50,8 +46,6 @@
end
context 'Unauthorized access' do
before(:each) do
Rails.application.load_seed
User.first.confirm
get api_v1_vehicles_path
end
it 'Respnse unauthrozed' do
Expand Down
26 changes: 26 additions & 0 deletions swagger/v1/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,15 @@ paths:
model: Benz-30
price: '90.0'
image: image-Benz
visible: 'true'
description: good and lightspeed with low consumptiom
created_at: '2022-10-01T04:51:07.296Z'
updated_at: '2022-10-01T04:51:07.296Z'
- id: 6
brand: G-Wagon
model: G-wagon-15
price: '95.0'
visible: 'true'
image: image-wagon
description: good and lightspeed with low consumptiom
created_at: '2022-10-01T04:51:07.302Z'
Expand All @@ -202,6 +204,7 @@ paths:
brand: Farari
model: BMW
price: '450.0'
visible: 'true'
image: farari.png
description: Some text here
created_at: '2022-10-01T12:39:00.705Z'
Expand Down Expand Up @@ -236,6 +239,7 @@ paths:
brand: G-Wagon
model: G-wagon-15
price: '95.0'
visible: 'true'
image: image-wagon
description: good and lightspeed with low consumptiom
created_at: '2022-10-01T22:01:18.479Z'
Expand All @@ -256,6 +260,8 @@ paths:
type: string
price:
type: decimal
visible:
type: boolean
description:
type: text
required:
Expand Down Expand Up @@ -304,6 +310,7 @@ paths:
brand: BWM
model: BMW-30
price: '80.0'
visible: 'true'
image: image-bmw
description: good and lightspeed with low consumptiom
created_at: '2022-10-01T04:51:07.286Z'
Expand Down Expand Up @@ -339,6 +346,7 @@ paths:
brand: BWM
model: BMW-30
price: '80.0'
visible: 'true'
image: image-bmw
description: good and lightspeed with low consumptiom
created_at: '2022-10-01T04:51:07.286Z'
Expand Down Expand Up @@ -374,6 +382,7 @@ paths:
brand: BWM
model: BMW-30
price: '80.0'
visible: 'true'
image: image-bmw
description: good and lightspeed with low consumptiom
created_at: '2022-10-01T04:51:07.286Z'
Expand Down Expand Up @@ -409,6 +418,7 @@ paths:
brand: BWM
model: BMW-30
price: '80.0'
visible: 'true'
image: image-bmw
description: good and lightspeed with low consumptiom
created_at: '2022-10-01T04:51:07.286Z'
Expand Down Expand Up @@ -518,6 +528,22 @@ paths:
required:
- email
- password
"/users/sign_out":
delete:
summary: delete session
tags:
- Sign-out
description: " Signs out user in session"
responses:
'401':
description: unauthorized
content:
application/json:
examples:
unauthorized:
value:
status: Failed
message: There is no user to sign out
servers:
- url: https://{herokuapp}
variables:
Expand Down

0 comments on commit eb0a61a

Please sign in to comment.