public
Rubygem
Description: Makes tests easy on the fingers and the eyes
Homepage: http://www.thoughtbot.com/projects/shoulda
Clone URL: git://github.com/thoughtbot/shoulda.git
Revert bunch of bad commits:

2442d1f6087041c18a2124bce4ea8a19599cde0f
35213b5a1b84c58064d8a13b50716b29a205ebb4
804f859435a3ffa3012466a8c3f745fdc8b33965
fc938bb18557c1f5a801e3e2a15c9e4e9f8f03db

Getting the following error when running tests in a real project:

  ...activesupport/lib/active_support/dependencies.rb:276:in 
  `load_missing_constant': uninitialized constant 
  Shoulda::ActiveRecord::Base (NameError)

Think this is because of the namespace changes, but not sure.  Will 
investigate later.
tsaleh (author)
Mon Jun 23 09:36:31 -0700 2008
commit  b415bff884a3c25a058c2600f86da80d4fa28fde
tree    68163b7b5be0a08989a6894bf3db96e92710fe05
parent  2442d1f6087041c18a2124bce4ea8a19599cde0f
...
10
11
12
13
 
14
15
16
...
43
44
45
46
 
47
48
49
...
73
74
75
76
 
77
78
79
...
105
106
107
108
 
109
110
111
...
10
11
12
 
13
14
15
16
...
43
44
45
 
46
47
48
49
...
73
74
75
 
76
77
78
79
...
105
106
107
 
108
109
110
111
0
@@ -10,7 +10,7 @@ Assertions:: Many common rails testing idioms have been distilled into a set of
0
 
0
 = Usage
0
 
0
-=== Context Helpers (Shoulda::Context)
0
+=== Context Helpers (ThoughtBot::Shoulda::Context)
0
 
0
 Stop killing your fingers with all of those underscores... Name your tests with plain sentences!
0
 
0
@@ -43,7 +43,7 @@ Produces the following test methods:
0
 
0
 So readable!
0
 
0
-=== ActiveRecord Tests (Shoulda::ActiveRecord)
0
+=== ActiveRecord Tests (ThoughtBot::Shoulda::ActiveRecord)
0
 
0
 Quick macro tests for your ActiveRecord associations and validations:
0
 
0
@@ -73,7 +73,7 @@ Quick macro tests for your ActiveRecord associations and validations:
0
 
0
 Makes TDD so much easier.
0
 
0
-=== Controller Tests (Shoulda::Controller::ClassMethods)
0
+=== Controller Tests (ThoughtBot::Shoulda::Controller::ClassMethods)
0
 
0
 Macros to test the most common controller patterns...
0
 
0
@@ -105,7 +105,7 @@ Test entire controllers in a few lines...
0
 
0
 should_be_restful generates 40 tests on the fly, for both html and xml requests.
0
 
0
-=== Helpful Assertions (Shoulda::General)
0
+=== Helpful Assertions (ThoughtBot::Shoulda::General)
0
 
0
 More to come here, but have fun with what's there.
0
 
...
6
7
8
9
 
10
11
12
...
6
7
8
 
9
10
11
12
0
@@ -6,7 +6,7 @@ require 'rake/rdoctask'
0
 
0
 Rake::TestTask.new do |t|
0
   t.libs << 'lib'
0
- t.pattern = 'test/**/*_test.rb'
0
+ t.pattern = 'test/{unit,functional,other}/**/*_test.rb'
0
   t.verbose = false
0
 end
0
 
...
1
 
2
3
 
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
 
 
 
 
21
22
23
24
 
 
 
 
25
 
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
 
63
64
65
66
67
68
69
70
71
 
 
 
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
 
124
125
126
127
128
129
130
 
131
132
133
134
135
136
137
138
139
140
 
 
 
 
141
142
143
144
...
 
1
2
3
4
5
6
7
 
 
 
 
 
 
 
 
 
8
 
 
 
9
 
10
11
12
13
14
15
 
 
 
16
17
18
19
20
21
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
24
 
 
 
 
 
 
 
 
25
26
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30
31
 
 
 
 
 
 
32
33
34
35
36
 
 
 
 
 
 
37
38
39
40
41
42
43
 
0
@@ -1,144 +1,43 @@
0
-require 'shoulda/context'
0
+require 'shoulda/gem/shoulda'
0
 require 'shoulda/private_helpers'
0
 require 'shoulda/general'
0
+require 'shoulda/active_record_helpers'
0
+require 'shoulda/controller_tests/controller_tests.rb'
0
 require 'yaml'
0
 
0
-require 'shoulda/active_record_helpers' if defined?(ActiveRecord)
0
-require 'shoulda/controller_tests/controller_tests.rb' if defined?(ActionController)
0
-
0
-config_files = []
0
-config_files << "shoulda.conf"
0
-config_files << File.join("test", "shoulda.conf")
0
-config_files << File.join(RAILS_ROOT, "test", "shoulda.conf") if defined?(RAILS_ROOT)
0
-config_files << File.join(ENV["HOME"], ".shoulda.conf") if ENV["HOME"]
0
-
0
 shoulda_options = {}
0
-config_files.each do |file|
0
- shoulda_options.merge!(YAML.load_file(file).symbolize_keys) if File.exists? file
0
-end
0
 
0
-require 'shoulda/color' if shoulda_options[:color]
0
+possible_config_paths = []
0
+possible_config_paths << File.join(ENV["HOME"], ".shoulda.conf") if ENV["HOME"]
0
+possible_config_paths << "shoulda.conf"
0
+possible_config_paths << File.join("test", "shoulda.conf")
0
+possible_config_paths << File.join(RAILS_ROOT, "test", "shoulda.conf") if defined?(RAILS_ROOT)
0
 
0
-module Shoulda
0
- class << self
0
- attr_accessor :current_context
0
+possible_config_paths.each do |config_file|
0
+ if File.exists? config_file
0
+ shoulda_options = YAML.load_file(config_file).symbolize_keys
0
+ break
0
   end
0
+end
0
 
0
- # Should statements are just syntactic sugar over normal Test::Unit test methods. A should block
0
- # contains all the normal code and assertions you're used to seeing, with the added benefit that
0
- # they can be wrapped inside context blocks (see below).
0
- #
0
- # == Example:
0
- #
0
- # class UserTest << Test::Unit::TestCase
0
- #
0
- # def setup
0
- # @user = User.new("John", "Doe")
0
- # end
0
- #
0
- # should "return its full name"
0
- # assert_equal 'John Doe', @user.full_name
0
- # end
0
- #
0
- # end
0
- #
0
- # ...will produce the following test:
0
- # * <tt>"test: User should return its full name. "</tt>
0
- #
0
- # Note: The part before <tt>should</tt> in the test name is gleamed from the name of the Test::Unit class.
0
-
0
- def should(name, &blk)
0
- should_eventually(name) && return unless block_given?
0
-
0
- if Shoulda.current_context
0
- Shoulda.current_context.should(name, &blk)
0
- else
0
- context_name = self.name.gsub(/Test/, "")
0
- context = Shoulda::Context.new(context_name, self) do
0
- should(name, &blk)
0
- end
0
- context.build
0
- end
0
- end
0
+require 'shoulda/color' if shoulda_options[:color]
0
 
0
- # Just like should, but never runs, and instead prints a differed message in the Test::Unit output.
0
- def should_eventually(name, &blk)
0
- context_name = self.name.gsub(/Test/, "")
0
- context = Shoulda::Context.new(context_name, self) do
0
- should_eventually(name, &blk)
0
- end
0
- context.build
0
- end
0
+module Test # :nodoc: all
0
+ module Unit
0
+ class TestCase
0
 
0
- # A context block groups should statements under a common set of setup/teardown methods.
0
- # Context blocks can be arbitrarily nested, and can do wonders for improving the maintainability
0
- # and readability of your test code.
0
- #
0
- # A context block can contain setup, should, should_eventually, and teardown blocks.
0
- #
0
- # class UserTest << Test::Unit::TestCase
0
- # context "A User instance" do
0
- # setup do
0
- # @user = User.find(:first)
0
- # end
0
- #
0
- # should "return its full name"
0
- # assert_equal 'John Doe', @user.full_name
0
- # end
0
- # end
0
- # end
0
- #
0
- # This code will produce the method <tt>"test: A User instance should return its full name. "</tt>.
0
- #
0
- # Contexts may be nested. Nested contexts run their setup blocks from out to in before each
0
- # should statement. They then run their teardown blocks from in to out after each should statement.
0
- #
0
- # class UserTest << Test::Unit::TestCase
0
- # context "A User instance" do
0
- # setup do
0
- # @user = User.find(:first)
0
- # end
0
- #
0
- # should "return its full name"
0
- # assert_equal 'John Doe', @user.full_name
0
- # end
0
- #
0
- # context "with a profile" do
0
- # setup do
0
- # @user.profile = Profile.find(:first)
0
- # end
0
- #
0
- # should "return true when sent :has_profile?"
0
- # assert @user.has_profile?
0
- # end
0
- # end
0
- # end
0
- # end
0
- #
0
- # This code will produce the following methods
0
- # * <tt>"test: A User instance should return its full name. "</tt>
0
- # * <tt>"test: A User instance with a profile should return true when sent :has_profile?. "</tt>
0
- #
0
- # <b>Just like should statements, a context block can exist next to normal <tt>def test_the_old_way; end</tt>
0
- # tests</b>. This means you do not have to fully commit to the context/should syntax in a test file.
0
+ include ThoughtBot::Shoulda::General
0
+ include ThoughtBot::Shoulda::Controller
0
 
0
- def context(name, &blk)
0
- if Shoulda.current_context
0
- Shoulda.current_context.context(name, &blk)
0
- else
0
- context = Shoulda::Context.new(name, self, &blk)
0
- context.build
0
+ extend ThoughtBot::Shoulda::ActiveRecord
0
     end
0
   end
0
 end
0
 
0
-module Test # :nodoc: all
0
- module Unit
0
- class TestCase
0
- include Shoulda::General
0
- include Shoulda::Controller
0
- extend Shoulda::ActiveRecord
0
+module ActionController #:nodoc: all
0
+ module Integration
0
+ class Session
0
+ include ThoughtBot::Shoulda::General
0
     end
0
   end
0
 end
0
-
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
 
 
96
97
98
99
100
101
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
104
105
106
107
108
109
110
111
112
113
114
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
117
118
119
120
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
123
124
125
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
148
149
150
151
 
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
 
 
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
 
206
207
208
209
210
211
 
 
212
213
214
215
 
 
 
 
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
 
 
232
233
 
234
235
 
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
304
305
306
307
308
309
310
 
311
312
313
314
315
316
317
318
319
 
 
 
 
 
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
388
389
390
391
392
393
394
395
396
397
398
399
 
 
 
400
401
 
402
403
404
405
 
 
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
 
 
 
 
 
 
 
 
 
 
 
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
 
 
 
 
 
 
 
 
 
 
 
 
497
498
499
500
501
502
503
504
505
506
507
508
509
510
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
512
513
514
515
516
517
518
519
520
521
522
523
524
 
 
 
 
 
 
 
 
 
 
 
525
526
527
 
 
 
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
566
567
568
569
570
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
 
 
 
 
 
 
 
 
 
594
595
 
 
 
 
596
597
598
599
600
601
602
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
 
 
 
 
 
 
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
 
175
 
 
 
 
 
 
 
 
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
 
 
 
 
 
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
 
 
 
 
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
 
274
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
 
302
303
 
 
304
 
 
 
 
 
 
 
 
 
 
 
305
306
307
308
309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310
311
 
312
 
 
 
313
314
315
 
 
 
316
317
318
319
320
 
 
 
 
 
 
 
 
 
 
 
321
 
 
 
322
323
324
 
325
326
 
327
328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
 
 
 
 
 
 
 
355
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
 
 
 
 
 
 
 
381
382
 
 
 
 
 
 
 
 
383
384
385
386
387
388
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
 
 
 
 
 
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
 
 
 
 
 
 
 
 
430
431
432
433
434
435
436
437
 
438
439
 
 
 
440
441
442
443
444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
 
 
463
464
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
487
488
489
490
491
492
493
494
495
496
497
498
499
500
 
 
 
 
 
 
 
 
 
 
 
 
501
502
503
504
505
506
507
508
509
510
511
512
513
514
 
515
 
 
 
 
 
 
 
 
 
 
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
 
532
 
 
 
 
 
 
 
 
 
 
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
552
 
 
 
 
 
 
 
 
 
 
 
 
 
 
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
 
570
 
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
 
 
 
 
603
604
0
@@ -1,602 +1,604 @@
0
-module Shoulda
0
- # = Macro test helpers for your active record models
0
- #
0
- # These helpers will test most of the validations and associations for your ActiveRecord models.
0
- #
0
- # class UserTest < Test::Unit::TestCase
0
- # should_require_attributes :name, :phone_number
0
- # should_not_allow_values_for :phone_number, "abcd", "1234"
0
- # should_allow_values_for :phone_number, "(123) 456-7890"
0
- #
0
- # should_protect_attributes :password
0
- #
0
- # should_have_one :profile
0
- # should_have_many :dogs
0
- # should_have_many :messes, :through => :dogs
0
- # should_belong_to :lover
0
- # end
0
- #
0
- # For all of these helpers, the last parameter may be a hash of options.
0
- #
0
- module ActiveRecord
0
- # Ensures that the model cannot be saved if one of the attributes listed is not present.
0
- #
0
- # Options:
0
- # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
- # Regexp or string. Default = <tt>/blank/</tt>
0
- #
0
- # Example:
0
- # should_require_attributes :name, :phone_number
0
- #
0
- def should_require_attributes(*attributes)
0
- message = get_options!(attributes, :message)
0
- message ||= /blank/
0
- klass = model_class
0
-
0
- attributes.each do |attribute|
0
- should "require #{attribute} to be set" do
0
- object = klass.new
0
- object.send("#{attribute}=", nil)
0
- assert !object.valid?, "#{klass.name} does not require #{attribute}."
0
- assert object.errors.on(attribute), "#{klass.name} does not require #{attribute}."
0
- assert_contains(object.errors.on(attribute), message)
0
+module ThoughtBot # :nodoc:
0
+ module Shoulda # :nodoc:
0
+ # = Macro test helpers for your active record models
0
+ #
0
+ # These helpers will test most of the validations and associations for your ActiveRecord models.
0
+ #
0
+ # class UserTest < Test::Unit::TestCase
0
+ # should_require_attributes :name, :phone_number
0
+ # should_not_allow_values_for :phone_number, "abcd", "1234"
0
+ # should_allow_values_for :phone_number, "(123) 456-7890"
0
+ #
0
+ # should_protect_attributes :password
0
+ #
0
+ # should_have_one :profile
0
+ # should_have_many :dogs
0
+ # should_have_many :messes, :through => :dogs
0
+ # should_belong_to :lover
0
+ # end
0
+ #
0
+ # For all of these helpers, the last parameter may be a hash of options.
0
+ #
0
+ module ActiveRecord
0
+ # Ensures that the model cannot be saved if one of the attributes listed is not present.
0
+ #
0
+ # Options:
0
+ # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
+ # Regexp or string. Default = <tt>/blank/</tt>
0
+ #
0
+ # Example:
0
+ # should_require_attributes :name, :phone_number
0
+ #
0
+ def should_require_attributes(*attributes)
0
+ message = get_options!(attributes, :message)
0
+ message ||= /blank/
0
+ klass = model_class
0
+
0
+ attributes.each do |attribute|
0
+ should "require #{attribute} to be set" do
0
+ object = klass.new
0
+ object.send("#{attribute}=", nil)
0
+ assert !object.valid?, "#{klass.name} does not require #{attribute}."
0
+ assert object.errors.on(attribute), "#{klass.name} does not require #{attribute}."
0
+ assert_contains(object.errors.on(attribute), message)
0
+ end
0
         end
0
       end
0
- end
0
 
0
- # Ensures that the model cannot be saved if one of the attributes listed is not unique.
0
- # Requires an existing record
0
- #
0
- # Options:
0
- # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
- # Regexp or string. Default = <tt>/taken/</tt>
0
- # * <tt>:scoped_to</tt> - field(s) to scope the uniqueness to.
0
- #
0
- # Examples:
0
- # should_require_unique_attributes :keyword, :username
0
- # should_require_unique_attributes :name, :message => "O NOES! SOMEONE STOELED YER NAME!"
0
- # should_require_unique_attributes :email, :scoped_to => :name
0
- # should_require_unique_attributes :address, :scoped_to => [:first_name, :last_name]
0
- #
0
- def should_require_unique_attributes(*attributes)
0
- message, scope = get_options!(attributes, :message, :scoped_to)
0
- scope = [*scope].compact
0
- message ||= /taken/
0
-
0
- klass = model_class
0
- attributes.each do |attribute|
0
- attribute = attribute.to_sym
0
- should "require unique value for #{attribute}#{" scoped to #{scope.join(', ')}" if scope}" do
0
- assert existing = klass.find(:first), "Can't find first #{klass}"
0
- object = klass.new
0
-
0
- object.send(:"#{attribute}=", existing.send(attribute))
0
- if !scope.blank?