@@ -1,94 +1,102 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 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. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
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 | require 'pp' | |
20 | class ApiTest::NewsTest < ActionController::IntegrationTest |
|
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 | def setup |
|
31 | def setup | |
24 | Setting.rest_api_enabled = '1' |
|
32 | Setting.rest_api_enabled = '1' | |
25 | end |
|
33 | end | |
26 |
|
34 | |||
27 | context "GET /news" do |
|
35 | context "GET /news" do | |
28 | context ".xml" do |
|
36 | context ".xml" do | |
29 | should "return news" do |
|
37 | should "return news" do | |
30 | get '/news.xml' |
|
38 | get '/news.xml' | |
31 |
|
39 | |||
32 | assert_tag :tag => 'news', |
|
40 | assert_tag :tag => 'news', | |
33 | :attributes => {:type => 'array'}, |
|
41 | :attributes => {:type => 'array'}, | |
34 | :child => { |
|
42 | :child => { | |
35 | :tag => 'news', |
|
43 | :tag => 'news', | |
36 | :child => { |
|
44 | :child => { | |
37 | :tag => 'id', |
|
45 | :tag => 'id', | |
38 | :content => '2' |
|
46 | :content => '2' | |
39 | } |
|
47 | } | |
40 | } |
|
48 | } | |
41 | end |
|
49 | end | |
42 | end |
|
50 | end | |
43 |
|
51 | |||
44 | context ".json" do |
|
52 | context ".json" do | |
45 | should "return news" do |
|
53 | should "return news" do | |
46 | get '/news.json' |
|
54 | get '/news.json' | |
47 |
|
55 | |||
48 | json = ActiveSupport::JSON.decode(response.body) |
|
56 | json = ActiveSupport::JSON.decode(response.body) | |
49 | assert_kind_of Hash, json |
|
57 | assert_kind_of Hash, json | |
50 | assert_kind_of Array, json['news'] |
|
58 | assert_kind_of Array, json['news'] | |
51 | assert_kind_of Hash, json['news'].first |
|
59 | assert_kind_of Hash, json['news'].first | |
52 | assert_equal 2, json['news'].first['id'] |
|
60 | assert_equal 2, json['news'].first['id'] | |
53 | end |
|
61 | end | |
54 | end |
|
62 | end | |
55 | end |
|
63 | end | |
56 |
|
64 | |||
57 | context "GET /projects/:project_id/news" do |
|
65 | context "GET /projects/:project_id/news" do | |
58 | context ".xml" do |
|
66 | context ".xml" do | |
59 | should_allow_api_authentication(:get, "/projects/onlinestore/news.xml") |
|
67 | should_allow_api_authentication(:get, "/projects/onlinestore/news.xml") | |
60 |
|
68 | |||
61 | should "return news" do |
|
69 | should "return news" do | |
62 | get '/projects/ecookbook/news.xml' |
|
70 | get '/projects/ecookbook/news.xml' | |
63 |
|
71 | |||
64 | assert_tag :tag => 'news', |
|
72 | assert_tag :tag => 'news', | |
65 | :attributes => {:type => 'array'}, |
|
73 | :attributes => {:type => 'array'}, | |
66 | :child => { |
|
74 | :child => { | |
67 | :tag => 'news', |
|
75 | :tag => 'news', | |
68 | :child => { |
|
76 | :child => { | |
69 | :tag => 'id', |
|
77 | :tag => 'id', | |
70 | :content => '2' |
|
78 | :content => '2' | |
71 | } |
|
79 | } | |
72 | } |
|
80 | } | |
73 | end |
|
81 | end | |
74 | end |
|
82 | end | |
75 |
|
83 | |||
76 | context ".json" do |
|
84 | context ".json" do | |
77 | should_allow_api_authentication(:get, "/projects/onlinestore/news.json") |
|
85 | should_allow_api_authentication(:get, "/projects/onlinestore/news.json") | |
78 |
|
86 | |||
79 | should "return news" do |
|
87 | should "return news" do | |
80 | get '/projects/ecookbook/news.json' |
|
88 | get '/projects/ecookbook/news.json' | |
81 |
|
89 | |||
82 | json = ActiveSupport::JSON.decode(response.body) |
|
90 | json = ActiveSupport::JSON.decode(response.body) | |
83 | assert_kind_of Hash, json |
|
91 | assert_kind_of Hash, json | |
84 | assert_kind_of Array, json['news'] |
|
92 | assert_kind_of Array, json['news'] | |
85 | assert_kind_of Hash, json['news'].first |
|
93 | assert_kind_of Hash, json['news'].first | |
86 | assert_equal 2, json['news'].first['id'] |
|
94 | assert_equal 2, json['news'].first['id'] | |
87 | end |
|
95 | end | |
88 | end |
|
96 | end | |
89 | end |
|
97 | end | |
90 |
|
98 | |||
91 | def credentials(user, password=nil) |
|
99 | def credentials(user, password=nil) | |
92 | ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) |
|
100 | ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) | |
93 | end |
|
101 | end | |
94 | end |
|
102 | end |
General Comments 0
You need to be logged in to leave comments.
Login now