Pruebas
This commit is contained in:
@ -27,7 +27,7 @@ FROM base AS build
|
||||
|
||||
# Install packages needed to build gems
|
||||
RUN apt-get update -qq && \
|
||||
apt-get install --no-install-recommends -y build-essential git pkg-config && \
|
||||
apt-get install --no-install-recommends -y build-essential default-libmysqlclient-dev git pkg-config && \
|
||||
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
||||
|
||||
# Install application gems
|
||||
|
4
Gemfile
4
Gemfile
@ -2,8 +2,8 @@ source "https://rubygems.org"
|
||||
|
||||
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
|
||||
gem "rails", "~> 7.2.1"
|
||||
# Use sqlite3 as the database for Active Record
|
||||
gem "sqlite3", ">= 1.4"
|
||||
# Use mysql2 as the database for Active Record
|
||||
gem "mysql2", "~> 0.5"
|
||||
# Use the Puma web server [https://github.com/puma/puma]
|
||||
gem "puma", ">= 5.0"
|
||||
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
|
||||
|
13
Gemfile.lock
13
Gemfile.lock
@ -111,6 +111,7 @@ GEM
|
||||
mini_mime (1.1.5)
|
||||
minitest (5.25.1)
|
||||
msgpack (1.7.2)
|
||||
mysql2 (0.5.6)
|
||||
net-imap (0.4.16)
|
||||
date
|
||||
net-protocol
|
||||
@ -216,16 +217,6 @@ GEM
|
||||
rubocop-rails
|
||||
ruby-progressbar (1.13.0)
|
||||
securerandom (0.3.1)
|
||||
sqlite3 (2.0.4-aarch64-linux-gnu)
|
||||
sqlite3 (2.0.4-aarch64-linux-musl)
|
||||
sqlite3 (2.0.4-arm-linux-gnu)
|
||||
sqlite3 (2.0.4-arm-linux-musl)
|
||||
sqlite3 (2.0.4-arm64-darwin)
|
||||
sqlite3 (2.0.4-x86-linux-gnu)
|
||||
sqlite3 (2.0.4-x86-linux-musl)
|
||||
sqlite3 (2.0.4-x86_64-darwin)
|
||||
sqlite3 (2.0.4-x86_64-linux-gnu)
|
||||
sqlite3 (2.0.4-x86_64-linux-musl)
|
||||
stringio (3.1.1)
|
||||
thor (1.3.2)
|
||||
timeout (0.4.1)
|
||||
@ -259,10 +250,10 @@ DEPENDENCIES
|
||||
bootsnap
|
||||
brakeman
|
||||
debug
|
||||
mysql2 (~> 0.5)
|
||||
puma (>= 5.0)
|
||||
rails (~> 7.2.1)
|
||||
rubocop-rails-omakase
|
||||
sqlite3 (>= 1.4)
|
||||
tzinfo-data
|
||||
|
||||
BUNDLED WITH
|
||||
|
19
app/controllers/ruta_controller.rb
Normal file
19
app/controllers/ruta_controller.rb
Normal file
@ -0,0 +1,19 @@
|
||||
class RutaController < ApplicationController
|
||||
def get
|
||||
Ruta.find(params[:ruta])
|
||||
end
|
||||
|
||||
def add
|
||||
@ruta = Ruta.create
|
||||
for data_viaje in params[:viajes] do
|
||||
viaje = @ruta.viajes.create(direccion_partida: data_viaje[:direccion_partida], direccion_llegada: data_viaje[:direccion_llegada], kms: data_viaje[:kms])
|
||||
for data_entrega in data_viaje[:entregas] do
|
||||
viaje.entregas.create(nombre_recibe: data_entrega[:nombre_recibe], carga: data_entrega[:carga])
|
||||
end
|
||||
for data_retiro in data_viaje[:retiros] do
|
||||
viaje.retiros.create(nombre_entrega: data_retiro[:nombre_recibe], carga: data_retiro[:carga])
|
||||
end
|
||||
end
|
||||
@ruta
|
||||
end
|
||||
end
|
@ -1,2 +1,3 @@
|
||||
class Entrega < ApplicationRecord
|
||||
belongs_to :viaje
|
||||
end
|
||||
|
@ -1,2 +1,3 @@
|
||||
class Retiro < ApplicationRecord
|
||||
belongs_to :viaje
|
||||
end
|
||||
|
@ -1,4 +1,6 @@
|
||||
class Ruta < ApplicationRecord
|
||||
has_many :viajes
|
||||
|
||||
def direccion_inicio
|
||||
@viajes.first.direccion_partida
|
||||
end
|
||||
|
@ -1,2 +1,5 @@
|
||||
class Viaje < ApplicationRecord
|
||||
belongs_to :ruta
|
||||
has_many :entregas
|
||||
has_many :retiros
|
||||
end
|
||||
|
@ -1,32 +1,51 @@
|
||||
# SQLite. Versions 3.8.0 and up are supported.
|
||||
# gem install sqlite3
|
||||
# MySQL. Versions 5.5.8 and up are supported.
|
||||
#
|
||||
# Ensure the SQLite 3 gem is defined in your Gemfile
|
||||
# gem "sqlite3"
|
||||
# Install the MySQL driver
|
||||
# gem install mysql2
|
||||
#
|
||||
# Ensure the MySQL gem is defined in your Gemfile
|
||||
# gem "mysql2"
|
||||
#
|
||||
# And be sure to use new-style password hashing:
|
||||
# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
|
||||
#
|
||||
default: &default
|
||||
adapter: sqlite3
|
||||
adapter: mysql2
|
||||
encoding: utf8mb4
|
||||
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
||||
timeout: 5000
|
||||
username: <%= ENV.fetch("DB_USER") {"root"} %>
|
||||
password: <%= ENV.fetch("DB_PASSWORD") {""} %>
|
||||
database: <%= ENV.fetch("DB_NAME") %>
|
||||
host: <%= ENV.fetch("DB_HOST") { "localhost" } %>
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
database: storage/development.sqlite3
|
||||
|
||||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
<<: *default
|
||||
database: storage/test.sqlite3
|
||||
|
||||
|
||||
# SQLite3 write its data on the local filesystem, as such it requires
|
||||
# persistent disks. If you are deploying to a managed service, you should
|
||||
# make sure it provides disk persistence, as many don't.
|
||||
# As with config/credentials.yml, you never want to store sensitive information,
|
||||
# like your database password, in your source code. If your source code is
|
||||
# ever seen by anyone, they now have access to your database.
|
||||
#
|
||||
# Instead, provide the password or a full connection URL as an environment
|
||||
# variable when you boot the app. For example:
|
||||
#
|
||||
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
|
||||
#
|
||||
# If the connection URL is provided in the special DATABASE_URL environment
|
||||
# variable, Rails will automatically merge its configuration values on top of
|
||||
# the values provided in this file. Alternatively, you can specify a connection
|
||||
# URL environment variable explicitly:
|
||||
#
|
||||
# production:
|
||||
# url: <%= ENV["MY_APP_DATABASE_URL"] %>
|
||||
#
|
||||
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
|
||||
# for a full overview on how database connection configuration can be specified.
|
||||
#
|
||||
# Similarly, if you deploy your application as a Docker container, you must
|
||||
# ensure the database is located in a persisted volume.
|
||||
production:
|
||||
<<: *default
|
||||
# database: path/to/persistent/storage/production.sqlite3
|
||||
|
@ -1,4 +1,6 @@
|
||||
Rails.application.routes.draw do
|
||||
get "/ruta", to: 'ruta#get'
|
||||
post "/ruta", to: 'ruta#add'
|
||||
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
||||
|
||||
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
|
||||
|
@ -1,7 +1,6 @@
|
||||
class CreateRuta < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
create_table :ruta do |t|
|
||||
t.has_many :viajes
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
@ -1,12 +1,9 @@
|
||||
class CreateViajes < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
create_table :viajes do |t|
|
||||
t.belongs_to :ruta
|
||||
t.string :direccion_partida
|
||||
t.string :direccion_llegada
|
||||
t.int :kms
|
||||
t.has_many :entregas
|
||||
t.has_many :retiros
|
||||
t.integer :kms
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,8 @@
|
||||
class CreateEntregas < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
create_table :entregas do |t|
|
||||
t.belongs_to :viaje
|
||||
t.string :nombre_recibe # Quien recibe
|
||||
t.string :carga # Detalles de la carga, serializado
|
||||
t.text :carga # Detalles de la carga, serializado
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,8 @@
|
||||
class CreateRetiros < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
create_table :retiros do |t|
|
||||
t.belongs_to :viaje
|
||||
t.string :nombre_entrega # Quien entrega
|
||||
t.string :carga # Detalles de la carga, serializado
|
||||
t.text :carga # Detalles de la carga, serializado
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
40
db/schema.rb
generated
Normal file
40
db/schema.rb
generated
Normal file
@ -0,0 +1,40 @@
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# This file is the source Rails uses to define your schema when running `bin/rails
|
||||
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
||||
# be faster and is potentially less error prone than running all of your
|
||||
# migrations from scratch. Old migrations may fail to apply correctly if those
|
||||
# migrations use external dependencies or application code.
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.2].define(version: 2024_09_11_233430) do
|
||||
create_table "entregas", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
|
||||
t.string "nombre_recibe"
|
||||
t.text "carga"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "retiros", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
|
||||
t.string "nombre_entrega"
|
||||
t.text "carga"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "ruta", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "viajes", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t|
|
||||
t.string "direccion_partida"
|
||||
t.string "direccion_llegada"
|
||||
t.integer "kms"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
end
|
13
test/controllers/ruta_controller_test.rb
Normal file
13
test/controllers/ruta_controller_test.rb
Normal file
@ -0,0 +1,13 @@
|
||||
require "test_helper"
|
||||
|
||||
class RutaControllerTest < ActionDispatch::IntegrationTest
|
||||
test "should get get" do
|
||||
get ruta_get_url, params: {ruta: 1}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get add" do
|
||||
post ruta_add_url, params: {viajes: [{direccion_partida: "Partida", direccion_llegada: "Llegada", kms: 10, entregas: [{nombre_recibe: "Recibe", carga: "{\"cantidad\": 10, \"descripcion\": \"Cajas\"}"}], retiros: [{nombre_entrega: "Entrega", carga: "{\"cantidad\": 2, \"descripcion\": \"Cajas\"}"}]}]}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
@ -4,4 +4,12 @@ class RutaTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
test "create" do
|
||||
assert Ruta.create
|
||||
end
|
||||
|
||||
test "get" do
|
||||
ruta = Ruta.find(1)
|
||||
assert Ruta.id === 1
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user