diff --git a/lib/ext/person.rb b/lib/ext/person.rb index 70ab6cd..8756ad5 100644 --- a/lib/ext/person.rb +++ b/lib/ext/person.rb @@ -11,8 +11,6 @@ class Person attrs = softwares_attrs(attrs) - attrs = activities_attrs(attrs) - attrs end @@ -49,21 +47,6 @@ class Person attrs end - def activities_attrs(attrs) - attrs['activities'] = [] - - ids = self.activities.collect { |a| a.id } - - ActionTracker::Record.find(ids).collect { |a| - attrs['activities'] << { - "verb" => a.verb, - "params" => a.params - } - } - - attrs - end - private def profile_attrs(profile) diff --git a/lib/ext/profile.rb b/lib/ext/profile.rb index 86046d5..bd44def 100644 --- a/lib/ext/profile.rb +++ b/lib/ext/profile.rb @@ -18,6 +18,24 @@ class Profile attrs['articles'] << article.attr_to_hash end + attrs['activities-count'] = self.activities.count + attrs['activities'] = activities_attrs + + attrs + end + + def activities_attrs + attrs = [] + + ids = self.activities.collect { |activity| activity.id } + + ActionTracker::Record.find(ids).collect { |activity| + attrs << { + 'verb' => activity.verb, + 'params' => activity.params + } + } + attrs end end diff --git a/test/functional/colab_integration_plugin_controller_test.rb b/test/functional/colab_integration_plugin_controller_test.rb index 6b2acbb..de84113 100644 --- a/test/functional/colab_integration_plugin_controller_test.rb +++ b/test/functional/colab_integration_plugin_controller_test.rb @@ -45,42 +45,14 @@ class ColabIntegrationPluginControllerTest < ActionController::TestCase assert_equal persons_with_article.count, 1 end - #TODO - FIXME - should "return a json with activities of the user" do - create_article_by_post @john, "The winter is coming", "help" - create_article_by_post @john, "The coming is winter", "help" - create_article_by_post @john, "winter is", "help" - - puts "="*80, @john.activities_attrs({}), "="*80 - - assert_equal 1, 1 - end - - private - - def create_article_by_post profile, article_name, article_body - @controller = CmsController.new - - post( - "new", - :article => { - :name => article_name, - :parent_id => "", - :license_id => "", - :abstract => "", - :body =>"
#{article_body}
", - :category_ids =>[""], - :tag_list => "", - :published => "true", - :show_to_followers =>"0", - :accept_comments => "1", - :notify_comments => "1", - :moderate_comments =>"0", - :display_hits => "1", - :display_versions => "0" - }, - :commit => "Save", - :profile => profile - ) + should "return a hash with activities of the user" do + user = fast_create(Person, :name => "User") + fast_create(Community, :name => "User Community").add_member user + fast_create(Community, :name => "User Community 2").add_member user + + assert_equal 2, user.activities_attrs.count + assert user.activities_attrs.first.has_key?("verb") + assert user.activities_attrs.first.has_key?("params") + assert user.activities_attrs.first["verb"] == "join_community" end end -- libgit2 0.21.2