annotate .svn/pristine/c8/c8ead97161810444d935cbc0189f12e56246f822.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 #require 'shoulda'
Chris@1296 19 ENV["RAILS_ENV"] = "test"
Chris@1296 20 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
Chris@1296 21 require 'rails/test_help'
Chris@1296 22 require Rails.root.join('test', 'mocks', 'open_id_authentication_mock.rb').to_s
Chris@1296 23
Chris@1296 24 require File.expand_path(File.dirname(__FILE__) + '/object_helpers')
Chris@1296 25 include ObjectHelpers
Chris@1296 26
Chris@1296 27 class ActiveSupport::TestCase
Chris@1296 28 include ActionDispatch::TestProcess
Chris@1296 29
Chris@1296 30 # Transactional fixtures accelerate your tests by wrapping each test method
Chris@1296 31 # in a transaction that's rolled back on completion. This ensures that the
Chris@1296 32 # test database remains unchanged so your fixtures don't have to be reloaded
Chris@1296 33 # between every test method. Fewer database queries means faster tests.
Chris@1296 34 #
Chris@1296 35 # Read Mike Clark's excellent walkthrough at
Chris@1296 36 # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
Chris@1296 37 #
Chris@1296 38 # Every Active Record database supports transactions except MyISAM tables
Chris@1296 39 # in MySQL. Turn off transactional fixtures in this case; however, if you
Chris@1296 40 # don't care one way or the other, switching from MyISAM to InnoDB tables
Chris@1296 41 # is recommended.
Chris@1296 42 self.use_transactional_fixtures = true
Chris@1296 43
Chris@1296 44 # Instantiated fixtures are slow, but give you @david where otherwise you
Chris@1296 45 # would need people(:david). If you don't want to migrate your existing
Chris@1296 46 # test cases which use the @david style and don't mind the speed hit (each
Chris@1296 47 # instantiated fixtures translates to a database query per test method),
Chris@1296 48 # then set this back to true.
Chris@1296 49 self.use_instantiated_fixtures = false
Chris@1296 50
Chris@1296 51 # Add more helper methods to be used by all tests here...
Chris@1296 52
Chris@1296 53 def log_user(login, password)
Chris@1296 54 User.anonymous
Chris@1296 55 get "/login"
Chris@1296 56 assert_equal nil, session[:user_id]
Chris@1296 57 assert_response :success
Chris@1296 58 assert_template "account/login"
Chris@1296 59 post "/login", :username => login, :password => password
Chris@1296 60 assert_equal login, User.find(session[:user_id]).login
Chris@1296 61 end
Chris@1296 62
Chris@1296 63 def uploaded_test_file(name, mime)
Chris@1296 64 fixture_file_upload("files/#{name}", mime, true)
Chris@1296 65 end
Chris@1296 66
Chris@1296 67 def credentials(user, password=nil)
Chris@1296 68 {'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)}
Chris@1296 69 end
Chris@1296 70
Chris@1296 71 # Mock out a file
Chris@1296 72 def self.mock_file
Chris@1296 73 file = 'a_file.png'
Chris@1296 74 file.stubs(:size).returns(32)
Chris@1296 75 file.stubs(:original_filename).returns('a_file.png')
Chris@1296 76 file.stubs(:content_type).returns('image/png')
Chris@1296 77 file.stubs(:read).returns(false)
Chris@1296 78 file
Chris@1296 79 end
Chris@1296 80
Chris@1296 81 def mock_file
Chris@1296 82 self.class.mock_file
Chris@1296 83 end
Chris@1296 84
Chris@1296 85 def mock_file_with_options(options={})
Chris@1296 86 file = ''
Chris@1296 87 file.stubs(:size).returns(32)
Chris@1296 88 original_filename = options[:original_filename] || nil
Chris@1296 89 file.stubs(:original_filename).returns(original_filename)
Chris@1296 90 content_type = options[:content_type] || nil
Chris@1296 91 file.stubs(:content_type).returns(content_type)
Chris@1296 92 file.stubs(:read).returns(false)
Chris@1296 93 file
Chris@1296 94 end
Chris@1296 95
Chris@1296 96 # Use a temporary directory for attachment related tests
Chris@1296 97 def set_tmp_attachments_directory
Chris@1296 98 Dir.mkdir "#{Rails.root}/tmp/test" unless File.directory?("#{Rails.root}/tmp/test")
Chris@1296 99 unless File.directory?("#{Rails.root}/tmp/test/attachments")
Chris@1296 100 Dir.mkdir "#{Rails.root}/tmp/test/attachments"
Chris@1296 101 end
Chris@1296 102 Attachment.storage_path = "#{Rails.root}/tmp/test/attachments"
Chris@1296 103 end
Chris@1296 104
Chris@1296 105 def set_fixtures_attachments_directory
Chris@1296 106 Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
Chris@1296 107 end
Chris@1296 108
Chris@1296 109 def with_settings(options, &block)
Chris@1296 110 saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].is_a?(Symbol) ? Setting[k] : Setting[k].dup; h}
Chris@1296 111 options.each {|k, v| Setting[k] = v}
Chris@1296 112 yield
Chris@1296 113 ensure
Chris@1296 114 saved_settings.each {|k, v| Setting[k] = v} if saved_settings
Chris@1296 115 end
Chris@1296 116
Chris@1296 117 # Yields the block with user as the current user
Chris@1296 118 def with_current_user(user, &block)
Chris@1296 119 saved_user = User.current
Chris@1296 120 User.current = user
Chris@1296 121 yield
Chris@1296 122 ensure
Chris@1296 123 User.current = saved_user
Chris@1296 124 end
Chris@1296 125
Chris@1296 126 def change_user_password(login, new_password)
Chris@1296 127 user = User.first(:conditions => {:login => login})
Chris@1296 128 user.password, user.password_confirmation = new_password, new_password
Chris@1296 129 user.save!
Chris@1296 130 end
Chris@1296 131
Chris@1296 132 def self.ldap_configured?
Chris@1296 133 @test_ldap = Net::LDAP.new(:host => '127.0.0.1', :port => 389)
Chris@1296 134 return @test_ldap.bind
Chris@1296 135 rescue Exception => e
Chris@1296 136 # LDAP is not listening
Chris@1296 137 return nil
Chris@1296 138 end
Chris@1296 139
Chris@1296 140 def self.convert_installed?
Chris@1296 141 Redmine::Thumbnail.convert_available?
Chris@1296 142 end
Chris@1296 143
Chris@1296 144 # Returns the path to the test +vendor+ repository
Chris@1296 145 def self.repository_path(vendor)
Chris@1296 146 Rails.root.join("tmp/test/#{vendor.downcase}_repository").to_s
Chris@1296 147 end
Chris@1296 148
Chris@1296 149 # Returns the url of the subversion test repository
Chris@1296 150 def self.subversion_repository_url
Chris@1296 151 path = repository_path('subversion')
Chris@1296 152 path = '/' + path unless path.starts_with?('/')
Chris@1296 153 "file://#{path}"
Chris@1296 154 end
Chris@1296 155
Chris@1296 156 # Returns true if the +vendor+ test repository is configured
Chris@1296 157 def self.repository_configured?(vendor)
Chris@1296 158 File.directory?(repository_path(vendor))
Chris@1296 159 end
Chris@1296 160
Chris@1296 161 def repository_path_hash(arr)
Chris@1296 162 hs = {}
Chris@1296 163 hs[:path] = arr.join("/")
Chris@1296 164 hs[:param] = arr.join("/")
Chris@1296 165 hs
Chris@1296 166 end
Chris@1296 167
Chris@1296 168 def assert_save(object)
Chris@1296 169 saved = object.save
Chris@1296 170 message = "#{object.class} could not be saved"
Chris@1296 171 errors = object.errors.full_messages.map {|m| "- #{m}"}
Chris@1296 172 message << ":\n#{errors.join("\n")}" if errors.any?
Chris@1296 173 assert_equal true, saved, message
Chris@1296 174 end
Chris@1296 175
Chris@1296 176 def assert_error_tag(options={})
Chris@1296 177 assert_tag({:attributes => { :id => 'errorExplanation' }}.merge(options))
Chris@1296 178 end
Chris@1296 179
Chris@1296 180 def assert_include(expected, s, message=nil)
Chris@1296 181 assert s.include?(expected), (message || "\"#{expected}\" not found in \"#{s}\"")
Chris@1296 182 end
Chris@1296 183
Chris@1296 184 def assert_not_include(expected, s)
Chris@1296 185 assert !s.include?(expected), "\"#{expected}\" found in \"#{s}\""
Chris@1296 186 end
Chris@1296 187
Chris@1296 188 def assert_select_in(text, *args, &block)
Chris@1296 189 d = HTML::Document.new(CGI::unescapeHTML(String.new(text))).root
Chris@1296 190 assert_select(d, *args, &block)
Chris@1296 191 end
Chris@1296 192
Chris@1296 193 def assert_mail_body_match(expected, mail)
Chris@1296 194 if expected.is_a?(String)
Chris@1296 195 assert_include expected, mail_body(mail)
Chris@1296 196 else
Chris@1296 197 assert_match expected, mail_body(mail)
Chris@1296 198 end
Chris@1296 199 end
Chris@1296 200
Chris@1296 201 def assert_mail_body_no_match(expected, mail)
Chris@1296 202 if expected.is_a?(String)
Chris@1296 203 assert_not_include expected, mail_body(mail)
Chris@1296 204 else
Chris@1296 205 assert_no_match expected, mail_body(mail)
Chris@1296 206 end
Chris@1296 207 end
Chris@1296 208
Chris@1296 209 def mail_body(mail)
Chris@1296 210 mail.parts.first.body.encoded
Chris@1296 211 end
Chris@1296 212
Chris@1296 213 # Shoulda macros
Chris@1296 214 def self.should_render_404
Chris@1296 215 should_respond_with :not_found
Chris@1296 216 should_render_template 'common/error'
Chris@1296 217 end
Chris@1296 218
Chris@1296 219 def self.should_have_before_filter(expected_method, options = {})
Chris@1296 220 should_have_filter('before', expected_method, options)
Chris@1296 221 end
Chris@1296 222
Chris@1296 223 def self.should_have_after_filter(expected_method, options = {})
Chris@1296 224 should_have_filter('after', expected_method, options)
Chris@1296 225 end
Chris@1296 226
Chris@1296 227 def self.should_have_filter(filter_type, expected_method, options)
Chris@1296 228 description = "have #{filter_type}_filter :#{expected_method}"
Chris@1296 229 description << " with #{options.inspect}" unless options.empty?
Chris@1296 230
Chris@1296 231 should description do
Chris@1296 232 klass = "action_controller/filters/#{filter_type}_filter".classify.constantize
Chris@1296 233 expected = klass.new(:filter, expected_method.to_sym, options)
Chris@1296 234 assert_equal 1, @controller.class.filter_chain.select { |filter|
Chris@1296 235 filter.method == expected.method && filter.kind == expected.kind &&
Chris@1296 236 filter.options == expected.options && filter.class == expected.class
Chris@1296 237 }.size
Chris@1296 238 end
Chris@1296 239 end
Chris@1296 240
Chris@1296 241 # Test that a request allows the three types of API authentication
Chris@1296 242 #
Chris@1296 243 # * HTTP Basic with username and password
Chris@1296 244 # * HTTP Basic with an api key for the username
Chris@1296 245 # * Key based with the key=X parameter
Chris@1296 246 #
Chris@1296 247 # @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete)
Chris@1296 248 # @param [String] url the request url
Chris@1296 249 # @param [optional, Hash] parameters additional request parameters
Chris@1296 250 # @param [optional, Hash] options additional options
Chris@1296 251 # @option options [Symbol] :success_code Successful response code (:success)
Chris@1296 252 # @option options [Symbol] :failure_code Failure response code (:unauthorized)
Chris@1296 253 def self.should_allow_api_authentication(http_method, url, parameters={}, options={})
Chris@1296 254 should_allow_http_basic_auth_with_username_and_password(http_method, url, parameters, options)
Chris@1296 255 should_allow_http_basic_auth_with_key(http_method, url, parameters, options)
Chris@1296 256 should_allow_key_based_auth(http_method, url, parameters, options)
Chris@1296 257 end
Chris@1296 258
Chris@1296 259 # Test that a request allows the username and password for HTTP BASIC
Chris@1296 260 #
Chris@1296 261 # @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete)
Chris@1296 262 # @param [String] url the request url
Chris@1296 263 # @param [optional, Hash] parameters additional request parameters
Chris@1296 264 # @param [optional, Hash] options additional options
Chris@1296 265 # @option options [Symbol] :success_code Successful response code (:success)
Chris@1296 266 # @option options [Symbol] :failure_code Failure response code (:unauthorized)
Chris@1296 267 def self.should_allow_http_basic_auth_with_username_and_password(http_method, url, parameters={}, options={})
Chris@1296 268 success_code = options[:success_code] || :success
Chris@1296 269 failure_code = options[:failure_code] || :unauthorized
Chris@1296 270
Chris@1296 271 context "should allow http basic auth using a username and password for #{http_method} #{url}" do
Chris@1296 272 context "with a valid HTTP authentication" do
Chris@1296 273 setup do
Chris@1296 274 @user = User.generate! do |user|
Chris@1296 275 user.admin = true
Chris@1296 276 user.password = 'my_password'
Chris@1296 277 end
Chris@1296 278 send(http_method, url, parameters, credentials(@user.login, 'my_password'))
Chris@1296 279 end
Chris@1296 280
Chris@1296 281 should_respond_with success_code
Chris@1296 282 should_respond_with_content_type_based_on_url(url)
Chris@1296 283 should "login as the user" do
Chris@1296 284 assert_equal @user, User.current
Chris@1296 285 end
Chris@1296 286 end
Chris@1296 287
Chris@1296 288 context "with an invalid HTTP authentication" do
Chris@1296 289 setup do
Chris@1296 290 @user = User.generate!
Chris@1296 291 send(http_method, url, parameters, credentials(@user.login, 'wrong_password'))
Chris@1296 292 end
Chris@1296 293
Chris@1296 294 should_respond_with failure_code
Chris@1296 295 should_respond_with_content_type_based_on_url(url)
Chris@1296 296 should "not login as the user" do
Chris@1296 297 assert_equal User.anonymous, User.current
Chris@1296 298 end
Chris@1296 299 end
Chris@1296 300
Chris@1296 301 context "without credentials" do
Chris@1296 302 setup do
Chris@1296 303 send(http_method, url, parameters)
Chris@1296 304 end
Chris@1296 305
Chris@1296 306 should_respond_with failure_code
Chris@1296 307 should_respond_with_content_type_based_on_url(url)
Chris@1296 308 should "include_www_authenticate_header" do
Chris@1296 309 assert @controller.response.headers.has_key?('WWW-Authenticate')
Chris@1296 310 end
Chris@1296 311 end
Chris@1296 312 end
Chris@1296 313 end
Chris@1296 314
Chris@1296 315 # Test that a request allows the API key with HTTP BASIC
Chris@1296 316 #
Chris@1296 317 # @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete)
Chris@1296 318 # @param [String] url the request url
Chris@1296 319 # @param [optional, Hash] parameters additional request parameters
Chris@1296 320 # @param [optional, Hash] options additional options
Chris@1296 321 # @option options [Symbol] :success_code Successful response code (:success)
Chris@1296 322 # @option options [Symbol] :failure_code Failure response code (:unauthorized)
Chris@1296 323 def self.should_allow_http_basic_auth_with_key(http_method, url, parameters={}, options={})
Chris@1296 324 success_code = options[:success_code] || :success
Chris@1296 325 failure_code = options[:failure_code] || :unauthorized
Chris@1296 326
Chris@1296 327 context "should allow http basic auth with a key for #{http_method} #{url}" do
Chris@1296 328 context "with a valid HTTP authentication using the API token" do
Chris@1296 329 setup do
Chris@1296 330 @user = User.generate! do |user|
Chris@1296 331 user.admin = true
Chris@1296 332 end
Chris@1296 333 @token = Token.create!(:user => @user, :action => 'api')
Chris@1296 334 send(http_method, url, parameters, credentials(@token.value, 'X'))
Chris@1296 335 end
Chris@1296 336 should_respond_with success_code
Chris@1296 337 should_respond_with_content_type_based_on_url(url)
Chris@1296 338 should_be_a_valid_response_string_based_on_url(url)
Chris@1296 339 should "login as the user" do
Chris@1296 340 assert_equal @user, User.current
Chris@1296 341 end
Chris@1296 342 end
Chris@1296 343
Chris@1296 344 context "with an invalid HTTP authentication" do
Chris@1296 345 setup do
Chris@1296 346 @user = User.generate!
Chris@1296 347 @token = Token.create!(:user => @user, :action => 'feeds')
Chris@1296 348 send(http_method, url, parameters, credentials(@token.value, 'X'))
Chris@1296 349 end
Chris@1296 350 should_respond_with failure_code
Chris@1296 351 should_respond_with_content_type_based_on_url(url)
Chris@1296 352 should "not login as the user" do
Chris@1296 353 assert_equal User.anonymous, User.current
Chris@1296 354 end
Chris@1296 355 end
Chris@1296 356 end
Chris@1296 357 end
Chris@1296 358
Chris@1296 359 # Test that a request allows full key authentication
Chris@1296 360 #
Chris@1296 361 # @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete)
Chris@1296 362 # @param [String] url the request url, without the key=ZXY parameter
Chris@1296 363 # @param [optional, Hash] parameters additional request parameters
Chris@1296 364 # @param [optional, Hash] options additional options
Chris@1296 365 # @option options [Symbol] :success_code Successful response code (:success)
Chris@1296 366 # @option options [Symbol] :failure_code Failure response code (:unauthorized)
Chris@1296 367 def self.should_allow_key_based_auth(http_method, url, parameters={}, options={})
Chris@1296 368 success_code = options[:success_code] || :success
Chris@1296 369 failure_code = options[:failure_code] || :unauthorized
Chris@1296 370
Chris@1296 371 context "should allow key based auth using key=X for #{http_method} #{url}" do
Chris@1296 372 context "with a valid api token" do
Chris@1296 373 setup do
Chris@1296 374 @user = User.generate! do |user|
Chris@1296 375 user.admin = true
Chris@1296 376 end
Chris@1296 377 @token = Token.create!(:user => @user, :action => 'api')
Chris@1296 378 # Simple url parse to add on ?key= or &key=
Chris@1296 379 request_url = if url.match(/\?/)
Chris@1296 380 url + "&key=#{@token.value}"
Chris@1296 381 else
Chris@1296 382 url + "?key=#{@token.value}"
Chris@1296 383 end
Chris@1296 384 send(http_method, request_url, parameters)
Chris@1296 385 end
Chris@1296 386 should_respond_with success_code
Chris@1296 387 should_respond_with_content_type_based_on_url(url)
Chris@1296 388 should_be_a_valid_response_string_based_on_url(url)
Chris@1296 389 should "login as the user" do
Chris@1296 390 assert_equal @user, User.current
Chris@1296 391 end
Chris@1296 392 end
Chris@1296 393
Chris@1296 394 context "with an invalid api token" do
Chris@1296 395 setup do
Chris@1296 396 @user = User.generate! do |user|
Chris@1296 397 user.admin = true
Chris@1296 398 end
Chris@1296 399 @token = Token.create!(:user => @user, :action => 'feeds')
Chris@1296 400 # Simple url parse to add on ?key= or &key=
Chris@1296 401 request_url = if url.match(/\?/)
Chris@1296 402 url + "&key=#{@token.value}"
Chris@1296 403 else
Chris@1296 404 url + "?key=#{@token.value}"
Chris@1296 405 end
Chris@1296 406 send(http_method, request_url, parameters)
Chris@1296 407 end
Chris@1296 408 should_respond_with failure_code
Chris@1296 409 should_respond_with_content_type_based_on_url(url)
Chris@1296 410 should "not login as the user" do
Chris@1296 411 assert_equal User.anonymous, User.current
Chris@1296 412 end
Chris@1296 413 end
Chris@1296 414 end
Chris@1296 415
Chris@1296 416 context "should allow key based auth using X-Redmine-API-Key header for #{http_method} #{url}" do
Chris@1296 417 setup do
Chris@1296 418 @user = User.generate! do |user|
Chris@1296 419 user.admin = true
Chris@1296 420 end
Chris@1296 421 @token = Token.create!(:user => @user, :action => 'api')
Chris@1296 422 send(http_method, url, parameters, {'X-Redmine-API-Key' => @token.value.to_s})
Chris@1296 423 end
Chris@1296 424 should_respond_with success_code
Chris@1296 425 should_respond_with_content_type_based_on_url(url)
Chris@1296 426 should_be_a_valid_response_string_based_on_url(url)
Chris@1296 427 should "login as the user" do
Chris@1296 428 assert_equal @user, User.current
Chris@1296 429 end
Chris@1296 430 end
Chris@1296 431 end
Chris@1296 432
Chris@1296 433 # Uses should_respond_with_content_type based on what's in the url:
Chris@1296 434 #
Chris@1296 435 # '/project/issues.xml' => should_respond_with_content_type :xml
Chris@1296 436 # '/project/issues.json' => should_respond_with_content_type :json
Chris@1296 437 #
Chris@1296 438 # @param [String] url Request
Chris@1296 439 def self.should_respond_with_content_type_based_on_url(url)
Chris@1296 440 case
Chris@1296 441 when url.match(/xml/i)
Chris@1296 442 should "respond with XML" do
Chris@1296 443 assert_equal 'application/xml', @response.content_type
Chris@1296 444 end
Chris@1296 445 when url.match(/json/i)
Chris@1296 446 should "respond with JSON" do
Chris@1296 447 assert_equal 'application/json', @response.content_type
Chris@1296 448 end
Chris@1296 449 else
Chris@1296 450 raise "Unknown content type for should_respond_with_content_type_based_on_url: #{url}"
Chris@1296 451 end
Chris@1296 452 end
Chris@1296 453
Chris@1296 454 # Uses the url to assert which format the response should be in
Chris@1296 455 #
Chris@1296 456 # '/project/issues.xml' => should_be_a_valid_xml_string
Chris@1296 457 # '/project/issues.json' => should_be_a_valid_json_string
Chris@1296 458 #
Chris@1296 459 # @param [String] url Request
Chris@1296 460 def self.should_be_a_valid_response_string_based_on_url(url)
Chris@1296 461 case
Chris@1296 462 when url.match(/xml/i)
Chris@1296 463 should_be_a_valid_xml_string
Chris@1296 464 when url.match(/json/i)
Chris@1296 465 should_be_a_valid_json_string
Chris@1296 466 else
Chris@1296 467 raise "Unknown content type for should_be_a_valid_response_based_on_url: #{url}"
Chris@1296 468 end
Chris@1296 469 end
Chris@1296 470
Chris@1296 471 # Checks that the response is a valid JSON string
Chris@1296 472 def self.should_be_a_valid_json_string
Chris@1296 473 should "be a valid JSON string (or empty)" do
Chris@1296 474 assert(response.body.blank? || ActiveSupport::JSON.decode(response.body))
Chris@1296 475 end
Chris@1296 476 end
Chris@1296 477
Chris@1296 478 # Checks that the response is a valid XML string
Chris@1296 479 def self.should_be_a_valid_xml_string
Chris@1296 480 should "be a valid XML string" do
Chris@1296 481 assert REXML::Document.new(response.body)
Chris@1296 482 end
Chris@1296 483 end
Chris@1296 484
Chris@1296 485 def self.should_respond_with(status)
Chris@1296 486 should "respond with #{status}" do
Chris@1296 487 assert_response status
Chris@1296 488 end
Chris@1296 489 end
Chris@1296 490 end
Chris@1296 491
Chris@1296 492 # Simple module to "namespace" all of the API tests
Chris@1296 493 module ApiTest
Chris@1296 494 end