X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/dae3dcf87edcfc0648cd0b93b069b0eee67d3ab7..212fe75b6fd26d01dfacf31650e7f71eb7f06a63:/test/controllers/oauth_clients_controller_test.rb diff --git a/test/controllers/oauth_clients_controller_test.rb b/test/controllers/oauth_clients_controller_test.rb index 6bafa62cc..c4dd4a181 100644 --- a/test/controllers/oauth_clients_controller_test.rb +++ b/test/controllers/oauth_clients_controller_test.rb @@ -1,8 +1,6 @@ require "test_helper" -class OauthClientsControllerTest < ActionController::TestCase - fixtures :users, :client_applications - +class OauthClientsControllerTest < ActionDispatch::IntegrationTest ## # test all routes which lead to this controller def test_routes @@ -37,26 +35,30 @@ class OauthClientsControllerTest < ActionController::TestCase end def test_index - user = users(:public_user) + user = create(:user) + create_list(:client_application, 2, :user => user) + create_list(:access_token, 2, :user => user) + + get oauth_clients_path(user) + assert_redirected_to login_path(:referer => oauth_clients_path(user)) - get :index, :display_name => user.display_name - assert_response :redirect - assert_redirected_to login_path(:referer => oauth_clients_path(:display_name => user.display_name)) + session_for(user) - get :index, { :display_name => user.display_name }, { :user => user } + get oauth_clients_path(user) assert_response :success assert_template "index" - assert_select "div.client_application", 2 + assert_select "li.client_application", 2 end def test_new - user = users(:public_user) + user = create(:user) - get :new, :display_name => user.display_name - assert_response :redirect - assert_redirected_to login_path(:referer => new_oauth_client_path(:display_name => user.display_name)) + get new_oauth_client_path(user) + assert_redirected_to login_path(:referer => new_oauth_client_path(user)) - get :new, { :display_name => user.display_name }, { :user => user } + session_for(user) + + get new_oauth_client_path(user) assert_response :success assert_template "new" assert_select "form", 1 do @@ -70,68 +72,77 @@ class OauthClientsControllerTest < ActionController::TestCase end end + def test_new_disabled + user = create(:user) + + with_settings(:oauth_10_registration => false) do + get new_oauth_client_path(user) + assert_redirected_to login_path(:referer => new_oauth_client_path(user)) + + session_for(user) + + get new_oauth_client_path(user) + assert_redirected_to oauth_clients_path(user) + end + end + def test_create - user = users(:public_user) + user = create(:user) assert_difference "ClientApplication.count", 0 do - post :create, :display_name => user.display_name + post oauth_clients_path(user) end assert_response :forbidden + session_for(user) + assert_difference "ClientApplication.count", 0 do - post :create, { - :display_name => user.display_name, - :client_application => { - :name => "Test Application" - } - }, { :user => user } + post oauth_clients_path(user, :client_application => { :name => "Test Application" }) end assert_response :success assert_template "new" assert_difference "ClientApplication.count", 1 do - post :create, { - :display_name => user.display_name, - :client_application => { - :name => "Test Application", - :url => "http://test.example.com/" - } - }, { :user => user } + post oauth_clients_path(user, :client_application => { :name => "Test Application", + :url => "http://test.example.com/" }) end - assert_response :redirect - assert_redirected_to oauth_client_path(:id => ClientApplication.find_by_name("Test Application").id) + assert_redirected_to oauth_client_path(:id => ClientApplication.find_by(:name => "Test Application").id) end def test_show - user = users(:public_user) - client = client_applications(:oauth_web_app) + user = create(:user) + client = create(:client_application, :user => user) + other_client = create(:client_application) + + get oauth_client_path(user, client) + assert_redirected_to login_path(:referer => oauth_client_path(user, client.id)) - get :show, :display_name => user.display_name, :id => client.id - assert_response :redirect - assert_redirected_to login_path(:referer => oauth_client_path(:display_name => user.display_name, :id => client.id)) + session_for(user) - get :show, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user } + get oauth_client_path(user, other_client) assert_response :not_found assert_template "not_found" - get :show, { :display_name => user.display_name, :id => client.id }, { :user => user } + get oauth_client_path(user, client) assert_response :success assert_template "show" end def test_edit - user = users(:public_user) - client = client_applications(:oauth_web_app) + user = create(:user) + client = create(:client_application, :user => user) + other_client = create(:client_application) - get :edit, :display_name => user.display_name, :id => client.id - assert_response :redirect - assert_redirected_to login_path(:referer => edit_oauth_client_path(:display_name => user.display_name, :id => client.id)) + get edit_oauth_client_path(user, client) + assert_redirected_to login_path(:referer => edit_oauth_client_path(user, client.id)) - get :edit, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user } + session_for(user) + + get edit_oauth_client_path(user, other_client) assert_response :not_found assert_template "not_found" - get :edit, { :display_name => user.display_name, :id => client.id }, { :user => user } + get edit_oauth_client_path(user, client) assert_response :success assert_template "edit" assert_select "form", 1 do @@ -146,58 +157,48 @@ class OauthClientsControllerTest < ActionController::TestCase end def test_update - user = users(:public_user) - client = client_applications(:oauth_web_app) + user = create(:user) + client = create(:client_application, :user => user) + other_client = create(:client_application) - put :update, :display_name => user.display_name, :id => client.id + put oauth_client_path(user, client) assert_response :forbidden - put :update, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user } + session_for(user) + + put oauth_client_path(user, other_client) assert_response :not_found assert_template "not_found" - put :update, { - :display_name => user.display_name, - :id => client.id, - :client_application => { - :name => "New Name", - :url => nil - } - }, { :user => user } + put oauth_client_path(user, client, :client_application => { :name => "New Name", :url => nil }) assert_response :success assert_template "edit" - put :update, { - :display_name => user.display_name, - :id => client.id, - :client_application => { - :name => "New Name", - :url => "http://new.example.com/url" - } - }, { :user => user } - assert_response :redirect + put oauth_client_path(user, client, :client_application => { :name => "New Name", :url => "http://new.example.com/url" }) assert_redirected_to oauth_client_path(:id => client.id) end def test_destroy - user = users(:public_user) - client = client_applications(:oauth_web_app) + user = create(:user) + client = create(:client_application, :user => user) + other_client = create(:client_application) assert_difference "ClientApplication.count", 0 do - delete :destroy, :display_name => user.display_name, :id => client.id + delete oauth_client_path(user, client) end assert_response :forbidden + session_for(user) + assert_difference "ClientApplication.count", 0 do - delete :destroy, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user } + delete oauth_client_path(user, other_client) end assert_response :not_found assert_template "not_found" assert_difference "ClientApplication.count", -1 do - delete :destroy, { :display_name => user.display_name, :id => client.id }, { :user => user } + delete oauth_client_path(user, client) end - assert_response :redirect - assert_redirected_to oauth_clients_path(:display_name => user.display_name) + assert_redirected_to oauth_clients_path(user) end end