angelo 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5dd4947d9238c95169d7a38db1ff5964db35efad
4
- data.tar.gz: 65d2a79bfca8c5879721516d31029fd756ebc1c5
3
+ metadata.gz: d8b3d7e04d65efc3b63b8e866b1831fe772457c3
4
+ data.tar.gz: e71d70c1f4685ed93631661d4b19600612c563dd
5
5
  SHA512:
6
- metadata.gz: 1da99edfa1e946edd6f62764a95ab09e999cc6eccef9d915d0741e6ed8912ed8629d28b58605c7960972c0795c5ab912b2824bb018322c82bd90b1c7fee08be9
7
- data.tar.gz: 194fda3f3e9bf9f7a7b0ce2156bf8e34d2134ba7013e1366a7a8363e1cbba72c826daed7b8f1c934894e9431c8bcc87ab1d9c2b905a0741151d212d9a6c238b2
6
+ metadata.gz: 89d7d40daa608b501aa3f4a24faa967b62bf6a346adf495c3838e0ed42e1cbaca2e10e50c9ae801d48113001afc69d67d9ee67f8b4b167a0b8363fcf0bb16d84
7
+ data.tar.gz: 4ab1b3d6e547d703733517f7b17e1d5aa56a3c544b6d28dc0a4619deab9c87468b7413f19bcf1e0150a1094c9e9878519177c5b6cb99801d53837c95420c89cb
@@ -30,7 +30,9 @@ module Angelo
30
30
  Angelo.log @connection, @request, @websocket, :switching_protocols
31
31
  @bound_response_handler ||= @response_handler.bind @base
32
32
  @websocket.on_pong &WebsocketResponder.on_pong
33
+ @base.before if @base.respond_to? :before
33
34
  @bound_response_handler[@websocket]
35
+ @base.after if @base.respond_to? :after
34
36
  else
35
37
  raise NotImplementedError
36
38
  end
@@ -55,7 +55,7 @@ module Angelo
55
55
  def handle_request
56
56
  if @response_handler
57
57
  @base.before if @base.respond_to? :before
58
- @body = catch(:halt) { @response_handler.bind(@base).call || '' }
58
+ @body = catch(:halt) { @response_handler.bind(@base).call || EMPTY_STRING }
59
59
  @base.after if @base.respond_to? :after
60
60
  respond
61
61
  else
@@ -108,6 +108,8 @@ module Angelo
108
108
  headers CONTENT_TYPE_HEADER_KEY => JSON_TYPE
109
109
  when :html
110
110
  headers CONTENT_TYPE_HEADER_KEY => HTML_TYPE
111
+ when :js
112
+ headers CONTENT_TYPE_HEADER_KEY => JS_TYPE
111
113
  else
112
114
  raise ArgumentError.new "invalid content_type: #{type}"
113
115
  end
@@ -1,3 +1,3 @@
1
1
  module Angelo
2
- VERSION = '0.1.11'
2
+ VERSION = '0.1.12'
3
3
  end
data/lib/angelo.rb CHANGED
@@ -30,6 +30,7 @@ module Angelo
30
30
  JSON_TYPE = 'application/json'
31
31
  FORM_TYPE = 'application/x-www-form-urlencoded'
32
32
  FILE_TYPE = 'application/octet-stream'
33
+ JS_TYPE = 'text/javascript'
33
34
 
34
35
  DEFAULT_ADDR = '127.0.0.1'
35
36
  DEFAULT_PORT = 4567
@@ -104,6 +104,88 @@ describe Angelo::WebsocketResponder do
104
104
 
105
105
  end
106
106
 
107
+ describe 'before blocks' do
108
+
109
+ define_app do
110
+ before do
111
+ @set_by_before = params
112
+ end
113
+
114
+ websocket '/before' do |ws|
115
+ ws.write @set_by_before[:before]
116
+ ws.close
117
+ end
118
+ end
119
+
120
+ it 'runs before blocks before websocket handlers' do
121
+ websocket_helper '/before?before=hi%20there' do |wsh|
122
+ latch = CountDownLatch.new 1
123
+ wsh.on_message = ->(e) {
124
+ assert_match /hi there/, e.data
125
+ latch.count_down
126
+ }
127
+ wsh.init
128
+ Reactor.testers[:tester] = wsh
129
+ Reactor.define_action :go do
130
+ every(0.01){ terminate if Reactor.stop? }
131
+ Reactor.testers[:tester].go
132
+ end
133
+ Reactor.unstop!
134
+ $reactor.async.go
135
+
136
+ latch.wait
137
+
138
+ Reactor.stop!
139
+ Reactor.testers.delete :tester
140
+ Reactor.remove_action :go
141
+ end
142
+ end
143
+
144
+ end
145
+
146
+ describe 'after blocks' do
147
+
148
+ invoked = 4
149
+
150
+ define_app do
151
+ websocket '/after' do |ws|
152
+ ws.write 'after'
153
+ ws.close
154
+ end
155
+
156
+ after do
157
+ invoked *= 2
158
+ end
159
+ end
160
+
161
+ it 'runs after filters after routes' do
162
+ websocket_helper '/after' do |wsh|
163
+ latch = CountDownLatch.new 1
164
+ wsh.on_message = ->(e) {
165
+ assert_match /after/, e.data
166
+ latch.count_down
167
+ }
168
+ wsh.init
169
+ Reactor.testers[:tester] = wsh
170
+ Reactor.define_action :go do
171
+ every(0.01){ terminate if Reactor.stop? }
172
+ Reactor.testers[:tester].go
173
+ end
174
+ Reactor.unstop!
175
+ $reactor.async.go
176
+
177
+ latch.wait
178
+
179
+ Reactor.stop!
180
+ Reactor.testers.delete :tester
181
+ Reactor.remove_action :go
182
+ end
183
+
184
+ invoked.must_equal 8
185
+ end
186
+
187
+ end
188
+
107
189
  describe 'concurrency' do
108
190
 
109
191
  define_app do
data/test/angelo_spec.rb CHANGED
@@ -186,6 +186,11 @@ describe Angelo::Base do
186
186
  {hi: 'there'}.to_json.gsub /{/, 'so doge'
187
187
  end
188
188
 
189
+ __send__ m, '/javascript' do
190
+ content_type :js
191
+ 'var foo = "bar";'
192
+ end
193
+
189
194
  end
190
195
  end
191
196
 
@@ -224,6 +229,15 @@ describe Angelo::Base do
224
229
  end
225
230
  end
226
231
 
232
+ it 'sets javascript content type for current route' do
233
+ Angelo::HTTPABLE.each do |m|
234
+ __send__ m, '/javascript'
235
+ last_response.status.must_equal 200
236
+ last_response.body.to_s.must_equal 'var foo = "bar";'
237
+ last_response.headers['Content-Type'].split(';').must_include Angelo::JS_TYPE
238
+ end
239
+ end
240
+
227
241
  end
228
242
 
229
243
  describe 'when in class def' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angelo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-13 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reel