test/angelo_spec.rb in angelo-0.1.22 vs test/angelo_spec.rb in angelo-0.1.23
- old
+ new
@@ -1,17 +1,9 @@
require_relative './spec_helper'
describe Angelo::Base do
- def obj
- {'foo' => 'bar', 'bar' => 123.4567890123456, 'bat' => true}
- end
-
- def obj_s
- obj.keys.reduce({}){|h,k| h[k] = obj[k].to_s; h}
- end
-
describe 'the basics' do
define_app do
Angelo::HTTPABLE.each do |m|
@@ -106,76 +98,10 @@
r.must_match /400 Bad Request/
end
end
- describe 'before filter' do
-
- define_app do
-
- before do
- @set_by_before = params
- end
-
- [:get, :post, :put].each do |m|
- __send__ m, '/before' do
- content_type :json
- @set_by_before
- end
- end
-
- end
-
- it 'runs before filters before routes' do
-
- get '/before', obj
- last_response_must_be_json obj_s
-
- [:post, :put].each do |m|
- __send__ m, '/before', obj.to_json, {Angelo::CONTENT_TYPE_HEADER_KEY => Angelo::JSON_TYPE}
- last_response_must_be_json obj
- end
-
- end
-
- end
-
- describe 'after filter' do
-
- invoked = 0
-
- define_app do
-
- before do
- invoked += 2
- end
-
- after do
- invoked *= 2
- end
-
- Angelo::HTTPABLE.each do |m|
- __send__ m, '/after' do
- invoked.to_s
- end
- end
-
- end
-
- it 'runs after filters after routes' do
- a = %w[2 6 14 30 62]
- b = [4, 12, 28, 60, 124]
-
- Angelo::HTTPABLE.each_with_index do |m,i|
- __send__ m, '/after', obj
- last_response_must_be_html a[i]
- invoked.must_equal b[i]
- end
- end
-
- end
-
describe 'headers helper' do
headers_count = 0
define_app do
@@ -383,11 +309,11 @@
describe 'params helper' do
define_app do
- [:get, :post].each do |m|
+ Angelo::HTTPABLE.each do |m|
__send__ m, '/json' do
content_type :json
params
end
end
@@ -405,9 +331,16 @@
end
it 'does not parse body when request content-type not set' do
post '/json', obj, {'Content-Type' => ''}
last_response_must_be_json({})
+ end
+
+ (Angelo::HTTPABLE - [:post, :put]).each do |m|
+ it "returns a populated hash for #{m.to_s.upcase} requests" do
+ send m, '/json?foo=bar'
+ last_response_must_be_json('foo' => 'bar')
+ end
end
end
describe 'request_headers helper' do