strelka 0.0.1.pre177 → 0.0.1.pre184

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. data/ChangeLog +111 -16
  2. data/Manifest.txt +8 -8
  3. data/Rakefile +3 -3
  4. data/bin/leash +51 -28
  5. data/examples/{auth-demo.rb → apps/auth-demo} +3 -3
  6. data/examples/{auth-demo2.rb → apps/auth-demo2} +0 -0
  7. data/examples/{sessions-demo.rb → apps/sessions-demo} +0 -0
  8. data/examples/config.yml +5 -1
  9. data/examples/{examples.css → static/examples.css} +0 -0
  10. data/examples/{examples.html → static/examples.html} +0 -0
  11. data/examples/{auth-form.tmpl → templates/auth-form.tmpl} +0 -0
  12. data/examples/{auth-success.tmpl → templates/auth-success.tmpl} +0 -0
  13. data/examples/{layout.tmpl → templates/layout.tmpl} +0 -0
  14. data/lib/strelka/app/auth.rb +18 -8
  15. data/lib/strelka/app/errors.rb +3 -2
  16. data/lib/strelka/app/filters.rb +2 -0
  17. data/lib/strelka/app/negotiation.rb +2 -0
  18. data/lib/strelka/app/parameters.rb +18 -140
  19. data/lib/strelka/app/plugins.rb +84 -26
  20. data/lib/strelka/app/restresources.rb +26 -18
  21. data/lib/strelka/app/routing.rb +8 -2
  22. data/lib/strelka/app/sessions.rb +7 -0
  23. data/lib/strelka/app/templating.rb +1 -1
  24. data/lib/strelka/app.rb +25 -1
  25. data/lib/strelka/constants.rb +3 -1
  26. data/lib/strelka/paramvalidator.rb +251 -74
  27. data/lib/strelka/session/default.rb +1 -1
  28. data/spec/strelka/app/auth_spec.rb +37 -0
  29. data/spec/strelka/app/errors_spec.rb +0 -2
  30. data/spec/strelka/app/filters_spec.rb +1 -1
  31. data/spec/strelka/app/parameters_spec.rb +4 -92
  32. data/spec/strelka/app/plugins_spec.rb +64 -2
  33. data/spec/strelka/app/restresources_spec.rb +3 -0
  34. data/spec/strelka/app/routing_spec.rb +5 -5
  35. data/spec/strelka/paramvalidator_spec.rb +294 -385
  36. data.tar.gz.sig +0 -0
  37. metadata +126 -46
  38. metadata.gz.sig +0 -0
@@ -33,11 +33,22 @@ describe Strelka::App::Plugins do
33
33
  reset_logging()
34
34
  end
35
35
 
36
+ after( :each ) do
37
+ Strelka::App.loaded_plugins.delete_if {|mod| mod =~ /anonymous/ }
38
+ end
39
+
36
40
  RSpec::Matchers.define( :order ) do |item|
37
41
  match do |enumerable|
42
+ raise "%p doesn't include %p" % [ enumerable, item ] unless
43
+ enumerable.include?( item )
38
44
  if defined?( @before )
45
+ raise "%p doesn't include %p" % [ enumerable, @before ] unless
46
+ enumerable.include?( @before )
39
47
  enumerable.index( @before ) < enumerable.index( item )
40
48
  elsif defined?( @after )
49
+ raise "%p doesn't include %p" % [ enumerable, @after ] unless
50
+ enumerable.include?( @after )
51
+ Strelka.log.debug "Enumerable is: %p" % [ enumerable ]
41
52
  enumerable.index( @after ) > enumerable.index( item )
42
53
  else
43
54
  raise "No .before or .after to compare against!"
@@ -85,6 +96,7 @@ describe Strelka::App::Plugins do
85
96
  end
86
97
  end
87
98
 
99
+
88
100
  it "sorts before it in the plugin registry" do
89
101
  Strelka::App.loaded_plugins.tsort.
90
102
  should order( @other_mod.plugin_name ).before( @before_mod.plugin_name )
@@ -124,7 +136,7 @@ describe Strelka::App::Plugins do
124
136
  end
125
137
 
126
138
  app = Class.new( Strelka::App )
127
- app.install_plugin( plugin )
139
+ app.register_plugin( plugin )
128
140
 
129
141
  app.a_class_method.should == "yep."
130
142
  end
@@ -139,7 +151,7 @@ describe Strelka::App::Plugins do
139
151
  end
140
152
 
141
153
  app = Class.new( Strelka::App )
142
- app.install_plugin( plugin )
154
+ app.register_plugin( plugin )
143
155
 
144
156
  app.testing_value.should == :default
145
157
  app.testing_value = :not_the_default
@@ -158,6 +170,7 @@ describe Strelka::App::Plugins do
158
170
  klass = Class.new( @including_class ) do
159
171
  plugin :routing
160
172
  end
173
+ klass.install_plugins
161
174
 
162
175
  klass.ancestors.should include( Strelka::App::Routing )
163
176
  end
@@ -166,10 +179,59 @@ describe Strelka::App::Plugins do
166
179
  klass = Class.new( @including_class ) do
167
180
  plugins :templating, :routing
168
181
  end
182
+ klass.install_plugins
169
183
 
170
184
  klass.ancestors.should include( Strelka::App::Routing, Strelka::App::Templating )
171
185
  end
172
186
 
187
+ it "installs the plugins in the right order even if they're loaded at separate times" do
188
+ superclass = Class.new( @including_class ) do
189
+ plugin :routing
190
+ end
191
+ subclass = Class.new( superclass ) do
192
+ plugin :templating
193
+ end
194
+ subclass.install_plugins
195
+
196
+ subclass.ancestors.should order( Strelka::App::Templating ).after( Strelka::App::Routing )
197
+ end
198
+
199
+ it "adds information about where plugins were installed from when they're installed" do
200
+ klass = Class.new( @including_class ) do
201
+ plugin :routing
202
+ end
203
+ klass.plugins_installed_from.should be_nil()
204
+ klass.install_plugins
205
+ klass.plugins_installed_from.should =~ /#{__FILE__}:#{__LINE__ - 1}/
206
+ end
207
+
208
+ end
209
+
210
+
211
+ context "Plugins loaded in a superclass" do
212
+
213
+ before( :each ) do
214
+ @base_class = Class.new { include Strelka::App::Plugins }
215
+ @superclass = Class.new( @base_class ) do
216
+ plugin :routing
217
+ end
218
+ end
219
+
220
+
221
+ it "are inherited by subclasses" do
222
+ subclass = Class.new( @superclass ) do
223
+ get 'foom' do |req|
224
+ res = req.response
225
+ res.puts( "Yep, it worked." )
226
+ return res
227
+ end
228
+ end
229
+
230
+ subclass.routes.should == [
231
+ [ :GET, ['foom'], {action: subclass.instance_method(:GET_foom), options: {}} ]
232
+ ]
233
+ end
234
+
173
235
  end
174
236
 
175
237
  end
@@ -160,7 +160,9 @@ describe Strelka::App::RestResources do
160
160
  end
161
161
 
162
162
  context "OPTIONS routes" do
163
+
163
164
  it "responds to a top-level OPTIONS request with a resource description (JSON Schema?)"
165
+
164
166
  it "responds to an OPTIONS request for a particular resource with details about it" do
165
167
  req = @request_factory.options( '/api/v1/servers' )
166
168
  res = @app.new.handle( req )
@@ -168,6 +170,7 @@ describe Strelka::App::RestResources do
168
170
  res.status.should == HTTP::OK
169
171
  res.headers.allowed.split( /\s*,\s*/ ).should include(*%w[GET HEAD POST PUT DELETE])
170
172
  end
173
+
171
174
  end # OPTIONS routes
172
175
 
173
176
 
@@ -48,7 +48,7 @@ describe Strelka::App::Routing do
48
48
  super
49
49
  end
50
50
  end
51
- Strelka.log.debug " new instance is: %p, routes array: 0x%016x" %
51
+ Strelka.log.debug " App class is: %p, routes array: 0x%016x" %
52
52
  [ @app, @app.routes.object_id * 2 ]
53
53
  end
54
54
 
@@ -236,7 +236,7 @@ describe Strelka::App::Routing do
236
236
  end
237
237
 
238
238
  @app.routes.should ==
239
- [[ :POST, ['userinfo', /(?<username>(?i-mx:[a-z]\w+))/],
239
+ [[ :POST, ['userinfo', /(?<username>[a-z]\w+)/i],
240
240
  {action: @app.instance_method(:POST_userinfo__username), options: {}} ]]
241
241
  end
242
242
 
@@ -248,7 +248,7 @@ describe Strelka::App::Routing do
248
248
  end
249
249
 
250
250
  @app.routes.should ==
251
- [[ :POST, ['userinfo', /(?<username>(?i-mx:[a-z]\w+))/],
251
+ [[ :POST, ['userinfo', /(?<username>[a-z]\w+)/i],
252
252
  {action: @app.instance_method(:POST_userinfo__username), options: {}} ]]
253
253
  end
254
254
 
@@ -260,7 +260,7 @@ describe Strelka::App::Routing do
260
260
  end
261
261
 
262
262
  @app.routes.should ==
263
- [[ :POST, ['userinfo', /(?<username>(?i-mx:[a-z]\w+))/],
263
+ [[ :POST, ['userinfo', /(?<username>[a-z]\w+)/i],
264
264
  {action: @app.instance_method(:POST_userinfo__username), options: {}} ]]
265
265
  end
266
266
 
@@ -272,7 +272,7 @@ describe Strelka::App::Routing do
272
272
  end
273
273
 
274
274
  @app.routes.should ==
275
- [[ :POST, ['userinfo', /(?<username>(?i-mx:[a-z]\w+))/],
275
+ [[ :POST, ['userinfo', /(?<username>[a-z]\w+)/i],
276
276
  {action: @app.instance_method(:POST_userinfo__username), options: {}} ]]
277
277
  end
278
278