Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions app/controllers/cars_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
class CarsController < ApplicationController

def index
@cars = Car.all
end

def new
@car = Car.new
@car_models = CarModel.all
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class HomeController < ApplicationController
def index
@cars = Car.all
@cars = Car.where(status: :available).order(:updated_at).last(10)
@all_cars = Car.all - @cars
end
end
20 changes: 7 additions & 13 deletions app/views/cars/_car.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<h1>Detalhes do Veículo</h1>
<dl>
<strong><dt>Modelo do Veículo</dt></strong>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Me parece meio brusca essa mudança ^^
Acredito que outros testes vão quebrar nas demais branches, talvez fosse uma boa alinhar com todo time

<dd><%= car.car_model.name %></dd>
<strong><dt>Placa</dt></strong>
<dd><%= car.license_plate %></dd>
<strong><dt>Ano</dt></strong>
<dd><%= car.car_model.year%></dd>
<strong><dt>Cor</dt></strong>
<dd><%= car.color %>
</dd><strong><dt>Informaçōes complementares sobre o veículo</dt></strong>
<dd><%= car.car_model.car_options %></dd>
</dl>
<div class="col-md-2 mb-3 mt-3" >
<div class="card p-3">
<strong><dt>Modelo do Veículo</dt></strong>
<dd><%= link_to car.car_identification, car %></dd>
<%= link_to "Ver detalhes", car %>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/cars/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render @cars %>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Poderia ter um titulo nessa tela

11 changes: 8 additions & 3 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<% @cars.each do |car|%>
<%= link_to "#{car.car_model.name} - #{car.license_plate}", car %>
<% end %>
<h2>Últimos carros disponíveis</h2>
<div class="row last-available-cars">
<%= render @cars %>
</div>
<%= link_to 'Ver todos disponíveis', cars_path, class: "btn btn-info float-right" %>
<h2>Todos os carros</h2>
<%= render @all_cars %>

2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
end
end
resources :subsidiary_car_models, only: %i[show new create]
resources :cars, only: %i[show new create] do
resources :cars, only: %i[index show new create] do
resources :fines, only: %i[show new create]
resources :maintenances, only: %i[show new create edit update]
resources :inspections, only: %i[ new create]
Expand Down
5 changes: 2 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
t.datetime "updated_at", null: false
t.string "license_plate"
t.string "color"
t.integer "subsidiary_id"
t.integer "status", default: 0
t.integer "subsidiary_id"
t.index ["car_model_id"], name: "index_cars_on_car_model_id"
t.index ["subsidiary_id"], name: "index_cars_on_subsidiary_id"
end
Expand Down Expand Up @@ -110,9 +110,8 @@
t.integer "customer_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "start_at"
t.datetime "finish_at"
t.datetime "finished_at"
t.datetime "start_at"
t.index ["car_id"], name: "index_rentals_on_car_id"
t.index ["customer_id"], name: "index_rentals_on_customer_id"
t.index ["user_id"], name: "index_rentals_on_user_id"
Expand Down
6 changes: 3 additions & 3 deletions spec/factories/car_models.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FactoryBot.define do
factory :car_model do
name { "Uno" }
year { "2008" }
name { Faker::Vehicle.make }
year { Faker::Vehicle.year }
manufacture
car_options { "3 portas" }
car_options { Faker::Vehicle.car_options.first }
end
end
43 changes: 43 additions & 0 deletions spec/features/admin/admin_view_cars_in_home_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'rails_helper'

feature 'List cars in home' do

scenario 'successfully' do

#arrange
user = create(:user)
login_as(user)

create_list(:car, 10, car_model: create(:car_model, name: 'Palio'))
create_list(:car, 5, car_model: create(:car_model, name: 'X1'))

#act
visit root_path

#assert
within("div.last-available-cars") do
expect(page).to have_content('X1', count: 5)
expect(page).to have_content('Palio', count: 5)
expect(page).not_to have_content('Palio', count: 10)
end


end

scenario 'has an option to view all cars' do

user = create(:user)
login_as(user)

create_list(:car, 10, car_model: create(:car_model, name: 'Palio'))
create_list(:car, 5, car_model: create(:car_model, name: 'X1'))

visit root_path
click_on "Ver todos"

expect(current_path).to eq cars_path
expect(page).to have_content('X1', count: 5)
expect(page).to have_content('Palio', count: 10)

end
end