Commit 93137fa5eba1c2b57c39280ffce52efac6c2d121

Authored by Fabio Teixeira
1 parent 9a9aee47
Exists in master

Get activities as attributes

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
lib/ext/person.rb
@@ -11,6 +11,8 @@ class Person @@ -11,6 +11,8 @@ class Person
11 11
12 attrs = softwares_attrs(attrs) 12 attrs = softwares_attrs(attrs)
13 13
  14 + attrs = activities_attrs(attrs)
  15 +
14 attrs 16 attrs
15 end 17 end
16 18
@@ -25,7 +27,7 @@ class Person @@ -25,7 +27,7 @@ class Person
25 27
26 def commuinities_attrs(attrs) 28 def commuinities_attrs(attrs)
27 attrs['communities-count'] = self.respond_to?("softwares") ? 29 attrs['communities-count'] = self.respond_to?("softwares") ?
28 - self.communities.count - self.softwares.count : 30 + self.communities.count - self.softwares.count :
29 self.communities.count 31 self.communities.count
30 attrs['communities'] = [] 32 attrs['communities'] = []
31 self.communities.each do |community| 33 self.communities.each do |community|
@@ -47,7 +49,22 @@ class Person @@ -47,7 +49,22 @@ class Person
47 attrs 49 attrs
48 end 50 end
49 51
50 - private 52 + def activities_attrs(attrs)
  53 + attrs['activities'] = []
  54 +
  55 + ids = self.activities.collect { |a| a.id }
  56 +
  57 + ActionTracker::Record.find(ids).collect { |a|
  58 + attrs['activities'] << {
  59 + "verb" => a.verb,
  60 + "params" => a.params
  61 + }
  62 + }
  63 +
  64 + attrs
  65 + end
  66 +
  67 + private
51 68
52 def profile_attrs(profile) 69 def profile_attrs(profile)
53 profile = { 70 profile = {
test/functional/colab_integration_plugin_controller_test.rb
@@ -6,6 +6,7 @@ class ColabIntegrationPluginController; def rescue_action(e) raise e end; end @@ -6,6 +6,7 @@ class ColabIntegrationPluginController; def rescue_action(e) raise e end; end
6 class ColabIntegrationPluginControllerTest < ActionController::TestCase 6 class ColabIntegrationPluginControllerTest < ActionController::TestCase
7 7
8 def setup 8 def setup
  9 + @controller = ColabIntegrationPluginController.new
9 @john = fast_create(Person, :name => "John Snow") 10 @john = fast_create(Person, :name => "John Snow")
10 @arya = fast_create(Person, :name => "Arya Stark") 11 @arya = fast_create(Person, :name => "Arya Stark")
11 @joffrey = fast_create(Person, :name => "Joffrey Lannister") 12 @joffrey = fast_create(Person, :name => "Joffrey Lannister")
@@ -43,4 +44,43 @@ class ColabIntegrationPluginControllerTest &lt; ActionController::TestCase @@ -43,4 +44,43 @@ class ColabIntegrationPluginControllerTest &lt; ActionController::TestCase
43 } 44 }
44 assert_equal persons_with_article.count, 1 45 assert_equal persons_with_article.count, 1
45 end 46 end
  47 +
  48 + #TODO - FIXME
  49 + should "return a json with activities of the user" do
  50 + create_article_by_post @john, "The winter is coming", "help"
  51 + create_article_by_post @john, "The coming is winter", "help"
  52 + create_article_by_post @john, "winter is", "help"
  53 +
  54 + puts "="*80, @john.activities_attrs({}), "="*80
  55 +
  56 + assert_equal 1, 1
  57 + end
  58 +
  59 + private
  60 +
  61 + def create_article_by_post profile, article_name, article_body
  62 + @controller = CmsController.new
  63 +
  64 + post(
  65 + "new",
  66 + :article => {
  67 + :name => article_name,
  68 + :parent_id => "",
  69 + :license_id => "",
  70 + :abstract => "",
  71 + :body =>"<p>#{article_body}</p> ",
  72 + :category_ids =>[""],
  73 + :tag_list => "",
  74 + :published => "true",
  75 + :show_to_followers =>"0",
  76 + :accept_comments => "1",
  77 + :notify_comments => "1",
  78 + :moderate_comments =>"0",
  79 + :display_hits => "1",
  80 + :display_versions => "0"
  81 + },
  82 + :commit => "Save",
  83 + :profile => profile
  84 + )
  85 + end
46 end 86 end