3 class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
 
   5   # test all routes which lead to this controller
 
   8       { :path => "/oauth2/applications", :method => :get },
 
   9       { :controller => "oauth2_applications", :action => "index" }
 
  12       { :path => "/oauth2/applications", :method => :post },
 
  13       { :controller => "oauth2_applications", :action => "create" }
 
  16       { :path => "/oauth2/applications/new", :method => :get },
 
  17       { :controller => "oauth2_applications", :action => "new" }
 
  20       { :path => "/oauth2/applications/1/edit", :method => :get },
 
  21       { :controller => "oauth2_applications", :action => "edit", :id => "1" }
 
  24       { :path => "/oauth2/applications/1", :method => :get },
 
  25       { :controller => "oauth2_applications", :action => "show", :id => "1" }
 
  28       { :path => "/oauth2/applications/1", :method => :patch },
 
  29       { :controller => "oauth2_applications", :action => "update", :id => "1" }
 
  32       { :path => "/oauth2/applications/1", :method => :put },
 
  33       { :controller => "oauth2_applications", :action => "update", :id => "1" }
 
  36       { :path => "/oauth2/applications/1", :method => :delete },
 
  37       { :controller => "oauth2_applications", :action => "destroy", :id => "1" }
 
  43     create_list(:oauth_application, 2, :owner => user)
 
  45     get oauth_applications_path
 
  46     assert_response :redirect
 
  47     assert_redirected_to login_path(:referer => oauth_applications_path)
 
  51     get oauth_applications_path
 
  52     assert_response :success
 
  53     assert_template "oauth2_applications/index"
 
  60     get new_oauth_application_path
 
  61     assert_response :redirect
 
  62     assert_redirected_to login_path(:referer => new_oauth_application_path)
 
  66     get new_oauth_application_path
 
  67     assert_response :success
 
  68     assert_template "oauth2_applications/new"
 
  69     assert_select "form", 1 do
 
  70       assert_select "input#doorkeeper_application_name", 1
 
  71       assert_select "textarea#doorkeeper_application_redirect_uri", 1
 
  72       assert_select "input#doorkeeper_application_confidential", 1
 
  73       Oauth.scopes.each do |scope|
 
  74         assert_select "input#doorkeeper_application_scopes_#{scope.name}", 1
 
  82     assert_difference "Doorkeeper::Application.count", 0 do
 
  83       post oauth_applications_path
 
  85     assert_response :forbidden
 
  89     assert_difference "Doorkeeper::Application.count", 0 do
 
  90       post oauth_applications_path(:doorkeeper_application => {
 
  91                                      :name => "Test Application"
 
  94     assert_response :success
 
  95     assert_template "oauth2_applications/new"
 
  97     assert_difference "Doorkeeper::Application.count", 0 do
 
  98       post oauth_applications_path(:doorkeeper_application => {
 
  99                                      :name => "Test Application",
 
 100                                      :redirect_uri => "https://test.example.com/",
 
 101                                      :scopes => ["bad_scope"]
 
 104     assert_response :success
 
 105     assert_template "oauth2_applications/new"
 
 107     assert_difference "Doorkeeper::Application.count", 1 do
 
 108       post oauth_applications_path(:doorkeeper_application => {
 
 109                                      :name => "Test Application",
 
 110                                      :redirect_uri => "https://test.example.com/",
 
 111                                      :scopes => ["read_prefs"]
 
 114     assert_response :redirect
 
 115     assert_redirected_to oauth_application_path(:id => Doorkeeper::Application.find_by(:name => "Test Application").id)
 
 120     client = create(:oauth_application, :owner => user)
 
 121     other_client = create(:oauth_application)
 
 123     get oauth_application_path(:id => client)
 
 124     assert_response :redirect
 
 125     assert_redirected_to login_path(:referer => oauth_application_path(:id => client.id))
 
 129     get oauth_application_path(:id => other_client)
 
 130     assert_response :not_found
 
 131     assert_template "oauth2_applications/not_found"
 
 133     get oauth_application_path(:id => client)
 
 134     assert_response :success
 
 135     assert_template "oauth2_applications/show"
 
 140     client = create(:oauth_application, :owner => user)
 
 141     other_client = create(:oauth_application)
 
 143     get edit_oauth_application_path(:id => client)
 
 144     assert_response :redirect
 
 145     assert_redirected_to login_path(:referer => edit_oauth_application_path(:id => client.id))
 
 149     get edit_oauth_application_path(:id => other_client)
 
 150     assert_response :not_found
 
 151     assert_template "oauth2_applications/not_found"
 
 153     get edit_oauth_application_path(:id => client)
 
 154     assert_response :success
 
 155     assert_template "oauth2_applications/edit"
 
 156     assert_select "form", 1 do
 
 157       assert_select "input#doorkeeper_application_name", 1
 
 158       assert_select "textarea#doorkeeper_application_redirect_uri", 1
 
 159       assert_select "input#doorkeeper_application_confidential", 1
 
 160       Oauth.scopes.each do |scope|
 
 161         assert_select "input#doorkeeper_application_scopes_#{scope.name}", 1
 
 168     client = create(:oauth_application, :owner => user)
 
 169     other_client = create(:oauth_application)
 
 171     put oauth_application_path(:id => client)
 
 172     assert_response :forbidden
 
 176     put oauth_application_path(:id => other_client)
 
 177     assert_response :not_found
 
 178     assert_template "oauth2_applications/not_found"
 
 180     put oauth_application_path(:id => client,
 
 181                                :doorkeeper_application => {
 
 185     assert_response :success
 
 186     assert_template "oauth2_applications/edit"
 
 188     put oauth_application_path(:id => client,
 
 189                                :doorkeeper_application => {
 
 191                                  :redirect_uri => "https://new.example.com/url"
 
 193     assert_response :redirect
 
 194     assert_redirected_to oauth_application_path(:id => client.id)
 
 199     client = create(:oauth_application, :owner => user)
 
 200     other_client = create(:oauth_application)
 
 202     assert_difference "Doorkeeper::Application.count", 0 do
 
 203       delete oauth_application_path(:id => client)
 
 205     assert_response :forbidden
 
 209     assert_difference "Doorkeeper::Application.count", 0 do
 
 210       delete oauth_application_path(:id => other_client)
 
 212     assert_response :not_found
 
 213     assert_template "oauth2_applications/not_found"
 
 215     assert_difference "Doorkeeper::Application.count", -1 do
 
 216       delete oauth_application_path(:id => client)
 
 218     assert_response :redirect
 
 219     assert_redirected_to oauth_applications_path