Commit 54d7aaef482657c61d183fe6c60b9361512ac81a

Authored by David Silva
1 parent 97e25590
Exists in master

Fixing person unit tests

  - Improves code style

Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
lib/person_data_export.rb
@@ -30,8 +30,9 @@ module PersonDataExport @@ -30,8 +30,9 @@ module PersonDataExport
30 end 30 end
31 31
32 def person_commuinities_attrs(attrs, person) 32 def person_commuinities_attrs(attrs, person)
  33 + communities_count = person.communities.count - person.softwares.count
33 attrs['communities-count'] = person.respond_to?("softwares") ? 34 attrs['communities-count'] = person.respond_to?("softwares") ?
34 - person.communities.count - person.softwares.count : 35 + communities_count :
35 person.communities.count 36 person.communities.count
36 attrs['communities'] = [] 37 attrs['communities'] = []
37 person.communities.each do |community| 38 person.communities.each do |community|
@@ -43,7 +44,8 @@ module PersonDataExport @@ -43,7 +44,8 @@ module PersonDataExport
43 end 44 end
44 45
45 def person_softwares_attrs(attrs, person) 46 def person_softwares_attrs(attrs, person)
46 - attrs['softwares-count'] = person.respond_to?("softwares") ? person.softwares.count : 0 47 + attrs['softwares-count'] = person.respond_to?("softwares") ?
  48 + person.softwares.count : 0
47 attrs['softwares'] = [] 49 attrs['softwares'] = []
48 if person.respond_to?("softwares") 50 if person.respond_to?("softwares")
49 person.softwares.each do |software| 51 person.softwares.each do |software|
test/unit/person_test.rb
1 require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 2
3 class PersonTest < ActiveSupport::TestCase 3 class PersonTest < ActiveSupport::TestCase
  4 + include PersonDataExport
  5 +
4 def setup 6 def setup
5 @john = fast_create(Person, :name => "John Snow") 7 @john = fast_create(Person, :name => "John Snow")
6 @arya = fast_create(Person, :name => "Arya Stark") 8 @arya = fast_create(Person, :name => "Arya Stark")
@@ -23,9 +25,9 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -23,9 +25,9 @@ class PersonTest &lt; ActiveSupport::TestCase
23 end 25 end
24 26
25 should 'get the attributes of Joffrey Lannister' do 27 should 'get the attributes of Joffrey Lannister' do
26 - attributes = @joffrey.attr_to_hash 28 + attributes = person_attr_to_hash @joffrey
27 29
28 - assert_equal attributes["type"], "Person" 30 + assert_equal attributes["data"]["type"], "Person"
29 assert_equal attributes["data"]["name"], "Joffrey Lannister" 31 assert_equal attributes["data"]["name"], "Joffrey Lannister"
30 32
31 assert_equal attributes["articles-count"], 0 33 assert_equal attributes["articles-count"], 0
@@ -36,8 +38,8 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -36,8 +38,8 @@ class PersonTest &lt; ActiveSupport::TestCase
36 end 38 end
37 39
38 should 'get friendship information' do 40 should 'get friendship information' do
39 - attributes_joffrey = @joffrey.attr_to_hash  
40 - attributes_arya = @arya.attr_to_hash 41 + attributes_joffrey = person_attr_to_hash @joffrey
  42 + attributes_arya = person_attr_to_hash @arya
41 43
42 assert_equal attributes_joffrey["friends-count"], 0 44 assert_equal attributes_joffrey["friends-count"], 0
43 assert_equal attributes_arya["friends-count"], 1 45 assert_equal attributes_arya["friends-count"], 1
@@ -50,11 +52,31 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -50,11 +52,31 @@ class PersonTest &lt; ActiveSupport::TestCase
50 @environment.add_admin(@arya) 52 @environment.add_admin(@arya)
51 @environment.save 53 @environment.save
52 54
53 - @thrones_the_game = SoftwareInfo.new  
54 - @thrones_the_game.community_id = @game_of_thrones.id  
55 - @thrones_the_game.save  
56 -  
57 - attributes = @john.attr_to_hash 55 + thrones_the_game = SoftwareInfo.new
  56 + thrones_the_game.community_id = @game_of_thrones.id
  57 + thrones_the_game.public_software = true
  58 +
  59 + license_gpl = LicenseInfo.create(
  60 + :version=>"CC-GPL-V2",
  61 + :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"
  62 + )
  63 + thrones_the_game.license_info = license_gpl
  64 +
  65 + software = Category.create(:name => _("Software"),
  66 + :environment => @environment)
  67 + categories = []
  68 + categories << Category.create(:name => "TBS",
  69 + :environment => @environment,
  70 + :parent => software)
  71 + categories << Category.create(:name => "War",
  72 + :environment => @environment,
  73 + :parent => software)
  74 + thrones_the_game.community.categories << categories
  75 +
  76 + thrones_the_game.finality = "teste"
  77 + thrones_the_game.save
  78 +
  79 + attributes = person_attr_to_hash @arya
58 80
59 assert_equal attributes["softwares-count"], 1 81 assert_equal attributes["softwares-count"], 1
60 assert_equal attributes["softwares"][0]["name"], "Game of Thrones" 82 assert_equal attributes["softwares"][0]["name"], "Game of Thrones"