-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
básicamente, representan un conjunto de relaciones entre productos y actividades. Eventualmente, se pueden modelar como subgrafos del total de las relaciones.
- Loading branch information
1 parent
f731324
commit 55d3c42
Showing
17 changed files
with
275 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
class CadenasController < ApplicationController | ||
# GET /cadenas | ||
# GET /cadenas.json | ||
def index | ||
@cadenas = Cadena.all | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json { render json: @cadenas } | ||
end | ||
end | ||
|
||
# GET /cadenas/1 | ||
# GET /cadenas/1.json | ||
def show | ||
@cadena = Cadena.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json { render json: @cadena } | ||
end | ||
end | ||
|
||
# GET /cadenas/new | ||
# GET /cadenas/new.json | ||
def new | ||
@cadena = Cadena.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.json { render json: @cadena } | ||
end | ||
end | ||
|
||
# GET /cadenas/1/edit | ||
def edit | ||
@cadena = Cadena.find(params[:id]) | ||
end | ||
|
||
# POST /cadenas | ||
# POST /cadenas.json | ||
def create | ||
@cadena = Cadena.new(params[:cadena]) | ||
|
||
respond_to do |format| | ||
if @cadena.save | ||
format.html { redirect_to @cadena, notice: 'Cadena was successfully created.' } | ||
format.json { render json: @cadena, status: :created, location: @cadena } | ||
else | ||
format.html { render action: "new" } | ||
format.json { render json: @cadena.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /cadenas/1 | ||
# PUT /cadenas/1.json | ||
def update | ||
@cadena = Cadena.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @cadena.update_attributes(params[:cadena]) | ||
format.html { redirect_to @cadena, notice: 'Cadena was successfully updated.' } | ||
format.json { head :no_content } | ||
else | ||
format.html { render action: "edit" } | ||
format.json { render json: @cadena.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /cadenas/1 | ||
# DELETE /cadenas/1.json | ||
def destroy | ||
@cadena = Cadena.find(params[:id]) | ||
@cadena.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to cadenas_url } | ||
format.json { head :no_content } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Cadena < ActiveRecord::Base | ||
attr_accessible :nombre | ||
|
||
has_and_belongs_to_many :relaciones | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
= form_for @cadena do |f| | ||
- if @cadena.errors.any? | ||
#error_explanation | ||
%h2= "#{pluralize(@cadena.errors.count, "error")} prohibited this cadena from being saved:" | ||
%ul | ||
- @cadena.errors.full_messages.each do |msg| | ||
%li= msg | ||
|
||
.field | ||
= f.label :nombre | ||
= f.text_field :nombre | ||
.actions | ||
= f.submit 'Save' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
%h1 Editing cadena | ||
|
||
= render 'form' | ||
|
||
= link_to 'Show', @cadena | ||
\| | ||
= link_to 'Back', cadenas_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
%h1 Listing cadenas | ||
|
||
%table | ||
%tr | ||
%th Nombre | ||
%th | ||
%th | ||
%th | ||
|
||
- @cadenas.each do |cadena| | ||
%tr | ||
%td= cadena.nombre | ||
%td= link_to 'Show', cadena | ||
%td= link_to 'Edit', edit_cadena_path(cadena) | ||
%td= link_to 'Destroy', cadena, method: :delete, data: { confirm: 'Are you sure?' } | ||
|
||
%br | ||
|
||
= link_to 'New Cadena', new_cadena_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
%h1 New cadena | ||
|
||
= render 'form' | ||
|
||
= link_to 'Back', cadenas_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
%p#notice= notice | ||
|
||
%p | ||
%b Nombre: | ||
= @cadena.nombre | ||
|
||
= link_to 'Edit', edit_cadena_path(@cadena) | ||
\| | ||
= link_to 'Back', cadenas_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateCadenas < ActiveRecord::Migration | ||
def change | ||
create_table :cadenas do |t| | ||
t.string :nombre | ||
t.timestamps | ||
end | ||
|
||
create_table :cadenas_relaciones, id: false do |t| | ||
t.references :cadena | ||
t.references :relacion | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# encoding: utf-8 | ||
FactoryGirl.define do | ||
factory :cadena do | ||
nombre { generate :cadena_unica } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# encoding: utf-8 | ||
FactoryGirl.define do | ||
factory :hs12 do | ||
codigo { generate :cadena_unica } | ||
descripcion "sarasa" | ||
comentario "sarasa" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
nombre { generate :cadena_unica } | ||
descripcion "sarasa" | ||
|
||
#hs12 | ||
hs12 | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# encoding: utf-8 | ||
FactoryGirl.define do | ||
factory :relacion do | ||
# por default producto -> actividad | ||
association :entrada, factory: :producto | ||
association :salida, factory: :actividad | ||
|
||
factory :relacion_actividad_producto do | ||
association :entrada, factory: :actividad | ||
association :salida, factory: :producto | ||
end | ||
|
||
factory :relacion_producto_actividad do | ||
# usa el default pero es más legible en los tests | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# encoding: utf-8 | ||
require './test/test_helper' | ||
|
||
class CadenasControllerTest < ActionController::TestCase | ||
|
||
test "debería acceder a la lista de cadenas" do | ||
get :index | ||
assert_response :success | ||
assert_not_nil assigns(:cadenas) | ||
end | ||
|
||
test "debería ir a 'nuevo'" do | ||
get :new | ||
assert_response :success | ||
end | ||
|
||
test "debería crear una cadena" do | ||
assert_difference('Cadena.count') do | ||
post :create, cadena: attributes_for(:cadena) | ||
end | ||
|
||
assert_redirected_to cadena_path(assigns(:cadena)) | ||
end | ||
|
||
test "debería mostrar una cadena" do | ||
get :show, id: create(:cadena).to_param | ||
assert_response :success | ||
end | ||
|
||
test "debería ir a editar" do | ||
get :edit, id: create(:cadena).to_param | ||
assert_response :success | ||
end | ||
|
||
test "debería actualizar una cadena" do | ||
put :update, id: create(:cadena).to_param, cadena: attributes_for(:cadena) | ||
|
||
assert_redirected_to cadena_path(assigns(:cadena)) | ||
end | ||
|
||
test "debería eliminar una cadena" do | ||
cadena = create(:cadena) | ||
assert_difference('Cadena.count', -1) do | ||
delete :destroy, id: cadena.to_param | ||
end | ||
|
||
assert_redirected_to cadenas_path | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# encoding: utf-8 | ||
require './test/test_helper' | ||
|
||
class RelacionTest < ActiveSupport::TestCase | ||
|
||
test 'la fábrica debería devolver asociaciones correctas' do | ||
producto_actividad = create(:relacion_producto_actividad) | ||
actividad_producto = create(:relacion_actividad_producto) | ||
|
||
assert_not_nil producto_actividad.entrada, "No le asignó un producto" | ||
assert_not_nil producto_actividad.salida, "No le asignó una actividad" | ||
assert_instance_of Producto, producto_actividad.entrada | ||
assert_instance_of Actividad, producto_actividad.salida | ||
|
||
assert_not_nil actividad_producto.entrada, "No le asignó una actividad" | ||
assert_not_nil actividad_producto.salida, "No le asignó un producto" | ||
assert_instance_of Actividad, actividad_producto.entrada | ||
assert_instance_of Producto, actividad_producto.salida | ||
end | ||
|
||
end |