Commit 746a07c576e3dee18c8c5267e18c2a77eea32653
1 parent
449ea30f
Exists in
gov-user-refactoring
gov-user: remove institution? from profile extension
Showing
4 changed files
with
35 additions
and
10 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/ext/person.rb
| @@ -10,10 +10,6 @@ class Person | @@ -10,10 +10,6 @@ class Person | ||
| 10 | 10 | ||
| 11 | delegate :login, :to => :user, :prefix => true | 11 | delegate :login, :to => :user, :prefix => true |
| 12 | 12 | ||
| 13 | - def institution? | ||
| 14 | - false | ||
| 15 | - end | ||
| 16 | - | ||
| 17 | def secondary_email | 13 | def secondary_email |
| 18 | self.user.secondary_email unless self.user.nil? | 14 | self.user.secondary_email unless self.user.nil? |
| 19 | end | 15 | end |
src/noosfero-spb/gov_user/lib/gov_user_plugin.rb
| @@ -17,6 +17,10 @@ class GovUserPlugin < Noosfero::Plugin | @@ -17,6 +17,10 @@ class GovUserPlugin < Noosfero::Plugin | ||
| 17 | _("Add features related to Brazilian government.") | 17 | _("Add features related to Brazilian government.") |
| 18 | end | 18 | end |
| 19 | 19 | ||
| 20 | + def self.institution?(community) | ||
| 21 | + GovUserPlugin::Institution.where(:community_id => community.id).present? | ||
| 22 | + end | ||
| 23 | + | ||
| 20 | def stylesheet? | 24 | def stylesheet? |
| 21 | true | 25 | true |
| 22 | end | 26 | end |
| @@ -74,12 +78,12 @@ class GovUserPlugin < Noosfero::Plugin | @@ -74,12 +78,12 @@ class GovUserPlugin < Noosfero::Plugin | ||
| 74 | 78 | ||
| 75 | def profile_tabs | 79 | def profile_tabs |
| 76 | if context.profile.community? | 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 | end | 82 | end |
| 79 | end | 83 | end |
| 80 | 84 | ||
| 81 | def control_panel_buttons | 85 | def control_panel_buttons |
| 82 | - if context.profile.institution? | 86 | + if GovUserPlugin.institution?(context.profile) |
| 83 | return institution_info_button | 87 | return institution_info_button |
| 84 | end | 88 | end |
| 85 | end | 89 | 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 |