# then we check that we get the correct 404 when a non-existant id is passed
# then we check that it will get a successful response, when we do pass an id
def browse_check(type, id)
- get type
- assert_response :not_found
- assert_template 'not_found'
- get type, {:id => -10} # we won't have an id that's negative
- assert_response :not_found
- assert_template 'not_found'
+ assert_raise ActionController::RoutingError do
+ get type
+ end
+ assert_raise ActionController::RoutingError do
+ get type, {:id => -10} # we won't have an id that's negative
+ end
get type, {:id => id}
assert_response :success
assert_template type
# check that a changeset that doesn't exist returns an appropriate message
def test_read_not_found
[0, -32, 233455644, "afg", "213"].each do |id|
- get :read, :id => id
- assert_response :not_found, "should get a not found"
+ begin
+ get :read, :id => id
+ assert_response :not_found, "should get a not found"
+ rescue ActionController::RoutingError => ex
+ assert_match /No route matches/, ex.to_s
+ end
end
end
# First try to do it with no auth
cs_ids.each do |id|
- put :close, :id => id
- assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized"
+ begin
+ put :close, :id => id
+ assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized"
+ rescue ActionController::RoutingError => ex
+ assert_match /No route matches/, ex.to_s
+ end
end
# Now try with auth
basic_authorization users(:public_user).email, "test"
cs_ids.each do |id|
- put :close, :id => id
- assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed"
+ begin
+ put :close, :id => id
+ assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed"
+ rescue ActionController::RoutingError => ex
+ assert_match /No route matches/, ex.to_s
+ end
end
end
def test_edit_diary_entry_i18n
@request.cookies["_osm_username"] = users(:normal_user).display_name
- get(:edit, {:id => diary_entries(:normal_user_entry_1).id}, {'user' => users(:normal_user).id})
+ get :edit, {:display_name => users(:normal_user).display_name, :id => diary_entries(:normal_user_entry_1).id}, {'user' => users(:normal_user).id}
assert_response :success
assert_select "span[class=translation_missing]", false, "Missing translation in edit diary entry"
end
assert_equal "Test message body", m.body
assert_equal "markdown", m.body_format
- # Asking to send a message with no user name should fail
- get :new
- assert_response :not_found
- assert_template "user/no_such_user"
- assert_select "h2", "The user does not exist"
-
# Asking to send a message with a bogus user name should fail
get :new, :display_name => "non_existent_user"
assert_response :not_found
end
# Asking to reply to a message with no ID should fail
- get :reply
- assert_response :not_found
- assert_template "no_such_message"
+ assert_raise ActionController::RoutingError do
+ get :reply
+ end
# Asking to reply to a message with a bogus ID should fail
get :reply, :message_id => 99999
assert_equal true, Message.find(messages(:unread_message).id).message_read
# Asking to read a message with no ID should fail
- get :read
- assert_response :not_found
- assert_template "no_such_message"
+ assert_raise ActionController::RoutingError do
+ get :read
+ end
# Asking to read a message with a bogus ID should fail
get :read, :message_id => 99999
assert_equal false, Message.find(messages(:unread_message).id).message_read
# Asking to mark a message with no ID should fail
- post :mark
- assert_response :not_found
- assert_template "no_such_message"
+ assert_raise ActionController::RoutingError do
+ post :mark
+ end
# Asking to mark a message with a bogus ID should fail
post :mark, :message_id => 99999
assert_equal true, m.to_user_visible
# Asking to delete a message with no ID should fail
- post :delete
- assert_response :not_found
- assert_template "no_such_message"
+ assert_raise ActionController::RoutingError do
+ post :delete
+ end
# Asking to delete a message with a bogus ID should fail
post :delete, :message_id => 99999
def check_not_found_id_version(id, version)
get :version, :id => id, :version => version
assert_response :not_found
+ rescue ActionController::RoutingError => ex
+ assert_match /No route matches/, ex.to_s
end
##
# test the show action
def test_show
# Viewing a block should fail when no ID is given
- get :show
- assert_response :not_found
- assert_template "not_found"
- assert_select "p", "Sorry, the user block with ID could not be found."
+ assert_raise ActionController::RoutingError do
+ get :show
+ end
# Viewing a block should fail when a bogus ID is given
get :show, :id => 99999
end
# We should get an error if no user is specified
- get :edit
- assert_response :not_found
- assert_template "not_found"
- assert_select "p", "Sorry, the user block with ID could not be found."
+ assert_raise ActionController::RoutingError do
+ get :edit
+ end
# We should get an error if the user doesn't exist
get :edit, :id => 99999
# test the update action
def test_update
# Not logged in yet, so updating a block should fail
- put :update
+ put :update, :id => user_blocks(:active_block).id
assert_response :forbidden
# Login as a normal user
cookies["_osm_username"] = users(:public_user).display_name
# Check that normal users can't update blocks
- put :update
+ put :update, :id => user_blocks(:active_block).id
assert_response :forbidden
# Login as the wrong moderator
assert_equal "Vandalism", b.reason
# We should get an error if no block ID is specified
- put :update
- assert_response :not_found
- assert_template "not_found"
- assert_select "p", "Sorry, the user block with ID could not be found."
+ assert_raise ActionController::RoutingError do
+ put :update
+ end
# We should get an error if the block doesn't exist
put :update, :id => 99999
assert_in_delta Time.now, b.ends_at, 1
# We should get an error if no block ID is specified
- get :revoke
- assert_response :not_found
- assert_template "not_found"
- assert_select "p", "Sorry, the user block with ID could not be found."
+ assert_raise ActionController::RoutingError do
+ get :revoke
+ end
# We should get an error if the block doesn't exist
get :revoke, :id => 99999
# test the blocks_on action
def test_blocks_on
# Asking for a list of blocks with no user name should fail
- get :blocks_on
- assert_response :not_found
- assert_template "user/no_such_user"
- assert_select "h2", "The user does not exist"
+ assert_raise ActionController::RoutingError do
+ get :blocks_on
+ end
# Asking for a list of blocks with a bogus user name should fail
get :blocks_on, :display_name => "non_existent_user"
# test the blocks_by action
def test_blocks_by
# Asking for a list of blocks with no user name should fail
- get :blocks_by
- assert_response :not_found
- assert_template "user/no_such_user"
- assert_select "h2", "The user does not exist"
+ assert_raise ActionController::RoutingError do
+ get :blocks_by
+ end
# Asking for a list of blocks with a bogus user name should fail
get :blocks_by, :display_name => "non_existent_user"