diff --git a/lib/ext/communities_block.rb b/lib/ext/communities_block.rb new file mode 100644 index 0000000..0da4201 --- /dev/null +++ b/lib/ext/communities_block.rb @@ -0,0 +1,29 @@ +require_dependency 'communities_block' + +class CommunitiesBlock + + def profile_list + result = nil + visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment]) + if !prioritize_profiles_with_image + result = visible_profiles.all(:limit => get_limit, :order => 'profiles.updated_at DESC').sort_by{ rand } + elsif profiles.visible.with_image.count >= get_limit + result = visible_profiles.with_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand } + else + result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand } + end + + list_without_software_and_institution = [] + + visible_profiles.each do |p| + if p.class == Community and !p.software? and !p.institution? + list_without_software_and_institution << p + end + end + + result = list_without_software_and_institution + + result.slice(0..get_limit-1) + end + +end \ No newline at end of file diff --git a/lib/ext/profile_helper.rb b/lib/ext/profile_helper.rb index ad6dd1f..c5a7a56 100644 --- a/lib/ext/profile_helper.rb +++ b/lib/ext/profile_helper.rb @@ -1,4 +1,6 @@ -module ProfileHelper extend ProfileHelper +require_dependency 'profile_helper' + +module ProfileHelper PERSON_CATEGORIES[:mpog_profile_information] = [:secondary_email, :institutions] def display_mpog_field(title, profile, field, force = false) diff --git a/test/unit/communities_block_test.rb b/test/unit/communities_block_test.rb new file mode 100644 index 0000000..80d7b71 --- /dev/null +++ b/test/unit/communities_block_test.rb @@ -0,0 +1,31 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/plugin_test_helper' + +class CommunitiesBlockTest < ActiveSupport::TestCase + include PluginTestHelper + def setup + @person = create_person("My Name", "user@email.com", "123456", "123456", "user@secondary_email.com", "Any State", "Some City") + + @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") + @juridical_nature = JuridicalNature.create(:name => "Autarquia") + + @institution = create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere) + @institution.community.add_member(@person) + + @software_info = create_software_info("Novo Software") + @software_info.community.add_member(@person) + + @community = create_community("Nova Comunidade") + @community.add_member(@person) + + + @comminities_block = CommunitiesBlock.new + @comminities_block.expects(:owner).at_least_once.returns(@person) + end + + should "not have community of software or institution in block" do + assert_equal 1, @comminities_block.profile_list.count + end + +end diff --git a/test/unit/plugin_test_helper.rb b/test/unit/plugin_test_helper.rb index f187fd7..31e9fad 100644 --- a/test/unit/plugin_test_helper.rb +++ b/test/unit/plugin_test_helper.rb @@ -1,5 +1,20 @@ module PluginTestHelper + def create_community name + community = fast_create(Community) + community.name = name + community.save + community + end + + def create_software_info name + community = create_community(name) + software_info = SoftwareInfo.new + software_info.community = community + software_info.save + software_info + end + def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s institution = PublicInstitution.new institution.community = create_community_institution(name, country, state, city) -- libgit2 0.21.2