]> git.openstreetmap.org Git - rails.git/blob - vendor/plugins/oauth-plugin/generators/oauth_provider/templates/oauth_token_test.rb
dc7f5cb22506ce5e07ef8eafad749e13a2c05200
[rails.git] / vendor / plugins / oauth-plugin / generators / oauth_provider / templates / oauth_token_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class RequestTokenTest < ActiveSupport::TestCase
4
5   fixtures :client_applications, :users, :oauth_tokens
6   
7   def setup
8     @token = RequestToken.create :client_application=>client_applications(:one)
9   end
10
11   def test_should_be_valid
12     assert @token.valid?
13   end
14   
15   def test_should_not_have_errors
16     assert @token.errors.empty?
17   end
18   
19   def test_should_have_a_token
20     assert_not_nil @token.token
21   end
22
23   def test_should_have_a_secret
24     assert_not_nil @token.secret
25   end
26   
27   def test_should_not_be_authorized 
28     assert !@token.authorized?
29   end
30
31   def test_should_not_be_invalidated
32     assert !@token.invalidated?
33   end
34   
35   def test_should_authorize_request
36     @token.authorize!(users(:quentin))
37     assert @token.authorized?
38     assert_not_nil @token.authorized_at
39     assert_equal users(:quentin), @token.user
40   end
41   
42   def test_should_not_exchange_without_approval
43     assert_equal false, @token.exchange!
44     assert_equal false, @token.invalidated?
45   end
46   
47   def test_should_not_exchange_without_approval
48     @token.authorize!(users(:quentin))
49     @access = @token.exchange!
50     assert_not_equal false, @access
51     assert @token.invalidated?
52     
53     assert_equal users(:quentin), @access.user
54     assert @access.authorized?
55   end
56   
57 end