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