Skip to content

Instantly share code, notes, and snippets.

@benlieb
Last active January 4, 2016 18:09
Show Gist options
  • Save benlieb/8658702 to your computer and use it in GitHub Desktop.
Save benlieb/8658702 to your computer and use it in GitHub Desktop.
# Handles all public requests for authors - like the list and show pages
class AuthorsController < ApplicationController
# Handle all other actions that are given from named routes gracefully
# by redirecting to the page not found page
%w{new create edit update destroy}.each do |name|
define_method name do
ap "-------1"
page_not_found and return
ap "-------2"
end
end
end
describe "handling GET /authors/new" do
def do_get
get :new, :id => "1"
end
it "should render record_not_found" do
get :new, :id => "1"
controller.should_receive(:page_not_found)
end
end
class ApplicationController < ActionController::Base
def page_not_found
ap "-------3"
respond_to do |format|
format.html do
ap "-------4"
render :file => File.join(RAILS_ROOT,"app","views","shared","page_not_found.html.erb"), :layout => true
end
format.xml do
format.xml { head :record_not_found }
end
end
end
/Users/benlieb/.rvm/gems/ruby-2.0.0-p247@csee.org_rails_4/gems/actionpack-4.0.2/lib/action_dispatch/http/mime_type.rb:166: warning: already initialized constant Mime::ZIP
/Users/benlieb/.rvm/gems/ruby-2.0.0-p247@csee.org_rails_4/gems/actionpack-4.0.2/lib/action_dispatch/http/mime_type.rb:166: warning: previous definition of ZIP was here
Run options: include {:focus=>true}
"-------1"
"-------3"
"-------4"
.
Finished in 0.03103 seconds
1 example, 0 failures
Randomized with seed 63699
benlieb@bens.local 02:47 PM ~/my_life/sites/2013/CSEE/apps/csee.org >
$ rspec --tag focus spec/controllers/authors_controller_spec.rb
/Users/benlieb/.rvm/gems/ruby-2.0.0-p247@csee.org_rails_4/gems/actionpack-4.0.2/lib/action_dispatch/http/mime_type.rb:166: warning: already initialized constant Mime::ZIP
/Users/benlieb/.rvm/gems/ruby-2.0.0-p247@csee.org_rails_4/gems/actionpack-4.0.2/lib/action_dispatch/http/mime_type.rb:166: warning: previous definition of ZIP was here
Run options: include {:focus=>true}
"-------1"
"-------2"
F
Failures:
1) AuthorsController handling GET /authors/new should render record_not_found
Failure/Error: get :new, :id => "1"
ActionView::MissingTemplate:
Missing template authors/new, application/new with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder, :haml]}. Searched in:
* "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007fdb36339dc0>"
# ./spec/controllers/authors_controller_spec.rb:162:in `do_get'
# ./spec/controllers/authors_controller_spec.rb:167:in `block (3 levels) in <top (required)>'
Finished in 0.02915 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/controllers/authors_controller_spec.rb:165 # AuthorsController handling GET /authors/new should render record_not_found
Randomized with seed 29334
benlieb@bens.local 02:48 PM ~/my_life/sites/2013/CSEE/apps/csee.org >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment