comparison test/integration/api_test/news_test.rb @ 1526:404aa68d4227

Merge from live branch
author Chris Cannam
date Thu, 11 Sep 2014 12:46:20 +0100
parents e248c7af89ec
children
comparison
equal deleted inserted replaced
1493:a5f2bdf3b486 1526:404aa68d4227
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
14 # You should have received a copy of the GNU General Public License 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 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. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.expand_path('../../../test_helper', __FILE__) 18 require File.expand_path('../../../test_helper', __FILE__)
19 require 'pp' 19
20 class ApiTest::NewsTest < ActionController::IntegrationTest 20 class Redmine::ApiTest::NewsTest < Redmine::ApiTest::Base
21 fixtures :projects, :trackers, :issue_statuses, :issues, 21 fixtures :projects, :trackers, :issue_statuses, :issues,
22 :enumerations, :users, :issue_categories, 22 :enumerations, :users, :issue_categories,
23 :projects_trackers, 23 :projects_trackers,
24 :roles, 24 :roles,
25 :member_roles, 25 :member_roles,
26 :members, 26 :members,
27 :enabled_modules, 27 :enabled_modules,
28 :workflows,
29 :news 28 :news
30 29
31 def setup 30 def setup
32 Setting.rest_api_enabled = '1' 31 Setting.rest_api_enabled = '1'
33 end 32 end
34 33
35 context "GET /news" do 34 should_allow_api_authentication(:get, "/projects/onlinestore/news.xml")
36 context ".xml" do 35 should_allow_api_authentication(:get, "/projects/onlinestore/news.json")
37 should "return news" do
38 get '/news.xml'
39 36
40 assert_tag :tag => 'news', 37 test "GET /news.xml should return news" do
41 :attributes => {:type => 'array'}, 38 get '/news.xml'
42 :child => {
43 :tag => 'news',
44 :child => {
45 :tag => 'id',
46 :content => '2'
47 }
48 }
49 end
50 end
51 39
52 context ".json" do 40 assert_tag :tag => 'news',
53 should "return news" do 41 :attributes => {:type => 'array'},
54 get '/news.json' 42 :child => {
55 43 :tag => 'news',
56 json = ActiveSupport::JSON.decode(response.body) 44 :child => {
57 assert_kind_of Hash, json 45 :tag => 'id',
58 assert_kind_of Array, json['news'] 46 :content => '2'
59 assert_kind_of Hash, json['news'].first 47 }
60 assert_equal 2, json['news'].first['id'] 48 }
61 end
62 end
63 end 49 end
64 50
65 context "GET /projects/:project_id/news" do 51 test "GET /news.json should return news" do
66 context ".xml" do 52 get '/news.json'
67 should_allow_api_authentication(:get, "/projects/onlinestore/news.xml")
68 53
69 should "return news" do 54 json = ActiveSupport::JSON.decode(response.body)
70 get '/projects/ecookbook/news.xml' 55 assert_kind_of Hash, json
56 assert_kind_of Array, json['news']
57 assert_kind_of Hash, json['news'].first
58 assert_equal 2, json['news'].first['id']
59 end
71 60
72 assert_tag :tag => 'news', 61 test "GET /projects/:project_id/news.xml should return news" do
73 :attributes => {:type => 'array'}, 62 get '/projects/ecookbook/news.xml'
74 :child => {
75 :tag => 'news',
76 :child => {
77 :tag => 'id',
78 :content => '2'
79 }
80 }
81 end
82 end
83 63
84 context ".json" do 64 assert_tag :tag => 'news',
85 should_allow_api_authentication(:get, "/projects/onlinestore/news.json") 65 :attributes => {:type => 'array'},
66 :child => {
67 :tag => 'news',
68 :child => {
69 :tag => 'id',
70 :content => '2'
71 }
72 }
73 end
86 74
87 should "return news" do 75 test "GET /projects/:project_id/news.json should return news" do
88 get '/projects/ecookbook/news.json' 76 get '/projects/ecookbook/news.json'
89 77
90 json = ActiveSupport::JSON.decode(response.body) 78 json = ActiveSupport::JSON.decode(response.body)
91 assert_kind_of Hash, json 79 assert_kind_of Hash, json
92 assert_kind_of Array, json['news'] 80 assert_kind_of Array, json['news']
93 assert_kind_of Hash, json['news'].first 81 assert_kind_of Hash, json['news'].first
94 assert_equal 2, json['news'].first['id'] 82 assert_equal 2, json['news'].first['id']
95 end
96 end
97 end 83 end
98 end 84 end