Commit f579218e0b4ae2873d97f3f4e26af85102b238b2
1 parent
c2ecb2c2
Exists in
master
and in
5 other branches
Removes institutions and software in Communities Block
Fixed bug in Profile Helper Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
4 changed files
with
78 additions
and
1 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +require_dependency 'communities_block' | |
| 2 | + | |
| 3 | +class CommunitiesBlock | |
| 4 | + | |
| 5 | + def profile_list | |
| 6 | + result = nil | |
| 7 | + visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment]) | |
| 8 | + if !prioritize_profiles_with_image | |
| 9 | + result = visible_profiles.all(:limit => get_limit, :order => 'profiles.updated_at DESC').sort_by{ rand } | |
| 10 | + elsif profiles.visible.with_image.count >= get_limit | |
| 11 | + result = visible_profiles.with_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand } | |
| 12 | + else | |
| 13 | + 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 } | |
| 14 | + end | |
| 15 | + | |
| 16 | + list_without_software_and_institution = [] | |
| 17 | + | |
| 18 | + visible_profiles.each do |p| | |
| 19 | + if p.class == Community and !p.software? and !p.institution? | |
| 20 | + list_without_software_and_institution << p | |
| 21 | + end | |
| 22 | + end | |
| 23 | + | |
| 24 | + result = list_without_software_and_institution | |
| 25 | + | |
| 26 | + result.slice(0..get_limit-1) | |
| 27 | + end | |
| 28 | + | |
| 29 | +end | |
| 0 | 30 | \ No newline at end of file | ... | ... |
lib/ext/profile_helper.rb
| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
| 2 | +require File.dirname(__FILE__) + '/plugin_test_helper' | |
| 3 | + | |
| 4 | +class CommunitiesBlockTest < ActiveSupport::TestCase | |
| 5 | + include PluginTestHelper | |
| 6 | + def setup | |
| 7 | + @person = create_person("My Name", "user@email.com", "123456", "123456", "user@secondary_email.com", "Any State", "Some City") | |
| 8 | + | |
| 9 | + @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") | |
| 10 | + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
| 11 | + @juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
| 12 | + | |
| 13 | + @institution = create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere) | |
| 14 | + @institution.community.add_member(@person) | |
| 15 | + | |
| 16 | + @software_info = create_software_info("Novo Software") | |
| 17 | + @software_info.community.add_member(@person) | |
| 18 | + | |
| 19 | + @community = create_community("Nova Comunidade") | |
| 20 | + @community.add_member(@person) | |
| 21 | + | |
| 22 | + | |
| 23 | + @comminities_block = CommunitiesBlock.new | |
| 24 | + @comminities_block.expects(:owner).at_least_once.returns(@person) | |
| 25 | + end | |
| 26 | + | |
| 27 | + should "not have community of software or institution in block" do | |
| 28 | + assert_equal 1, @comminities_block.profile_list.count | |
| 29 | + end | |
| 30 | + | |
| 31 | +end | ... | ... |
test/unit/plugin_test_helper.rb
| 1 | 1 | module PluginTestHelper |
| 2 | 2 | |
| 3 | + def create_community name | |
| 4 | + community = fast_create(Community) | |
| 5 | + community.name = name | |
| 6 | + community.save | |
| 7 | + community | |
| 8 | + end | |
| 9 | + | |
| 10 | + def create_software_info name | |
| 11 | + community = create_community(name) | |
| 12 | + software_info = SoftwareInfo.new | |
| 13 | + software_info.community = community | |
| 14 | + software_info.save | |
| 15 | + software_info | |
| 16 | + end | |
| 17 | + | |
| 3 | 18 | def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s |
| 4 | 19 | institution = PublicInstitution.new |
| 5 | 20 | institution.community = create_community_institution(name, country, state, city) | ... | ... |