draftsman 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,30 +4,63 @@ require 'spec_helper'
4
4
  # attribute, which allows deletes to be drafts too.
5
5
  describe Trashable do
6
6
  let(:trashable) { Trashable.new :name => 'Bob' }
7
- it { should be_draftable }
7
+
8
+ it 'is draftable' do
9
+ expect(subject.class.draftable?).to eql true
10
+ end
8
11
 
9
12
  # Not affected by this customization
10
- describe :draft_creation do
13
+ describe 'draft_creation' do
11
14
  end
12
15
 
13
16
  # Not affected by this customization
14
- describe :draft_update do
17
+ describe 'draft_update' do
15
18
  end
16
19
 
17
- describe :draft_destroy do
20
+ describe 'draft_destroy' do
18
21
  context 'with `:create` draft' do
19
22
  before { trashable.draft_creation }
20
23
  subject { trashable.draft_destroy; return trashable }
21
- it { should be_persisted }
22
- it { should_not be_published }
23
- it { should be_draft }
24
- it { should be_trashed}
25
- its(:published_at) { should be_nil }
26
- its(:trashed_at) { should be_present }
27
- its(:draft_id) { should be_present }
28
- its(:draft) { should be_present }
29
- its(:draft) { should be_destroy }
30
- its(:name) { should eql 'Bob' }
24
+
25
+ it 'is persisted' do
26
+ expect(subject).to be_persisted
27
+ end
28
+
29
+ it 'is not published' do
30
+ expect(subject.published?).to eql false
31
+ end
32
+
33
+ it 'is a draft' do
34
+ expect(subject.draft?).to eql true
35
+ end
36
+
37
+ it 'is trashed' do
38
+ expect(subject.trashed?).to eql true
39
+ end
40
+
41
+ it 'does not have a `published_at` timestamp' do
42
+ expect(subject.published_at).to be_nil
43
+ end
44
+
45
+ it 'has a `trashed_at` timestamp' do
46
+ expect(subject.trashed_at).to be_present
47
+ end
48
+
49
+ it 'has a `draft_id`' do
50
+ expect(subject.draft_id).to be_present
51
+ end
52
+
53
+ it 'has a `draft`' do
54
+ expect(subject.draft).to be_present
55
+ end
56
+
57
+ it 'has a `destroy` draft' do
58
+ expect(subject.draft.destroy?).to eql true
59
+ end
60
+
61
+ it 'retains its `name`' do
62
+ expect(subject.name).to eql 'Bob'
63
+ end
31
64
 
32
65
  it 'keeps the item' do
33
66
  expect { subject }.to_not change(Trashable, :count)
@@ -37,8 +70,8 @@ describe Trashable do
37
70
  expect { subject }.to_not change(Draftsman::Draft.where(:id => trashable.draft_id), :count)
38
71
  end
39
72
 
40
- its "draft's name should be 'Bob'" do
41
- subject.draft.reify.name.should eql 'Bob'
73
+ it 'retains its `name` in the draft' do
74
+ expect(subject.draft.reify.name).to eql 'Bob'
42
75
  end
43
76
  end
44
77
 
@@ -52,16 +85,46 @@ describe Trashable do
52
85
  end
53
86
 
54
87
  subject { trashable.draft_destroy; return trashable.reload }
55
- it { should be_persisted }
56
- it { should be_published }
57
- it { should be_draft }
58
- it { should be_trashed}
59
- its(:published_at) { should be_present }
60
- its(:trashed_at) { should be_present }
61
- its(:draft_id) { should be_present }
62
- its(:draft) { should be_present }
63
- its(:draft) { should be_destroy }
64
- its(:name) { should eql 'Bob' }
88
+
89
+ it 'is persisted' do
90
+ expect(subject).to be_persisted
91
+ end
92
+
93
+ it 'is published' do
94
+ expect(subject.published?).to eql true
95
+ end
96
+
97
+ it 'is a draft' do
98
+ expect(subject.draft?).to eql true
99
+ end
100
+
101
+ it 'is trashed' do
102
+ expect(subject.trashed?).to eql true
103
+ end
104
+
105
+ it 'has a `published_at` timestamp' do
106
+ expect(subject.published_at).to be_present
107
+ end
108
+
109
+ it 'has a `trashed_at` timestamp' do
110
+ expect(subject.trashed_at).to be_present
111
+ end
112
+
113
+ it 'has a `draft_id`' do
114
+ expect(subject.draft_id).to be_present
115
+ end
116
+
117
+ it 'has a `draft`' do
118
+ expect(subject.draft).to be_present
119
+ end
120
+
121
+ it 'has a `destroy` draft' do
122
+ expect(subject.draft.destroy?).to eql true
123
+ end
124
+
125
+ it 'retains its original `name`' do
126
+ expect(subject.name).to eql 'Bob'
127
+ end
65
128
 
66
129
  it 'keeps the item' do
67
130
  expect { subject }.to_not change(Trashable, :count)
@@ -71,8 +134,8 @@ describe Trashable do
71
134
  expect { subject }.to_not change(Draftsman::Draft.where(:id => trashable.draft_id), :count)
72
135
  end
73
136
 
74
- its "draft's name should be 'Sam'" do
75
- subject.draft.reify.name.should eql 'Sam'
137
+ it "retains the updated draft's name in the draft" do
138
+ expect(subject.draft.reify.name).to eql 'Sam'
76
139
  end
77
140
  end
78
141
 
@@ -83,16 +146,46 @@ describe Trashable do
83
146
  end
84
147
 
85
148
  subject { trashable.draft_destroy; return trashable.reload }
86
- it { should be_persisted }
87
- it { should be_published }
88
- it { should be_draft }
89
- it { should be_trashed }
90
- its(:published_at) { should be_present }
91
- its(:trashed_at) { should be_present }
92
- its(:draft_id) { should be_present }
93
- its(:draft) { should be_present }
94
- its(:draft) { should be_destroy }
95
- its(:name) { should eql 'Bob' }
149
+
150
+ it 'is persisted' do
151
+ expect(subject).to be_persisted
152
+ end
153
+
154
+ it 'is published' do
155
+ expect(subject.published?).to eql true
156
+ end
157
+
158
+ it 'is a draft' do
159
+ expect(subject.draft?).to eql true
160
+ end
161
+
162
+ it 'is trashed' do
163
+ expect(subject.trashed?).to eql true
164
+ end
165
+
166
+ it 'has a `published_at` timestamp' do
167
+ expect(subject.published_at).to be_present
168
+ end
169
+
170
+ it 'has a `trashed_at` timestamp' do
171
+ expect(subject.trashed_at).to be_present
172
+ end
173
+
174
+ it 'has a `draft_id`' do
175
+ expect(subject.draft_id).to be_present
176
+ end
177
+
178
+ it 'has a `draft`' do
179
+ expect(subject.draft).to be_present
180
+ end
181
+
182
+ it 'has a `destroy` draft' do
183
+ expect(subject.draft.destroy?).to eql true
184
+ end
185
+
186
+ it 'retains its `name`' do
187
+ expect(subject.name).to eql 'Bob'
188
+ end
96
189
 
97
190
  it 'keeps the item' do
98
191
  expect { subject }.to_not change(Trashable, :count)
@@ -110,54 +203,60 @@ describe Trashable do
110
203
  let!(:trashed_trashable) { Trashable.create :name => 'Ralph' }
111
204
 
112
205
  # Not affected by this customization
113
- describe :drafted do
206
+ describe 'drafted' do
114
207
  end
115
208
 
116
- describe :live do
209
+ describe 'live' do
117
210
  before { trashed_trashable.draft_destroy }
118
211
  subject { Trashable.live }
119
- its(:count) { should eql 2 }
212
+
213
+ it 'returns 2 records' do
214
+ expect(subject.count).to eql 2
215
+ end
120
216
 
121
217
  it 'does not raise an exception' do
122
218
  expect { subject }.to_not raise_exception
123
219
  end
124
220
 
125
221
  it 'includes the drafted item' do
126
- subject.should include drafted_trashable
222
+ expect(subject).to include drafted_trashable
127
223
  end
128
224
 
129
225
  it 'includes the published item' do
130
- subject.should include published_trashable
226
+ expect(subject).to include published_trashable
131
227
  end
132
228
 
133
229
  it 'does not include the trashed item' do
134
- subject.should_not include trashed_trashable
230
+ expect(subject).to_not include trashed_trashable
135
231
  end
136
232
  end
137
233
 
138
234
  # Not affected by this customization
139
- describe :published do
235
+ describe 'published' do
140
236
  end
141
237
 
142
- describe :trashed do
238
+ describe 'trashed' do
143
239
  before { trashed_trashable.draft_destroy }
144
240
  subject { Trashable.trashed }
145
- its(:count) { should eql 1 }
241
+
242
+ it 'returns 1 record' do
243
+ expect(subject.count).to eql 1
244
+ end
146
245
 
147
246
  it 'does not raise an exception' do
148
247
  expect { subject.load }.to_not raise_exception
149
248
  end
150
249
 
151
250
  it 'does not include the drafted item' do
152
- subject.should_not include drafted_trashable
251
+ expect(subject).to_not include drafted_trashable
153
252
  end
154
253
 
155
254
  it 'does not include the published item' do
156
- subject.should_not include published_trashable
255
+ expect(subject).to_not include published_trashable
157
256
  end
158
257
 
159
258
  it 'includes the trashed item' do
160
- subject.should include trashed_trashable
259
+ expect(subject).to include trashed_trashable
161
260
  end
162
261
  end
163
262
  end
@@ -5,21 +5,38 @@ describe Vanilla do
5
5
  let(:vanilla) { Vanilla.new :name => 'Bob' }
6
6
  it { should be_draftable }
7
7
 
8
- describe :draft_creation do
8
+ describe 'draft_creation' do
9
9
  subject do
10
10
  vanilla.draft_creation
11
11
  vanilla.reload
12
12
  end
13
13
 
14
- it { should be_persisted }
15
- it { should be_draft }
16
- its(:draft_id) { should be_present }
17
- its(:draft) { should be_present }
18
- its(:draft) { should be_create }
19
- its(:name) { should eql 'Bob' }
14
+ it 'is persisted' do
15
+ expect(subject).to be_persisted
16
+ end
17
+
18
+ it 'is a draft' do
19
+ expect(subject.draft?).to eql true
20
+ end
21
+
22
+ it 'has a `draft_id`' do
23
+ expect(subject.draft_id).to be_present
24
+ end
25
+
26
+ it 'has a `draft`' do
27
+ expect(subject.draft).to be_present
28
+ end
29
+
30
+ it 'has a `create` draft' do
31
+ expect(subject.draft.create?).to eql true
32
+ end
33
+
34
+ it 'saves the `name`' do
35
+ expect(subject.name).to eql 'Bob'
36
+ end
20
37
  end
21
38
 
22
- describe :draft_update do
39
+ describe 'draft_update' do
23
40
  subject do
24
41
  vanilla.draft_update
25
42
  vanilla.reload
@@ -31,12 +48,29 @@ describe Vanilla do
31
48
  vanilla.name = 'Sam'
32
49
  end
33
50
 
34
- it { should be_persisted }
35
- it { should be_draft }
36
- its(:draft_id) { should be_present }
37
- its(:draft) { should be_present }
38
- its(:draft) { should be_update }
39
- its(:name) { should eql 'Bob' }
51
+ it 'is persisted' do
52
+ expect(subject).to be_persisted
53
+ end
54
+
55
+ it 'is a draft' do
56
+ expect(subject.draft?).to eql true
57
+ end
58
+
59
+ it 'has a `draft_id`' do
60
+ expect(subject.draft_id).to be_present
61
+ end
62
+
63
+ it 'has a `draft`' do
64
+ expect(subject.draft).to be_present
65
+ end
66
+
67
+ it 'has an `update` draft' do
68
+ expect(subject.draft.update?).to eql true
69
+ end
70
+
71
+ it 'has the original `name`' do
72
+ expect(subject.name).to eql 'Bob'
73
+ end
40
74
 
41
75
  it 'creates a new draft' do
42
76
  expect { subject }.to change(Draftsman::Draft, :count).by(1)
@@ -53,10 +87,21 @@ describe Vanilla do
53
87
  vanilla.name = 'Bob'
54
88
  end
55
89
 
56
- it { should_not be_draft }
57
- its(:name) { should eql 'Bob' }
58
- its(:draft_id) { should be_nil }
59
- its(:draft) { should be_nil }
90
+ it 'is no longer a draft' do
91
+ expect(subject.draft?).to eql false
92
+ end
93
+
94
+ it 'has the original `name`' do
95
+ expect(subject.name).to eql 'Bob'
96
+ end
97
+
98
+ it 'does not have a `draft_id`' do
99
+ expect(subject.draft_id).to be_nil
100
+ end
101
+
102
+ it 'has no `draft`' do
103
+ expect(subject.draft).to be_nil
104
+ end
60
105
 
61
106
  it 'destroys the draft' do
62
107
  expect { subject }.to change(Draftsman::Draft.where(:id => vanilla.draft_id), :count).by(-1)
@@ -68,32 +113,64 @@ describe Vanilla do
68
113
 
69
114
  context 'with changes' do
70
115
  before { vanilla.name = 'Sam' }
71
- it { should be_persisted }
72
- it { should be_draft }
73
- its(:draft_id) { should be_present }
74
- its(:draft) { should be_present }
75
- its(:name) { should eql 'Sam' }
116
+
117
+ it 'is persisted' do
118
+ expect(subject).to be_persisted
119
+ end
120
+
121
+ it 'is a draft' do
122
+ expect(subject.draft?).to eql true
123
+ end
124
+
125
+ it 'has a `draft_id`' do
126
+ expect(subject.draft_id).to be_present
127
+ end
128
+
129
+ it 'has a `draft`' do
130
+ expect(subject.draft).to be_present
131
+ end
132
+
133
+ it 'records the new `name`' do
134
+ expect(subject.name).to eql 'Sam'
135
+ end
76
136
 
77
137
  it 'updates the existing draft' do
78
138
  expect { subject }.to_not change(Draftsman::Draft.where(:id => vanilla.draft_id), :count)
79
139
  end
80
140
 
81
- its "draft's `name` is updated" do
82
- subject.draft.reify.name.should eql 'Sam'
141
+ it "updates the draft's `name`" do
142
+ expect(subject.draft.reify.name).to eql 'Sam'
83
143
  end
84
144
 
85
145
  it 'has a `create` draft' do
86
- subject.draft.should be_create
146
+ expect(subject.draft.create?).to eql true
87
147
  end
88
148
  end
89
149
 
90
150
  context 'with no changes' do
91
- it { should be_persisted }
92
- it { should be_draft }
93
- its(:draft_id) { should be_present }
94
- its(:draft) { should be_present }
95
- its(:draft) { should be_create }
96
- its(:name) { should eql 'Bob' }
151
+ it 'is persisted' do
152
+ expect(subject).to be_persisted
153
+ end
154
+
155
+ it 'is a draft' do
156
+ expect(subject.draft?).to eql true
157
+ end
158
+
159
+ it 'has a `draft_id`' do
160
+ expect(subject.draft_id).to be_present
161
+ end
162
+
163
+ it 'has a `draft`' do
164
+ expect(subject.draft).to be_present
165
+ end
166
+
167
+ it 'has a `create` draft' do
168
+ expect(subject.draft.create?).to eql true
169
+ end
170
+
171
+ it 'has the same `name`' do
172
+ expect(subject.name).to eql 'Bob'
173
+ end
97
174
 
98
175
  it "doesn't change the number of drafts" do
99
176
  expect { subject }.to_not change(Draftsman::Draft.where(:id => vanilla.draft_id), :count)
@@ -112,60 +189,101 @@ describe Vanilla do
112
189
 
113
190
  context 'with changes' do
114
191
  before { vanilla.name = 'Steve' }
115
- it { should be_persisted }
116
- it { should be_draft }
117
- its(:draft_id) { should be_present }
118
- its(:draft) { should be_present }
119
- its(:name) { should eql 'Bob' }
192
+
193
+ it 'is persisted' do
194
+ expect(subject).to be_persisted
195
+ end
196
+
197
+ it 'is a draft' do
198
+ expect(subject.draft?).to eql true
199
+ end
200
+
201
+ it 'has a `draft_id`' do
202
+ expect(subject.draft_id).to be_present
203
+ end
204
+
205
+ it 'has a `draft`' do
206
+ expect(subject.draft).to be_present
207
+ end
208
+
209
+ it 'has the original `name`' do
210
+ expect(subject.name).to eql 'Bob'
211
+ end
120
212
 
121
213
  it 'updates the existing draft' do
122
214
  expect { subject }.to_not change(Draftsman::Draft.where(:id => vanilla.draft_id), :count)
123
215
  end
124
216
 
125
- its "draft's `name` is updated" do
126
- subject.draft.reify.name.should eql 'Steve'
217
+ it "updates the draft's `name`" do
218
+ expect(subject.draft.reify.name).to eql 'Steve'
127
219
  end
128
220
 
129
221
  it 'has a `create` draft' do
130
- subject.draft.update?.should be_true
222
+ expect(subject.draft.update?).to eql true
131
223
  end
132
224
  end
133
225
 
134
226
  context 'with no changes' do
135
- it { should be_persisted }
136
- it { should be_draft }
137
- its(:draft_id) { should be_present }
138
- its(:draft) { should be_present }
139
- its(:draft) { should be_update }
140
- its(:name) { should eql 'Bob' }
227
+ it 'is persisted' do
228
+ expect(subject).to be_persisted
229
+ end
230
+
231
+ it 'is a draft' do
232
+ expect(subject.draft?).to eql true
233
+ end
234
+
235
+ it 'has a `draft_id`' do
236
+ expect(subject.draft_id).to be_present
237
+ end
238
+
239
+ it 'has a `draft`' do
240
+ expect(subject.draft).to be_present
241
+ end
242
+
243
+ it 'has an `update` draft' do
244
+ expect(subject.draft.update?).to eql true
245
+ end
246
+
247
+ it 'has the original `name`' do
248
+ expect(subject.name).to eql 'Bob'
249
+ end
141
250
 
142
251
  it "doesn't change the number of drafts" do
143
252
  expect { subject }.to_not change(Draftsman::Draft.where(:id => vanilla.draft_id), :count)
144
253
  end
145
254
 
146
- its "draft's `name` is not updated" do
147
- subject.draft.reify.name.should eql 'Sam'
255
+ it "does not update the draft's `name`" do
256
+ expect(subject.draft.reify.name).to eql 'Sam'
148
257
  end
149
258
  end
150
259
  end
151
260
  end
152
261
 
153
262
  # Not applicable to this customization
154
- describe :draft_destroy do
263
+ describe 'draft_destroy' do
155
264
  end
156
265
 
157
266
  describe 'scopes' do
158
267
  let!(:drafted_vanilla) { vanilla.draft_creation; return vanilla }
159
268
  let!(:published_vanilla) { Vanilla.create :name => 'Jane', :published_at => Time.now }
160
269
 
161
- describe :drafted do
270
+ describe 'drafted' do
162
271
  subject { Vanilla.drafted }
163
- its(:count) { should eql 1 }
164
- it { should include drafted_vanilla }
165
- it { should_not include published_vanilla }
272
+
273
+ it 'returns 1 record' do
274
+ expect(subject.count).to eql 1
275
+ end
276
+
277
+ it 'includes the drafted record' do
278
+ expect(subject).to include drafted_vanilla
279
+ end
280
+
281
+ it 'does not include the published record' do
282
+ expect(subject).to_not include published_vanilla
283
+ end
166
284
  end
167
285
 
168
- describe :live do
286
+ describe 'live' do
169
287
  subject { Vanilla.live }
170
288
 
171
289
  it 'raises an exception' do
@@ -173,14 +291,23 @@ describe Vanilla do
173
291
  end
174
292
  end
175
293
 
176
- describe :published do
294
+ describe 'published' do
177
295
  subject { Vanilla.published }
178
- its(:count) { should eql 1 }
179
- it { should_not include drafted_vanilla }
180
- it { subject.should include published_vanilla }
296
+
297
+ it 'returns 1 record' do
298
+ expect(subject.count).to eql 1
299
+ end
300
+
301
+ it 'does not include the drafted record' do
302
+ expect(subject).to_not include drafted_vanilla
303
+ end
304
+
305
+ it 'includes the published record' do
306
+ expect(subject).to include published_vanilla
307
+ end
181
308
  end
182
309
 
183
- describe :trashed do
310
+ describe 'trashed' do
184
311
  subject { Vanilla.trashed }
185
312
 
186
313
  it 'raises an exception' do