[Git][noosfero/noosfero][master] 2 commits: exposing url parameter of articles and created_by of LinkArticle

Leandro Nunes gitlab at mg.gitlab.com
Thu Jun 14 14:17:48 BRT 2018


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
277bedce by Leandro Nunes dos Santos at 2018-06-13T21:23:59Z
exposing url parameter of articles and created_by of LinkArticle

- - - - -
405801f4 by Leandro Nunes at 2018-06-14T17:17:37Z
Merge branch 'exposing-api-parameters' into 'master'

exposing url parameter of articles and created_by of LinkArticle

See merge request noosfero/noosfero!1532
- - - - -


4 changed files:

- app/api/entities.rb
- app/models/link_article.rb
- test/api/articles_test.rb
- test/unit/link_article_test.rb


Changes:

=====================================
app/api/entities.rb
=====================================
--- a/app/api/entities.rb
+++ b/app/api/entities.rb
@@ -215,6 +215,7 @@ module Api
       expose :abstract, documentation: {type: 'String', desc: 'Teaser of the body'}
       expose :created_at
       expose :updated_at
+      expose :url
       expose :title, :documentation => {:type => "String", :desc => "Title of the article"}
       expose :created_by, :as => :author, :using => Profile, :documentation => {type: 'Profile', desc: 'The profile author that create the article'}
       expose :profile, :using => Profile, :documentation => {type: 'Profile', desc: 'The profile associated with the article'}


=====================================
app/models/link_article.rb
=====================================
--- a/app/models/link_article.rb
+++ b/app/models/link_article.rb
@@ -11,5 +11,6 @@ class LinkArticle < Article
   delegate :abstract, :to => :reference_article
   delegate :url, :to => :reference_article
   delegate :author, :to => :reference_article
+  delegate :created_by, :to => :reference_article
 
 end


=====================================
test/api/articles_test.rb
=====================================
--- a/test/api/articles_test.rb
+++ b/test/api/articles_test.rb
@@ -215,7 +215,7 @@ class ArticlesTest < ActiveSupport::TestCase
     assert_equal true, json['success']
   end
 
-  expose_attributes = %w(id body abstract created_at title author profile categories image votes_for votes_against setting position hits start_date end_date tag_list parent children children_count)
+  expose_attributes = %w(id body abstract created_at title author profile categories image votes_for votes_against setting position hits start_date end_date tag_list parent children children_count url)
 
   expose_attributes.each do |attr|
     should "expose article #{attr} attribute by default" do


=====================================
test/unit/link_article_test.rb
=====================================
--- a/test/unit/link_article_test.rb
+++ b/test/unit/link_article_test.rb
@@ -4,26 +4,19 @@ class LinkArticleTest < ActiveSupport::TestCase
 
   def setup
     @profile = create_user('testing').person
+    @article = fast_create(Article, :profile_id => profile.id, 
+                name: 'some name', body: 'some content', abstract: 'some abstract', 
+                author_id: @profile.id, created_by_id: @profile.id )
   end
-  attr_reader :profile
+  attr_reader :profile, :article
 
-  should 'url of article link redirects to referenced article' do
-    article = fast_create(Article, :profile_id => profile.id)
-    link = LinkArticle.new(:reference_article => article)
-    assert_equal article.url, link.url
-  end
-
-  should 'name of article link is the same as the name of referenced article' do
-    article = fast_create(Article, :profile_id => profile.id)
-    link = LinkArticle.new(:reference_article => article)
-    assert_equal article.name, link.name
-  end
+  ORIGINAL_ARTICLE_FIELDS = %w(name body abstract url author created_by)
 
-  should 'author of article link is the same as the name of referenced article' do
-    author = fast_create(Person)
-    article = fast_create(Article, :profile_id => profile.id, :author_id => author.id)
-    link = LinkArticle.new(:reference_article => article)
-    assert_equal article.author, link.author
+  ORIGINAL_ARTICLE_FIELDS.map do |field|
+    should "#{field} of article link redirects to referenced article" do
+      link = LinkArticle.new(:reference_article => article)
+      assert_equal article.send(field), link.send(field)
+    end
   end
 
   should 'destroy link article when reference article is removed' do



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/468f20d0247546d1e5a1d4760f99eb5958794c28...405801f4e9e6a23b7003a8851970f35496c26a06

-- 
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/468f20d0247546d1e5a1d4760f99eb5958794c28...405801f4e9e6a23b7003a8851970f35496c26a06
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20180614/6f88181c/attachment-0001.html>


More information about the Noosfero-dev mailing list