Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

not_found response for resource_controller

  • Loading branch information...
commit bf2eaa940895100f4d13b4f41f7b1548ae305b67 1 parent 4623613
@saturnflyer saturnflyer authored seancribbs committed
View
6 CHANGELOG
@@ -1,10 +1,14 @@
== Change Log
+=== Edge
+
+* Catch ActiveRecord::RecordNotFound in Admin::ResourceController
+[Jim Gay]
+* Catch missing template errors for show routes [Jim Gay]
* Fix with_error in render_matcher not causing the spec to fail when no exception raised. [Jason Garber]
=== 0.8.0 RC1
-* Catch missing template errors for show routes [Jim Gay]
* Make features task run in instance mode. [Sean Cribbs]
* Remove Admin::AbstractModelController. [Sean Cribbs]
* Cleanup deprecated Gem::manage_gems. [Sean Cribbs]
View
2  app/controllers/admin/pages_controller.rb
@@ -17,7 +17,7 @@ def index
end
def show
- redirect_to edit_admin_page_path
+ redirect_to edit_admin_page_path(params[:id])
end
def new
View
9 app/controllers/admin/resource_controller.rb
@@ -21,6 +21,9 @@ def self.model_class(model_class = nil)
r.plural.publish(:xml, :json) { render format_symbol => models }
r.singular.publish(:xml, :json) { render format_symbol => model }
+
+ r.not_found.publish(:xml, :json) { head :not_found }
+ r.not_found.default { announce_not_found; redirect_to continue_url(params) }
r.invalid.publish(:xml, :json) { render format_symbol => model.errors, :status => :unprocessable_entity }
r.invalid.default { announce_validation_errors; render :action => template_name }
@@ -87,6 +90,8 @@ def rescue_action(exception)
response_for :invalid
when ActiveRecord::StaleObjectError
response_for :stale
+ when ActiveRecord::RecordNotFound
+ response_for :not_found
else
super
end
@@ -157,6 +162,10 @@ def announce_validation_errors
def announce_removed
flash[:notice] = "#{humanized_model_name} has been deleted."
end
+
+ def announce_not_found
+ flash[:notice] = "#{humanized_model_name} could not be found."
+ end
def announce_update_conflict
flash.now[:error] = "#{humanized_model_name} has been modified since it was last loaded. Changes cannot be saved without potentially losing data."
View
40 spec/controllers/admin/layouts_controller_spec.rb
@@ -14,6 +14,46 @@
it "should handle Layouts" do
controller.class.model_class.should == Layout
end
+
+
+ describe "show" do
+ it "should redirect to the edit action" do
+ get :show, :id => 1
+ response.should redirect_to(edit_admin_layout_path(params[:id]))
+ end
+ end
+
+ describe "with invalid page id" do
+ [:edit, :remove].each do |action|
+ before do
+ @parameters = {:id => 999}
+ end
+ it "should redirect the #{action} action to the index action" do
+ get action, @parameters
+ response.should redirect_to(admin_layouts_path)
+ end
+ it "should say that the 'Layout could not be found.' after the #{action} action" do
+ get action, @parameters
+ flash[:notice].should == 'Layout could not be found.'
+ end
+ end
+ it 'should redirect the update action to the index action' do
+ put :update, @parameters
+ response.should redirect_to(admin_layouts_path)
+ end
+ it "should say that the 'Layout could not be found.' after the update action" do
+ put :update, @parameters
+ flash[:notice].should == 'Layout could not be found.'
+ end
+ it 'should redirect the destroy action to the index action' do
+ delete :destroy, @parameters
+ response.should redirect_to(admin_layouts_path)
+ end
+ it "should say that the 'Layout could not be found.' after the destroy action" do
+ delete :destroy, @parameters
+ flash[:notice].should == 'Layout could not be found.'
+ end
+ end
{ :get => [:index, :new, :edit, :remove],
:post => [:create],
View
39 spec/controllers/admin/pages_controller_spec.rb
@@ -14,6 +14,45 @@
:action => 'new').should == '/admin/pages/1/children/new'
end
+ describe "show" do
+ it "should redirect to the edit action" do
+ get :show, :id => 1
+ response.should redirect_to(edit_admin_page_path(params[:id]))
+ end
+ end
+
+ describe "with invalid page id" do
+ [:edit, :remove].each do |action|
+ before do
+ @parameters = {:id => 999}
+ end
+ it "should redirect the #{action} action to the index action" do
+ get action, @parameters
+ response.should redirect_to(admin_pages_path)
+ end
+ it "should say that the 'Page could not be found.' after the #{action} action" do
+ get action, @parameters
+ flash[:notice].should == 'Page could not be found.'
+ end
+ end
+ it 'should redirect the update action to the index action' do
+ put :update, @parameters
+ response.should redirect_to(admin_pages_path)
+ end
+ it "should say that the 'Page could not be found.' after the update action" do
+ put :update, @parameters
+ flash[:notice].should == 'Page could not be found.'
+ end
+ it 'should redirect the destroy action to the index action' do
+ delete :destroy, @parameters
+ response.should redirect_to(admin_pages_path)
+ end
+ it "should say that the 'Page could not be found.' after the destroy action" do
+ delete :destroy, @parameters
+ flash[:notice].should == 'Page could not be found.'
+ end
+ end
+
describe "viewing the sitemap" do
integrate_views
View
40 spec/controllers/admin/snippets_controller_spec.rb
@@ -15,6 +15,46 @@
it "should handle Snippets" do
controller.class.model_class.should == Snippet
end
+
+
+ describe "show" do
+ it "should redirect to the edit action" do
+ get :show, :id => 1
+ response.should redirect_to(edit_admin_snippet_path(params[:id]))
+ end
+ end
+
+ describe "with invalid snippet id" do
+ [:edit, :remove].each do |action|
+ before do
+ @parameters = {:id => 999}
+ end
+ it "should redirect the #{action} action to the index action" do
+ get action, @parameters
+ response.should redirect_to(admin_snippets_path)
+ end
+ it "should say that the 'Snippet could not be found.' after the #{action} action" do
+ get action, @parameters
+ flash[:notice].should == 'Snippet could not be found.'
+ end
+ end
+ it 'should redirect the update action to the index action' do
+ put :update, @parameters
+ response.should redirect_to(admin_snippets_path)
+ end
+ it "should say that the 'Snippet could not be found.' after the update action" do
+ put :update, @parameters
+ flash[:notice].should == 'Snippet could not be found.'
+ end
+ it 'should redirect the destroy action to the index action' do
+ delete :destroy, @parameters
+ response.should redirect_to(admin_snippets_path)
+ end
+ it "should say that the 'Snippet could not be found.' after the destroy action" do
+ delete :destroy, @parameters
+ flash[:notice].should == 'Snippet could not be found.'
+ end
+ end
{:get => [:index, :show, :new, :edit, :remove],
:post => [:create],
View
44 spec/controllers/admin/users_controller_spec.rb
@@ -10,6 +10,50 @@
it "should handle Users" do
controller.class.model_class.should == User
end
+
+
+ describe "show" do
+ it "should redirect to the edit action" do
+ login_as :admin
+ get :show, :id => 1
+ response.should redirect_to(edit_admin_user_path(params[:id]))
+ end
+ end
+
+ describe "with invalid page id" do
+ before do
+ login_as :admin
+ end
+ [:edit, :remove].each do |action|
+ before do
+ @parameters = {:id => 999}
+ end
+ it "should redirect the #{action} action to the index action" do
+ get action, @parameters
+ response.should redirect_to(admin_users_path)
+ end
+ it "should say that the 'User could not be found.' after the #{action} action" do
+ get action, @parameters
+ flash[:notice].should == 'User could not be found.'
+ end
+ end
+ it 'should redirect the update action to the index action' do
+ put :update, @parameters
+ response.should redirect_to(admin_users_path)
+ end
+ it "should say that the 'User could not be found.' after the update action" do
+ put :update, @parameters
+ flash[:notice].should == 'User could not be found.'
+ end
+ it 'should redirect the destroy action to the index action' do
+ delete :destroy, @parameters
+ response.should redirect_to(admin_users_path)
+ end
+ it "should say that the 'User could not be found.' after the destroy action" do
+ delete :destroy, @parameters
+ flash[:notice].should == 'User could not be found.'
+ end
+ end
{ :get => [:index, :new, :edit, :remove],
:post => [:create],
Please sign in to comment.
Something went wrong with that request. Please try again.