dao 2.2.3 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/Rakefile +68 -113
  2. data/TODO +3 -9
  3. data/a.rb +25 -0
  4. data/dao.gemspec +70 -14
  5. data/lib/dao.rb +8 -8
  6. data/lib/dao/api.rb +1 -0
  7. data/lib/dao/api/context.rb +48 -23
  8. data/lib/dao/api/dsl.rb +1 -1
  9. data/lib/dao/api/interfaces.rb +149 -117
  10. data/lib/dao/api/modes.rb +24 -23
  11. data/lib/dao/api/routes.rb +9 -0
  12. data/lib/dao/data.rb +9 -2
  13. data/lib/dao/errors.rb +15 -11
  14. data/lib/dao/form.rb +46 -37
  15. data/lib/dao/interface.rb +1 -1
  16. data/lib/dao/mode.rb +45 -20
  17. data/lib/dao/params.rb +35 -53
  18. data/lib/dao/path.rb +6 -9
  19. data/lib/dao/rails/lib/generators/dao/templates/api.rb +1 -1
  20. data/lib/dao/rails/lib/generators/dao/templates/dao_helper.rb +16 -0
  21. data/lib/dao/result.rb +26 -133
  22. data/lib/dao/route.rb +87 -0
  23. data/lib/dao/status.rb +96 -94
  24. data/lib/dao/support.rb +5 -3
  25. data/lib/dao/validations.rb +46 -442
  26. data/lib/dao/validations/base.rb +68 -0
  27. data/lib/dao/validations/common.rb +463 -0
  28. data/test/dao_test.rb +214 -33
  29. metadata +20 -112
  30. data/lib/dao/rails/app/api.rb +0 -55
  31. data/lib/dao/rails/app/controllers/api_controller.rb +0 -99
  32. data/sample/rails_app/Gemfile +0 -33
  33. data/sample/rails_app/Gemfile.lock +0 -88
  34. data/sample/rails_app/README +0 -1
  35. data/sample/rails_app/Rakefile +0 -7
  36. data/sample/rails_app/app/api.rb +0 -55
  37. data/sample/rails_app/app/controllers/api_controller.rb +0 -99
  38. data/sample/rails_app/app/controllers/application_controller.rb +0 -3
  39. data/sample/rails_app/app/helpers/application_helper.rb +0 -2
  40. data/sample/rails_app/app/views/layouts/application.html.erb +0 -14
  41. data/sample/rails_app/config.ru +0 -4
  42. data/sample/rails_app/config/application.rb +0 -51
  43. data/sample/rails_app/config/boot.rb +0 -13
  44. data/sample/rails_app/config/database.yml +0 -22
  45. data/sample/rails_app/config/environment.rb +0 -5
  46. data/sample/rails_app/config/environments/development.rb +0 -26
  47. data/sample/rails_app/config/environments/production.rb +0 -49
  48. data/sample/rails_app/config/environments/test.rb +0 -35
  49. data/sample/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  50. data/sample/rails_app/config/initializers/inflections.rb +0 -10
  51. data/sample/rails_app/config/initializers/mime_types.rb +0 -5
  52. data/sample/rails_app/config/initializers/secret_token.rb +0 -7
  53. data/sample/rails_app/config/initializers/session_store.rb +0 -8
  54. data/sample/rails_app/config/locales/en.yml +0 -5
  55. data/sample/rails_app/config/routes.rb +0 -62
  56. data/sample/rails_app/db/development.sqlite3 +0 -0
  57. data/sample/rails_app/db/seeds.rb +0 -7
  58. data/sample/rails_app/doc/README_FOR_APP +0 -2
  59. data/sample/rails_app/log/development.log +0 -27
  60. data/sample/rails_app/log/production.log +0 -0
  61. data/sample/rails_app/log/server.log +0 -0
  62. data/sample/rails_app/log/test.log +0 -0
  63. data/sample/rails_app/pubic/javascripts/dao.js +0 -148
  64. data/sample/rails_app/public/404.html +0 -26
  65. data/sample/rails_app/public/422.html +0 -26
  66. data/sample/rails_app/public/500.html +0 -26
  67. data/sample/rails_app/public/favicon.ico +0 -0
  68. data/sample/rails_app/public/images/rails.png +0 -0
  69. data/sample/rails_app/public/index.html +0 -239
  70. data/sample/rails_app/public/javascripts/application.js +0 -2
  71. data/sample/rails_app/public/javascripts/controls.js +0 -965
  72. data/sample/rails_app/public/javascripts/dragdrop.js +0 -974
  73. data/sample/rails_app/public/javascripts/effects.js +0 -1123
  74. data/sample/rails_app/public/javascripts/prototype.js +0 -6001
  75. data/sample/rails_app/public/javascripts/rails.js +0 -175
  76. data/sample/rails_app/public/robots.txt +0 -5
  77. data/sample/rails_app/script/rails +0 -6
  78. data/sample/rails_app/test/performance/browsing_test.rb +0 -9
  79. data/sample/rails_app/test/test_helper.rb +0 -13
@@ -8,7 +8,7 @@ require File.join(testdir, 'helper')
8
8
 
9
9
 
10
10
  Testing Dao do
11
- # api
11
+ ## api
12
12
  #
13
13
  testing 'that an api class for your application can be built using a simple dsl' do
14
14
  assert{
@@ -53,15 +53,101 @@ Testing Dao do
53
53
  assert{ result.path.to_s =~ /foo/ }
54
54
  end
55
55
 
56
- # results
56
+ testing 'that an api can be called with different modes' do
57
+ api_class =
58
+ assert{
59
+ Dao.api do
60
+ call(:foo) do
61
+ data.modes = []
62
+
63
+ Dao::Mode.list.each do |mode|
64
+ send(mode){ data.modes.push(mode) }
65
+ end
66
+ end
67
+ end
68
+ }
69
+ api = assert{ api_class.new }
70
+
71
+ Dao::Mode.list.each do |mode|
72
+ result = api.mode(mode).call(:foo)
73
+ assert{ result.data.modes.include?(mode) }
74
+ end
75
+ end
76
+
77
+ testing 'that options/head/get are considered read modes' do
78
+ read_mode = assert{ Dao::Mode.read }
79
+
80
+ api_class =
81
+ assert{
82
+ Dao.api do
83
+ call(:foo) do
84
+ data.update :modes => []
85
+ read { data.modes.push(read_mode) }
86
+ end
87
+ end
88
+ }
89
+ api = assert{ api_class.new }
90
+
91
+ Dao::Mode::Read.each do |mode|
92
+ result = assert{ api.mode(mode).call(:foo) }
93
+ assert{ result.data.modes == [read_mode] }
94
+ end
95
+ end
96
+
97
+ testing 'that post/put/delete/trace/connect are considered write modes' do
98
+ write_mode = assert{ Dao::Mode.write }
99
+
100
+ api_class =
101
+ assert{
102
+ Dao.api do
103
+ call(:foo) do
104
+ data.update :modes => []
105
+ write { data.modes.push(write_mode) }
106
+ end
107
+ end
108
+ }
109
+ api = assert{ api_class.new }
110
+
111
+ Dao::Mode::Write.each do |mode|
112
+ result = assert{ api.mode(mode).call(:foo) }
113
+ assert{ result.data.modes == [write_mode] }
114
+ end
115
+ end
116
+
117
+ testing 'that the first, most specific, mode block encountered fires first' do
118
+ api_class =
119
+ assert{
120
+ Dao.api do
121
+ call(:foo) do
122
+ data.update :modes => []
123
+ Dao::Mode::Read.each do |mode|
124
+ send(mode){ data.modes.push(mode) }
125
+ end
126
+ read { data.modes.push(Dao::Mode.read) }
127
+ end
128
+ end
129
+ }
130
+ api = assert{ api_class.new }
131
+
132
+ read = Dao::Mode.read
133
+ result = assert{ api.mode(read).call(:foo) }
134
+ assert{ result.data.modes == [read] }
135
+
136
+ Dao::Mode::Read.each do |mode|
137
+ result = assert{ api.mode(mode).call(:foo) }
138
+ assert{ result.data.modes == [mode] }
139
+ end
140
+ end
141
+
142
+ ## results
57
143
  #
58
144
  testing 'that results can be created' do
59
145
  result = assert{ Dao::Result.new }
60
146
  assert{ result.path }
61
147
  assert{ result.status }
62
- assert{ result.data }
63
148
  assert{ result.errors }
64
- assert{ result.validations }
149
+ assert{ result.params }
150
+ assert{ result.data }
65
151
  end
66
152
 
67
153
  testing 'that results can be created with a path' do
@@ -80,7 +166,54 @@ Testing Dao do
80
166
  assert{ path.pattern.is_a?(Regexp) }
81
167
  end
82
168
 
83
- # status
169
+ ## routes
170
+ #
171
+ testing 'that an api has a list of routes' do
172
+ api_class =
173
+ assert{
174
+ Dao.api do
175
+ end
176
+ }
177
+ assert{ api_class.routes.is_a?(Array) }
178
+ end
179
+
180
+ testing 'that routed interfaces call be declared' do
181
+ api_class =
182
+ assert{
183
+ Dao.api do
184
+ call('/users/:user_id/comments/:comment_id') do
185
+ data.update(params)
186
+ end
187
+ end
188
+ }
189
+ api = api_class.new
190
+ end
191
+
192
+ testing 'that routed methods can be called with embedded params' do
193
+ api_class =
194
+ assert{
195
+ Dao.api do
196
+ call('/users/:user_id/comments/:comment_id') do
197
+ data.update(params)
198
+ end
199
+ end
200
+ }
201
+ api = api_class.new
202
+
203
+ {
204
+ '/users/4/comments/2' => {},
205
+ #'/users/comments' => {:user_id => 4, :comment_id => 2},
206
+ '/users/:user_id/comments/:comment_id' => {:user_id => 4, :comment_id => 2},
207
+ }.each do |path, params|
208
+ result = assert{ api.call(path, params) }
209
+ assert{ result.data.user_id.to_s =~ /4/ }
210
+ assert{ result.data.comment_id.to_s =~ /2/ }
211
+ assert{ result.path == '/users/4/comments/2' }
212
+ end
213
+ end
214
+
215
+
216
+ ## status
84
217
  #
85
218
  testing 'Status.for' do
86
219
  assert{ Dao::Status.for(:unauthorized).code == 401 }
@@ -100,7 +233,7 @@ Testing Dao do
100
233
  assert{ s != Array.new }
101
234
  end
102
235
 
103
- # parser
236
+ ## parser
104
237
  #
105
238
  testing 'parsing a simple hash by key' do
106
239
  params = {
@@ -136,7 +269,7 @@ Testing Dao do
136
269
  assert{
137
270
  api_class =
138
271
  Dao.api do
139
- interface('/foobar'){
272
+ call('/foobar'){
140
273
  data.update(params)
141
274
  }
142
275
  end
@@ -205,7 +338,7 @@ Testing Dao do
205
338
  assert{ parsed =~ expected }
206
339
  end
207
340
 
208
- # errors.rb
341
+ ## errors
209
342
  #
210
343
  testing 'that clear does not drop sticky errors' do
211
344
  errors = Dao::Errors.new
@@ -235,13 +368,13 @@ Testing Dao do
235
368
  assert{ errors[global].nil? }
236
369
  end
237
370
 
238
- # validations
371
+ ## validations
239
372
  #
240
373
  testing 'that simple validations work' do
241
- result = Dao::Result.new
242
- assert{ result.validates(:password){|password| password=='haxor'} }
243
- result.data.set(:password, 'haxor')
244
- assert{ result.valid? }
374
+ params = Dao::Params.new
375
+ assert{ params.validates(:password){|password| password=='haxor'} }
376
+ params.set(:password, 'haxor')
377
+ assert{ params.valid? }
245
378
  end
246
379
 
247
380
  testing 'that validations have some syntax sugar' do
@@ -249,38 +382,81 @@ Testing Dao do
249
382
  api_class =
250
383
  Dao.api do
251
384
  interface('/foobar'){
252
- result.validates(:a)
253
- params.validate(:b)
254
- validates(:c)
385
+ params.validate(:a)
386
+ validates(:b)
387
+ validate!
255
388
  }
256
389
  end
257
390
  api = api_class.new
258
391
 
259
- result = assert{ api.call('/foobar', 'a' => true, 'b' => true, 'c' => true) }
392
+ result = assert{ api.call('/foobar', 'a' => true, 'b' => true) }
393
+ assert{ result.status.ok? }
394
+
395
+ result = assert{ api.call('/foobar') }
396
+ assert{ !result.status.ok? }
397
+ assert{ result.errors.size==2 }
260
398
  }
261
399
  end
262
400
 
263
- # validating
401
+ testing 'that validations use instance_exec' do
402
+ a, b = nil
403
+
404
+ api_class =
405
+ Dao.api do
406
+ interface('/foobar'){
407
+ params.validate(:a){ b = get(:b) }
408
+ params.validate(:b){ a = get(:a) }
409
+ validate!
410
+ }
411
+ end
412
+ api = api_class.new
413
+
414
+ result = assert{ api.call('/foobar', 'a' => 40, 'b' => 2) }
415
+ assert{ result.status.ok? }
416
+ assert{ a == 40 }
417
+ assert{ b == 2 }
418
+ end
419
+
420
+ testing 'simple validates_confirmation_of' do
421
+ api_class =
422
+ Dao.api do
423
+ interface('/foobar'){
424
+ params.validates_as_email(:email)
425
+ params.validates_confirmation_of(:email)
426
+ validate!
427
+ }
428
+ end
429
+ api = api_class.new
430
+
431
+ result = assert{ api.call('/foobar', 'email' => 'ara.t.howard@gmail.com', 'email_confirmation' => 'ara.t.howard@gmail.com') }
432
+ assert{ result.status.ok? }
433
+ assert{ result.errors.empty? }
434
+
435
+ result = assert{ api.call('/foobar', 'email' => 'ara.t.howard@gmail.com', 'email_confirmation' => 'ara@dojo4.com') }
436
+ assert{ !result.status.ok? }
437
+ assert{ !result.errors.empty? }
438
+ end
439
+
440
+ ## validating
264
441
  #
265
442
  testing 'that validations can be cleared and do not clobber manually added errors' do
266
- result = Dao::Result.new
267
- data = result.data
268
- errors = result.errors
443
+ params = Dao::Params.new
444
+ errors = params.errors
269
445
 
270
- assert{ result.validates(:email){|email| email.to_s.split(/@/).size == 2} }
271
- assert{ result.validates(:password){|password| password == 'pa$$w0rd'} }
446
+ assert{ params.validates(:email){|email| email.to_s.split(/@/).size == 2} }
447
+ assert{ params.validates(:password){|password| password == 'pa$$w0rd'} }
272
448
 
273
- data.set(:email => 'ara@dojo4.com', :password => 'pa$$w0rd')
274
- assert{ result.valid? }
449
+ params.set(:email => 'ara@dojo4.com', :password => 'pa$$w0rd')
450
+ assert{ params.valid? }
275
451
 
276
- data.set(:password => 'haxor')
277
- assert{ !result.valid?(:validate => true) }
452
+ params.set(:password => 'haxor')
453
+ assert{ !params.valid?(:validate => true) }
278
454
 
279
455
  errors.add(:name, 'ara')
280
- assert{ not result.valid? }
456
+ assert{ not params.valid? }
281
457
  end
282
458
 
283
- # doc
459
+ ## doc
284
460
  #
285
461
  testing 'that apis can be documented via the api' do
286
462
  api_class =
@@ -318,8 +494,13 @@ Testing Dao do
318
494
 
319
495
  =end
320
496
 
321
- def hash_equal(a, b)
322
- array = lambda{|h| h.to_a.map{|k,v| [k.to_s, v]}.sort}
323
- array[a] == array[b]
324
- end
497
+ def hash_equal(a, b)
498
+ array = lambda{|h| h.to_a.map{|k,v| [k.to_s, v]}.sort}
499
+ array[a] == array[b]
500
+ end
501
+
502
+ def api(&block)
503
+ api_class = assert{ Dao.api(&block) }
504
+ api = assert{ api_class.new }
505
+ end
325
506
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dao
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
- - 2
8
- - 2
9
7
  - 3
10
- version: 2.2.3
8
+ - 1
9
+ - 0
10
+ version: 3.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ara T. Howard
@@ -15,57 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-15 00:00:00 -06:00
18
+ date: 2011-05-17 00:00:00 -06:00
19
19
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: tagz
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 87
30
- segments:
31
- - 8
32
- - 2
33
- - 0
34
- version: 8.2.0
35
- type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: map
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 19
46
- segments:
47
- - 2
48
- - 7
49
- - 0
50
- version: 2.7.0
51
- type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: yajl-ruby
55
- prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 61
62
- segments:
63
- - 0
64
- - 8
65
- - 1
66
- version: 0.8.1
67
- type: :runtime
68
- version_requirements: *id003
20
+ dependencies: []
21
+
69
22
  description: "description: dao kicks the ass"
70
23
  email: ara.t.howard@gmail.com
71
24
  executables: []
@@ -75,15 +28,21 @@ extensions: []
75
28
  extra_rdoc_files: []
76
29
 
77
30
  files:
31
+ - README
32
+ - Rakefile
33
+ - TODO
34
+ - a.rb
78
35
  - dao.gemspec
36
+ - lib/dao.rb
79
37
  - lib/dao/active_record.rb
38
+ - lib/dao/api.rb
80
39
  - lib/dao/api/context.rb
81
40
  - lib/dao/api/dsl.rb
82
41
  - lib/dao/api/endpoints.rb
83
42
  - lib/dao/api/initializers.rb
84
43
  - lib/dao/api/interfaces.rb
85
44
  - lib/dao/api/modes.rb
86
- - lib/dao/api.rb
45
+ - lib/dao/api/routes.rb
87
46
  - lib/dao/blankslate.rb
88
47
  - lib/dao/data.rb
89
48
  - lib/dao/db.rb
@@ -99,8 +58,8 @@ files:
99
58
  - lib/dao/params.rb
100
59
  - lib/dao/path.rb
101
60
  - lib/dao/presenter.rb
102
- - lib/dao/rails/app/api.rb
103
- - lib/dao/rails/app/controllers/api_controller.rb
61
+ - lib/dao/rails.rb
62
+ - lib/dao/rails/lib/generators/dao/USAGE
104
63
  - lib/dao/rails/lib/generators/dao/api_generator.rb
105
64
  - lib/dao/rails/lib/generators/dao/dao_generator.rb
106
65
  - lib/dao/rails/lib/generators/dao/templates/api.rb
@@ -108,71 +67,20 @@ files:
108
67
  - lib/dao/rails/lib/generators/dao/templates/dao.css
109
68
  - lib/dao/rails/lib/generators/dao/templates/dao.js
110
69
  - lib/dao/rails/lib/generators/dao/templates/dao_helper.rb
111
- - lib/dao/rails/lib/generators/dao/USAGE
112
- - lib/dao/rails.rb
113
70
  - lib/dao/result.rb
71
+ - lib/dao/route.rb
114
72
  - lib/dao/slug.rb
115
73
  - lib/dao/status.rb
116
74
  - lib/dao/stdext.rb
117
75
  - lib/dao/support.rb
118
76
  - lib/dao/validations.rb
119
- - lib/dao.rb
120
- - Rakefile
121
- - README
122
- - sample/rails_app/app/api.rb
123
- - sample/rails_app/app/controllers/api_controller.rb
124
- - sample/rails_app/app/controllers/application_controller.rb
125
- - sample/rails_app/app/helpers/application_helper.rb
126
- - sample/rails_app/app/views/layouts/application.html.erb
127
- - sample/rails_app/config/application.rb
128
- - sample/rails_app/config/boot.rb
129
- - sample/rails_app/config/database.yml
130
- - sample/rails_app/config/environment.rb
131
- - sample/rails_app/config/environments/development.rb
132
- - sample/rails_app/config/environments/production.rb
133
- - sample/rails_app/config/environments/test.rb
134
- - sample/rails_app/config/initializers/backtrace_silencers.rb
135
- - sample/rails_app/config/initializers/inflections.rb
136
- - sample/rails_app/config/initializers/mime_types.rb
137
- - sample/rails_app/config/initializers/secret_token.rb
138
- - sample/rails_app/config/initializers/session_store.rb
139
- - sample/rails_app/config/locales/en.yml
140
- - sample/rails_app/config/routes.rb
141
- - sample/rails_app/config.ru
142
- - sample/rails_app/db/development.sqlite3
143
- - sample/rails_app/db/seeds.rb
144
- - sample/rails_app/doc/README_FOR_APP
145
- - sample/rails_app/Gemfile
146
- - sample/rails_app/Gemfile.lock
147
- - sample/rails_app/log/development.log
148
- - sample/rails_app/log/production.log
149
- - sample/rails_app/log/server.log
150
- - sample/rails_app/log/test.log
151
- - sample/rails_app/pubic/javascripts/dao.js
152
- - sample/rails_app/public/404.html
153
- - sample/rails_app/public/422.html
154
- - sample/rails_app/public/500.html
155
- - sample/rails_app/public/favicon.ico
156
- - sample/rails_app/public/images/rails.png
157
- - sample/rails_app/public/index.html
158
- - sample/rails_app/public/javascripts/application.js
159
- - sample/rails_app/public/javascripts/controls.js
160
- - sample/rails_app/public/javascripts/dragdrop.js
161
- - sample/rails_app/public/javascripts/effects.js
162
- - sample/rails_app/public/javascripts/prototype.js
163
- - sample/rails_app/public/javascripts/rails.js
164
- - sample/rails_app/public/robots.txt
165
- - sample/rails_app/Rakefile
166
- - sample/rails_app/README
167
- - sample/rails_app/script/rails
168
- - sample/rails_app/test/performance/browsing_test.rb
169
- - sample/rails_app/test/test_helper.rb
77
+ - lib/dao/validations/base.rb
78
+ - lib/dao/validations/common.rb
170
79
  - test/dao_test.rb
171
80
  - test/helper.rb
172
81
  - test/testing.rb
173
- - TODO
174
82
  has_rdoc: true
175
- homepage: http://github.com/ahoward/dao
83
+ homepage: https://github.com/ahoward/dao
176
84
  licenses: []
177
85
 
178
86
  post_install_message: