Commit ee3960460e15a2a0adb82cca1adc0edd01736419
1 parent
83342d44
Exists in
master
and in
5 other branches
Add method to get a list of softwares for a person
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
2 changed files
with
25 additions
and
1 deletions
Show diff stats
lib/ext/person.rb
| @@ -32,4 +32,15 @@ class Person | @@ -32,4 +32,15 @@ class Person | ||
| 32 | false | 32 | false |
| 33 | end | 33 | end |
| 34 | 34 | ||
| 35 | + def softwares | ||
| 36 | + softwares = [] | ||
| 37 | + self.communities.each do |community| | ||
| 38 | + if community.software? | ||
| 39 | + softwares << community | ||
| 40 | + end | ||
| 41 | + end | ||
| 42 | + | ||
| 43 | + softwares | ||
| 44 | + end | ||
| 45 | + | ||
| 35 | end | 46 | end |
test/unit/mpog_person_test.rb
| @@ -79,4 +79,17 @@ class MpogSoftwarePluginPersonTest < ActiveSupport::TestCase | @@ -79,4 +79,17 @@ class MpogSoftwarePluginPersonTest < ActiveSupport::TestCase | ||
| 79 | 79 | ||
| 80 | assert_equal(100, @plugin.calc_percentage_registration(@person)) | 80 | assert_equal(100, @plugin.calc_percentage_registration(@person)) |
| 81 | end | 81 | end |
| 82 | -end | ||
| 83 | \ No newline at end of file | 82 | \ No newline at end of file |
| 83 | + | ||
| 84 | + should 'get a list of softwares of a person' do | ||
| 85 | + software1 = create_software_info "noosfero" | ||
| 86 | + software2 = create_software_info "colab" | ||
| 87 | + community = create_community "simple_community" | ||
| 88 | + | ||
| 89 | + software1.community.add_member @person | ||
| 90 | + software1.save! | ||
| 91 | + community.add_member @person | ||
| 92 | + community.save! | ||
| 93 | + | ||
| 94 | + assert_equal 1, @person.softwares.count | ||
| 95 | + end | ||
| 96 | +end |