diff --git a/app/admin/notas.rb b/app/admin/notas.rb index 2f7a1ec..9bb2e95 100644 --- a/app/admin/notas.rb +++ b/app/admin/notas.rb @@ -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 @@ -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 diff --git a/app/models/expediente.rb b/app/models/expediente.rb index e54ec2f..f21ff2e 100644 --- a/app/models/expediente.rb +++ b/app/models/expediente.rb @@ -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" @@ -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 diff --git a/app/models/initiator.rb b/app/models/initiator.rb new file mode 100644 index 0000000..b172921 --- /dev/null +++ b/app/models/initiator.rb @@ -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 diff --git a/app/models/initiators_kind.rb b/app/models/initiators_kind.rb new file mode 100644 index 0000000..810b505 --- /dev/null +++ b/app/models/initiators_kind.rb @@ -0,0 +1,4 @@ +class InitiatorsKind < ActiveRecord::Base + attr_accessible :name + has_many :initiators +end diff --git a/app/models/nota.rb b/app/models/nota.rb index 1cc4582..11f4e49 100644 --- a/app/models/nota.rb +++ b/app/models/nota.rb @@ -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") diff --git a/app/views/admin/notas/_form.html.erb b/app/views/admin/notas/_form.html.erb index efdf474..8100b14 100644 --- a/app/views/admin/notas/_form.html.erb +++ b/app/views/admin/notas/_form.html.erb @@ -1,8 +1,11 @@ <%= 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 %> @@ -10,7 +13,6 @@ <%= f.input :tags_tokens, :input_html => { "data-pre" => f.object.tags.to_json(:methods => :name), :only => [:id, :name] } %> - <% end %> <%= f.actions %> <% end %> diff --git a/db/migrate/20130428195717_create_initiators.rb b/db/migrate/20130428195717_create_initiators.rb new file mode 100644 index 0000000..f124274 --- /dev/null +++ b/db/migrate/20130428195717_create_initiators.rb @@ -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 diff --git a/db/migrate/20130428195751_create_initiators_kinds.rb b/db/migrate/20130428195751_create_initiators_kinds.rb new file mode 100644 index 0000000..2489a67 --- /dev/null +++ b/db/migrate/20130428195751_create_initiators_kinds.rb @@ -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 diff --git a/db/migrate/20130428200955_add_iniciator_to_expediente.rb b/db/migrate/20130428200955_add_iniciator_to_expediente.rb new file mode 100644 index 0000000..b385d6d --- /dev/null +++ b/db/migrate/20130428200955_add_iniciator_to_expediente.rb @@ -0,0 +1,6 @@ +class AddIniciatorToExpediente < ActiveRecord::Migration + def change + add_column :expedientes, :initiator_id, :integer + add_index :expedientes, :initiator_id + end +end diff --git a/db/schema.rb b/db/schema.rb index c2fc3b6..1d379ec 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 @@ -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" @@ -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" diff --git a/db/seeds.rb b/db/seeds.rb index 63cb82e..233509e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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 diff --git a/spec/factories/area.rb b/spec/factories/area.rb new file mode 100644 index 0000000..ad1a04f --- /dev/null +++ b/spec/factories/area.rb @@ -0,0 +1,7 @@ +# encoding: utf-8 + +FactoryGirl.define do + factory :area do + name "informática" + end +end diff --git a/spec/factories/initiators.rb b/spec/factories/initiators.rb new file mode 100644 index 0000000..e8bab79 --- /dev/null +++ b/spec/factories/initiators.rb @@ -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 diff --git a/spec/factories/initiators_kinds.rb b/spec/factories/initiators_kinds.rb new file mode 100644 index 0000000..93f2c5e --- /dev/null +++ b/spec/factories/initiators_kinds.rb @@ -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 diff --git a/spec/factories/notas.rb b/spec/factories/notas.rb index f304fcb..f278438 100644 --- a/spec/factories/notas.rb +++ b/spec/factories/notas.rb @@ -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 diff --git a/spec/factories/pase.rb b/spec/factories/pase.rb new file mode 100644 index 0000000..ae34f6c --- /dev/null +++ b/spec/factories/pase.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :pase do + area + ingreso { 2.days.ago } + end +end diff --git a/spec/models/initiator_spec.rb b/spec/models/initiator_spec.rb new file mode 100644 index 0000000..569e277 --- /dev/null +++ b/spec/models/initiator_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Initiator do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/initiators_kind_spec.rb b/spec/models/initiators_kind_spec.rb new file mode 100644 index 0000000..0eb4b24 --- /dev/null +++ b/spec/models/initiators_kind_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe InitiatorsKind do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/nota_spec.rb b/spec/models/nota_spec.rb new file mode 100644 index 0000000..9dcbf98 --- /dev/null +++ b/spec/models/nota_spec.rb @@ -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