Commit eecc8ff382ffc8e13e1b48d3891197c901effc04
1 parent
93137fa5
Exists in
master
Refactoring the activities hash to general profiles
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Showing
3 changed files
with
27 additions
and
54 deletions
Show diff stats
lib/ext/person.rb
... | ... | @@ -11,8 +11,6 @@ class Person |
11 | 11 | |
12 | 12 | attrs = softwares_attrs(attrs) |
13 | 13 | |
14 | - attrs = activities_attrs(attrs) | |
15 | - | |
16 | 14 | attrs |
17 | 15 | end |
18 | 16 | |
... | ... | @@ -49,21 +47,6 @@ class Person |
49 | 47 | attrs |
50 | 48 | end |
51 | 49 | |
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 | 50 | private |
68 | 51 | |
69 | 52 | def profile_attrs(profile) | ... | ... |
lib/ext/profile.rb
... | ... | @@ -18,6 +18,24 @@ class Profile |
18 | 18 | attrs['articles'] << article.attr_to_hash |
19 | 19 | end |
20 | 20 | |
21 | + attrs['activities-count'] = self.activities.count | |
22 | + attrs['activities'] = activities_attrs | |
23 | + | |
24 | + attrs | |
25 | + end | |
26 | + | |
27 | + def activities_attrs | |
28 | + attrs = [] | |
29 | + | |
30 | + ids = self.activities.collect { |activity| activity.id } | |
31 | + | |
32 | + ActionTracker::Record.find(ids).collect { |activity| | |
33 | + attrs << { | |
34 | + 'verb' => activity.verb, | |
35 | + 'params' => activity.params | |
36 | + } | |
37 | + } | |
38 | + | |
21 | 39 | attrs |
22 | 40 | end |
23 | 41 | end | ... | ... |
test/functional/colab_integration_plugin_controller_test.rb
... | ... | @@ -45,42 +45,14 @@ class ColabIntegrationPluginControllerTest < ActionController::TestCase |
45 | 45 | assert_equal persons_with_article.count, 1 |
46 | 46 | end |
47 | 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 | - ) | |
48 | + should "return a hash with activities of the user" do | |
49 | + user = fast_create(Person, :name => "User") | |
50 | + fast_create(Community, :name => "User Community").add_member user | |
51 | + fast_create(Community, :name => "User Community 2").add_member user | |
52 | + | |
53 | + assert_equal 2, user.activities_attrs.count | |
54 | + assert user.activities_attrs.first.has_key?("verb") | |
55 | + assert user.activities_attrs.first.has_key?("params") | |
56 | + assert user.activities_attrs.first["verb"] == "join_community" | |
85 | 57 | end |
86 | 58 | end | ... | ... |