]> git.openstreetmap.org Git - rails.git/commitdiff
Split api changeset comment create fail tests
authorAnton Khorev <tony29@yandex.ru>
Wed, 12 Feb 2025 15:56:09 +0000 (18:56 +0300)
committerAnton Khorev <tony29@yandex.ru>
Thu, 13 Feb 2025 21:15:52 +0000 (00:15 +0300)
test/controllers/api/changeset_comments_controller_test.rb

index cc257eb9d63aa3f53779e78dd8dc65fd1e5d6b93..b3b3d9c757d9ce0904b57930a5f314c72fae3592 100644 (file)
@@ -98,38 +98,39 @@ module Api
       ActionMailer::Base.deliveries.clear
     end
 
-    ##
-    # create comment fail
-    def test_create_fail
-      # unauthorized
-      post changeset_comment_path(create(:changeset, :closed), :text => "This is a comment")
-      assert_response :unauthorized
-
-      auth_header = bearer_authorization_header
+    def test_create_by_unauthorized
+      assert_no_difference "ChangesetComment.count" do
+        post changeset_comment_path(create(:changeset, :closed), :text => "This is a comment")
+        assert_response :unauthorized
+      end
+    end
 
-      # bad changeset id
+    def test_create_on_missing_changeset
       assert_no_difference "ChangesetComment.count" do
-        post changeset_comment_path(999111, :text => "This is a comment"), :headers => auth_header
+        post changeset_comment_path(999111, :text => "This is a comment"), :headers => bearer_authorization_header
+        assert_response :not_found
       end
-      assert_response :not_found
+    end
 
-      # not closed changeset
+    def test_create_on_open_changeset
       assert_no_difference "ChangesetComment.count" do
-        post changeset_comment_path(create(:changeset), :text => "This is a comment"), :headers => auth_header
+        post changeset_comment_path(create(:changeset), :text => "This is a comment"), :headers => bearer_authorization_header
+        assert_response :conflict
       end
-      assert_response :conflict
+    end
 
-      # no text
+    def test_create_without_text
       assert_no_difference "ChangesetComment.count" do
-        post changeset_comment_path(create(:changeset, :closed)), :headers => auth_header
+        post changeset_comment_path(create(:changeset, :closed)), :headers => bearer_authorization_header
+        assert_response :bad_request
       end
-      assert_response :bad_request
+    end
 
-      # empty text
+    def test_create_with_empty_text
       assert_no_difference "ChangesetComment.count" do
-        post changeset_comment_path(create(:changeset, :closed), :text => ""), :headers => auth_header
+        post changeset_comment_path(create(:changeset, :closed), :text => ""), :headers => bearer_authorization_header
+        assert_response :bad_request
       end
-      assert_response :bad_request
     end
 
     ##