Commit 6dfb97e5ce2c75c5c34698f31c4e2064adfc9ee9
Committed by
Marcos Pereira
1 parent
2cd18c7c
Exists in
gov-user-to-organization
and in
1 other branch
gov-user: remove institution? from profile extension
Showing
3 changed files
with
35 additions
and
6 deletions
Show diff stats
src/noosfero-spb/gov_user/lib/ext/community.rb
@@ -2,8 +2,4 @@ require_dependency 'community' | @@ -2,8 +2,4 @@ require_dependency 'community' | ||
2 | 2 | ||
3 | class Community | 3 | class Community |
4 | has_one :institution, :class_name => 'GovUserPlugin::Institution', :dependent=>:destroy | 4 | has_one :institution, :class_name => 'GovUserPlugin::Institution', :dependent=>:destroy |
5 | - | ||
6 | - def institution? | ||
7 | - return !institution.nil? | ||
8 | - end | ||
9 | end | 5 | end |
src/noosfero-spb/gov_user/lib/gov_user_plugin.rb
@@ -21,6 +21,10 @@ class GovUserPlugin < Noosfero::Plugin | @@ -21,6 +21,10 @@ class GovUserPlugin < Noosfero::Plugin | ||
21 | _("Add features related to Brazilian government.") | 21 | _("Add features related to Brazilian government.") |
22 | end | 22 | end |
23 | 23 | ||
24 | + def self.institution?(community) | ||
25 | + GovUserPlugin::Institution.where(:community_id => community.id).present? | ||
26 | + end | ||
27 | + | ||
24 | def stylesheet? | 28 | def stylesheet? |
25 | true | 29 | true |
26 | end | 30 | end |
@@ -76,12 +80,12 @@ class GovUserPlugin < Noosfero::Plugin | @@ -76,12 +80,12 @@ class GovUserPlugin < Noosfero::Plugin | ||
76 | 80 | ||
77 | def profile_tabs | 81 | def profile_tabs |
78 | if context.profile.community? | 82 | if context.profile.community? |
79 | - return profile_tabs_institution if context.profile.institution? | 83 | + return profile_tabs_institution if GovUserPlugin.institution?(context.profile) |
80 | end | 84 | end |
81 | end | 85 | end |
82 | 86 | ||
83 | def control_panel_buttons | 87 | def control_panel_buttons |
84 | - if context.profile.institution? | 88 | + if GovUserPlugin.institution?(context.profile) |
85 | return institution_info_button | 89 | return institution_info_button |
86 | end | 90 | end |
87 | end | 91 | end |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin_test.rb
0 → 100644
@@ -0,0 +1,29 @@ | @@ -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 |