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 30 end
31 31  
32 32 def person_commuinities_attrs(attrs, person)
  33 + communities_count = person.communities.count - person.softwares.count
33 34 attrs['communities-count'] = person.respond_to?("softwares") ?
34   - person.communities.count - person.softwares.count :
  35 + communities_count :
35 36 person.communities.count
36 37 attrs['communities'] = []
37 38 person.communities.each do |community|
... ... @@ -43,7 +44,8 @@ module PersonDataExport
43 44 end
44 45  
45 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 49 attrs['softwares'] = []
48 50 if person.respond_to?("softwares")
49 51 person.softwares.each do |software|
... ...
test/unit/person_test.rb
1 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 2  
3 3 class PersonTest < ActiveSupport::TestCase
  4 + include PersonDataExport
  5 +
4 6 def setup
5 7 @john = fast_create(Person, :name => "John Snow")
6 8 @arya = fast_create(Person, :name => "Arya Stark")
... ... @@ -23,9 +25,9 @@ class PersonTest &lt; ActiveSupport::TestCase
23 25 end
24 26  
25 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 31 assert_equal attributes["data"]["name"], "Joffrey Lannister"
30 32  
31 33 assert_equal attributes["articles-count"], 0
... ... @@ -36,8 +38,8 @@ class PersonTest &lt; ActiveSupport::TestCase
36 38 end
37 39  
38 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 44 assert_equal attributes_joffrey["friends-count"], 0
43 45 assert_equal attributes_arya["friends-count"], 1
... ... @@ -50,11 +52,31 @@ class PersonTest &lt; ActiveSupport::TestCase
50 52 @environment.add_admin(@arya)
51 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 81 assert_equal attributes["softwares-count"], 1
60 82 assert_equal attributes["softwares"][0]["name"], "Game of Thrones"
... ...