diff --git a/lib/ext/person.rb b/lib/ext/person.rb index e966594..70ab6cd 100644 --- a/lib/ext/person.rb +++ b/lib/ext/person.rb @@ -11,6 +11,8 @@ class Person attrs = softwares_attrs(attrs) + attrs = activities_attrs(attrs) + attrs end @@ -25,7 +27,7 @@ class Person def commuinities_attrs(attrs) attrs['communities-count'] = self.respond_to?("softwares") ? - self.communities.count - self.softwares.count : + self.communities.count - self.softwares.count : self.communities.count attrs['communities'] = [] self.communities.each do |community| @@ -47,7 +49,22 @@ class Person attrs end - private + 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) profile = { diff --git a/test/functional/colab_integration_plugin_controller_test.rb b/test/functional/colab_integration_plugin_controller_test.rb index f393ac6..6b2acbb 100644 --- a/test/functional/colab_integration_plugin_controller_test.rb +++ b/test/functional/colab_integration_plugin_controller_test.rb @@ -6,6 +6,7 @@ class ColabIntegrationPluginController; def rescue_action(e) raise e end; end class ColabIntegrationPluginControllerTest < ActionController::TestCase def setup + @controller = ColabIntegrationPluginController.new @john = fast_create(Person, :name => "John Snow") @arya = fast_create(Person, :name => "Arya Stark") @joffrey = fast_create(Person, :name => "Joffrey Lannister") @@ -43,4 +44,43 @@ 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 + ) + end end -- libgit2 0.21.2