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/test2'}
11 assert_response :redirect
13 assert_response :success
14 assert_template 'user/view'
16 # check that the form to allow new client application creations exists
18 assert_select "a[href='/oauth_clients']"
21 # now we follow the link to the oauth client list
23 assert_response :success
25 assert_select "a[href='/oauth_clients/new']"
28 # now we follow the link to the new oauth client page
29 get '/oauth_clients/new'
30 assert_response :success
32 assert_select "h1", "Register a new application"
33 assert_select "form[action='/oauth_clients']" do
34 [ :name, :url, :callback_url, :support_url ].each do |inp|
35 assert_select "input[name=?]", "client_application[#{inp}]"
37 ClientApplication.all_permissions.each do |perm|
38 assert_select "input[name=?]", "client_application[#{perm}]"
43 post '/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
50 assert_response :success
51 assert_template 'oauth_clients/show'
52 assert_equal 'Registered the information successfully', flash[:notice]
54 # now go back to the account page and check its listed under this user
56 assert_response :success
57 assert_template 'oauth_clients/index'
58 assert_in_body { assert_select "div>a", "My New App" }
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.
70 # utility method to make the HTML screening easier to read.
72 assert_select "html:root" do
73 assert_select "body" do
74 assert_select "div#content" do