annotate test/integration/api_test/.svn/text-base/news_test.rb.svn-base @ 507:0c939c159af4 redmine-1.2

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