draftsman 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Child do
3
+ describe Child, :type => :model do
4
4
  let(:parent) { Parent.new(:name => 'Marge') }
5
5
  let(:child) { Child.new(:name => 'Lisa', :parent => parent) }
6
6
 
7
- describe :publish! do
7
+ describe 'publish!' do
8
8
  context 'parent `create` draft with child `create` draft' do
9
9
  before do
10
10
  parent.draft_creation
@@ -13,27 +13,27 @@ describe Child do
13
13
 
14
14
  subject { child.draft.publish! }
15
15
 
16
- its 'child should not be a draft' do
16
+ it "destroys the child's draft" do
17
17
  subject
18
- child.reload.should_not be_draft
18
+ expect(child.reload).to_not be_draft
19
19
  end
20
20
 
21
- its 'child should be published' do
21
+ it 'publishes the child' do
22
22
  subject
23
- child.reload.should be_published
23
+ expect(child.reload).to be_published
24
24
  end
25
25
 
26
- its 'parent should be published' do
26
+ it 'publishes the parent' do
27
27
  subject
28
- parent.reload.should be_published
28
+ expect(parent.reload).to be_published
29
29
  end
30
30
 
31
- its 'parent should not be a draft' do
31
+ it "destroys the parent's draft" do
32
32
  subject
33
- parent.reload.should_not be_draft
33
+ expect(parent.reload).to_not be_draft
34
34
  end
35
35
 
36
- it 'destroys both drafts' do
36
+ it 'destroys 2 drafts overall' do
37
37
  expect { subject }.to change(Draftsman::Draft, :count).by(-2)
38
38
  end
39
39
 
@@ -64,7 +64,7 @@ describe Child do
64
64
  expect { subject }.to_not change(Parent, :count)
65
65
  end
66
66
 
67
- it 'destroys 1 draft' do
67
+ it 'destroys 1 draft overall' do
68
68
  expect { subject }.to change(Draftsman::Draft, :count).by(-1)
69
69
  end
70
70
 
@@ -74,7 +74,7 @@ describe Child do
74
74
  end
75
75
  end
76
76
 
77
- describe :revert! do
77
+ describe 'revert!' do
78
78
  context 'parent `create` draft with child `create` draft' do
79
79
  before do
80
80
  parent.draft_creation
@@ -84,18 +84,18 @@ describe Child do
84
84
  subject { child.draft.revert! }
85
85
 
86
86
  it 'destroys the parent' do
87
- expect { subject }.to_not change(Parent, :count).by(-1)
87
+ expect { subject }.to_not change(Parent, :count)
88
88
  end
89
89
 
90
90
  it 'destroys the child' do
91
91
  expect { subject }.to change(Child, :count).by(-1)
92
92
  end
93
93
 
94
- it 'only destroys 1 draft overall' do
94
+ it 'destroys 1 draft overall' do
95
95
  expect { subject }.to change(Draftsman::Draft, :count).by(-1)
96
96
  end
97
97
 
98
- it 'destroys the child draft' do
98
+ it "destroys the child's draft" do
99
99
  expect { subject }.to change(Draftsman::Draft.where(:item_type => 'Child'), :count).by(-1)
100
100
  end
101
101
  end
@@ -114,35 +114,43 @@ describe Child do
114
114
  child.reload
115
115
  end
116
116
 
117
- it { should be_persisted }
118
- it { should_not be_trashed }
119
- it { should_not be_draft }
117
+ it 'does not persist the child' do
118
+ expect(subject.persisted?).to eql true
119
+ end
120
+
121
+ it 'removes the child from the trash' do
122
+ expect(subject.trashed?).to eql false
123
+ end
124
+
125
+ it "destroys the child's draft" do
126
+ expect(subject.draft?).to eql false
127
+ end
120
128
 
121
- it 'deletes both drafts' do
129
+ it 'destroys 2 drafts overall' do
122
130
  expect { subject }.to change(Draftsman::Draft, :count).by(-2)
123
131
  end
124
132
 
125
- it "deletes the parent's draft" do
133
+ it "destroys the parent's draft" do
126
134
  expect { subject }.to change(Draftsman::Draft.where(:item_type => 'Parent'), :count).by(-1)
127
135
  end
128
136
 
129
- it "deletes the child's draft" do
137
+ it "destroys the child's draft" do
130
138
  expect { subject }.to change(Draftsman::Draft.where(:item_type => 'Child'), :count).by(-1)
131
139
  end
132
140
 
133
- its 'parent should not be trashed anymore' do
141
+ it 'removes the parent from the trash' do
134
142
  subject
135
- parent.should_not be_trashed
143
+ expect(parent).to_not be_trashed
136
144
  end
137
145
 
138
- its 'child should not be a draft anymore' do
146
+ it "destroys the child's draft" do
139
147
  subject
140
- child.should_not be_draft
148
+ expect(child).to_not be_draft
141
149
  end
142
150
  end
143
151
  end
144
152
 
145
- describe :draft_publication_dependencies do
153
+ describe 'draft_publication_dependencies' do
146
154
  context 'parent `create` draft with child `create` draft' do
147
155
  before do
148
156
  parent.draft_creation
@@ -150,8 +158,14 @@ describe Child do
150
158
  end
151
159
 
152
160
  subject { child.draft }
153
- its(:draft_publication_dependencies) { should_not be_empty }
154
- its(:draft_publication_dependencies) { should include parent.draft }
161
+
162
+ it "creates publication dependencies for the child's draft" do
163
+ expect(subject.draft_publication_dependencies).to_not be_empty
164
+ end
165
+
166
+ it "includes the parent as a publication dependency for the child's draft" do
167
+ expect(subject.draft_publication_dependencies).to include parent.draft
168
+ end
155
169
  end
156
170
 
157
171
  context 'parent `create` draft with child `update` draft' do
@@ -163,12 +177,19 @@ describe Child do
163
177
  end
164
178
 
165
179
  subject { child.draft }
166
- its(:draft_publication_dependencies) { should_not be_empty }
167
- its(:draft_publication_dependencies) { should include parent.draft }
180
+
181
+ it "creates publication dependencies for the child's draft" do
182
+ expect(subject.draft_publication_dependencies).to_not be_empty
183
+ end
184
+
185
+ it "includes the parent as a publication dependency for the child's draft" do
186
+ expect(subject.draft_publication_dependencies).to include parent.draft
187
+ end
168
188
  end
169
189
 
170
190
  context 'parent `create` draft with child `update` draft pointing to new parent' do
171
191
  let(:new_parent) { Parent.new(:name => 'Patty') }
192
+
172
193
  before do
173
194
  parent.draft_creation
174
195
  child.save!
@@ -178,9 +199,18 @@ describe Child do
178
199
  end
179
200
 
180
201
  subject { child.draft }
181
- its(:draft_publication_dependencies) { should_not be_empty }
182
- its(:draft_publication_dependencies) { should_not include parent.draft}
183
- its(:draft_publication_dependencies) { should include new_parent.draft }
202
+
203
+ it "creates publication dependencies for the child's draft" do
204
+ expect(subject.draft_publication_dependencies).to_not be_empty
205
+ end
206
+
207
+ it "removes the old parent as a publication dependency for the child's draft" do
208
+ expect(subject.draft_publication_dependencies).to_not include parent.draft
209
+ end
210
+
211
+ it "includes the new parent as a publication dependency for the child's draft" do
212
+ expect(subject.draft_publication_dependencies).to include new_parent.draft
213
+ end
184
214
  end
185
215
 
186
216
  context 'parent `destroy` draft with child `destroy` draft' do
@@ -191,11 +221,14 @@ describe Child do
191
221
  end
192
222
 
193
223
  subject { child.draft }
194
- its(:draft_publication_dependencies) { should be_empty }
224
+
225
+ it "has no publication dependencies for the child's draft" do
226
+ expect(subject.draft_publication_dependencies).to be_empty
227
+ end
195
228
  end
196
229
  end
197
230
 
198
- describe :draft_reversion_dependencies do
231
+ describe 'draft_reversion_dependencies' do
199
232
  context 'parent `create` draft with child `create` draft' do
200
233
  before do
201
234
  parent.draft_creation
@@ -203,7 +236,10 @@ describe Child do
203
236
  end
204
237
 
205
238
  subject { child.draft }
206
- its(:draft_reversion_dependencies) { should be_empty }
239
+
240
+ it "has no reversion dependencies for the child's draft" do
241
+ expect(subject.draft_reversion_dependencies).to be_empty
242
+ end
207
243
  end
208
244
 
209
245
  context 'parent `destroy` draft with child `destroy` draft' do
@@ -214,8 +250,14 @@ describe Child do
214
250
  end
215
251
 
216
252
  subject { child.draft }
217
- its(:draft_reversion_dependencies) { should be_present }
218
- its(:draft_reversion_dependencies) { should include parent.draft }
253
+
254
+ it "creates reversion dependencies for the child's draft" do
255
+ expect(subject.draft_reversion_dependencies).to be_present
256
+ end
257
+
258
+ it "includes the parent as a reversion dependency for the child's draft" do
259
+ expect(subject.draft_reversion_dependencies).to include parent.draft
260
+ end
219
261
  end
220
262
  end
221
263
  end