From 519d402cb2234844f3dfee62cdcb2f3f44d5d618 Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Mon, 17 Nov 2008 11:59:42 +0000 Subject: [PATCH 1/1] Added tests for changeset close method. --- app/controllers/changeset_controller.rb | 37 +++++++++++--------- test/functional/changeset_controller_test.rb | 16 ++++++++- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index cd49176e6..1e6a44189 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -38,25 +38,28 @@ class ChangesetController < ApplicationController end end + ## + # marks a changeset as closed. this may be called multiple times + # on the same changeset, so is idempotent. def close - begin - unless request.put? - render :nothing => true, :status => :method_not_allowed - return - end - - changeset = Changeset.find(params[:id]) - - unless @user.id == changeset.user_id - raise OSM::APIUserChangesetMismatchError - end - - changeset.open = false - changeset.save! - render :nothing => true - rescue ActiveRecord::RecordNotFound - render :nothing => true, :status => :not_found + unless request.put? + render :nothing => true, :status => :method_not_allowed + return + end + + changeset = Changeset.find(params[:id]) + + unless @user.id == changeset.user_id + raise OSM::APIUserChangesetMismatchError end + + changeset.open = false + changeset.save! + render :nothing => true + rescue ActiveRecord::RecordNotFound + render :nothing => true, :status => :not_found + rescue OSM::APIError => ex + render ex.render_opts end ## diff --git a/test/functional/changeset_controller_test.rb b/test/functional/changeset_controller_test.rb index 1b0c63e2d..6cbee1eb8 100644 --- a/test/functional/changeset_controller_test.rb +++ b/test/functional/changeset_controller_test.rb @@ -48,8 +48,22 @@ class ChangesetControllerTest < ActionController::TestCase assert_select "osm>changeset[id=#{changeset_id}]", 1 end + ## + # test that the user who opened a change can close it def test_close - # FIXME FIXME FIXME! + basic_authorization "test@openstreetmap.org", "test" + + put :close, :id => changesets(:normal_user_first_change).id + assert_response :success + end + + ## + # test that a different user can't close another user's changeset + def test_close_invalid + basic_authorization "test@example.com", "test" + + put :close, :id => changesets(:normal_user_first_change).id + assert_response :conflict end ## -- 2.39.5