1 require File.dirname(__FILE__) + '/../test_helper'
3 class ClientApplicationTest < ActionController::IntegrationTest
4 fixtures :users, :client_applications
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
11 assert_response :redirect
12 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
14 assert_response :success
15 post '/login', {'username' => "test@example.com", 'password' => "test", :referer => '/user/test2'}
16 assert_response :redirect
18 assert_response :success
19 assert_template 'user/view'
20 get '/user/test2/account'
21 assert_response :success
22 assert_template 'user/account'
24 # check that the form to allow new client application creations exists
26 assert_select "a[href='/user/test2/oauth_clients']"
29 # now we follow the link to the oauth client list
30 get '/user/test2/oauth_clients'
31 assert_response :success
33 assert_select "a[href='/user/test2/oauth_clients/new']"
36 # now we follow the link to the new oauth client page
37 get '/user/test2/oauth_clients/new'
38 assert_response :success
40 assert_select "h1", "Register a new application"
41 assert_select "form[action='/user/test2/oauth_clients']" do
42 [ :name, :url, :callback_url, :support_url ].each do |inp|
43 assert_select "input[name=?]", "client_application[#{inp}]"
45 ClientApplication.all_permissions.each do |perm|
46 assert_select "input[name=?]", "client_application[#{perm}]"
51 post '/user/test2/oauth_clients', {
52 'client_application[name]' => 'My New App',
53 'client_application[url]' => 'http://my.new.app.org/',
54 'client_application[callback_url]' => 'http://my.new.app.org/callback',
55 'client_application[support_url]' => 'http://my.new.app.org/support'}
56 assert_response :redirect
58 assert_response :success
59 assert_template 'oauth_clients/show'
60 assert_equal 'Registered the information successfully', flash[:notice]
62 # now go back to the account page and check its listed under this user
63 get '/user/test2/oauth_clients'
64 assert_response :success
65 assert_template 'oauth_clients/index'
66 assert_in_body { assert_select "div>a", "My New App" }
70 # fake client workflow.
71 # this acts like a 3rd party client trying to access the site.
72 def test_3rd_party_token
73 # apparently the oauth gem doesn't really support being used inside integration
74 # tests, as its too tied into the HTTP headers and stuff that it signs.
78 # utility method to make the HTML screening easier to read.
80 assert_select "html:root" do
81 assert_select "body" do
82 assert_select "div#content" do