test/angelo/mustermann_spec.rb in angelo-0.1.22 vs test/angelo/mustermann_spec.rb in angelo-0.1.23

- old
+ new

@@ -92,6 +92,94 @@ end end + describe 'filters' do + + describe 'params in route blocks' do + + define_app do + include Angelo::Mustermann + + before '/before/:foo' do + @foo = params[:foo] + end + + content_type :json + + [:get, :post, :put].each do |m| + __send__ m, '/before/:bar' do + { bar: params[:bar], foo: params[:foo], foo_from_before: @foo } + end + end + + end + + it 'does not infect route block params with filter pattern params' do + [:get, :post, :put].each do |m| + __send__ m, '/before/hi' + last_response_must_be_json 'bar' => 'hi', 'foo' => nil, 'foo_from_before' => 'hi' + end + end + + end + + describe 'wildcard' do + + define_app do + include Angelo::Mustermann + + before do + @foo = params[:foo] + end + + before path: '/before*' do + @bar = params[:bar] if @foo + @bat = params[:bat] if @foo + end + + [:get, :post, :put].each do |m| + + __send__ m, '/before' do + content_type :json + { foo: @foo, bar: @bar, bat: @bat }.select {|k,v| !v.nil?} + end + + __send__ m, '/before_bar' do + content_type :json + { foo: @foo, bar: @bar, bat: @bat }.select {|k,v| !v.nil?} + end + + __send__ m, '/before_bat' do + content_type :json + { foo: @foo, bar: @bar, bat: @bat }.select {|k,v| !v.nil?} + end + end + + end + + it 'runs wildcarded before filters' do + + get '/before_bar', obj + last_response_must_be_json obj_s + + [:post, :put].each do |m| + __send__ m, '/before_bar', obj.to_json, {Angelo::CONTENT_TYPE_HEADER_KEY => Angelo::JSON_TYPE} + last_response_must_be_json obj + end + + get '/before_bat', obj + last_response_must_be_json obj_s + + [:post, :put].each do |m| + __send__ m, '/before_bat', obj.to_json, {Angelo::CONTENT_TYPE_HEADER_KEY => Angelo::JSON_TYPE} + last_response_must_be_json obj + end + + end + + end + + end + end