]> git.openstreetmap.org Git - rails.git/blob - test/integration/client_applications_test.rb
Change roundabout exit logic and remove blank string from locale file
[rails.git] / test / integration / client_applications_test.rb
1 require "test_helper"
2
3 class ClientApplicationsTest < ActionDispatch::IntegrationTest
4   ##
5   # run through the procedure of creating a client application and checking
6   # that it shows up on the user's account page.
7   def test_create_application
8     user = create(:user)
9
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", :params => { "username" => user.email, "password" => "test", :referer => "/user/#{ERB::Util.u(user.display_name)}" }
16     assert_response :redirect
17     follow_redirect!
18     assert_response :success
19     assert_template "user/view"
20     get "/user/#{ERB::Util.u(user.display_name)}/account"
21     assert_response :success
22     assert_template "user/account"
23
24     # check that the form to allow new client application creations exists
25     assert_in_heading do
26       assert_select "ul.secondary-actions li a[href='/user/#{ERB::Util.u(user.display_name)}/oauth_clients']"
27     end
28
29     # now we follow the link to the oauth client list
30     get "/user/#{ERB::Util.u(user.display_name)}/oauth_clients"
31     assert_response :success
32     assert_in_body do
33       assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/oauth_clients/new']"
34     end
35
36     # now we follow the link to the new oauth client page
37     get "/user/#{ERB::Util.u(user.display_name)}/oauth_clients/new"
38     assert_response :success
39     assert_in_heading do
40       assert_select "h1", "Register a new application"
41     end
42     assert_in_body do
43       assert_select "form[action='/user/#{ERB::Util.u(user.display_name)}/oauth_clients']" do
44         [:name, :url, :callback_url, :support_url].each do |inp|
45           assert_select "input[name=?]", "client_application[#{inp}]"
46         end
47         ClientApplication.all_permissions.each do |perm|
48           assert_select "input[name=?]", "client_application[#{perm}]"
49         end
50       end
51     end
52
53     post "/user/#{ERB::Util.u(user.display_name)}/oauth_clients",
54          :params => { "client_application[name]" => "My New App",
55                       "client_application[url]" => "http://my.new.app.org/",
56                       "client_application[callback_url]" => "http://my.new.app.org/callback",
57                       "client_application[support_url]" => "http://my.new.app.org/support" }
58     assert_response :redirect
59     follow_redirect!
60     assert_response :success
61     assert_template "oauth_clients/show"
62     assert_equal "Registered the information successfully", flash[:notice]
63
64     # now go back to the account page and check its listed under this user
65     get "/user/#{ERB::Util.u(user.display_name)}/oauth_clients"
66     assert_response :success
67     assert_template "oauth_clients/index"
68     assert_in_body { assert_select "div>a", "My New App" }
69   end
70
71   ##
72   # fake client workflow.
73   # this acts like a 3rd party client trying to access the site.
74   def test_3rd_party_token
75     # apparently the oauth gem doesn't really support being used inside integration
76     # tests, as its too tied into the HTTP headers and stuff that it signs.
77   end
78
79   ##
80   # utility method to make the HTML screening easier to read.
81   def assert_in_heading
82     assert_select "div.content-heading" do
83       yield
84     end
85   end
86
87   ##
88   # utility method to make the HTML screening easier to read.
89   def assert_in_body
90     assert_select "div#content" do
91       yield
92     end
93   end
94 end