annotate test/integration/api_test/news_test.rb @ 1176:7d9db6065048 bug_352

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