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'
21 # check that the form to allow new client application creations exists
23 assert_select "a[href='/user/test2/oauth_clients']"
26 # now we follow the link to the oauth client list
27 get '/user/test2/oauth_clients'
28 assert_response :success
30 assert_select "a[href='/user/test2/oauth_clients/new']"
33 # now we follow the link to the new oauth client page
34 get '/user/test2/oauth_clients/new'
35 assert_response :success
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}]"
42 ClientApplication.all_permissions.each do |perm|
43 assert_select "input[name=?]", "client_application[#{perm}]"
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
55 assert_response :success
56 assert_template 'oauth_clients/show'
57 assert_equal 'Registered the information successfully', flash[:notice]
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" }
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.
75 # utility method to make the HTML screening easier to read.
77 assert_select "html:root" do
78 assert_select "body" do
79 assert_select "div#content" do