diff test/test_helper.rb @ 514:7eba09d624db live

Merge
author Chris Cannam
date Thu, 14 Jul 2011 10:50:53 +0100
parents 753f1380d6bc
children 5e80956cc792
line wrap: on
line diff
--- a/test/test_helper.rb	Thu Jul 14 10:46:20 2011 +0100
+++ b/test/test_helper.rb	Thu Jul 14 10:50:53 2011 +0100
@@ -1,5 +1,5 @@
-# redMine - project management software
-# Copyright (C) 2006  Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -59,7 +59,7 @@
   end
   
   def uploaded_test_file(name, mime)
-    ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime)
+    ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime, true)
   end
 
   # Mock out a file
@@ -87,6 +87,7 @@
     saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].dup; h}
     options.each {|k, v| Setting[k] = v}
     yield
+  ensure
     saved_settings.each {|k, v| Setting[k] = v}
   end
 
@@ -109,13 +110,20 @@
     File.join(RAILS_ROOT.gsub(%r{config\/\.\.}, ''), "/tmp/test/#{vendor.downcase}_repository")
   end
   
+  # Returns the url of the subversion test repository
+  def self.subversion_repository_url
+    path = repository_path('subversion')
+    path = '/' + path unless path.starts_with?('/')
+    "file://#{path}"
+  end
+  
   # Returns true if the +vendor+ test repository is configured
   def self.repository_configured?(vendor)
     File.directory?(repository_path(vendor))
   end
   
   def assert_error_tag(options={})
-    assert_tag({:tag => 'p', :attributes => { :id => 'errorExplanation' }}.merge(options))
+    assert_tag({:attributes => { :id => 'errorExplanation' }}.merge(options))
   end
 
   # Shoulda macros
@@ -361,6 +369,20 @@
       end
     end
     
+    context "should allow key based auth using X-Redmine-API-Key header for #{http_method} #{url}" do
+      setup do
+        @user = User.generate_with_protected!(:admin => true)
+        @token = Token.generate!(:user => @user, :action => 'api')
+        send(http_method, url, parameters, {'X-Redmine-API-Key' => @token.value.to_s})
+      end
+      
+      should_respond_with success_code
+      should_respond_with_content_type_based_on_url(url)
+      should_be_a_valid_response_string_based_on_url(url)
+      should "login as the user" do
+        assert_equal @user, User.current
+      end
+    end
   end
 
   # Uses should_respond_with_content_type based on what's in the url:
@@ -402,7 +424,7 @@
   # Checks that the response is a valid JSON string
   def self.should_be_a_valid_json_string
     should "be a valid JSON string (or empty)" do
-      assert (response.body.blank? || ActiveSupport::JSON.decode(response.body))
+      assert(response.body.blank? || ActiveSupport::JSON.decode(response.body))
     end
   end