Skip to content

Commit

Permalink
Added (failing) specs for new controller filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtodd committed Jun 24, 2008
1 parent 395f97f commit 4ef3fd4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
16 changes: 8 additions & 8 deletions spec/halcyon/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@
end

it "should run filters before or after actions" do
response = Rack::MockRequest.new(@app).get("/hello/Matt")
response.body.should =~ %r{Hello Matt}
response = Rack::MockRequest.new(@app).get("/index")
response.body.should =~ %r{Found}

# The Accepted exception is raised if +cause_exception_in_filter+ is set
response = Rack::MockRequest.new(@app).get("/hello/Matt?cause_exception_in_filter=true")
response = Rack::MockRequest.new(@app).get("/index?cause_exception_in_filter=true")
response.body.should =~ %r{Accepted}

response = Rack::MockRequest.new(@app).get("/time")
response.body.should =~ Regexp.new(Time.now.to_s.gsub(/[0-9]/, '\d'))
response = Rack::MockRequest.new(@app).get("/foobar")
response.body.should =~ %r{fubr}

# The Created exception is raised if +cause_exception_in_filter+ is set
response = Rack::MockRequest.new(@app).get("/time?cause_exception_in_filter=true")
response = Rack::MockRequest.new(@app).get("/foobar?cause_exception_in_filter=true")
response.body.should =~ %r{Created}

response = Rack::MockRequest.new(@app).get("/hello/Matt?cause_exception_in_filter=true")
response.body.should =~ %r{Hello Matt}
response = Rack::MockRequest.new(@app).get("/hello/Matt?cause_exception_in_filter_block=true")
response.body.should =~ %r{Not Found}
end

end
7 changes: 7 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Specs < Application

before :before_index, :only => [:index]
after :after_everything_but_index, :except => [:index]
before :greeter do |controller|
raise NotFound.new if controller.params[:cause_exception_in_filter_block]
end

def greeter
$hello = params[:name]
Expand All @@ -26,6 +29,10 @@ def index
ok('Found')
end

def foobar
ok('fubr')
end

def cause_exception
raise Exception.new("Oops!")
end
Expand Down

0 comments on commit 4ef3fd4

Please sign in to comment.