To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / test / integration / api_test / news_test.rb @ 442:753f1380d6bc
History | View | Annotate | Download (2.73 KB)
| 1 |
# Redmine - project management software
|
|---|---|
| 2 |
# Copyright (C) 2006-2010 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 |
|
| 18 |
require File.expand_path('../../../test_helper', __FILE__) |
| 19 |
require 'pp'
|
| 20 |
class ApiTest::NewsTest < ActionController::IntegrationTest |
| 21 |
fixtures :all
|
| 22 |
|
| 23 |
def setup |
| 24 |
Setting.rest_api_enabled = '1' |
| 25 |
end
|
| 26 |
|
| 27 |
context "GET /news" do |
| 28 |
context ".xml" do |
| 29 |
should "return news" do |
| 30 |
get '/news.xml'
|
| 31 |
|
| 32 |
assert_tag :tag => 'news', |
| 33 |
:attributes => {:type => 'array'}, |
| 34 |
:child => {
|
| 35 |
:tag => 'news', |
| 36 |
:child => {
|
| 37 |
:tag => 'id', |
| 38 |
:content => '2' |
| 39 |
} |
| 40 |
} |
| 41 |
end
|
| 42 |
end
|
| 43 |
|
| 44 |
context ".json" do |
| 45 |
should "return news" do |
| 46 |
get '/news.json'
|
| 47 |
|
| 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 |
|
| 57 |
context "GET /projects/:project_id/news" do |
| 58 |
context ".xml" do |
| 59 |
should_allow_api_authentication(:get, "/projects/onlinestore/news.xml") |
| 60 |
|
| 61 |
should "return news" do |
| 62 |
get '/projects/ecookbook/news.xml'
|
| 63 |
|
| 64 |
assert_tag :tag => 'news', |
| 65 |
:attributes => {:type => 'array'}, |
| 66 |
:child => {
|
| 67 |
:tag => 'news', |
| 68 |
:child => {
|
| 69 |
:tag => 'id', |
| 70 |
:content => '2' |
| 71 |
} |
| 72 |
} |
| 73 |
end
|
| 74 |
end
|
| 75 |
|
| 76 |
context ".json" do |
| 77 |
should_allow_api_authentication(:get, "/projects/onlinestore/news.json") |
| 78 |
|
| 79 |
should "return news" do |
| 80 |
get '/projects/ecookbook/news.json'
|
| 81 |
|
| 82 |
json = ActiveSupport::JSON.decode(response.body) |
| 83 |
assert_kind_of Hash, json
|
| 84 |
assert_kind_of Array, json['news'] |
| 85 |
assert_kind_of Hash, json['news'].first |
| 86 |
assert_equal 2, json['news'].first['id'] |
| 87 |
end
|
| 88 |
end
|
| 89 |
end
|
| 90 |
|
| 91 |
def credentials(user, password=nil) |
| 92 |
ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) |
| 93 |
end
|
| 94 |
end
|