@note = Note.find(id)
raise OSM::APINotFoundError unless @note
raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
+ raise OSM::APINoteAlreadyClosedError.new(@note) if @note.closed?
# Add a comment to the note
Note.transaction do
@note = Note.find_by_id(id)
raise OSM::APINotFoundError unless @note
raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
+ raise OSM::APINoteAlreadyClosedError.new(@note) if @note.closed?
# Close the note and add a comment
Note.transaction do
status != "hidden"
end
+ # Check if a note is closed
+ def closed?
+ not closed_at.nil?
+ end
+
# Return the author object, derived from the first comment
def author
self.comments.first.author
end
end
+ # Raised when the note provided is already closed
+ class APINoteAlreadyClosedError < APIError
+ def initialize(note)
+ @note = note
+ end
+
+ attr_reader :note
+
+ def status
+ :conflict
+ end
+
+ def to_s
+ "The note #{@note.id} was closed at #{@note.closed_at}"
+ end
+ end
+
# Helper methods for going to/from mercator and lat/lng.
class Mercator
include Math
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(: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