]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/oauth2_applications_controller_test.rb
Merge branch 'pull/5218'
[rails.git] / test / controllers / oauth2_applications_controller_test.rb
index eec5e02ec926d46dd64a4eea1e3d7670427f35d6..1333fa000cca1c4ba69d2dc67e94f56a286142da 100644 (file)
@@ -43,7 +43,6 @@ class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
     create_list(:oauth_application, 2, :owner => user)
 
     get oauth_applications_path
-    assert_response :redirect
     assert_redirected_to login_path(:referer => oauth_applications_path)
 
     session_for(user)
@@ -51,14 +50,23 @@ class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
     get oauth_applications_path
     assert_response :success
     assert_template "oauth2_applications/index"
-    assert_select "tr", 2
+    assert_select "tbody tr", 2
+  end
+
+  def test_index_with_moderator_app
+    user = create(:user)
+    create(:oauth_application, :owner => user, :scopes => "write_redactions")
+
+    session_for(user)
+
+    get oauth_applications_path
+    assert_response :success
   end
 
   def test_new
     user = create(:user)
 
     get new_oauth_application_path
-    assert_response :redirect
     assert_redirected_to login_path(:referer => new_oauth_application_path)
 
     session_for(user)
@@ -67,11 +75,11 @@ class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
     assert_response :success
     assert_template "oauth2_applications/new"
     assert_select "form", 1 do
-      assert_select "input#doorkeeper_application_name", 1
-      assert_select "textarea#doorkeeper_application_redirect_uri", 1
-      assert_select "input#doorkeeper_application_confidential", 1
+      assert_select "input#oauth2_application_name", 1
+      assert_select "textarea#oauth2_application_redirect_uri", 1
+      assert_select "input#oauth2_application_confidential", 1
       Oauth.scopes.each do |scope|
-        assert_select "input#doorkeeper_application_scopes_#{scope.name}", 1
+        assert_select "input#oauth2_application_scopes_#{scope.name}", 1
       end
     end
   end
@@ -87,7 +95,7 @@ class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
     session_for(user)
 
     assert_difference "Doorkeeper::Application.count", 0 do
-      post oauth_applications_path(:doorkeeper_application => {
+      post oauth_applications_path(:oauth2_application => {
                                      :name => "Test Application"
                                    })
     end
@@ -95,7 +103,7 @@ class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
     assert_template "oauth2_applications/new"
 
     assert_difference "Doorkeeper::Application.count", 0 do
-      post oauth_applications_path(:doorkeeper_application => {
+      post oauth_applications_path(:oauth2_application => {
                                      :name => "Test Application",
                                      :redirect_uri => "https://test.example.com/",
                                      :scopes => ["bad_scope"]
@@ -105,13 +113,37 @@ class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
     assert_template "oauth2_applications/new"
 
     assert_difference "Doorkeeper::Application.count", 1 do
-      post oauth_applications_path(:doorkeeper_application => {
+      post oauth_applications_path(:oauth2_application => {
                                      :name => "Test Application",
                                      :redirect_uri => "https://test.example.com/",
                                      :scopes => ["read_prefs"]
                                    })
     end
-    assert_response :redirect
+    assert_redirected_to oauth_application_path(:id => Doorkeeper::Application.find_by(:name => "Test Application").id)
+  end
+
+  def test_create_privileged
+    session_for(create(:user))
+
+    assert_difference "Doorkeeper::Application.count", 0 do
+      post oauth_applications_path(:oauth2_application => {
+                                     :name => "Test Application",
+                                     :redirect_uri => "https://test.example.com/",
+                                     :scopes => ["read_email"]
+                                   })
+    end
+    assert_response :success
+    assert_template "oauth2_applications/new"
+
+    session_for(create(:administrator_user))
+
+    assert_difference "Doorkeeper::Application.count", 1 do
+      post oauth_applications_path(:oauth2_application => {
+                                     :name => "Test Application",
+                                     :redirect_uri => "https://test.example.com/",
+                                     :scopes => ["read_email"]
+                                   })
+    end
     assert_redirected_to oauth_application_path(:id => Doorkeeper::Application.find_by(:name => "Test Application").id)
   end
 
@@ -121,7 +153,6 @@ class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
     other_client = create(:oauth_application)
 
     get oauth_application_path(:id => client)
-    assert_response :redirect
     assert_redirected_to login_path(:referer => oauth_application_path(:id => client.id))
 
     session_for(user)
@@ -141,7 +172,6 @@ class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
     other_client = create(:oauth_application)
 
     get edit_oauth_application_path(:id => client)
-    assert_response :redirect
     assert_redirected_to login_path(:referer => edit_oauth_application_path(:id => client.id))
 
     session_for(user)
@@ -154,11 +184,11 @@ class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
     assert_response :success
     assert_template "oauth2_applications/edit"
     assert_select "form", 1 do
-      assert_select "input#doorkeeper_application_name", 1
-      assert_select "textarea#doorkeeper_application_redirect_uri", 1
-      assert_select "input#doorkeeper_application_confidential", 1
+      assert_select "input#oauth2_application_name", 1
+      assert_select "textarea#oauth2_application_redirect_uri", 1
+      assert_select "input#oauth2_application_confidential", 1
       Oauth.scopes.each do |scope|
-        assert_select "input#doorkeeper_application_scopes_#{scope.name}", 1
+        assert_select "input#oauth2_application_scopes_#{scope.name}", 1
       end
     end
   end
@@ -178,7 +208,7 @@ class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
     assert_template "oauth2_applications/not_found"
 
     put oauth_application_path(:id => client,
-                               :doorkeeper_application => {
+                               :oauth2_application => {
                                  :name => "New Name",
                                  :redirect_uri => nil
                                })
@@ -186,11 +216,10 @@ class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
     assert_template "oauth2_applications/edit"
 
     put oauth_application_path(:id => client,
-                               :doorkeeper_application => {
+                               :oauth2_application => {
                                  :name => "New Name",
                                  :redirect_uri => "https://new.example.com/url"
                                })
-    assert_response :redirect
     assert_redirected_to oauth_application_path(:id => client.id)
   end
 
@@ -215,7 +244,6 @@ class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
     assert_difference "Doorkeeper::Application.count", -1 do
       delete oauth_application_path(:id => client)
     end
-    assert_response :redirect
     assert_redirected_to oauth_applications_path
   end
 end