Commit 8fe68e885c20effb56179c25fb9e92e39a45481f

Authored by Caio Almeida
1 parent 3b69b25a

API: Adding endpoint followed by me

app/models/person.rb
... ... @@ -4,7 +4,7 @@ class Person < Profile
4 4 attr_accessible :organization, :contact_information, :sex, :birth_date, :cell_phone,
5 5 :comercial_phone, :jabber_id, :personal_website, :nationality, :address_reference,
6 6 :district, :schooling, :schooling_status, :formation, :custom_formation, :area_of_study,
7   - :custom_area_of_study, :professional_activity, :organization_website, :following_articiles
  7 + :custom_area_of_study, :professional_activity, :organization_website, :following_articles
8 8  
9 9 SEARCH_FILTERS = {
10 10 :order => %w[more_recent more_popular more_active],
... ... @@ -89,7 +89,7 @@ class Person < Profile
89 89  
90 90 #Article followers relation
91 91 has_many :article_followers, :dependent => :destroy
92   - has_many :following_articiles, :class_name => 'Article', :through => :article_followers, :source => :article
  92 + has_many :following_articles, :class_name => 'Article', :through => :article_followers, :source => :article
93 93  
94 94 has_many :friendships, :dependent => :destroy
95 95 has_many :friends, :class_name => 'Person', :through => :friendships
... ...
lib/noosfero/api/helpers.rb
... ... @@ -97,8 +97,8 @@ require 'grape'
97 97 present article, :with => Entities::Article, :fields => params[:fields]
98 98 end
99 99  
100   - def present_articles(asset)
101   - articles = find_articles(asset)
  100 + def present_articles(asset, method = 'articles')
  101 + articles = find_articles(asset, method)
102 102 articles = paginate articles
103 103 present articles, :with => Entities::Article, :fields => params[:fields]
104 104 end
... ...
lib/noosfero/api/v1/articles.rb
... ... @@ -25,6 +25,11 @@ module Noosfero
25 25 present_articles(environment)
26 26 end
27 27  
  28 + desc "Return the articles followed by me"
  29 + get 'followed_by_me' do
  30 + present_articles(current_person, 'following_articles')
  31 + end
  32 +
28 33 desc "Return the article id"
29 34 get ':id' do
30 35 present_article(environment)
... ...
test/unit/article_follower_test.rb
... ... @@ -72,7 +72,7 @@ class ArticleFollowerTest < ActiveSupport::TestCase
72 72 article_follower.person = p1
73 73 article_follower.save!
74 74  
75   - assert_equal p1.following_articiles.size, 2
  75 + assert_equal p1.following_articles.size, 2
76 76 end
77 77  
78 78  
... ...