has_moderated 1.0.rc2 → 1.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,12 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
+ def reload_task_subtask
4
+ Object.send(:remove_const, 'Task') if defined? Task
5
+ load 'task.rb'
6
+ Object.send(:remove_const, 'Subtask') if defined? Subtask
7
+ load 'subtask.rb'
8
+ end
9
+
3
10
  describe Task do
4
11
 
5
12
  #
@@ -9,10 +16,7 @@ describe Task do
9
16
 
10
17
  context "has_many association:" do
11
18
  before do
12
- Object.send(:remove_const, 'Task') if defined? Task
13
- load 'task.rb'
14
- Object.send(:remove_const, 'Subtask') if defined? Subtask
15
- load 'subtask.rb'
19
+ reload_task_subtask
16
20
  Task.has_many :renamed_subtasks, :class_name => "Subtask"
17
21
  Task.has_moderated_association :renamed_subtasks
18
22
  end
@@ -121,10 +125,7 @@ describe Task do
121
125
 
122
126
  context "has_many polymorphic association:" do
123
127
  before do
124
- Object.send(:remove_const, 'Task') if defined? Task
125
- load 'task.rb'
126
- Object.send(:remove_const, 'Subtask') if defined? Subtask
127
- load 'subtask.rb'
128
+ reload_task_subtask
128
129
  Task.has_many :renamed_subtasks, :class_name => "Subtask", :as => :parentable
129
130
  Subtask.belongs_to :parentable, :polymorphic => true
130
131
  Task.has_moderated_association :renamed_subtasks
@@ -155,10 +156,7 @@ describe Task do
155
156
 
156
157
  context "has_one polymorphic association:" do
157
158
  before do
158
- Object.send(:remove_const, 'Task') if defined? Task
159
- load 'task.rb'
160
- Object.send(:remove_const, 'Subtask') if defined? Subtask
161
- load 'subtask.rb'
159
+ reload_task_subtask
162
160
  Task.has_one :renamed_subtask, :class_name => "Subtask", :as => :parentable
163
161
  Subtask.belongs_to :parentable, :polymorphic => true
164
162
  Task.has_moderated_association :renamed_subtask
@@ -190,10 +188,7 @@ describe Task do
190
188
 
191
189
  context "has_and_belongs_to_many association:" do
192
190
  before do
193
- Object.send(:remove_const, 'Task')
194
- load 'task.rb'
195
- Object.send(:remove_const, 'Subtask')
196
- load 'subtask.rb'
191
+ reload_task_subtask
197
192
  Task.has_and_belongs_to_many :renamed_subtasks, :class_name => "Subtask", :join_table => "tasks_jointable", :foreign_key => "m1_id", :association_foreign_key => "m2_id"
198
193
  Subtask.has_and_belongs_to_many :renamed_tasks, :class_name => "Task", :join_table => "tasks_jointable", :foreign_key => "m2_id", :association_foreign_key => "m1_id"
199
194
  Task.has_moderated_association :renamed_subtasks
@@ -234,18 +229,34 @@ describe Task do
234
229
  end
235
230
  end
236
231
  context "has_and_belongs_to_many association (create moderation):" do
237
- before do
238
- Object.send(:remove_const, 'Task')
239
- load 'task.rb'
240
- Object.send(:remove_const, 'Subtask')
241
- load 'subtask.rb'
232
+ before :each do # important that we do this before EACH
233
+ reload_task_subtask
242
234
  Task.has_moderated_create :with_associations => [:renamed_subtasks]
243
235
  Task.has_and_belongs_to_many :renamed_subtasks, :class_name => "Subtask", :join_table => "tasks_jointable", :foreign_key => "m1_id", :association_foreign_key => "m2_id"
244
236
  Subtask.has_and_belongs_to_many :renamed_tasks, :class_name => "Task", :join_table => "tasks_jointable", :foreign_key => "m2_id", :association_foreign_key => "m1_id"
245
- Task.has_moderated_association :renamed_subtasks
246
237
  end
247
238
 
248
- it "associates an existing subtask on create" do
239
+ it "associates an existing subtask on create 1" do
240
+ Task.has_moderated_association :renamed_subtasks # important difference (had different behavior based
241
+ # on presence of this line, need to test with and without)
242
+ Subtask.create! :title => "Subtask 1"
243
+ Subtask.count.should eq(1)
244
+ Moderation.count.should eq(0)
245
+
246
+ task = Task.new :title => "Task 1"
247
+ task.renamed_subtasks << Subtask.first
248
+ task.save
249
+
250
+ Moderation.count.should eq(1)
251
+ Moderation.last.accept
252
+ Moderation.count.should eq(0)
253
+
254
+ Task.first.renamed_subtasks.count.should eq(1)
255
+ subtask = Task.first.renamed_subtasks.first
256
+ subtask.title.should eq("Subtask 1")
257
+ end
258
+
259
+ it "associates an existing subtask on create 2", :focus => true do
249
260
  Subtask.create! :title => "Subtask 1"
250
261
  Subtask.count.should eq(1)
251
262
  Moderation.count.should eq(0)
@@ -271,10 +282,7 @@ describe Task do
271
282
 
272
283
  context "has_many :through association:" do
273
284
  before do
274
- Object.send(:remove_const, 'Task') if defined? Task
275
- load 'task.rb'
276
- Object.send(:remove_const, 'Subtask') if defined? Subtask
277
- load 'subtask.rb'
285
+ reload_task_subtask
278
286
  Task.has_many :renamed_connections, :class_name => "TaskConnection", :foreign_key => "m1_id"
279
287
  Task.has_many :renamed_subtasks, :class_name => "Subtask", :through => :renamed_connections, :source => :renamed_subtask
280
288
  Subtask.has_many :renamed_connections, :class_name => "TaskConnection", :foreign_key => "m2_id"
@@ -364,10 +372,7 @@ describe Task do
364
372
 
365
373
  context "has_one association:" do
366
374
  before do
367
- Object.send(:remove_const, 'Task')
368
- load 'task.rb'
369
- Object.send(:remove_const, 'Subtask')
370
- load 'subtask.rb'
375
+ reload_task_subtask
371
376
  Task.has_one :renamed_subtask, :class_name => "Subtask"
372
377
  Task.has_moderated_association :renamed_subtask
373
378
  end
@@ -430,10 +435,7 @@ describe Task do
430
435
 
431
436
  context "create moderation with association:" do
432
437
  before do
433
- Object.send(:remove_const, 'Task')
434
- load 'task.rb'
435
- Object.send(:remove_const, 'Subtask')
436
- load 'subtask.rb'
438
+ reload_task_subtask
437
439
  Task.has_many :renamed_subtasks, :class_name => "Subtask"
438
440
  Task.has_moderated_create :with_associations => [:renamed_subtasks]
439
441
  end
@@ -467,10 +469,7 @@ describe Task do
467
469
 
468
470
  context "destroy moderation:" do
469
471
  before do
470
- Object.send(:remove_const, 'Task')
471
- load 'task.rb'
472
- Object.send(:remove_const, 'Subtask')
473
- load 'subtask.rb'
472
+ reload_task_subtask
474
473
  Task.has_moderated_destroy
475
474
  end
476
475
 
@@ -490,10 +489,7 @@ describe Task do
490
489
 
491
490
  context "moderates attributes:" do
492
491
  before do
493
- Object.send(:remove_const, 'Task')
494
- load 'task.rb'
495
- Object.send(:remove_const, 'Subtask')
496
- load 'subtask.rb'
492
+ reload_task_subtask
497
493
  Task.has_moderated :title
498
494
  end
499
495
 
@@ -515,10 +511,7 @@ describe Task do
515
511
 
516
512
  context "common features:" do
517
513
  it "get_moderation_attributes can be overriden in model" do
518
- Object.send(:remove_const, 'Task')
519
- load 'task.rb'
520
- Object.send(:remove_const, 'Subtask')
521
- load 'subtask.rb'
514
+ reload_task_subtask
522
515
  Task.has_moderated_create
523
516
  Task.class_eval do
524
517
  def get_moderation_attributes
@@ -534,10 +527,7 @@ describe Task do
534
527
  end
535
528
 
536
529
  it "knows if it's a create moderation" do
537
- Object.send(:remove_const, 'Task')
538
- load 'task.rb'
539
- Object.send(:remove_const, 'Subtask')
540
- load 'subtask.rb'
530
+ reload_task_subtask
541
531
  Task.has_moderated_create
542
532
 
543
533
  Task.create! :title => "Task 1"
@@ -548,10 +538,7 @@ describe Task do
548
538
  end
549
539
 
550
540
  it "knows if it's a destroy moderation" do
551
- Object.send(:remove_const, 'Task')
552
- load 'task.rb'
553
- Object.send(:remove_const, 'Subtask')
554
- load 'subtask.rb'
541
+ reload_task_subtask
555
542
  Task.has_moderated_destroy
556
543
 
557
544
  Task.create! :title => "Task 1"
@@ -565,10 +552,7 @@ describe Task do
565
552
 
566
553
  context "hooks:" do
567
554
  before do
568
- Object.send(:remove_const, 'Task')
569
- load 'task.rb'
570
- Object.send(:remove_const, 'Subtask')
571
- load 'subtask.rb'
555
+ reload_task_subtask
572
556
  Task.has_moderated :title
573
557
  Task.moderation_creating do |moderation|
574
558
  moderation.data = "Test!"
@@ -584,8 +568,7 @@ describe Task do
584
568
 
585
569
  context "preview:" do
586
570
  before do
587
- Object.send(:remove_const, 'Task')
588
- load 'task.rb'
571
+ reload_task_subtask
589
572
  Task.has_moderated :title
590
573
  end
591
574
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_moderated
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.rc2
4
+ version: 1.0.rc3
5
5
  prerelease: 4
6
6
  platform: ruby
7
7
  authors:
@@ -265,7 +265,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
265
265
  version: '0'
266
266
  segments:
267
267
  - 0
268
- hash: -2683879995284600772
268
+ hash: -754626760659402804
269
269
  required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  none: false
271
271
  requirements: