remarkable_activerecord 3.1.9 → 3.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,671 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe 'association_matcher' do
4
- include ModelBuilder
5
-
6
- describe 'belong_to' do
7
-
8
- # Defines a model, create a validation and returns a raw matcher
9
- def define_and_validate(options={})
10
- columns = options.delete(:association_columns) || { :projects_count => :integer }
11
- define_model :company, columns
12
- define_model :super_company, columns
13
-
14
- columns = options.delete(:model_columns) || { :company_id => :integer, :company_type => :string }
15
- @model = define_model :project, columns do
16
- belongs_to :company, options
17
- belongs_to :unknown
18
- belongs_to :accountable, :polymorphic => true
19
- end
20
-
21
- belong_to :company
22
- end
23
-
24
- describe 'messages' do
25
- it 'should contain a description' do
26
- matcher = define_and_validate
27
- matcher.description.should == 'belong to company'
28
-
29
- matcher.class_name('Company')
30
- matcher.description.should == 'belong to company with class name "Company"'
31
-
32
- matcher.foreign_key('company_id')
33
- matcher.description.should == 'belong to company with class name "Company" and with foreign key "company_id"'
34
-
35
- matcher = belong_to(:company).dependent(:destroy)
36
- matcher.description.should == 'belong to company with dependent :destroy'
37
-
38
- matcher.readonly
39
- matcher.description.should == 'belong to company with dependent :destroy and with readonly records'
40
-
41
- matcher.as(:interface)
42
- matcher.description.should == 'belong to company with dependent :destroy, through the polymorphic interface :interface, and with readonly records'
43
-
44
- matcher.counter_cache('projects_count')
45
- matcher.description.should == 'belong to company with dependent :destroy, through the polymorphic interface :interface, ' <<
46
- 'with readonly records, and with counter cache "projects_count"'
47
- end
48
-
49
- it 'should set association_exists? message' do
50
- define_and_validate
51
- matcher = belong_to('whatever')
52
- matcher.matches?(@model)
53
- matcher.failure_message.should == 'Expected Project records belong to whatever, but the association does not exist'
54
- end
55
-
56
- it 'should set macro_matches? message' do
57
- define_and_validate
58
- matcher = have_one('company')
59
- matcher.matches?(@model)
60
- matcher.failure_message.should == 'Expected Project records have one company, got Project records belong to company'
61
- end
62
-
63
- it 'should set klass_exists? message' do
64
- define_and_validate
65
- matcher = belong_to('unknown')
66
- matcher.matches?(@model)
67
- matcher.failure_message.should == 'Expected Project records belong to unknown, but the association class does not exist'
68
- end
69
-
70
- it 'should set foreign_key_exists? message' do
71
- matcher = define_and_validate(:model_columns => {})
72
- matcher.matches?(@model)
73
- matcher.failure_message.should == 'Expected foreign key "company_id" to exist on "projects", but does not'
74
- end
75
-
76
- it 'should set polymorphic_exists? message' do
77
- matcher = define_and_validate(:model_columns => { :company_id => :integer }, :polymorphic => true)
78
- matcher.polymorphic.matches?(@model)
79
- matcher.failure_message.should == 'Expected "projects" to have "company_type" as column, but does not'
80
- end
81
-
82
- it 'should set counter_cache_exists? message' do
83
- matcher = define_and_validate(:association_columns => {}, :counter_cache => true)
84
- matcher.counter_cache.matches?(@model)
85
- matcher.failure_message.should == 'Expected "companies" to have "projects_count" as column, but does not'
86
- end
87
-
88
- it 'should set options_matches? message when polymorphic is given' do
89
- matcher = define_and_validate(:polymorphic => false)
90
- matcher.polymorphic.matches?(@model)
91
- matcher.failure_message.should == 'Expected Project records belong to company with options {:polymorphic=>"true"}, got {:polymorphic=>"false"}'
92
- end
93
-
94
- it 'should set options_matches? message when counter_cache is given' do
95
- matcher = define_and_validate(:counter_cache => true)
96
- matcher.counter_cache(false).matches?(@model)
97
- matcher.failure_message.should == 'Expected Project records belong to company with options {:counter_cache=>"false"}, got {:counter_cache=>"true"}'
98
- end
99
- end
100
-
101
- describe 'matchers' do
102
- describe 'without options' do
103
- before(:each){ define_and_validate }
104
-
105
- it { should belong_to(:company) }
106
- it { should_not belong_to(:unknown) }
107
- it { should_not belong_to(:project) }
108
- it { should_not have_one(:company) }
109
- it { should_not have_many(:company) }
110
- end
111
-
112
- describe 'with class name option' do
113
- it { should define_and_validate.class_name('Company') }
114
- it { should define_and_validate(:class_name => 'SuperCompany').class_name('SuperCompany') }
115
-
116
- it { should_not define_and_validate.class_name('SuperCompany') }
117
- it { should_not define_and_validate(:class_name => 'Company').class_name('SuperCompany') }
118
- end
119
-
120
- describe 'with foreign_key option' do
121
- it { should define_and_validate.foreign_key(:company_id) }
122
- it { should_not define_and_validate.foreign_key(:association_id) }
123
-
124
- # Checks whether fk exists or not
125
- it { should define_and_validate(:foreign_key => :association_id,
126
- :model_columns => { :association_id => :integer }).foreign_key(:association_id) }
127
-
128
- it { should_not define_and_validate(:foreign_key => :association_id).foreign_key(:association_id) }
129
- it { should_not define_and_validate(:model_columns => { :association_id => :integer }).foreign_key(:association_id) }
130
- end
131
-
132
- describe 'with dependent option' do
133
- it { should define_and_validate(:dependent => :delete).dependent(:delete) }
134
- it { should define_and_validate(:dependent => :destroy).dependent(:destroy) }
135
-
136
- it { should_not define_and_validate(:dependent => :delete).dependent(:destroy) }
137
- it { should_not define_and_validate(:dependent => :destroy).dependent(:delete) }
138
- end
139
-
140
- describe 'with counter_cache option' do
141
- # Checks whether fk exists or not
142
- it { should define_and_validate(:counter_cache => :association_count,
143
- :association_columns => { :association_count => :integer }).counter_cache(:association_count) }
144
-
145
- it { should_not define_and_validate(:counter_cache => :association_count).counter_cache(:association_count) }
146
- it { should_not define_and_validate(:association_columns => { :association_count => :integer }).counter_cache(:association_count) }
147
- end
148
-
149
- describe "with polymorphic option" do
150
- before(:each){ define_and_validate(:model_columns => {:accountable_id => :integer, :accountable_type => :string}) }
151
- it { should belong_to(:accountable).polymorphic }
152
- end
153
-
154
- create_optional_boolean_specs(:readonly, self)
155
- create_optional_boolean_specs(:validate, self)
156
- create_optional_boolean_specs(:autosave, self) if RAILS_VERSION =~ /^2.3/
157
- create_optional_boolean_specs(:polymorphic, self)
158
- create_optional_boolean_specs(:counter_cache, self)
159
- end
160
-
161
- describe 'macros' do
162
- before(:each){ define_and_validate(:validate => true, :readonly => true) }
163
-
164
- should_belong_to :company
165
- should_belong_to :company, :readonly => true
166
- should_belong_to :company, :validate => true
167
- should_belong_to :company, :class_name => "Company"
168
- should_belong_to :company, :foreign_key => :company_id
169
-
170
- should_belong_to :company do |m|
171
- m.readonly
172
- m.validate
173
- m.class_name = "Company"
174
- m.foreign_key = :company_id
175
- end
176
-
177
- should_not_belong_to :unknown
178
- should_not_belong_to :project
179
- should_not_have_one :company
180
- should_not_have_many :companies
181
-
182
- should_not_belong_to :company, :readonly => false
183
- should_not_belong_to :company, :validate => false
184
- should_not_belong_to :company, :class_name => "Anything"
185
- should_not_belong_to :company, :foreign_key => :anything_id
186
- end
187
- end
188
-
189
- describe 'have_and_belong_to_many' do
190
-
191
- # Defines a model, create a validation and returns a raw matcher
192
- def define_and_validate(options={})
193
- define_model :label
194
- define_model :super_label
195
-
196
- columns = options.delete(:association_columns) || [ :label_id, :project_id ]
197
- create_table(options.delete(:association_table) || :labels_projects) do |table|
198
- columns.each { |name| table.column(name, :integer) }
199
- end
200
-
201
- @model = define_model :project, options.delete(:model_columns) || {} do
202
- has_and_belongs_to_many :labels, options
203
- end
204
-
205
- have_and_belong_to_many :labels
206
- end
207
-
208
- describe 'messages' do
209
- it 'should contain a description' do
210
- matcher = define_and_validate
211
- matcher.description.should == 'have and belong to many labels'
212
-
213
- matcher.class_name('Label')
214
- matcher.description.should == 'have and belong to many labels with class name "Label"'
215
-
216
- matcher.foreign_key('label_id')
217
- matcher.description.should == 'have and belong to many labels with class name "Label" and with foreign key "label_id"'
218
-
219
- matcher = have_and_belong_to_many(:labels).autosave
220
- matcher.description.should == 'have and belong to many labels autosaving associated records'
221
-
222
- matcher.uniq
223
- matcher.description.should == 'have and belong to many labels with unique records and autosaving associated records'
224
- end
225
-
226
- it 'should set association_exists? message' do
227
- define_and_validate
228
- matcher = have_and_belong_to_many('whatever')
229
- matcher.matches?(@model)
230
- matcher.failure_message.should == 'Expected Project records have and belong to many whatever, but the association does not exist'
231
- end
232
-
233
- it 'should set macro_matches? message' do
234
- define_and_validate
235
- matcher = have_many('labels')
236
- matcher.matches?(@model)
237
- matcher.failure_message.should == 'Expected Project records have many labels, got Project records have and belong to many labels'
238
- end
239
-
240
- it 'should set join_table_exists? message' do
241
- matcher = define_and_validate(:association_table => 'another_name')
242
- matcher.matches?(@model)
243
- matcher.failure_message.should == 'Expected join table "labels_projects" to exist, but does not'
244
- end
245
-
246
- it 'should set foreign_key_exists? message' do
247
- matcher = define_and_validate(:association_columns => [])
248
- matcher.matches?(@model)
249
- matcher.failure_message.should == 'Expected foreign key "project_id" to exist on "labels_projects", but does not'
250
- end
251
-
252
- it 'should set options_matches? message' do
253
- matcher = define_and_validate(:uniq => false)
254
- matcher.uniq.matches?(@model)
255
- matcher.failure_message.should == 'Expected Project records have and belong to many labels with options {:uniq=>"true"}, got {:uniq=>"false"}'
256
- end
257
- end
258
-
259
- describe 'matchers' do
260
- describe 'without options' do
261
- before(:each){ define_and_validate }
262
-
263
- it { should have_and_belong_to_many(:labels) }
264
- it { should_not belong_to(:label) }
265
- it { should_not have_one(:label) }
266
- it { should_not have_many(:labels) }
267
- it { should_not have_and_belong_to_many(:companies) }
268
- end
269
-
270
- describe 'with class name option' do
271
- it { should define_and_validate.class_name('Label') }
272
-
273
- it { should define_and_validate(:class_name => 'SuperLabel',
274
- :association_table => 'projects_super_labels').class_name('SuperLabel') }
275
-
276
- it { should_not define_and_validate.class_name('SuperLabel') }
277
- end
278
-
279
- describe 'with foreign_key option' do
280
- it { should define_and_validate.foreign_key(:project_id) }
281
- it { should_not define_and_validate.foreign_key(:association_id) }
282
-
283
- # Checks whether fk exists or not
284
- it { should define_and_validate(:foreign_key => :association_id,
285
- :association_columns => [ :association_id ]).foreign_key(:association_id) }
286
-
287
- it { should_not define_and_validate(:foreign_key => :association_id).foreign_key(:association_id) }
288
- it { should_not define_and_validate(:association_columns => [ :association_id ]).foreign_key(:association_id) }
289
- end
290
-
291
- describe 'with join table option' do
292
- it { should define_and_validate.join_table('labels_projects') }
293
- it { should define_and_validate(:join_table => 'my_table',
294
- :association_table => 'my_table').join_table('my_table') }
295
-
296
- it { should define_and_validate(:join_table => :my_table,
297
- :association_table => :my_table).join_table(:my_table) }
298
-
299
- it { should_not define_and_validate.join_table('projects_labels') }
300
-
301
- it { should_not define_and_validate(:join_table => 'my_table',
302
- :association_table => 'another_table').join_table('my_table') }
303
- it { should_not define_and_validate(:join_table => 'another_table',
304
- :association_table => 'my_table').join_table('my_table') }
305
- it { should_not define_and_validate(:join_table => 'my_table',
306
- :association_table => 'my_table').join_table('another_table') }
307
- end
308
-
309
- create_optional_boolean_specs(:uniq, self)
310
- create_optional_boolean_specs(:readonly, self)
311
- create_optional_boolean_specs(:validate, self)
312
- create_optional_boolean_specs(:autosave, self) if RAILS_VERSION =~ /^2.3/
313
- end
314
-
315
- describe 'macros' do
316
- before(:each){ define_and_validate(:validate => true, :readonly => true) }
317
-
318
- should_have_and_belong_to_many :labels
319
- should_have_and_belong_to_many :labels, :readonly => true
320
- should_have_and_belong_to_many :labels, :validate => true
321
- should_have_and_belong_to_many :labels, :class_name => "Label"
322
- should_have_and_belong_to_many :labels, :foreign_key => :project_id
323
-
324
- should_have_and_belong_to_many :labels do |m|
325
- m.readonly
326
- m.validate
327
- m.class_name "Label"
328
- m.foreign_key :project_id
329
- end
330
-
331
- should_not_have_and_belong_to_many :companies
332
- should_not_have_one :label
333
- should_not_have_many :labels
334
-
335
- should_not_have_and_belong_to_many :labels, :readonly => false
336
- should_not_have_and_belong_to_many :labels, :validate => false
337
- should_not_have_and_belong_to_many :labels, :class_name => "Anything"
338
- should_not_have_and_belong_to_many :labels, :foreign_key => :anything_id
339
- end
340
- end
341
-
342
- describe 'have_many' do
343
-
344
- # Defines a model, create a validation and returns a raw matcher
345
- def define_and_validate(options={})
346
- columns = options.delete(:association_columns) || { :task_id => :integer, :project_id => :integer, :todo_id => :integer }
347
- define_model :task, columns
348
- define_model :todo, columns
349
-
350
- define_model :project_task, columns do
351
- belongs_to :task
352
- belongs_to :project
353
- belongs_to :todo
354
- end unless options.delete(:skip_source)
355
-
356
- @model = define_model :project, options.delete(:model_columns) || {} do
357
- has_many :project_tasks unless options.delete(:skip_through)
358
- has_many :tasks, options
359
- end
360
-
361
- have_many :tasks
362
- end
363
-
364
- describe 'messages' do
365
- it 'should contain a description' do
366
- matcher = define_and_validate
367
- matcher.description.should == 'have many tasks'
368
-
369
- matcher.class_name('Task')
370
- matcher.description.should == 'have many tasks with class name "Task"'
371
-
372
- matcher.foreign_key('task_id')
373
- matcher.description.should == 'have many tasks with class name "Task" and with foreign key "task_id"'
374
-
375
- matcher = have_many(:tasks).autosave
376
- matcher.description.should == 'have many tasks autosaving associated records'
377
-
378
- matcher.uniq
379
- matcher.description.should == 'have many tasks with unique records and autosaving associated records'
380
- end
381
-
382
- it 'should set association_exists? message' do
383
- define_and_validate
384
- matcher = have_many('whatever')
385
- matcher.matches?(@model)
386
- matcher.failure_message.should == 'Expected Project records have many whatever, but the association does not exist'
387
- end
388
-
389
- it 'should set macro_matches? message' do
390
- define_and_validate
391
- matcher = have_and_belong_to_many('tasks')
392
- matcher.matches?(@model)
393
- matcher.failure_message.should == 'Expected Project records have and belong to many tasks, got Project records have many tasks'
394
- end
395
-
396
- it 'should set foreign_key_exists? message' do
397
- matcher = define_and_validate(:association_columns => {})
398
- matcher.matches?(@model)
399
- matcher.failure_message.should == 'Expected foreign key "project_id" to exist on "tasks", but does not'
400
- end
401
-
402
- it 'should set through_exists? message' do
403
- matcher = define_and_validate(:through => :project_tasks, :skip_through => true)
404
- matcher.through(:project_tasks).matches?(@model)
405
- matcher.failure_message.should == 'Expected Project records have many tasks through :project_tasks, through association does not exist'
406
- end
407
-
408
- it 'should set source_exists? message' do
409
- matcher = define_and_validate(:through => :project_tasks, :skip_source => true)
410
- matcher.through(:project_tasks).matches?(@model)
411
- matcher.failure_message.should == 'Expected Project records have many tasks through :project_tasks, source association does not exist'
412
- end
413
-
414
- it 'should set options_matches? message when dependent is given' do
415
- matcher = define_and_validate(:dependent => :destroy)
416
- matcher.dependent(:nullify).matches?(@model)
417
- matcher.failure_message.should == 'Expected Project records have many tasks with options {:dependent=>"nullify"}, got {:dependent=>"destroy"}'
418
- end
419
-
420
- it 'should set options_matches? message when source is given' do
421
- matcher = define_and_validate(:through => :project_tasks, :source => :todo)
422
- matcher.through(:project_tasks).source(:task).matches?(@model)
423
- matcher.failure_message.should match(/:source=>"task"/)
424
- matcher.failure_message.should match(/:source=>"todo"/)
425
- end
426
- end
427
-
428
- describe 'matchers' do
429
- describe 'without options' do
430
- before(:each){ define_and_validate }
431
-
432
- it { should have_many(:tasks) }
433
- it { should_not belong_to(:task) }
434
- it { should_not have_one(:task) }
435
- it { should_not have_and_belong_to_many(:tasks) }
436
- end
437
-
438
- describe 'with class name option' do
439
- before(:each){ define_model :super_task, :project_id => :integer }
440
-
441
- it { should define_and_validate.class_name('Task') }
442
- it { should define_and_validate(:class_name => 'SuperTask').class_name('SuperTask') }
443
-
444
- it { should_not define_and_validate.class_name('SuperTask') }
445
- it { should_not define_and_validate(:class_name => 'SuperTask').class_name('Task') }
446
- end
447
-
448
- describe 'with foreign_key option' do
449
- it { should define_and_validate.foreign_key(:project_id) }
450
- it { should_not define_and_validate.foreign_key(:association_id) }
451
-
452
- # Checks whether fk exists or not
453
- it { should define_and_validate(:foreign_key => :association_id,
454
- :association_columns => { :association_id => :integer }).foreign_key(:association_id) }
455
-
456
- it { should_not define_and_validate(:foreign_key => :association_id).foreign_key(:association_id) }
457
- it { should_not define_and_validate(:association_columns => { :association_id => :integer }).foreign_key(:association_id) }
458
- end
459
-
460
- describe 'with dependent option' do
461
- it { should define_and_validate(:dependent => :delete_all).dependent(:delete_all) }
462
- it { should define_and_validate(:dependent => :destroy).dependent(:destroy) }
463
-
464
- it { should_not define_and_validate(:dependent => :delete_all).dependent(:destroy) }
465
- it { should_not define_and_validate(:dependent => :destroy).dependent(:delete_all) }
466
- end
467
-
468
- describe 'with through option' do
469
- it { should define_and_validate(:through => :project_tasks) }
470
- it { should define_and_validate(:through => :project_tasks).through(:project_tasks) }
471
-
472
- it { should_not define_and_validate(:through => :project_tasks).through(:something) }
473
- it { should_not define_and_validate(:through => :project_tasks, :skip_through => true).through(:project_tasks) }
474
- end
475
-
476
- describe 'with source option' do
477
- it { should define_and_validate(:through => :project_tasks, :source => :todo).source(:todo) }
478
- it { should_not define_and_validate(:through => :project_tasks, :source => :todo).source(:task) }
479
- end
480
-
481
- create_optional_boolean_specs(:uniq, self)
482
- create_optional_boolean_specs(:readonly, self)
483
- create_optional_boolean_specs(:validate, self)
484
- create_optional_boolean_specs(:autosave, self) if RAILS_VERSION =~ /^2.3/
485
- end
486
-
487
- describe 'macros' do
488
- before(:each){ define_and_validate(:through => :project_tasks, :readonly => true, :validate => true) }
489
-
490
- should_have_many :tasks
491
- should_have_many :tasks, :readonly => true
492
- should_have_many :tasks, :validate => true
493
- should_have_many :tasks, :through => :project_tasks
494
-
495
- should_have_many :tasks do |m|
496
- m.readonly
497
- m.validate
498
- m.through = :project_tasks
499
- end
500
-
501
- should_not_have_many :tasks, :readonly => false
502
- should_not_have_many :tasks, :validate => false
503
- should_not_have_many :tasks, :through => :another_thing
504
- end
505
- end
506
-
507
- describe 'have_one' do
508
-
509
- # Defines a model, create a validation and returns a raw matcher
510
- def define_and_validate(options={})
511
- columns = options.delete(:association_columns) || { :manager_id => :integer, :project_id => :integer, :boss_id => :integer }
512
- define_model :manager, columns
513
- define_model :boss, columns
514
-
515
- define_model :project_manager, columns do
516
- belongs_to :manager
517
- belongs_to :project
518
- belongs_to :boss
519
- end unless options.delete(:skip_source)
520
-
521
- @model = define_model :project, options.delete(:model_columns) || {} do
522
- has_many :project_managers unless options.delete(:skip_through)
523
- has_one :manager, options
524
- has_one :unknown
525
- end
526
-
527
- have_one :manager
528
- end
529
-
530
- describe 'messages' do
531
- it 'should contain a description' do
532
- matcher = define_and_validate
533
- matcher.description.should == 'have one manager'
534
-
535
- matcher.class_name('Manager')
536
- matcher.description.should == 'have one manager with class name "Manager"'
537
-
538
- matcher.foreign_key('manager_id')
539
- matcher.description.should == 'have one manager with class name "Manager" and with foreign key "manager_id"'
540
- end
541
-
542
- it 'should set association_exists? message' do
543
- define_and_validate
544
- matcher = have_one('whatever')
545
- matcher.matches?(@model)
546
- matcher.failure_message.should == 'Expected Project records have one whatever, but the association does not exist'
547
- end
548
-
549
- it 'should set klass_exists? message' do
550
- define_and_validate
551
- matcher = have_one('unknown')
552
- matcher.matches?(@model)
553
- matcher.failure_message.should == 'Expected Project records have one unknown, but the association class does not exist'
554
- end
555
-
556
- it 'should set macro_matches? message' do
557
- define_and_validate
558
- matcher = belong_to('manager')
559
- matcher.matches?(@model)
560
- matcher.failure_message.should == 'Expected Project records belong to manager, got Project records have one manager'
561
- end
562
-
563
- it 'should set foreign_key_exists? message' do
564
- matcher = define_and_validate(:association_columns => {})
565
- matcher.matches?(@model)
566
- matcher.failure_message.should == 'Expected foreign key "project_id" to exist on "managers", but does not'
567
- end
568
-
569
- it 'should set through_exists? message' do
570
- matcher = define_and_validate(:through => :project_managers, :skip_through => true)
571
- matcher.through(:project_managers).matches?(@model)
572
- matcher.failure_message.should == 'Expected Project records have one manager through :project_managers, through association does not exist'
573
- end
574
-
575
- it 'should set source_exists? message' do
576
- matcher = define_and_validate(:through => :project_managers, :skip_source => true)
577
- matcher.through(:project_managers).matches?(@model)
578
- matcher.failure_message.should == 'Expected Project records have one manager through :project_managers, source association does not exist'
579
- end
580
-
581
- it 'should set options_matches? message when dependent is given' do
582
- matcher = define_and_validate(:dependent => :destroy)
583
- matcher.dependent(:nullify).matches?(@model)
584
- matcher.failure_message.should == 'Expected Project records have one manager with options {:dependent=>"nullify"}, got {:dependent=>"destroy"}'
585
- end
586
-
587
- it 'should set options_matches? message when source is given' do
588
- matcher = define_and_validate(:through => :project_managers, :source => :boss)
589
- matcher.through(:project_managers).source(:manager).matches?(@model)
590
- matcher.failure_message.should match(/:source=>"manager"/)
591
- matcher.failure_message.should match(/:source=>"boss"/)
592
- end
593
- end
594
-
595
- describe 'matchers' do
596
- describe 'without options' do
597
- before(:each){ define_and_validate }
598
-
599
- it { should have_one(:manager) }
600
- it { should_not have_one(:unknown) }
601
- it { should_not belong_to(:manager) }
602
- it { should_not have_many(:managers) }
603
- it { should_not have_and_belong_to_many(:managers) }
604
- end
605
-
606
- describe 'with class name option' do
607
- before(:each){ define_model :super_manager, :project_id => :integer }
608
-
609
- it { should define_and_validate.class_name('Manager') }
610
- it { should define_and_validate(:class_name => 'SuperManager').class_name('SuperManager') }
611
-
612
- it { should_not define_and_validate.class_name('SuperManager') }
613
- it { should_not define_and_validate(:class_name => 'SuperManager').class_name('Manager') }
614
- end
615
-
616
- describe 'with foreign_key option' do
617
- it { should define_and_validate.foreign_key(:project_id) }
618
- it { should_not define_and_validate.foreign_key(:association_id) }
619
-
620
- # Checks whether fk exists or not
621
- it { should define_and_validate(:foreign_key => :association_id,
622
- :association_columns => { :association_id => :integer }).foreign_key(:association_id) }
623
-
624
- it { should_not define_and_validate(:foreign_key => :association_id).foreign_key(:association_id) }
625
- it { should_not define_and_validate(:association_columns => { :association_id => :integer }).foreign_key(:association_id) }
626
- end
627
-
628
- describe 'with dependent option' do
629
- it { should define_and_validate(:dependent => :delete).dependent(:delete) }
630
- it { should define_and_validate(:dependent => :destroy).dependent(:destroy) }
631
-
632
- it { should_not define_and_validate(:dependent => :delete).dependent(:destroy) }
633
- it { should_not define_and_validate(:dependent => :destroy).dependent(:delete) }
634
- end
635
-
636
- describe 'with through option' do
637
- it { should define_and_validate(:through => :project_managers) }
638
- it { should define_and_validate(:through => :project_managers).through(:project_managers) }
639
-
640
- it { should_not define_and_validate(:through => :project_managers).through(:something) }
641
- it { should_not define_and_validate(:through => :project_managers, :skip_through => true).through(:project_managers) }
642
- end
643
-
644
- describe 'with source option' do
645
- it { should define_and_validate(:through => :project_managers, :source => :boss).source(:boss) }
646
- it { should_not define_and_validate(:through => :project_managers, :source => :boss).source(:manager) }
647
- end
648
-
649
- create_optional_boolean_specs(:validate, self)
650
- create_optional_boolean_specs(:autosave, self) if RAILS_VERSION =~ /^2.3/
651
- end
652
-
653
- describe 'macros' do
654
- before(:each){ define_and_validate(:through => :project_managers, :validate => true) }
655
-
656
- should_have_one :manager
657
- should_have_one :manager, :validate => true
658
- should_have_one :manager, :through => :project_managers
659
-
660
- should_have_one :manager do |m|
661
- m.validate
662
- m.through = :project_managers
663
- end
664
-
665
- should_not_have_one :unknown
666
- should_not_have_one :manager, :validate => false
667
- should_not_have_one :manager, :through => :another_thing
668
- end
669
- end
670
-
671
- end