articles_test.rb 942 Bytes
require_relative '../test_helper'
require_relative '../../../../test/unit/api/test_helper'

class APITest <  ActiveSupport::TestCase

  def setup
    login_api
  end

  should 'list article children with author.name without filtering for that' do
  	article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing", author_id: user.person.id)
  	child1 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :author_id => user.person.id,:name => "Some thing")
    child2 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :author_id => user.person.id,:name => "Some thing")

    params['fields'] = 'title,id'
    get "/api/v1/articles/#{article.id}/children?#{params.to_query}"
    json = JSON.parse(last_response.body)
    assert_equivalent [child1.author.name, child2.author.name], json["articles"].map { |a| a["author"]["name"] unless a['author'].nil? }
  end

end