Skip to content

Commit

Permalink
Cherry-pick changes from simulacre. Appears to break things
Browse files Browse the repository at this point in the history
fixes raggi#17; refs raggi#16

17: check arity before calling route block

16: adds a failing test case: "route parameters not in params"

Conflicts:

	test/test_async.rb
  • Loading branch information
gruis authored and raggi committed Feb 20, 2012
1 parent b0ded5b commit ee8b85a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/sinatra/async.rb
Expand Up @@ -131,8 +131,11 @@ def async_response
throw :async
end

def async_runner(method, *bargs)
async_schedule { __send__(method, *bargs); nil }
def async_runner(meth, *bargs)
async_schedule do
method(meth).arity == 0 ? send(meth) : send(meth, *bargs)
nil
end
end

def async_catch_execute(&b)
Expand Down
23 changes: 22 additions & 1 deletion test/test_async.rb
Expand Up @@ -99,6 +99,14 @@ def self.singletons
body { settings.call_count += 1; '' }
end

aget '/param/:a/' do |ma|
body { ma }
end

aget '/params/:a/' do
body { params[:a] }
end

# Defeat the test environment semantics, ensuring we actually follow the
# non-test branch of async_schedule. You would normally just call
# async_schedule in user apps, and use test helpers appropriately.
Expand All @@ -112,7 +120,7 @@ def em_async_schedule
end

def app
TestApp.new
TestApp
end

def assert_redirect(path)
Expand Down Expand Up @@ -254,4 +262,17 @@ def test_double_body_bug
aget '/double_body_bug/example'
assert_equal 1, settings.call_count
end

def test_block_with_no_args
err = aget('/params/test/') rescue $!
assert_nil err
assert_equal 'test', last_response.body
end

def test_block_with_an_arg
err = aget('/param/test/') rescue $!
assert_nil err
assert_equal 'test', last_response.body
end

end

0 comments on commit ee8b85a

Please sign in to comment.