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
10 post '/login', {'user[email]' => "test@example.com", 'user[password]' => "test", :referer => '/user/test/account'}
11 assert_response :redirect
13 assert_response :success
14 assert_template 'user/account'
16 # check that the form to allow new client application creations exists
18 assert_select "h2", "Application Developers"
19 assert_select "a[href='/oauth_clients/new']"
22 # now we follow the link to the new oauth client page
23 get '/oauth_clients/new'
24 assert_response :success
26 assert_select "h1", "Register a new application"
27 assert_select "form[action='/oauth_clients']" do
28 [ :name, :url, :callback_url, :support_url ].each do |inp|
29 assert_select "input[name=?]", "client_application[#{inp}]"
31 ClientApplication.all_permissions.each do |perm|
32 assert_select "input[name=?]", "client_application[#{perm}]"
37 post '/oauth_clients', {
38 'client_application[name]' => 'My New App',
39 'client_application[url]' => 'http://my.new.app.org/',
40 'client_application[callback_url]' => 'http://my.new.app.org/callback',
41 'client_application[support_url]' => 'http://my.new.app.org/support'}
42 assert_response :redirect
44 assert_response :success
45 assert_template 'oauth_clients/show'
46 assert_equal 'Registered the information successfully', flash[:notice]
48 # now go back to the account page and check its listed under this user
49 get '/user/test/account'
50 assert_response :success
51 assert_template 'user/account'
52 assert_in_body { assert_select "li>div>a", "My New App" }
56 # fake client workflow.
57 # this acts like a 3rd party client trying to access the site.
58 def test_3rd_party_token
59 # apparently the oauth gem doesn't really support being used inside integration
60 # tests, as its too tied into the HTTP headers and stuff that it signs.
64 # utility method to make the HTML screening easier to read.
66 assert_select "html:root" do
67 assert_select "body" do
68 assert_select "div#content" do