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"}
end
assert_response :bad_request
+ assert_no_difference('NoteComment.count') do
+ post :comment, {:id => notes(:open_note_with_comment).id, :text => ""}
+ end
+ assert_response :bad_request
+
assert_no_difference('NoteComment.count') do
post :comment, {:id => 12345, :text => "This is an additional comment"}
end
post :comment, {:id => notes(:hidden_note_with_comment).id, :text => "This is an additional comment"}
end
assert_response :gone
+
+ assert_no_difference('NoteComment.count') do
+ post :comment, {:id => notes(:closed_note_with_comment).id, :text => "This is an additional comment"}
+ end
+ assert_response :conflict
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)
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
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
post :close, {:id => notes(:hidden_note_with_comment).id}
assert_response :gone
+
+ post :close, {:id => notes(:closed_note_with_comment).id}
+ assert_response :conflict
end
def test_note_read_success
end
def test_note_delete_success
- delete :destroy, {:id => notes(:open_note_with_comment).id}
+ delete :destroy, {:id => notes(:open_note_with_comment).id, :text => "This is a hide comment", :format => "json"}
+ assert_response :unauthorized
+
+ basic_authorization(users(:public_user).email, "test")
+
+ delete :destroy, {:id => notes(:open_note_with_comment).id, :text => "This is a hide comment", :format => "json"}
+ assert_response :forbidden
+
+ basic_authorization(users(:moderator_user).email, "test")
+
+ delete :destroy, {:id => notes(:open_note_with_comment).id, :text => "This is a hide comment", :format => "json"}
assert_response :success
+ js = ActiveSupport::JSON.decode(@response.body)
+ assert_not_nil js
+ assert_equal "Feature", js["type"]
+ assert_equal notes(:open_note_with_comment).id, js["properties"]["id"]
+ assert_equal "hidden", js["properties"]["status"]
+ assert_equal 3, js["properties"]["comments"].count
+ assert_equal "hidden", js["properties"]["comments"].last["action"]
+ assert_equal "This is a hide comment", js["properties"]["comments"].last["text"]
+ assert_equal "moderator", js["properties"]["comments"].last["user"]
get :show, {:id => notes(:open_note_with_comment).id, :format => 'json'}
assert_response :gone
end
def test_note_delete_fail
- delete :destroy, {:id => 12345}
+ delete :destroy, {:id => 12345, :format => "json"}
+ assert_response :unauthorized
+
+ basic_authorization(users(:public_user).email, "test")
+
+ delete :destroy, {:id => 12345, :format => "json"}
+ assert_response :forbidden
+
+ basic_authorization(users(:moderator_user).email, "test")
+
+ delete :destroy, {:id => 12345, :format => "json"}
assert_response :not_found
- delete :destroy, {:id => notes(:hidden_note_with_comment).id}
+ delete :destroy, {:id => notes(:hidden_note_with_comment).id, :format => "json"}
assert_response :gone
end