diff --git a/lib/ext/profile.rb b/lib/ext/profile.rb index 77a1264..86046d5 100644 --- a/lib/ext/profile.rb +++ b/lib/ext/profile.rb @@ -3,7 +3,7 @@ require_dependency 'profile' class Profile def attr_to_hash attrs = { - "type" => self.type, + "type" => self.type.to_s, "data" => { "id" => self.id, "identifier" => self.identifier, @@ -12,6 +12,7 @@ class Profile } } + attrs['articles-count'] = self.articles.count attrs['articles'] = [] self.articles.each do |article| attrs['articles'] << article.attr_to_hash diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb new file mode 100644 index 0000000..2c842be --- /dev/null +++ b/test/unit/person_test.rb @@ -0,0 +1,62 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' + +class PersonTest < ActiveSupport::TestCase + def setup + @john = fast_create(Person, :name => "John Snow") + @arya = fast_create(Person, :name => "Arya Stark") + @joffrey = fast_create(Person, :name => "Joffrey Lannister") + + @arya.add_friend @john + @arya.friends.reload + + @stark = fast_create(Community, :name => "House Stark") + @stark.add_member @john + @stark.add_admin @arya + + @lannister = fast_create(Community, :name => "House Lannister") + @lannister.add_admin @joffrey + + @game_of_thrones = fast_create(Community, :name => "Game of Thrones") + @game_of_thrones.add_member @john + @game_of_thrones.add_member @arya + @game_of_thrones.add_member @joffrey + end + + should 'get the attributes of Joffrey Lannister' do + attributes = @joffrey.attr_to_hash + + assert_equal attributes["type"], "Person" + assert_equal attributes["data"]["name"], "Joffrey Lannister" + + assert_equal attributes["articles-count"], 0 + + assert_equal attributes["friends-count"], 0 + + assert_equal attributes["communities-count"], 2 + end + + should 'get friendship information' do + attributes_joffrey = @joffrey.attr_to_hash + attributes_arya = @arya.attr_to_hash + + assert_equal attributes_joffrey["friends-count"], 0 + assert_equal attributes_arya["friends-count"], 1 + assert_equal attributes_arya["friends"][0]["name"], "John Snow" + end + + should 'get softwares information' do + @environment = Environment.default + @environment.enabled_plugins = ['MpogSoftwarePlugin'] + @environment.add_admin(@arya) + @environment.save + + @thrones_the_game = SoftwareInfo.new + @thrones_the_game.community_id = @game_of_thrones.id + @thrones_the_game.save + + attributes = @john.attr_to_hash + + assert_equal attributes["softwares-count"], 1 + assert_equal attributes["softwares"][0]["name"], "Game of Thrones" + end +end -- libgit2 0.21.2