From: Martyn Taylor <mtaylor(a)redhat.com>
---
src/app/controllers/admin/users_controller.rb | 6 ++--
src/app/controllers/application_controller.rb | 6 +++++
src/features/error_handling.feature | 21 ++++++++++++++++++++
.../step_definitions/error_handling_steps.rb | 4 +++
4 files changed, 34 insertions(+), 3 deletions(-)
create mode 100644 src/features/error_handling.feature
create mode 100644 src/features/step_definitions/error_handling_steps.rb
diff --git a/src/app/controllers/admin/users_controller.rb
b/src/app/controllers/admin/users_controller.rb
index 4635f41..6134cd3 100644
--- a/src/app/controllers/admin/users_controller.rb
+++ b/src/app/controllers/admin/users_controller.rb
@@ -47,7 +47,7 @@ class Admin::UsersController < ApplicationController
end
def show
- @user = User.find_by_id(params[:id]) || current_user
+ @user = params[:id] ? User.find(params[:id]) : current_user
require_privilege(Privilege::VIEW, User) unless current_user == @user
@quota_resources = @user.quota.quota_resources
@@ -66,12 +66,12 @@ class Admin::UsersController < ApplicationController
end
def edit
- @user = User.find_by_id(params[:id]) || current_user
+ @user = params[:id] ? User.find(params[:id]) : current_user
require_privilege(Privilege::MODIFY, User) unless @user == current_user
end
def update
- @user = User.find_by_id(params[:id]) || current_user
+ @user = params[:id] ? User.find(params[:id]) : current_user
require_privilege(Privilege::MODIFY, User) unless @user == current_user
if params[:commit] == "Reset"
diff --git a/src/app/controllers/application_controller.rb
b/src/app/controllers/application_controller.rb
index a720939..6bda765 100644
--- a/src/app/controllers/application_controller.rb
+++ b/src/app/controllers/application_controller.rb
@@ -35,6 +35,7 @@ class ApplicationController < ActionController::Base
rescue_from PermissionError, :with => :handle_perm_error
rescue_from ActionError, :with => :handle_action_error
rescue_from PartialSuccessError, :with => :handle_partial_success_error
+ rescue_from ActiveRecord::RecordNotFound, :with =>
:handle_active_record_not_found_error
helper_method :check_privilege
@@ -136,6 +137,11 @@ class ApplicationController < ActionController::Base
end
end
+ def handle_active_record_not_found_error(error)
+ redirect_to :controller => params[:controller]
+ flash[:notice] = "The record you tried to access does not exist, it may have
been deleted"
+ end
+
private
def json_error_hash(msg, status)
json = {}
diff --git a/src/features/error_handling.feature b/src/features/error_handling.feature
new file mode 100644
index 0000000..bc5d171
--- /dev/null
+++ b/src/features/error_handling.feature
@@ -0,0 +1,21 @@
+Feature: Error Handling
+ In order to order to perform operations upon site objects
+ As a user
+ I must be able to correctly view any object errors
+
+ Background:
+ Given I am an authorised user
+ And I am logged in
+
+ @allow-rescue
+ Scenario: Display Record Not Found error for a deleted object
+ Given there are the following conductor hardware profiles:
+ | name | memory | cpu |storage | architecture |
+ | m1-small | 1740 | 2 | 160 | i386 |
+ | m1-large | 4096 | 4 | 850 | x86_64 |
+ | m1-xlarge | 8192 | 8 | 1690 | x86_64 |
+ And I am on the hardware profiles page
+ When another user deletes hardware profile "m1-small"
+ And I follow "m1-small"
+ Then I should be on the hardware profiles page
+ And I should see "The record you tried to access does not exist, it may have
been deleted"
\ No newline at end of file
diff --git a/src/features/step_definitions/error_handling_steps.rb
b/src/features/step_definitions/error_handling_steps.rb
new file mode 100644
index 0000000..6889de0
--- /dev/null
+++ b/src/features/step_definitions/error_handling_steps.rb
@@ -0,0 +1,4 @@
+When /^another user deletes hardware profile "([^"]*)"$/ do |name|
+ hwp = HardwareProfile.find_by_name(name)
+ hwp.delete
+end
\ No newline at end of file
--
1.7.4