Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 11 additions & 8 deletions app/admin/notas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@
show do
columns do
column do
attributes_table_for nota, :numero, :autor, :tags_list
panel 'Historico De Pases' do
table_for nota.pases do
column :ingreso
column :area
column :descripcion
end
end
attributes_table_for nota, :numero, :initiator,
:initiators_kind_name, :tags_list

panel 'Archivos' do
table_for nota.assets do
Expand Down Expand Up @@ -77,6 +71,15 @@
end
end
end

panel 'Historico De Pases' do
table_for nota.pases do
column :ingreso
column :area
column :session
column :descripcion
end
end
end

end
7 changes: 7 additions & 0 deletions app/models/expediente.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ def tipoperiod
has_one :estado_actual, :class_name => :Estado, :conditions => { :fechasal => nil }
has_one :comision, :through => :estado_actual

belongs_to :initiator
has_many :assets, :as => :adjuntable, dependent: :destroy
has_many :pases, dependent: :destroy

accepts_nested_attributes_for :initiator
# has_one :primer_pase, :class_name => :Pase, :order => "id asc", :conditions => "1=1"
# has_one :ultimo_pase, :class_name => :Pase, :order => "id desc", :conditions => "1=1"

Expand Down Expand Up @@ -131,4 +133,9 @@ def tags_list
tags.pluck :name
end

def initiators=(attrs)
init = Initiator.where(attrs).first_or_create
self.initiator = init
end

end
6 changes: 6 additions & 0 deletions app/models/initiator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Initiator < ActiveRecord::Base
belongs_to :initiators_kind
attr_accessible :name, :initiators_kind_id

delegate :name, to: :initiators_kind, prefix: true
end
4 changes: 4 additions & 0 deletions app/models/initiators_kind.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class InitiatorsKind < ActiveRecord::Base
attr_accessible :name
has_many :initiators
end
1 change: 1 addition & 0 deletions app/models/nota.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Nota < Expediente

delegate :area, to: :ultimo_pase, prefix: true
delegate :ingreso, to: :primer_pase
delegate :initiators_kind_name, to: :initiator, allow_nil: true

def year
ingreso.strftime("%Y")
Expand Down
6 changes: 4 additions & 2 deletions app/views/admin/notas/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<%= semantic_form_for nota, :url => url || admin_notas_path do |f| %>
<%= f.inputs 'Detalles generales' do %>
<%= f.input :numero %>
<%= f.input :autor %>
<% if f.object.new_record? %>
<%= f.semantic_fields_for :initiator, Initiator.new do |initiator| %>
<%= initiator.input :name, :label => "Iniciador"%>
<%= initiator.input :initiators_kind, collection: InitiatorsKind.all %>
<% end %>
<%= f.semantic_fields_for :pases do |pase| %>
<%= render partial: 'admin/pases/form_inputs', locals: { pase: pase }%>
<% end %>
<% end %>
<%= f.input :tags_tokens,
:input_html => {
"data-pre" => f.object.tags.to_json(:methods => :name), :only => [:id, :name] } %>

<% end %>
<%= f.actions %>
<% end %>
12 changes: 12 additions & 0 deletions db/migrate/20130428195717_create_initiators.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateInitiators < ActiveRecord::Migration
def change
create_table :initiators do |t|
t.string :name
t.references :initiators_kind

t.timestamps
end
add_index :initiators, :name
add_index :initiators, :initiators_kind_id
end
end
10 changes: 10 additions & 0 deletions db/migrate/20130428195751_create_initiators_kinds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateInitiatorsKinds < ActiveRecord::Migration
def change
create_table :initiators_kinds do |t|
t.string :name

t.timestamps
end
add_index :initiators_kinds, :name
end
end
6 changes: 6 additions & 0 deletions db/migrate/20130428200955_add_iniciator_to_expediente.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddIniciatorToExpediente < ActiveRecord::Migration
def change
add_column :expedientes, :initiator_id, :integer
add_index :expedientes, :initiator_id
end
end
22 changes: 21 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20130408232519) do
ActiveRecord::Schema.define(:version => 20130428200955) do

create_table "active_admin_comments", :force => true do |t|
t.string "resource_id", :null => false
Expand Down Expand Up @@ -198,9 +198,11 @@
t.string "type"
t.integer "primer_pase_id"
t.integer "ultimo_pase_id"
t.integer "initiator_id"
end

add_index "expedientes", ["estado_id"], :name => "index_expedientes_on_estado_id"
add_index "expedientes", ["initiator_id"], :name => "index_expedientes_on_initiator_id"
add_index "expedientes", ["numero", "pasada", "letra", "tipo"], :name => "index_expedientes_on_legacy_id"
add_index "expedientes", ["tema_id"], :name => "index_expedientes_on_tema_id"

Expand Down Expand Up @@ -236,6 +238,24 @@
add_index "finals", ["expediente_id"], :name => "index_finals_on_expediente_id"
add_index "finals", ["numero"], :name => "index_finals_on_numero"

create_table "initiators", :force => true do |t|
t.string "name"
t.integer "initiators_kind_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

add_index "initiators", ["initiators_kind_id"], :name => "index_initiators_on_initiators_kind_id"
add_index "initiators", ["name"], :name => "index_initiators_on_name"

create_table "initiators_kinds", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

add_index "initiators_kinds", ["name"], :name => "index_initiators_kinds_on_name"

create_table "pases", :force => true do |t|
t.integer "area_id"
t.text "descripcion"
Expand Down
4 changes: 4 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# encoding: UTF-8
initiators_kind = ['Particular', 'Poder judicial']
initiators_kind.each do |initiator|
InitiatorsKind.where(name: initiator).first_or_create
end
puts 'Tipos de sessions'
sessions = ['Ordinario', 'Extraordinario', 'Prórroga']
if SessionType.count == 0
Expand Down
7 changes: 7 additions & 0 deletions spec/factories/area.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# encoding: utf-8

FactoryGirl.define do
factory :area do
name "informática"
end
end
8 changes: 8 additions & 0 deletions spec/factories/initiators.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do
factory :initiator do
name "He-man"
initiators_kind
end
end
7 changes: 7 additions & 0 deletions spec/factories/initiators_kinds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do
factory :initiators_kind do
name "Amos del universo"
end
end
5 changes: 4 additions & 1 deletion spec/factories/notas.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do
factory :notas, class: Nota do
factory :nota, class: Nota do
after(:build) do |nota|
nota.pases << FactoryGirl.build(:pase)
end
end
end
6 changes: 6 additions & 0 deletions spec/factories/pase.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryGirl.define do
factory :pase do
area
ingreso { 2.days.ago }
end
end
5 changes: 5 additions & 0 deletions spec/models/initiator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe Initiator do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/models/initiators_kind_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe InitiatorsKind do
pending "add some examples to (or delete) #{__FILE__}"
end
26 changes: 26 additions & 0 deletions spec/models/nota_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'spec_helper'

describe Nota do

context 'when creating a new expediente' do

it 'should create a new initiator and relate it to the expediente' do
nota = FactoryGirl.create :nota
kind = FactoryGirl.create :initiators_kind
Initiator.where(name: 'judicial').count.should == 0
nota.initiators = {name: 'judicial', initiators_kind_id: kind.id}
Initiator.where(name: 'judicial').count.should == 1
end

it 'should relate it to an existent initiator' do
nota = FactoryGirl.create :nota
kind = FactoryGirl.create :initiators_kind
Initiator.where(name: 'judicial').count.should == 0
nota.initiators = {name: 'judicial', initiators_kind_id: kind.id}
Initiator.where(name: 'judicial').count.should == 1
nota.initiators = {name: 'judicial', initiators_kind_id: kind.id}
Initiator.where(name: 'judicial').count.should == 1
end
end

end