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
##
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
##