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