problem_destroy_spec.rb
2.59 KB
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
require 'spec_helper'
describe ProblemDestroy do
let(:problem_destroy) {
ProblemDestroy.new(problem)
}
context "in unit way" do
let(:problem) {
problem = Problem.new()
problem.stub(:errs).and_return(mock(:criteria, :only => [err_1, err_2]))
problem.stub(:comments).and_return(mock(:criteria, :only => [comment_1, comment_2]))
problem.stub(:delete)
problem
}
let(:err_1) { Err.new }
let(:err_2) { Err.new }
let(:comment_1) { Comment.new }
let(:comment_2) { Comment.new }
describe "#initialize" do
it 'take a problem like args' do
problem_destroy.problem.should == problem
end
end
describe "#execute" do
it 'destroy the problem himself' do
problem.should_receive(:delete).and_return(true)
problem_destroy.execute
end
it 'delete all errs associate' do
Err.collection.should_receive(:remove).with(:_id => { '$in' => [err_1.id, err_2.id] })
problem_destroy.execute
end
it 'delete all comments associate' do
Comment.collection.should_receive(:remove).with(:_id => { '$in' => [comment_1.id, comment_2.id] })
problem_destroy.execute
end
it 'delete all notice of associate to this errs' do
Notice.collection.should_receive(:remove).with({:err_id => { '$in' => [err_1.id, err_2.id] }})
problem_destroy.execute
end
end
end
context "in integration way" do
let!(:problem) { Fabricate(:problem) }
let!(:comment_1) { Fabricate(:comment, :err => problem) }
let!(:comment_2) { Fabricate(:comment, :err => problem) }
let!(:err_1) { Fabricate(:err, :problem => problem) }
let!(:err_2) { Fabricate(:err, :problem => problem) }
let!(:notice_1_1) { Fabricate(:notice, :err => err_1) }
let!(:notice_1_2) { Fabricate(:notice, :err => err_1) }
let!(:notice_2_1) { Fabricate(:notice, :err => err_2) }
let!(:notice_2_2) { Fabricate(:notice, :err => err_2) }
it 'should all destroy' do
problem_destroy.execute
Problem.where(:_id => problem.id).entries.should be_empty
Err.where(:_id => err_1.id).entries.should be_empty
Err.where(:_id => err_2.id).entries.should be_empty
Comment.where(:_id => comment_1.id).entries.should be_empty
Comment.where(:_id => comment_2.id).entries.should be_empty
Notice.where(:_id => notice_1_1.id).entries.should be_empty
Notice.where(:_id => notice_1_2.id).entries.should be_empty
Notice.where(:_id => notice_2_1.id).entries.should be_empty
Notice.where(:_id => notice_2_2.id).entries.should be_empty
end
end
end