X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/8090e086daad67eac711ad6fd6a5eba6f28d44fd..f4b599e8fd3a6998618dcbb4a1aae60ed5bbf2e4:/test/functional/notes_controller_test.rb diff --git a/test/functional/notes_controller_test.rb b/test/functional/notes_controller_test.rb index 3d12d151f..bfea29592 100644 --- a/test/functional/notes_controller_test.rb +++ b/test/functional/notes_controller_test.rb @@ -173,6 +173,13 @@ class NotesControllerTest < ActionController::TestCase end assert_response :bad_request + assert_no_difference('Note.count') do + assert_no_difference('NoteComment.count') do + post :create, {:lat => -1.0, :lon => -1.0, :text => ""} + end + end + assert_response :bad_request + assert_no_difference('Note.count') do assert_no_difference('NoteComment.count') do post :create, {:lat => -100.0, :lon => -1.0, :text => "This is a comment"} @@ -249,6 +256,11 @@ class NotesControllerTest < ActionController::TestCase end def test_note_close_success + post :close, {:id => notes(:open_note_with_comment).id, :text => "This is a close comment", :format => "json"} + assert_response :unauthorized + + basic_authorization(users(:public_user).email, "test") + post :close, {:id => notes(:open_note_with_comment).id, :text => "This is a close comment", :format => "json"} assert_response :success js = ActiveSupport::JSON.decode(@response.body) @@ -259,7 +271,7 @@ class NotesControllerTest < ActionController::TestCase assert_equal 3, js["properties"]["comments"].count assert_equal "closed", js["properties"]["comments"].last["action"] assert_equal "This is a close comment", js["properties"]["comments"].last["text"] - assert_nil js["properties"]["comments"].last["user"] + assert_equal "test2", js["properties"]["comments"].last["user"] get :show, {:id => notes(:open_note_with_comment).id, :format => "json"} assert_response :success @@ -271,10 +283,15 @@ class NotesControllerTest < ActionController::TestCase assert_equal 3, js["properties"]["comments"].count assert_equal "closed", js["properties"]["comments"].last["action"] assert_equal "This is a close comment", js["properties"]["comments"].last["text"] - assert_nil js["properties"]["comments"].last["user"] + assert_equal "test2", js["properties"]["comments"].last["user"] end def test_note_close_fail + post :close + assert_response :unauthorized + + basic_authorization(users(:public_user).email, "test") + post :close assert_response :bad_request @@ -326,6 +343,16 @@ class NotesControllerTest < ActionController::TestCase end def test_note_delete_success + delete :destroy, {:id => notes(:open_note_with_comment).id} + assert_response :unauthorized + + basic_authorization(users(:public_user).email, "test") + + delete :destroy, {:id => notes(:open_note_with_comment).id} + assert_response :forbidden + + basic_authorization(users(:moderator_user).email, "test") + delete :destroy, {:id => notes(:open_note_with_comment).id} assert_response :success @@ -334,6 +361,16 @@ class NotesControllerTest < ActionController::TestCase end def test_note_delete_fail + delete :destroy, {:id => 12345} + assert_response :unauthorized + + basic_authorization(users(:public_user).email, "test") + + delete :destroy, {:id => 12345} + assert_response :forbidden + + basic_authorization(users(:moderator_user).email, "test") + delete :destroy, {:id => 12345} assert_response :not_found