summaryrefslogtreecommitdiffstats
path: root/test/integration/api_test/token_authentication_test.rb
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-11-01 15:45:03 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-11-01 15:45:03 +0000
commitbed79f523bd64d900a4e615efe7eb3e0cfc0abd8 (patch)
tree74d935f4e66cf1ad0e9d943dc8f55b4cf1c35ffd /test/integration/api_test/token_authentication_test.rb
parentd5fde17bf5d0b8788871f60ff08b203da527de92 (diff)
downloadredmine-bed79f523bd64d900a4e615efe7eb3e0cfc0abd8.tar.gz
redmine-bed79f523bd64d900a4e615efe7eb3e0cfc0abd8.zip
Refactor: convert api key tests to shoulda macros for reuse. #6447
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4358 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/integration/api_test/token_authentication_test.rb')
-rw-r--r--test/integration/api_test/token_authentication_test.rb58
1 files changed, 2 insertions, 56 deletions
diff --git a/test/integration/api_test/token_authentication_test.rb b/test/integration/api_test/token_authentication_test.rb
index 7d6cb2e1d..5c116c161 100644
--- a/test/integration/api_test/token_authentication_test.rb
+++ b/test/integration/api_test/token_authentication_test.rb
@@ -15,66 +15,12 @@ class ApiTest::TokenAuthenticationTest < ActionController::IntegrationTest
# Using the NewsController because it's a simple API.
context "get /news" do
-
context "in :xml format" do
- context "with a valid api token" do
- setup do
- @user = User.generate_with_protected!
- @token = Token.generate!(:user => @user, :action => 'api')
- get "/news.xml?key=#{@token.value}"
- end
-
- should_respond_with :success
- should_respond_with_content_type :xml
- should "login as the user" do
- assert_equal @user, User.current
- end
- end
-
- context "with an invalid api token" do
- setup do
- @user = User.generate_with_protected!
- @token = Token.generate!(:user => @user, :action => 'feeds')
- get "/news.xml?key=#{@token.value}"
- end
-
- should_respond_with :unauthorized
- should_respond_with_content_type :xml
- should "not login as the user" do
- assert_equal User.anonymous, User.current
- end
- end
+ should_allow_key_based_auth(:get, "/news.xml")
end
context "in :json format" do
- context "with a valid api token" do
- setup do
- @user = User.generate_with_protected!
- @token = Token.generate!(:user => @user, :action => 'api')
- get "/news.json?key=#{@token.value}"
- end
-
- should_respond_with :success
- should_respond_with_content_type :json
- should "login as the user" do
- assert_equal @user, User.current
- end
- end
-
- context "with an invalid api token" do
- setup do
- @user = User.generate_with_protected!
- @token = Token.generate!(:user => @user, :action => 'feeds')
- get "/news.json?key=#{@token.value}"
- end
-
- should_respond_with :unauthorized
- should_respond_with_content_type :json
- should "not login as the user" do
- assert_equal User.anonymous, User.current
- end
- end
+ should_allow_key_based_auth(:get, "/news.json")
end
-
end
end