async_sinatra 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +5 -0
- data/Manifest.txt +0 -1
- data/Rakefile +1 -0
- data/lib/async_sinatra.rb +1 -1
- data/lib/sinatra/async.rb +5 -6
- data/lib/sinatra/async/test.rb +5 -0
- data/test/test_async.rb +44 -3
- metadata +21 -8
- data/test/gemloader.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88155191c2f2520c93ed812212df0467b9fade93
|
4
|
+
data.tar.gz: e24790e795892a895fd12dbfabae797066251337
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0264d3896a5269259293fe49258b7c0cca738bdb715999077ad3c9de0570dd5ce6c87c947e0b789e08b58d7214cef2c4b45d338f62a09099b5cf356fc66f41b7
|
7
|
+
data.tar.gz: d3934e32a91a32d3ca4d94c1ffe64d6fc480da6a6193caf206c56faa346ae07c5a3ed70bcb68d0fdc8d140d437ef7cf627e15eee1639bbef501ffd4525b579e0
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
=== 1.2.1 / 2016-01-16
|
2
|
+
|
3
|
+
* Fix a bug where in ahalt, the async.callback was called twice (boxofbrad)
|
4
|
+
* Improve testing support, allowing multiple requests (emschwar)
|
5
|
+
|
1
6
|
=== 1.2.0 / 2015-05-09
|
2
7
|
|
3
8
|
* Added apatch, alink, aunlink for PATCH, LINK, UNLINK (thanks dalehamel)
|
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -10,6 +10,7 @@ Hoe.spec 'async_sinatra' do
|
|
10
10
|
extra_deps << %w[rack >=1.4.1]
|
11
11
|
extra_deps << %w[sinatra >=1.3.2]
|
12
12
|
|
13
|
+
extra_dev_deps << %w(rack-test)
|
13
14
|
extra_dev_deps << %w(hoe-doofus >=1.0)
|
14
15
|
extra_dev_deps << %w(hoe-seattlerb >=1.2)
|
15
16
|
extra_dev_deps << %w(hoe-git >=1.3)
|
data/lib/async_sinatra.rb
CHANGED
data/lib/sinatra/async.rb
CHANGED
@@ -87,7 +87,7 @@ module Sinatra #:nodoc:
|
|
87
87
|
# Send the given body or block as the final response to the asynchronous
|
88
88
|
# request.
|
89
89
|
def body(value = nil)
|
90
|
-
if @async_running
|
90
|
+
if @async_running
|
91
91
|
if block_given?
|
92
92
|
super { async_handle_exception { yield } }
|
93
93
|
else
|
@@ -100,8 +100,8 @@ module Sinatra #:nodoc:
|
|
100
100
|
|
101
101
|
# Taken from Base#call
|
102
102
|
unless @response['Content-Type']
|
103
|
-
if Array === body and body[0].respond_to? :content_type
|
104
|
-
content_type body[0].content_type
|
103
|
+
if Array === response.body and response.body[0].respond_to? :content_type
|
104
|
+
content_type response.body[0].content_type
|
105
105
|
else
|
106
106
|
content_type :html
|
107
107
|
end
|
@@ -114,7 +114,7 @@ module Sinatra #:nodoc:
|
|
114
114
|
result[-1] = [] if request.head?
|
115
115
|
|
116
116
|
request.env['async.callback'][ result ]
|
117
|
-
body
|
117
|
+
response.body
|
118
118
|
else
|
119
119
|
super
|
120
120
|
end
|
@@ -187,8 +187,7 @@ module Sinatra #:nodoc:
|
|
187
187
|
# the original call stack.
|
188
188
|
def ahalt(*args)
|
189
189
|
invoke { halt(*args) }
|
190
|
-
invoke { error_block! response.status }
|
191
|
-
body response.body
|
190
|
+
invoke { error_block! response.status } unless @env['sinatra.error']
|
192
191
|
end
|
193
192
|
|
194
193
|
# The given block will be executed if the user closes the connection
|
data/lib/sinatra/async/test.rb
CHANGED
@@ -46,6 +46,10 @@ class Sinatra::Async::Test
|
|
46
46
|
@after_request.each { |hook| hook.call }
|
47
47
|
@last_response
|
48
48
|
end
|
49
|
+
|
50
|
+
def reset_last_response
|
51
|
+
@last_response = nil
|
52
|
+
end
|
49
53
|
end
|
50
54
|
|
51
55
|
module Methods
|
@@ -54,6 +58,7 @@ class Sinatra::Async::Test
|
|
54
58
|
%w(get put post delete head options).each do |m|
|
55
59
|
eval <<-RUBY, binding, __FILE__, __LINE__ + 1
|
56
60
|
def a#{m}(*args)
|
61
|
+
rack_mock_session.reset_last_response
|
57
62
|
#{m}(*args)
|
58
63
|
assert_async
|
59
64
|
async_continue
|
data/test/test_async.rb
CHANGED
@@ -1,15 +1,37 @@
|
|
1
|
-
require 'gemloader'
|
2
1
|
require 'minitest/autorun'
|
3
2
|
|
4
3
|
require 'eventmachine'
|
5
4
|
|
6
5
|
require "sinatra/async/test"
|
7
6
|
|
7
|
+
class CallbackCounter
|
8
|
+
@@count = 0
|
9
|
+
|
10
|
+
def self.count
|
11
|
+
@@count
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(app)
|
15
|
+
@app = app
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
callback = env['async.callback']
|
20
|
+
env['async.callback'] = lambda do |response|
|
21
|
+
@@count += 1
|
22
|
+
callback.call(response)
|
23
|
+
end
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
8
28
|
class TestSinatraAsync < MiniTest::Unit::TestCase
|
9
29
|
include Sinatra::Async::Test::Methods
|
10
30
|
|
11
31
|
class TestApp < Sinatra::Base
|
12
32
|
set :environment, :test
|
33
|
+
set :call_count, 0
|
34
|
+
|
13
35
|
register Sinatra::Async
|
14
36
|
|
15
37
|
# Hack for storing some global data accessible in tests (normally you
|
@@ -94,7 +116,6 @@ class TestSinatraAsync < MiniTest::Unit::TestCase
|
|
94
116
|
body { 'other' }
|
95
117
|
end
|
96
118
|
|
97
|
-
set :call_count, 0
|
98
119
|
aget '/double_body_bug/:subdomain' do |subdomain|
|
99
120
|
body { settings.call_count += 1; '' }
|
100
121
|
end
|
@@ -111,6 +132,10 @@ class TestSinatraAsync < MiniTest::Unit::TestCase
|
|
111
132
|
async_schedule { body { aparams[:a] } }
|
112
133
|
end
|
113
134
|
|
135
|
+
aget '/halt-with-body' do
|
136
|
+
async_schedule { ahalt 404, 'halted' }
|
137
|
+
end
|
138
|
+
|
114
139
|
# Defeat the test environment semantics, ensuring we actually follow the
|
115
140
|
# non-test branch of async_schedule. You would normally just call
|
116
141
|
# async_schedule in user apps, and use test helpers appropriately.
|
@@ -124,7 +149,10 @@ class TestSinatraAsync < MiniTest::Unit::TestCase
|
|
124
149
|
end
|
125
150
|
|
126
151
|
def app
|
127
|
-
|
152
|
+
Rack::Builder.new do
|
153
|
+
use CallbackCounter
|
154
|
+
run TestApp.new
|
155
|
+
end.to_app
|
128
156
|
end
|
129
157
|
|
130
158
|
def assert_redirect(path)
|
@@ -282,4 +310,17 @@ class TestSinatraAsync < MiniTest::Unit::TestCase
|
|
282
310
|
assert_equal 'test', last_response.body
|
283
311
|
end
|
284
312
|
|
313
|
+
def test_two_requests
|
314
|
+
aget '/hello'
|
315
|
+
assert last_response.ok?
|
316
|
+
aget '/302'
|
317
|
+
assert_equal 302, last_response.status
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_bug_42_halt_with_body_should_only_call_callback_once
|
321
|
+
start = CallbackCounter.count
|
322
|
+
aget '/halt-with-body'
|
323
|
+
assert_equal 'halted', last_response.body
|
324
|
+
assert_equal start + 1, CallbackCounter.count
|
325
|
+
end
|
285
326
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async_sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- raggi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '5.
|
47
|
+
version: '5.8'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '5.
|
54
|
+
version: '5.8'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rdoc
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '4.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: hoe-doofus
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +156,14 @@ dependencies:
|
|
142
156
|
requirements:
|
143
157
|
- - "~>"
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version: '3.
|
159
|
+
version: '3.14'
|
146
160
|
type: :development
|
147
161
|
prerelease: false
|
148
162
|
version_requirements: !ruby/object:Gem::Requirement
|
149
163
|
requirements:
|
150
164
|
- - "~>"
|
151
165
|
- !ruby/object:Gem::Version
|
152
|
-
version: '3.
|
166
|
+
version: '3.14'
|
153
167
|
description: |-
|
154
168
|
A Sinatra plugin to provide convenience whilst performing asynchronous
|
155
169
|
responses inside of the Sinatra framework running under async webservers.
|
@@ -180,7 +194,6 @@ files:
|
|
180
194
|
- lib/async_sinatra.rb
|
181
195
|
- lib/sinatra/async.rb
|
182
196
|
- lib/sinatra/async/test.rb
|
183
|
-
- test/gemloader.rb
|
184
197
|
- test/test_async.rb
|
185
198
|
homepage: http://github.com/raggi/async_sinatra
|
186
199
|
licenses:
|
@@ -204,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
217
|
version: '0'
|
205
218
|
requirements: []
|
206
219
|
rubyforge_project:
|
207
|
-
rubygems_version: 2.
|
220
|
+
rubygems_version: 2.5.1
|
208
221
|
signing_key:
|
209
222
|
specification_version: 4
|
210
223
|
summary: A Sinatra plugin to provide convenience whilst performing asynchronous responses
|
data/test/gemloader.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
begin
|
3
|
-
project = File.basename(Dir['*.gemspec'].first, '.gemspec')
|
4
|
-
gemspec = File.expand_path("#{project}.gemspec", Dir.pwd)
|
5
|
-
spec = Gem::Specification.load(gemspec)
|
6
|
-
(spec.dependencies + spec.development_dependencies).each do |dep|
|
7
|
-
gem dep.name, dep.requirement.to_s
|
8
|
-
end
|
9
|
-
rescue
|
10
|
-
warn "#{__FILE__}: Can't preload project dependencies: #{$!}"
|
11
|
-
end
|