Commit fc1161f0b9295e609c43f65dda016bb2d3272aa8
1 parent
c74fdadd
Exists in
master
and in
5 other branches
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>
Showing
6 changed files
with
47 additions
and
0 deletions
Show diff stats
controllers/mpog_software_plugin_controller.rb
1 | require 'csv' | 1 | require 'csv' |
2 | class MpogSoftwarePluginController < ApplicationController | 2 | class MpogSoftwarePluginController < ApplicationController |
3 | + include InstitutionHelper | ||
3 | 4 | ||
4 | def archive_software | 5 | def archive_software |
5 | per_page = 10 | 6 | per_page = 10 |
@@ -158,6 +159,8 @@ class MpogSoftwarePluginController < ApplicationController | @@ -158,6 +159,8 @@ class MpogSoftwarePluginController < ApplicationController | ||
158 | institution.name = community[:name] | 159 | institution.name = community[:name] |
159 | institution.community = community | 160 | institution.community = community |
160 | 161 | ||
162 | + InstitutionHelper.register_institution_modification institution | ||
163 | + | ||
161 | if institution.type == "PublicInstitution" | 164 | if institution.type == "PublicInstitution" |
162 | begin | 165 | begin |
163 | govPower = GovernmentalPower.find params[:governmental][:power] | 166 | govPower = GovernmentalPower.find params[:governmental][:power] |
db/migrate/20140815194530_register_institution_modification.rb
1 | class RegisterInstitutionModification < ActiveRecord::Migration | 1 | class RegisterInstitutionModification < ActiveRecord::Migration |
2 | def up | 2 | def up |
3 | + change_table :institutions do |t| | ||
4 | + t.string :date_modification | ||
5 | + end | ||
3 | end | 6 | end |
4 | 7 | ||
5 | def down | 8 | def down |
9 | + change_table :institutions do |t| | ||
10 | + t.remove :date_modification | ||
11 | + end | ||
6 | end | 12 | end |
7 | end | 13 | end |
lib/institution_helper.rb
@@ -47,6 +47,10 @@ module InstitutionHelper | @@ -47,6 +47,10 @@ module InstitutionHelper | ||
47 | end | 47 | end |
48 | end | 48 | end |
49 | 49 | ||
50 | + def self.register_institution_modification institution | ||
51 | + institution.date_modification = current_date | ||
52 | + end | ||
53 | + | ||
50 | protected | 54 | protected |
51 | 55 | ||
52 | def self.web_service_info | 56 | def self.web_service_info |
@@ -96,4 +100,9 @@ module InstitutionHelper | @@ -96,4 +100,9 @@ module InstitutionHelper | ||
96 | institution.governmental_sphere = GovernmentalSphere.where(:name=>self.retrieve_code(unit,"codigoEsfera")).first | 100 | institution.governmental_sphere = GovernmentalSphere.where(:name=>self.retrieve_code(unit,"codigoEsfera")).first |
97 | institution | 101 | institution |
98 | end | 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 | end | 108 | end |
lib/mpog_software_plugin.rb
@@ -6,6 +6,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin | @@ -6,6 +6,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin | ||
6 | include ActionView::Helpers::AssetTagHelper | 6 | include ActionView::Helpers::AssetTagHelper |
7 | include FormsHelper | 7 | include FormsHelper |
8 | include LibraryHelper | 8 | include LibraryHelper |
9 | + include InstitutionHelper | ||
9 | 10 | ||
10 | def self.plugin_name | 11 | def self.plugin_name |
11 | "MpogSoftwarePlugin" | 12 | "MpogSoftwarePlugin" |
@@ -246,6 +247,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin | @@ -246,6 +247,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin | ||
246 | def institution_transaction | 247 | def institution_transaction |
247 | if context.params.has_key?(:governmental_power) | 248 | if context.params.has_key?(:governmental_power) |
248 | context.profile.institution.governmental_power_id = context.params[:governmental_power] | 249 | context.profile.institution.governmental_power_id = context.params[:governmental_power] |
250 | + InstitutionHelper.register_institution_modification context.profile.institution | ||
249 | context.profile.institution.save! | 251 | context.profile.institution.save! |
250 | end | 252 | end |
251 | 253 |
@@ -0,0 +1,26 @@ | @@ -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,6 +5,7 @@ | ||
5 | 5 | ||
6 | <%= display_field(_('Type:'), profile.institution, :type, true) %> | 6 | <%= display_field(_('Type:'), profile.institution, :type, true) %> |
7 | <%= display_field(_('CNPJ:'), profile.institution, :cnpj, true) %> | 7 | <%= display_field(_('CNPJ:'), profile.institution, :cnpj, true) %> |
8 | + <%= display_field(_('Last modification:'), profile.institution, :date_modification, true) %> | ||
8 | <% if profile.institution.type == "PrivateInstitution"%> | 9 | <% if profile.institution.type == "PrivateInstitution"%> |
9 | <%= display_field(_('Fantasy Name:'), profile.institution, :acronym, true) %> | 10 | <%= display_field(_('Fantasy Name:'), profile.institution, :acronym, true) %> |
10 | <% else %> | 11 | <% else %> |