Commit 049fef28bee83befca0862fdd1794e76a26e0caa
1 parent
998c6298
Exists in
master
Fix type to return a string instead of the class. Add tests for person
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
2 changed files
with
64 additions
and
1 deletions
Show diff stats
lib/ext/profile.rb
@@ -3,7 +3,7 @@ require_dependency 'profile' | @@ -3,7 +3,7 @@ require_dependency 'profile' | ||
3 | class Profile | 3 | class Profile |
4 | def attr_to_hash | 4 | def attr_to_hash |
5 | attrs = { | 5 | attrs = { |
6 | - "type" => self.type, | 6 | + "type" => self.type.to_s, |
7 | "data" => { | 7 | "data" => { |
8 | "id" => self.id, | 8 | "id" => self.id, |
9 | "identifier" => self.identifier, | 9 | "identifier" => self.identifier, |
@@ -12,6 +12,7 @@ class Profile | @@ -12,6 +12,7 @@ class Profile | ||
12 | } | 12 | } |
13 | } | 13 | } |
14 | 14 | ||
15 | + attrs['articles-count'] = self.articles.count | ||
15 | attrs['articles'] = [] | 16 | attrs['articles'] = [] |
16 | self.articles.each do |article| | 17 | self.articles.each do |article| |
17 | attrs['articles'] << article.attr_to_hash | 18 | attrs['articles'] << article.attr_to_hash |
@@ -0,0 +1,62 @@ | @@ -0,0 +1,62 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | + | ||
3 | +class PersonTest < ActiveSupport::TestCase | ||
4 | + def setup | ||
5 | + @john = fast_create(Person, :name => "John Snow") | ||
6 | + @arya = fast_create(Person, :name => "Arya Stark") | ||
7 | + @joffrey = fast_create(Person, :name => "Joffrey Lannister") | ||
8 | + | ||
9 | + @arya.add_friend @john | ||
10 | + @arya.friends.reload | ||
11 | + | ||
12 | + @stark = fast_create(Community, :name => "House Stark") | ||
13 | + @stark.add_member @john | ||
14 | + @stark.add_admin @arya | ||
15 | + | ||
16 | + @lannister = fast_create(Community, :name => "House Lannister") | ||
17 | + @lannister.add_admin @joffrey | ||
18 | + | ||
19 | + @game_of_thrones = fast_create(Community, :name => "Game of Thrones") | ||
20 | + @game_of_thrones.add_member @john | ||
21 | + @game_of_thrones.add_member @arya | ||
22 | + @game_of_thrones.add_member @joffrey | ||
23 | + end | ||
24 | + | ||
25 | + should 'get the attributes of Joffrey Lannister' do | ||
26 | + attributes = @joffrey.attr_to_hash | ||
27 | + | ||
28 | + assert_equal attributes["type"], "Person" | ||
29 | + assert_equal attributes["data"]["name"], "Joffrey Lannister" | ||
30 | + | ||
31 | + assert_equal attributes["articles-count"], 0 | ||
32 | + | ||
33 | + assert_equal attributes["friends-count"], 0 | ||
34 | + | ||
35 | + assert_equal attributes["communities-count"], 2 | ||
36 | + end | ||
37 | + | ||
38 | + should 'get friendship information' do | ||
39 | + attributes_joffrey = @joffrey.attr_to_hash | ||
40 | + attributes_arya = @arya.attr_to_hash | ||
41 | + | ||
42 | + assert_equal attributes_joffrey["friends-count"], 0 | ||
43 | + assert_equal attributes_arya["friends-count"], 1 | ||
44 | + assert_equal attributes_arya["friends"][0]["name"], "John Snow" | ||
45 | + end | ||
46 | + | ||
47 | + should 'get softwares information' do | ||
48 | + @environment = Environment.default | ||
49 | + @environment.enabled_plugins = ['MpogSoftwarePlugin'] | ||
50 | + @environment.add_admin(@arya) | ||
51 | + @environment.save | ||
52 | + | ||
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 | ||
58 | + | ||
59 | + assert_equal attributes["softwares-count"], 1 | ||
60 | + assert_equal attributes["softwares"][0]["name"], "Game of Thrones" | ||
61 | + end | ||
62 | +end |