dao 5.6.1 → 7.0.0

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.
@@ -1,20 +1,12 @@
1
1
  # -*- encoding : utf-8 -*-
2
- class LintTest < ActiveModel::TestCase
2
+ require './test/test_helper'
3
+ class LintTest < Dao::TestCase
3
4
  include ActiveModel::Lint::Tests
4
5
 
5
6
  class LintConducer < Dao::Conducer; end
6
-
7
+
7
8
  def setup
8
9
  @model = LintConducer.new
9
10
  end
10
11
  end
11
12
 
12
-
13
- BEGIN {
14
- testdir = File.dirname(File.expand_path(__FILE__))
15
- rootdir = File.dirname(testdir)
16
- libdir = File.join(rootdir, 'lib')
17
-
18
- require File.join(libdir, 'dao')
19
- require File.join(testdir, 'testing')
20
- }
@@ -1,19 +1,18 @@
1
1
  # -*- encoding : utf-8 -*-
2
+ require_relative 'test_helper'
2
3
 
3
-
4
- Testing Dao do
4
+ class DaoTest < ::Dao::TestCase
5
5
  ## api
6
6
  #
7
- testing 'that an api class for your application can be built using a simple dsl' do
7
+ test 'that an api class for your application can be built using a simple dsl' do
8
8
  assert{
9
- api_class =
10
- Dao.api do
11
- ### dsl
12
- end
9
+ Dao.api do
10
+ ### dsl
11
+ end
13
12
  }
14
13
  end
15
14
 
16
- testing 'that apis can have callable endpoints added to them which accept params and return results' do
15
+ test 'that apis can have callable endpoints added to them which accept params and return results' do
17
16
  captured = []
18
17
 
19
18
  api_class =
@@ -29,7 +28,7 @@ Testing Dao do
29
28
  assert{ result.is_a?(Hash) }
30
29
  end
31
30
 
32
- testing 'that endpoints are automatically called according to arity' do
31
+ test 'that endpoints are automatically called according to arity' do
33
32
  api = assert{ Class.new(Dao.api) }
34
33
  assert{ api.class_eval{ endpoint(:zero){|| result.update :args => [] } } }
35
34
  assert{ api.class_eval{ endpoint(:one){|a| result.update :args => [a]} } }
@@ -40,14 +39,14 @@ Testing Dao do
40
39
  assert{ api.new.call(:two).args.size == 2 }
41
40
  end
42
41
 
43
- testing 'that endpoints have an auto-vivifying params/result' do
42
+ test 'that endpoints have an auto-vivifying params/result' do
44
43
  api = assert{ Class.new(Dao.api) }
45
44
  assert{ api.class_eval{ endpoint(:foo){ params; result; } } }
46
45
  result = assert{ api.new.call(:foo) }
47
46
  assert{ result.path.to_s =~ /foo/ }
48
47
  end
49
48
 
50
- testing 'that an api can be called with different modes' do
49
+ test 'that an api can be called with different modes' do
51
50
  Dao::Mode.list.each do |mode|
52
51
  api_class =
53
52
  assert{
@@ -63,7 +62,7 @@ Testing Dao do
63
62
  end
64
63
  end
65
64
 
66
- testing 'that read==get' do
65
+ test 'that read==get' do
67
66
  api_class =
68
67
  assert{
69
68
  Dao.api do
@@ -85,7 +84,7 @@ Testing Dao do
85
84
  assert{ api.get.call(:bar).data.answer == 42.0 }
86
85
  end
87
86
 
88
- testing 'that write==post' do
87
+ test 'that write==post' do
89
88
  api_class =
90
89
  assert{
91
90
  Dao.api do
@@ -107,7 +106,7 @@ Testing Dao do
107
106
  assert{ api.post.call(:bar).data.answer == 42.0 }
108
107
  end
109
108
 
110
- testing 'that aliases are re-defined in scope' do
109
+ test 'that aliases are re-defined in scope' do
111
110
  api_class =
112
111
  assert{
113
112
  Dao.api do
@@ -149,7 +148,7 @@ Testing Dao do
149
148
 
150
149
  ## context
151
150
  #
152
- testing 'that calls have a shortcut to status' do
151
+ test 'that calls have a shortcut to status' do
153
152
  api_class =
154
153
  assert{
155
154
  Dao.api do
@@ -163,7 +162,7 @@ Testing Dao do
163
162
 
164
163
  ## results
165
164
  #
166
- testing 'that results can be created' do
165
+ test 'that results can be created' do
167
166
  result = assert{ Dao::Result.new }
168
167
  assert{ result.path }
169
168
  assert{ result.status }
@@ -172,14 +171,14 @@ Testing Dao do
172
171
  assert{ result.data }
173
172
  end
174
173
 
175
- testing 'that results can be created with a path' do
174
+ test 'that results can be created with a path' do
176
175
  result = assert{ Dao::Result.new('/api/foo/bar') }
177
176
  assert{ result.path == '/api/foo/bar' }
178
177
  end
179
178
 
180
179
  ## paths
181
180
  #
182
- testing 'that simple paths can be contstructed/compiled' do
181
+ test 'that simple paths can be contstructed/compiled' do
183
182
  path = assert{ Dao::Path.for('./api/../foo/bar') }
184
183
  assert{ path =~ %r|^/| }
185
184
  assert{ path !~ %r|[.]| }
@@ -190,7 +189,7 @@ Testing Dao do
190
189
 
191
190
  ## routes
192
191
  #
193
- testing 'that an api has a list of routes' do
192
+ test 'that an api has a list of routes' do
194
193
  api_class =
195
194
  assert{
196
195
  Dao.api do
@@ -199,7 +198,7 @@ Testing Dao do
199
198
  assert{ api_class.routes.is_a?(Array) }
200
199
  end
201
200
 
202
- testing 'that routed endpoints call be declared' do
201
+ test 'that routed endpoints call be declared' do
203
202
  api_class =
204
203
  assert{
205
204
  Dao.api do
@@ -208,10 +207,10 @@ Testing Dao do
208
207
  end
209
208
  end
210
209
  }
211
- api = api_class.new
210
+ api_class.new
212
211
  end
213
212
 
214
- testing 'that routed methods can be called with embedded params' do
213
+ test 'that routed methods can be called with embedded params' do
215
214
  api_class =
216
215
  assert{
217
216
  Dao.api do
@@ -236,7 +235,7 @@ Testing Dao do
236
235
 
237
236
  ## doc
238
237
  #
239
- testing 'that apis can be documented via the api' do
238
+ test 'that apis can be documented via the api' do
240
239
  api_class =
241
240
  assert {
242
241
  Dao.api {
@@ -253,7 +252,7 @@ Testing Dao do
253
252
 
254
253
  # aliases
255
254
  #
256
- testing 'that apis can alias methods' do
255
+ test 'that apis can alias methods' do
257
256
  api_class =
258
257
  assert {
259
258
  Dao.api {
@@ -274,17 +273,7 @@ protected
274
273
 
275
274
  def api(&block)
276
275
  api_class = assert{ Dao.api(&block) }
277
- api = assert{ api_class.new }
276
+ assert{ api_class.new }
278
277
  end
279
278
  end
280
279
 
281
-
282
- BEGIN {
283
- testdir = File.dirname(File.expand_path(__FILE__))
284
- rootdir = File.dirname(testdir)
285
- libdir = File.join(rootdir, 'lib')
286
-
287
- require File.join(libdir, 'dao')
288
- require File.join(testdir, 'testing')
289
- require File.join(testdir, 'helper')
290
- }
@@ -1,12 +1,12 @@
1
1
  # -*- encoding : utf-8 -*-
2
+ require_relative 'test_helper'
2
3
 
3
-
4
- Testing Dao::Conducer do
4
+ class Dao::ConducerTest < Dao::TestCase
5
5
  ##
6
6
  #
7
7
  context :teh_ctor do
8
8
  #
9
- testing 'conducers have a POLS .new method' do
9
+ test 'conducers have a POLS .new method' do
10
10
  [
11
11
  {:key => :val, :array => [0,1,2]},
12
12
  {}
@@ -17,7 +17,7 @@ Testing Dao::Conducer do
17
17
  end
18
18
 
19
19
  #
20
- testing 'models passed to .new are automatically tracked' do
20
+ test 'models passed to .new are automatically tracked' do
21
21
  user = User.new
22
22
  post = Post.new
23
23
  comment = Comment.new
@@ -33,7 +33,7 @@ Testing Dao::Conducer do
33
33
  end
34
34
 
35
35
  #
36
- testing 'that the conduced model can be declared at the class level' do
36
+ test 'that the conduced model can be declared at the class level' do
37
37
  user = User.new
38
38
  post = Post.new
39
39
  comment = Comment.new
@@ -49,7 +49,7 @@ Testing Dao::Conducer do
49
49
  end
50
50
 
51
51
  #
52
- testing 'that the conduced model can be declared at the instance level' do
52
+ test 'that the conduced model can be declared at the instance level' do
53
53
  user = User.new
54
54
  post = Post.new
55
55
  comment = Comment.new
@@ -71,7 +71,7 @@ Testing Dao::Conducer do
71
71
  #
72
72
  context :teh_default_initialize do
73
73
  #
74
- testing 'that the last mode determines the lifecycle state when a models are passed in' do
74
+ test 'that the last mode determines the lifecycle state when a models are passed in' do
75
75
  user = User.new
76
76
  post = Post.new
77
77
  comment = Comment.new
@@ -92,7 +92,7 @@ Testing Dao::Conducer do
92
92
  end
93
93
 
94
94
  #
95
- testing 'that passed in models/params are sanely ker-sploded onto the attributes' do
95
+ test 'that passed in models/params are sanely ker-sploded onto the attributes' do
96
96
  user = User.new :k => 1
97
97
  post = Post.new :k => 2
98
98
  comment = Comment.new :k => 3, :x => 4
@@ -119,7 +119,7 @@ Testing Dao::Conducer do
119
119
  end
120
120
 
121
121
  #
122
- testing 'that .new specialises based on current action' do
122
+ test 'that .new specialises based on current action' do
123
123
  conducer_class =
124
124
  new_conducer_class do
125
125
  def initialize_for_new
@@ -145,7 +145,7 @@ Testing Dao::Conducer do
145
145
  end
146
146
 
147
147
  #
148
- testing 'that conducers can build a highly specialized .new method based on action' do
148
+ test 'that conducers can build a highly specialized .new method based on action' do
149
149
  c =
150
150
  new_conducer_class do
151
151
  def initialize(a, b, c, params)
@@ -181,7 +181,7 @@ Testing Dao::Conducer do
181
181
  end
182
182
 
183
183
  #
184
- testing 'that conducers *fold* in attributes' do
184
+ test 'that conducers *fold* in attributes' do
185
185
  c = new_conducer
186
186
 
187
187
  assert{ c.update_attributes :key => {:a => :b} }
@@ -193,7 +193,7 @@ Testing Dao::Conducer do
193
193
  #
194
194
  context :teh_default_save do
195
195
  #
196
- testing 'is sane and based solely on the last model' do
196
+ test 'is sane and based solely on the last model' do
197
197
  user = User.new
198
198
  post = Post.new
199
199
  comment = Comment.new
@@ -211,7 +211,7 @@ Testing Dao::Conducer do
211
211
  end
212
212
 
213
213
  #
214
- testing 'halts when the conducer is invalid with errors' do
214
+ test 'halts when the conducer is invalid with errors' do
215
215
  conducer_class =
216
216
  new_conducer_class do
217
217
  validates_presence_of(:foo)
@@ -225,7 +225,7 @@ Testing Dao::Conducer do
225
225
  end
226
226
 
227
227
  #
228
- testing 'halts when the model is invalid and relays errors' do
228
+ test 'halts when the model is invalid and relays errors' do
229
229
  post = Post.new
230
230
  post.errors[:foo] = 'is fucked'
231
231
  c = new_conducer(post)
@@ -234,7 +234,7 @@ Testing Dao::Conducer do
234
234
  end
235
235
 
236
236
  #
237
- testing 'raises a validation error on #save!' do
237
+ test 'raises a validation error on #save!' do
238
238
  post = Post.new
239
239
  post.errors[:foo] = 'is fucked'
240
240
  c = new_conducer(post)
@@ -251,7 +251,7 @@ Testing Dao::Conducer do
251
251
  #
252
252
  context :validations do
253
253
  #
254
- testing 'that simple validations/errors work' do
254
+ test 'that simple validations/errors work' do
255
255
  c =
256
256
  assert{
257
257
  new_foo_conducer_class do
@@ -276,7 +276,7 @@ Testing Dao::Conducer do
276
276
  end
277
277
 
278
278
  #
279
- testing 'that validations are evaluated in the context of the object' do
279
+ test 'that validations are evaluated in the context of the object' do
280
280
  c =
281
281
  assert{
282
282
  new_foo_conducer_class do
@@ -296,7 +296,7 @@ Testing Dao::Conducer do
296
296
  end
297
297
 
298
298
  #
299
- testing 'that validates_each werks at the class and instance level' do
299
+ test 'that validates_each werks at the class and instance level' do
300
300
  conducer_class =
301
301
  new_conducer_class do
302
302
  validates_each :a do |item|
@@ -335,7 +335,7 @@ Testing Dao::Conducer do
335
335
  #
336
336
  context :forms do
337
337
  #
338
- testing 'that basic form helpers work' do
338
+ test 'that basic form helpers work' do
339
339
  c =
340
340
  assert{
341
341
  new_foo_conducer_class do
@@ -357,12 +357,12 @@ Testing Dao::Conducer do
357
357
  #
358
358
  context :class_methods do
359
359
  #
360
- testing 'that base classes can be constructed and named' do
360
+ test 'that base classes can be constructed and named' do
361
361
  new_foo_conducer_class()
362
362
  end
363
363
 
364
364
  #
365
- testing '.new' do
365
+ test '.new' do
366
366
  c = assert{ new_foo_conducer_class }
367
367
  controller = assert{ Dao.mock_controller }
368
368
 
@@ -386,7 +386,7 @@ Testing Dao::Conducer do
386
386
  end
387
387
 
388
388
  #
389
- testing '.model_name' do
389
+ test '.model_name' do
390
390
  c = assert{ new_foo_conducer_class }
391
391
  assert{ c.model_name }
392
392
  o = assert{ c.new }
@@ -397,7 +397,7 @@ Testing Dao::Conducer do
397
397
  ##
398
398
  #
399
399
  context :instance_methods do
400
- testing '#id' do
400
+ test '#id' do
401
401
  [:_id, :id].each do |id_key|
402
402
  o = assert{ new_foo_conducer() }
403
403
  assert{ o.id.nil? }
@@ -410,20 +410,20 @@ Testing Dao::Conducer do
410
410
  end
411
411
  end
412
412
 
413
- testing '#to_param' do
413
+ test '#to_param' do
414
414
  o = assert{ new_foo_conducer() }
415
415
  assert{ o.to_param.nil? }
416
416
  o.id = 42
417
417
  assert{ o.to_param }
418
418
  end
419
419
 
420
- testing '#errors' do
420
+ test '#errors' do
421
421
  o = assert{ new_foo_conducer() }
422
422
  assert{ o.errors.respond_to?(:[]) }
423
423
  end
424
424
 
425
425
  =begin
426
- testing 'that conducers can register handlers for setting deeply nested attributes' do
426
+ test 'that conducers can register handlers for setting deeply nested attributes' do
427
427
  c =
428
428
  new_conducer_class do
429
429
  def _update_attributes(attributes = {})
@@ -454,7 +454,7 @@ Testing Dao::Conducer do
454
454
  #
455
455
  context :teh_mount do
456
456
  #
457
- testing 'that mounted objects can be declared at the class level' do
457
+ test 'that mounted objects can be declared at the class level' do
458
458
  conducer_class =
459
459
  new_conducer_class do
460
460
  mount Dao::Upload, :a, :b, :placeholder => '/images/foo.jpg'
@@ -470,7 +470,7 @@ Testing Dao::Conducer do
470
470
  end
471
471
 
472
472
  #
473
- testing 'that mounted objects replace their location in attributes' do
473
+ test 'that mounted objects replace their location in attributes' do
474
474
  conducer_class =
475
475
  new_conducer_class do
476
476
  mount Dao::Upload, :a, :b, :placeholder => '/images/foo.jpg'
@@ -488,7 +488,7 @@ Testing Dao::Conducer do
488
488
  end
489
489
 
490
490
  #
491
- testing 'that the default save uses the mounted _value and _clears it' do
491
+ test 'that the default save uses the mounted _value and _clears it' do
492
492
  begin
493
493
  $pry=true
494
494
  conducer_class =
@@ -525,7 +525,7 @@ end
525
525
  ##
526
526
  #
527
527
  context :collections do
528
- testing 'can be created from page-y blessed arrays' do
528
+ test 'can be created from page-y blessed arrays' do
529
529
  paginated = Paginated[Post.new, Post.new, Post.new]
530
530
  paginated.limit = 42
531
531
  paginated.offset = 42.0
@@ -551,7 +551,7 @@ end
551
551
  ##
552
552
  #
553
553
  context :callbacks do
554
- testing 'can be added lazily in an ad-hoc fashion' do
554
+ test 'can be added lazily in an ad-hoc fashion' do
555
555
  callbacks = []
556
556
 
557
557
  conducer_class =
@@ -602,7 +602,7 @@ protected
602
602
  end
603
603
  alias_method :new_conducer, :new_foo_conducer
604
604
 
605
- prepare do
605
+ def setup
606
606
  $db = Dao::Db.new(:path => 'test/db.yml')
607
607
  Dao::Db.instance = $db
608
608
  collection = $db['foos']
@@ -613,7 +613,7 @@ protected
613
613
  end
614
614
  end
615
615
 
616
- cleanup do
616
+ def teardown
617
617
  $db = Dao::Db.new(:path => 'test/db.yml')
618
618
  $db.rm_f
619
619
  end
@@ -758,13 +758,3 @@ protected
758
758
  class Comment < Model
759
759
  end
760
760
  end
761
-
762
-
763
- BEGIN {
764
- testdir = File.dirname(File.expand_path(__FILE__))
765
- rootdir = File.dirname(testdir)
766
- libdir = File.join(rootdir, 'lib')
767
- require File.join(libdir, 'dao')
768
- require File.join(testdir, 'testing')
769
- require 'stringio'
770
- }