Commit fc1161f0b9295e609c43f65dda016bb2d3272aa8

Authored by Luciano Prestes
1 parent c74fdadd

Create new Institution's attribute to register the last modification date

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Sygned-off-by: David Carlos <ddavidcarlos1392@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
controllers/mpog_software_plugin_controller.rb
1 1 require 'csv'
2 2 class MpogSoftwarePluginController < ApplicationController
  3 + include InstitutionHelper
3 4  
4 5 def archive_software
5 6 per_page = 10
... ... @@ -158,6 +159,8 @@ class MpogSoftwarePluginController &lt; ApplicationController
158 159 institution.name = community[:name]
159 160 institution.community = community
160 161  
  162 + InstitutionHelper.register_institution_modification institution
  163 +
161 164 if institution.type == "PublicInstitution"
162 165 begin
163 166 govPower = GovernmentalPower.find params[:governmental][:power]
... ...
db/migrate/20140815194530_register_institution_modification.rb
1 1 class RegisterInstitutionModification < ActiveRecord::Migration
2 2 def up
  3 + change_table :institutions do |t|
  4 + t.string :date_modification
  5 + end
3 6 end
4 7  
5 8 def down
  9 + change_table :institutions do |t|
  10 + t.remove :date_modification
  11 + end
6 12 end
7 13 end
... ...
lib/institution_helper.rb
... ... @@ -47,6 +47,10 @@ module InstitutionHelper
47 47 end
48 48 end
49 49  
  50 + def self.register_institution_modification institution
  51 + institution.date_modification = current_date
  52 + end
  53 +
50 54 protected
51 55  
52 56 def self.web_service_info
... ... @@ -96,4 +100,9 @@ module InstitutionHelper
96 100 institution.governmental_sphere = GovernmentalSphere.where(:name=>self.retrieve_code(unit,"codigoEsfera")).first
97 101 institution
98 102 end
  103 +
  104 + def self.current_date
  105 + date = Time.now.day.to_s + "/" + Time.now.month.to_s + "/" + Time.now.year.to_s
  106 + date
  107 + end
99 108 end
... ...
lib/mpog_software_plugin.rb
... ... @@ -6,6 +6,7 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
6 6 include ActionView::Helpers::AssetTagHelper
7 7 include FormsHelper
8 8 include LibraryHelper
  9 + include InstitutionHelper
9 10  
10 11 def self.plugin_name
11 12 "MpogSoftwarePlugin"
... ... @@ -246,6 +247,7 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
246 247 def institution_transaction
247 248 if context.params.has_key?(:governmental_power)
248 249 context.profile.institution.governmental_power_id = context.params[:governmental_power]
  250 + InstitutionHelper.register_institution_modification context.profile.institution
249 251 context.profile.institution.save!
250 252 end
251 253  
... ...
test/unit/institution_helper_test.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +
  3 +class InstitutionHelperTest < ActiveSupport::TestCase
  4 +
  5 + should "populate public institutions with data from SIORG" do
  6 + Institution.destroy_all
  7 +
  8 + InstitutionHelper.mass_update
  9 +
  10 + assert Institution.count != 0
  11 + end
  12 +
  13 + should "receive json data from SIORG" do
  14 + data = InstitutionHelper.get_json(2, 1)
  15 +
  16 + assert data["unidades"].count != 0
  17 + end
  18 +
  19 + should "update Institution's date modification when edit the Institution" do
  20 + institution = Institution.new
  21 + InstitutionHelper.register_institution_modification institution
  22 + date = Time.now.day.to_s + "/" + Time.now.month.to_s + "/" + Time.now.year.to_s
  23 +
  24 + assert_equal date, institution.date_modification
  25 + end
  26 +end
... ...
views/profile/_institution_tab.html.erb
... ... @@ -5,6 +5,7 @@
5 5  
6 6 <%= display_field(_('Type:'), profile.institution, :type, true) %>
7 7 <%= display_field(_('CNPJ:'), profile.institution, :cnpj, true) %>
  8 + <%= display_field(_('Last modification:'), profile.institution, :date_modification, true) %>
8 9 <% if profile.institution.type == "PrivateInstitution"%>
9 10 <%= display_field(_('Fantasy Name:'), profile.institution, :acronym, true) %>
10 11 <% else %>
... ...