Commit 75de40246eafd1596c168ee050c8e35b33aa7602

Authored by Rodrigo Souto
1 parent aa0b1b8b

gov-user: remove institution? from profile extension

src/noosfero-spb/gov_user/lib/ext/community.rb
... ... @@ -2,8 +2,4 @@ require_dependency 'community'
2 2  
3 3 class Community
4 4 has_one :institution, :class_name => 'GovUserPlugin::Institution', :dependent=>:destroy
5   -
6   - def institution?
7   - return !institution.nil?
8   - end
9 5 end
... ...
src/noosfero-spb/gov_user/lib/ext/person.rb
... ... @@ -10,10 +10,6 @@ class Person
10 10  
11 11 delegate :login, :to => :user, :prefix => true
12 12  
13   - def institution?
14   - false
15   - end
16   -
17 13 def secondary_email
18 14 self.user.secondary_email unless self.user.nil?
19 15 end
... ...
src/noosfero-spb/gov_user/lib/gov_user_plugin.rb
... ... @@ -17,6 +17,10 @@ class GovUserPlugin < Noosfero::Plugin
17 17 _("Add features related to Brazilian government.")
18 18 end
19 19  
  20 + def self.institution?(community)
  21 + GovUserPlugin::Institution.where(:community_id => community.id).present?
  22 + end
  23 +
20 24 def stylesheet?
21 25 true
22 26 end
... ... @@ -74,12 +78,12 @@ class GovUserPlugin < Noosfero::Plugin
74 78  
75 79 def profile_tabs
76 80 if context.profile.community?
77   - return profile_tabs_institution if context.profile.institution?
  81 + return profile_tabs_institution if GovUserPlugin.institution?(context.profile)
78 82 end
79 83 end
80 84  
81 85 def control_panel_buttons
82   - if context.profile.institution?
  86 + if GovUserPlugin.institution?(context.profile)
83 87 return institution_info_button
84 88 end
85 89 end
... ...
src/noosfero-spb/gov_user/test/unit/gov_user_plugin_test.rb 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class GovUserPluginTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 +
  7 + def setup
  8 + @gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power")
  9 + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere")
  10 + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia")
  11 +
  12 + @institution = create_public_institution(
  13 + "Ministerio Publico da Uniao",
  14 + "MPU",
  15 + "BR",
  16 + "DF",
  17 + "Gama",
  18 + @juridical_nature,
  19 + @gov_power,
  20 + @gov_sphere,
  21 + "11.222.333/4444-55"
  22 + )
  23 + end
  24 +
  25 + should 'check if profile is an institution' do
  26 + assert GovUserPlugin.institution?(@institution.community)
  27 + assert !GovUserPlugin.institution?(fast_create(Community))
  28 + end
  29 +end
... ...