From: Martyn Taylor mtaylor@redhat.com
--- src/app/controllers/application_controller.rb | 6 +++++ src/features/error_handling.feature | 21 ++++++++++++++++++++ .../step_definitions/error_handling_steps.rb | 4 +++ 3 files changed, 31 insertions(+), 0 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/application_controller.rb b/src/app/controllers/application_controller.rb index a720939..380cfac 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 :back + 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