You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

news_test.rb 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../../test_helper', __FILE__)
  18. class Redmine::ApiTest::NewsTest < Redmine::ApiTest::Base
  19. fixtures :projects, :trackers, :issue_statuses, :issues,
  20. :enumerations, :users, :issue_categories,
  21. :projects_trackers,
  22. :roles,
  23. :member_roles,
  24. :members,
  25. :enabled_modules,
  26. :news
  27. def setup
  28. Setting.rest_api_enabled = '1'
  29. end
  30. context "GET /news" do
  31. context ".xml" do
  32. should "return news" do
  33. get '/news.xml'
  34. assert_tag :tag => 'news',
  35. :attributes => {:type => 'array'},
  36. :child => {
  37. :tag => 'news',
  38. :child => {
  39. :tag => 'id',
  40. :content => '2'
  41. }
  42. }
  43. end
  44. end
  45. context ".json" do
  46. should "return news" do
  47. get '/news.json'
  48. json = ActiveSupport::JSON.decode(response.body)
  49. assert_kind_of Hash, json
  50. assert_kind_of Array, json['news']
  51. assert_kind_of Hash, json['news'].first
  52. assert_equal 2, json['news'].first['id']
  53. end
  54. end
  55. end
  56. context "GET /projects/:project_id/news" do
  57. context ".xml" do
  58. should_allow_api_authentication(:get, "/projects/onlinestore/news.xml")
  59. should "return news" do
  60. get '/projects/ecookbook/news.xml'
  61. assert_tag :tag => 'news',
  62. :attributes => {:type => 'array'},
  63. :child => {
  64. :tag => 'news',
  65. :child => {
  66. :tag => 'id',
  67. :content => '2'
  68. }
  69. }
  70. end
  71. end
  72. context ".json" do
  73. should_allow_api_authentication(:get, "/projects/onlinestore/news.json")
  74. should "return news" do
  75. get '/projects/ecookbook/news.json'
  76. json = ActiveSupport::JSON.decode(response.body)
  77. assert_kind_of Hash, json
  78. assert_kind_of Array, json['news']
  79. assert_kind_of Hash, json['news'].first
  80. assert_equal 2, json['news'].first['id']
  81. end
  82. end
  83. end
  84. end