Correccion de nombre ruta y se agregan metodos
This commit is contained in:
16
app/models/ruta.rb
Normal file
16
app/models/ruta.rb
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
class Ruta < ApplicationRecord
|
||||||
|
def direccion_inicio
|
||||||
|
@viajes.first.direccion_partida
|
||||||
|
end
|
||||||
|
|
||||||
|
def direccion_final
|
||||||
|
@viajes.last.direccion_llegada
|
||||||
|
end
|
||||||
|
|
||||||
|
def kms_total
|
||||||
|
@viajes.reduce(0) do |sum, viaje|
|
||||||
|
sum += viaje.kms
|
||||||
|
sum
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
7
test/models/ruta_test.rb
Normal file
7
test/models/ruta_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class RutaTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Reference in New Issue
Block a user