diff --git a/src/noosfero-spb/gov_user/lib/ext/community.rb b/src/noosfero-spb/gov_user/lib/ext/community.rb index dca2013..74e1d0c 100644 --- a/src/noosfero-spb/gov_user/lib/ext/community.rb +++ b/src/noosfero-spb/gov_user/lib/ext/community.rb @@ -2,8 +2,4 @@ require_dependency 'community' class Community has_one :institution, :class_name => 'GovUserPlugin::Institution', :dependent=>:destroy - - def institution? - return !institution.nil? - end end diff --git a/src/noosfero-spb/gov_user/lib/ext/person.rb b/src/noosfero-spb/gov_user/lib/ext/person.rb index 0260a99..08e9614 100644 --- a/src/noosfero-spb/gov_user/lib/ext/person.rb +++ b/src/noosfero-spb/gov_user/lib/ext/person.rb @@ -10,10 +10,6 @@ class Person delegate :login, :to => :user, :prefix => true - def institution? - false - end - def secondary_email self.user.secondary_email unless self.user.nil? end diff --git a/src/noosfero-spb/gov_user/lib/gov_user_plugin.rb b/src/noosfero-spb/gov_user/lib/gov_user_plugin.rb index 0a36554..b56a325 100644 --- a/src/noosfero-spb/gov_user/lib/gov_user_plugin.rb +++ b/src/noosfero-spb/gov_user/lib/gov_user_plugin.rb @@ -17,6 +17,10 @@ class GovUserPlugin < Noosfero::Plugin _("Add features related to Brazilian government.") end + def self.institution?(community) + GovUserPlugin::Institution.where(:community_id => community.id).present? + end + def stylesheet? true end @@ -74,12 +78,12 @@ class GovUserPlugin < Noosfero::Plugin def profile_tabs if context.profile.community? - return profile_tabs_institution if context.profile.institution? + return profile_tabs_institution if GovUserPlugin.institution?(context.profile) end end def control_panel_buttons - if context.profile.institution? + if GovUserPlugin.institution?(context.profile) return institution_info_button end end diff --git a/src/noosfero-spb/gov_user/test/unit/gov_user_plugin_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin_test.rb new file mode 100644 index 0000000..c8aa4f3 --- /dev/null +++ b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin_test.rb @@ -0,0 +1,29 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' + +class GovUserPluginTest < ActiveSupport::TestCase + include PluginTestHelper + + def setup + @gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power") + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere") + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia") + + @institution = create_public_institution( + "Ministerio Publico da Uniao", + "MPU", + "BR", + "DF", + "Gama", + @juridical_nature, + @gov_power, + @gov_sphere, + "11.222.333/4444-55" + ) + end + + should 'check if profile is an institution' do + assert GovUserPlugin.institution?(@institution.community) + assert !GovUserPlugin.institution?(fast_create(Community)) + end +end -- libgit2 0.21.2