Mercurial > hg > soundsoftware-site
comparison test/integration/api_token_login_test.rb @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
1 require "#{File.dirname(__FILE__)}/../test_helper" | |
2 | |
3 class ApiTokenLoginTest < ActionController::IntegrationTest | |
4 fixtures :all | |
5 | |
6 def setup | |
7 Setting.rest_api_enabled = '1' | |
8 Setting.login_required = '1' | |
9 end | |
10 | |
11 def teardown | |
12 Setting.rest_api_enabled = '0' | |
13 Setting.login_required = '0' | |
14 end | |
15 | |
16 # Using the NewsController because it's a simple API. | |
17 context "get /news" do | |
18 | |
19 context "in :xml format" do | |
20 context "with a valid api token" do | |
21 setup do | |
22 @user = User.generate_with_protected! | |
23 @token = Token.generate!(:user => @user, :action => 'api') | |
24 get "/news.xml?key=#{@token.value}" | |
25 end | |
26 | |
27 should_respond_with :success | |
28 should_respond_with_content_type :xml | |
29 should "login as the user" do | |
30 assert_equal @user, User.current | |
31 end | |
32 end | |
33 | |
34 context "with an invalid api token" do | |
35 setup do | |
36 @user = User.generate_with_protected! | |
37 @token = Token.generate!(:user => @user, :action => 'feeds') | |
38 get "/news.xml?key=#{@token.value}" | |
39 end | |
40 | |
41 should_respond_with :unauthorized | |
42 should_respond_with_content_type :xml | |
43 should "not login as the user" do | |
44 assert_equal User.anonymous, User.current | |
45 end | |
46 end | |
47 end | |
48 | |
49 context "in :json format" do | |
50 context "with a valid api token" do | |
51 setup do | |
52 @user = User.generate_with_protected! | |
53 @token = Token.generate!(:user => @user, :action => 'api') | |
54 get "/news.json?key=#{@token.value}" | |
55 end | |
56 | |
57 should_respond_with :success | |
58 should_respond_with_content_type :json | |
59 should "login as the user" do | |
60 assert_equal @user, User.current | |
61 end | |
62 end | |
63 | |
64 context "with an invalid api token" do | |
65 setup do | |
66 @user = User.generate_with_protected! | |
67 @token = Token.generate!(:user => @user, :action => 'feeds') | |
68 get "/news.json?key=#{@token.value}" | |
69 end | |
70 | |
71 should_respond_with :unauthorized | |
72 should_respond_with_content_type :json | |
73 should "not login as the user" do | |
74 assert_equal User.anonymous, User.current | |
75 end | |
76 end | |
77 end | |
78 | |
79 end | |
80 end |