]> git.openstreetmap.org Git - rails.git/blob - test/integration/client_application_test.rb
Workaround rails 2.3.4 bogus deprecation warnings.
[rails.git] / test / integration / client_application_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class ClientApplicationTest < ActionController::IntegrationTest
4   fixtures :users, :client_applications
5
6   ##
7   # run through the procedure of creating a client application and checking
8   # that it shows up on the user's account page.
9   def test_create_application
10     post '/login', {'user[email]' => "test@example.com", 'user[password]' => "test", :referer => '/user/test2'}
11     assert_response :redirect
12     follow_redirect!
13     assert_response :success
14     assert_template 'user/view'
15
16     # check that the form to allow new client application creations exists
17     assert_in_body do
18       assert_select "a[href='/user/test2/oauth_clients']"
19     end
20
21     # now we follow the link to the oauth client list
22     get '/user/test2/oauth_clients'
23     assert_response :success
24     assert_in_body do
25       assert_select "a[href='/user/test2/oauth_clients/new']"
26     end
27
28     # now we follow the link to the new oauth client page
29     get '/user/test2/oauth_clients/new'
30     assert_response :success
31     assert_in_body do
32       assert_select "h1", "Register a new application"
33       assert_select "form[action='/user/test2/oauth_clients']" do
34         [ :name, :url, :callback_url, :support_url ].each do |inp|
35           assert_select "input[name=?]", "client_application[#{inp}]"
36         end
37         ClientApplication.all_permissions.each do |perm|
38           assert_select "input[name=?]", "client_application[#{perm}]"
39         end
40       end
41     end
42
43     post '/user/test2/oauth_clients', {
44       'client_application[name]' => 'My New App',
45       'client_application[url]' => 'http://my.new.app.org/',
46       'client_application[callback_url]' => 'http://my.new.app.org/callback',
47       'client_application[support_url]' => 'http://my.new.app.org/support'}
48     assert_response :redirect
49     follow_redirect!
50     assert_response :success
51     assert_template 'oauth_clients/show'
52     assert_equal 'Registered the information successfully', flash[:notice]
53
54     # now go back to the account page and check its listed under this user
55     get '/user/test2/oauth_clients'
56     assert_response :success
57     assert_template 'oauth_clients/index'
58     assert_in_body { assert_select "div>a", "My New App" }
59   end
60
61   ##
62   # fake client workflow.
63   # this acts like a 3rd party client trying to access the site.
64   def test_3rd_party_token
65     # apparently the oauth gem doesn't really support being used inside integration
66     # tests, as its too tied into the HTTP headers and stuff that it signs.
67   end
68
69   ##
70   # utility method to make the HTML screening easier to read.
71   def assert_in_body
72     assert_select "html:root" do
73       assert_select "body" do
74         assert_select "div#content" do
75           yield
76         end
77       end
78     end
79   end
80
81 end