draftsman 0.5.1 → 0.6.0

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.
@@ -1,17 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
- # A Talkative has a call to `has_drafts` and all nine callbacks defined:
3
+ # A Talkative has a call to `has_drafts` and all six callbacks defined:
4
4
  #
5
- # - `before_draft_creation`
6
- # - `around_draft_creation`
7
- # - `after_draft_creation`
8
- # - `before_draft_update`
9
- # - `around_draft_update`
10
- # - `after_draft_update`
5
+ # - `before_save_draft`
6
+ # - `around_save_draft`
7
+ # - `after_save_draft`
11
8
  # - `before_draft_destruction`
12
9
  # - `around_draft_destruction`
13
10
  # - `after_draft_destruction`
14
- RSpec.describe Talkative do
11
+ RSpec.describe Talkative, type: :model do
15
12
  let(:talkative) { subject }
16
13
 
17
14
  describe '.draftable?' do
@@ -20,164 +17,166 @@ RSpec.describe Talkative do
20
17
  end
21
18
  end
22
19
 
23
- describe '#draft_creation' do
24
- before { talkative.draft_creation }
20
+ describe '#save_draft' do
21
+ context 'on create' do
22
+ before { talkative.save_draft }
25
23
 
26
- describe '`before_draft_creation` callback' do
27
- it 'changes `before_comment` attribute' do
28
- expect(talkative.before_comment).to eql "I changed before creation"
29
- end
24
+ describe '`before_save_draft` callback' do
25
+ it 'changes `before_comment` attribute' do
26
+ expect(talkative.before_comment).to eql 'I changed before save'
27
+ end
30
28
 
31
- it 'persists updated `before_comment` attribute to draft' do
32
- talkative.reload
33
- expect(talkative.draft.reify.before_comment).to eql "I changed before creation"
29
+ it 'persists updated `before_comment` attribute to draft' do
30
+ talkative.reload
31
+ expect(talkative.draft.reify.before_comment).to eql 'I changed before save'
32
+ end
34
33
  end
35
- end
36
34
 
37
- describe 'around_draft_creation callback' do
38
- it 'changes `around_early_comment` attribute (before yield)' do
39
- expect(talkative.around_early_comment).to eql "I changed around creation (before yield)"
40
- end
35
+ describe '`around_save_draft` callback' do
36
+ it 'changes `around_early_comment` attribute (before yield)' do
37
+ expect(talkative.around_early_comment).to eql 'I changed around save (before yield)'
38
+ end
41
39
 
42
- it 'persists updated `around_early_comment` attribute to draft' do
43
- talkative.reload
44
- expect(talkative.draft.reify.around_late_comment).to be_nil
45
- end
40
+ it 'does not persist updated `around_early_comment` attribute to draft' do
41
+ talkative.reload
42
+ expect(talkative.draft.reify.around_late_comment).to be_nil
43
+ end
46
44
 
47
- it 'changes `around_late_comment` attribute (after yield)' do
48
- expect(talkative.around_late_comment).to eql "I changed around creation (after yield)"
49
- end
45
+ it 'changes `around_late_comment` attribute (after yield)' do
46
+ expect(talkative.around_late_comment).to eql 'I changed around save (after yield)'
47
+ end
50
48
 
51
- it 'does not persist updated `around_late_comment` attribute' do
52
- talkative.reload
53
- expect(talkative.around_late_comment).to be_nil
54
- end
49
+ it 'does not persist updated `around_late_comment` attribute' do
50
+ talkative.reload
51
+ expect(talkative.around_late_comment).to be_nil
52
+ end
55
53
 
56
- it 'does not persist updated `around_late_comment` attribute to draft' do
57
- talkative.reload
58
- expect(talkative.draft.reify.around_late_comment).to be_nil
54
+ it 'does not persist updated `around_late_comment` attribute to draft' do
55
+ talkative.reload
56
+ expect(talkative.draft.reify.around_late_comment).to be_nil
57
+ end
59
58
  end
60
- end
61
59
 
62
- describe '`after_draft_creation` callback' do
63
- it 'changes `after_comment` attribute' do
64
- expect(talkative.after_comment).to eql "I changed after creation"
65
- end
60
+ describe '`after_save_draft` callback' do
61
+ it 'changes `after_comment` attribute' do
62
+ expect(talkative.after_comment).to eql 'I changed after save'
63
+ end
66
64
 
67
- it 'does not persist updated `after_comment` attribute' do
68
- talkative.reload
69
- expect(talkative.after_comment).to be_nil
70
- end
65
+ it 'does not persist updated `after_comment` attribute' do
66
+ talkative.reload
67
+ expect(talkative.after_comment).to be_nil
68
+ end
71
69
 
72
- it 'does not persist updated `after_comment` attribute to draft' do
73
- talkative.reload
74
- expect(talkative.draft.reify.after_comment).to be_nil
70
+ it 'does not persist updated `after_comment` attribute to draft' do
71
+ talkative.reload
72
+ expect(talkative.draft.reify.after_comment).to be_nil
73
+ end
75
74
  end
76
75
  end
77
- end
78
76
 
79
- describe '#draft_update' do
80
- before do
81
- talkative.draft_creation
82
- talkative.draft_update
83
- end
84
-
85
- describe '`before_draft_update` callback' do
86
- it 'changes `before_comment` attribute' do
87
- expect(talkative.before_comment).to eql "I changed before update"
77
+ context 'on update' do
78
+ before do
79
+ talkative.save
80
+ talkative.save_draft
88
81
  end
89
82
 
90
- it 'persists updated `before_comment` attribute to draft' do
91
- talkative.reload
92
- expect(talkative.draft.reify.before_comment).to eql "I changed before update"
93
- end
94
- end
83
+ describe '`before_save_draft` callback' do
84
+ it 'changes `before_comment` attribute' do
85
+ expect(talkative.before_comment).to eql 'I changed before save'
86
+ end
95
87
 
96
- describe '`around_draft_update` callback' do
97
- it 'changes `around_early_comment` attribute (before yield)' do
98
- expect(talkative.around_early_comment).to eql "I changed around update (before yield)"
88
+ it 'persists updated `before_comment` attribute to draft' do
89
+ talkative.reload
90
+ expect(talkative.draft.reify.before_comment).to eql 'I changed before save'
91
+ end
99
92
  end
100
93
 
101
- it 'persists updated `around_early_comment` attribute' do
102
- talkative.reload
103
- expect(talkative.around_early_comment).to eql "I changed around update (before yield)"
104
- end
94
+ describe '`around_save_draft` callback' do
95
+ it 'changes `around_early_comment` attribute (before yield)' do
96
+ expect(talkative.around_early_comment).to eql 'I changed around save (before yield)'
97
+ end
105
98
 
106
- it 'persists updated `around_early_comment` attribute to draft' do
107
- talkative.reload
108
- expect(talkative.draft.reify.around_early_comment).to eql "I changed around update (before yield)"
109
- end
99
+ it 'does not persist updated `around_early_comment` attribute' do
100
+ talkative.reload
101
+ expect(talkative.around_early_comment).to be_nil
102
+ end
110
103
 
111
- it 'changes `around_late_comment` attribute (after yield)' do
112
- expect(talkative.around_late_comment).to eql "I changed around update (after yield)"
113
- end
104
+ it 'persists updated `around_early_comment` attribute to draft' do
105
+ talkative.reload
106
+ expect(talkative.draft.reify.around_early_comment).to eql 'I changed around save (before yield)'
107
+ end
114
108
 
115
- it 'does not persist updated `around_late_comment` attribute' do
116
- talkative.reload
117
- expect(talkative.around_late_comment).to eql 'I changed around creation (after yield)'
118
- end
109
+ it 'changes `around_late_comment` attribute (after yield)' do
110
+ expect(talkative.around_late_comment).to eql 'I changed around save (after yield)'
111
+ end
119
112
 
120
- it 'does not persist updated `around_late_comment` attribute to draft' do
121
- talkative.reload
122
- expect(talkative.draft.reify.around_late_comment).to eql 'I changed around creation (after yield)'
123
- end
124
- end
113
+ it 'does not persist updated `around_late_comment` attribute' do
114
+ talkative.reload
115
+ expect(talkative.around_late_comment).to be_nil
116
+ end
125
117
 
126
- describe 'after callback' do
127
- it 'changes `after_comment` attribute' do
128
- expect(talkative.after_comment).to eql "I changed after update"
118
+ it 'does not persist updated `around_late_comment` attribute to draft' do
119
+ talkative.reload
120
+ expect(talkative.draft.reify.around_late_comment).to be_nil
121
+ end
129
122
  end
130
123
 
131
- it 'does not persist updated `after_comment` attribute' do
132
- talkative.reload
133
- expect(talkative.after_comment).to eql 'I changed after creation'
134
- end
124
+ describe 'after callback' do
125
+ it 'changes `after_comment` attribute' do
126
+ expect(talkative.after_comment).to eql 'I changed after save'
127
+ end
135
128
 
136
- it 'does not persist updated `after_comment` attribute to draft' do
137
- talkative.reload
138
- expect(talkative.draft.reify.after_comment).to eql 'I changed after creation'
129
+ it 'does not persist updated `after_comment` attribute' do
130
+ talkative.reload
131
+ expect(talkative.after_comment).to be_nil
132
+ end
133
+
134
+ it 'does not persist updated `after_comment` attribute to draft' do
135
+ talkative.reload
136
+ expect(talkative.draft.reify.after_comment).to be_nil
137
+ end
139
138
  end
140
139
  end
141
140
  end
142
141
 
143
142
  describe '#draft_destruction' do
144
143
  before do
145
- talkative.draft_creation
144
+ talkative.save_draft
146
145
  talkative.draft_destruction
147
146
  end
148
147
 
149
148
  describe '`before_draft_destruction` callback' do
150
149
  it 'changes `before_comment` attribute' do
151
- expect(talkative.before_comment).to eql "I changed before destroy"
150
+ expect(talkative.before_comment).to eql 'I changed before destroy'
152
151
  end
153
152
 
154
153
  it 'does not persist updated `before_comment` attribute' do
155
154
  talkative.reload
156
- expect(talkative.before_comment).to eql "I changed before creation"
155
+ expect(talkative.before_comment).to eql 'I changed before save'
157
156
  end
158
157
 
159
158
  it 'does not persist updated `before_comment` attribute to draft' do
160
159
  talkative.reload
161
- expect(talkative.draft.reify.before_comment).to eql "I changed before creation"
160
+ expect(talkative.draft.reify.before_comment).to eql 'I changed before save'
162
161
  end
163
162
  end
164
163
 
165
164
  describe '`around_draft_destruction` callback' do
166
165
  it 'changes `around_early_comment` attribute (before yield)' do
167
- expect(talkative.around_early_comment).to eql "I changed around destroy (before yield)"
166
+ expect(talkative.around_early_comment).to eql 'I changed around destroy (before yield)'
168
167
  end
169
168
 
170
169
  it 'does not persist `around_early_comment` attribute (before yield)' do
171
- expect(talkative.around_early_comment).to eql "I changed around destroy (before yield)"
170
+ expect(talkative.around_early_comment).to eql 'I changed around destroy (before yield)'
172
171
  end
173
172
 
174
173
  it 'does not persist updated `around_early_comment` attribute to draft' do
175
174
  talkative.reload
176
- expect(talkative.draft.reify.around_early_comment).to eql "I changed around creation (before yield)"
175
+ expect(talkative.draft.reify.around_early_comment).to eql 'I changed around save (before yield)'
177
176
  end
178
177
 
179
178
  it 'changes `around_late_comment` attribute (after yield)' do
180
- expect(talkative.around_late_comment).to eql "I changed around destroy (after yield)"
179
+ expect(talkative.around_late_comment).to eql 'I changed around destroy (after yield)'
181
180
  end
182
181
 
183
182
  it 'does not persist updated `around_late_comment` attribute' do
@@ -193,21 +192,21 @@ RSpec.describe Talkative do
193
192
 
194
193
  describe '`after_draft_destruction` callback' do
195
194
  it 'changes `before_comment` attribute' do
196
- expect(talkative.before_comment).to eql "I changed before destroy"
195
+ expect(talkative.before_comment).to eql 'I changed before destroy'
197
196
  end
198
197
 
199
198
  it 'does not persist updated `before_comment` attribute' do
200
199
  talkative.reload
201
- expect(talkative.before_comment).to eql 'I changed before creation'
200
+ expect(talkative.before_comment).to eql 'I changed before save'
202
201
  end
203
202
 
204
203
  it 'does not persist updated `before_comment` attribute to draft' do
205
204
  talkative.reload
206
- expect(talkative.draft.reify.before_comment).to eql 'I changed before creation'
205
+ expect(talkative.draft.reify.before_comment).to eql 'I changed before save'
207
206
  end
208
207
 
209
208
  it 'changes `after_comment` attribute' do
210
- expect(talkative.after_comment).to eql "I changed after destroy"
209
+ expect(talkative.after_comment).to eql 'I changed after destroy'
211
210
  end
212
211
 
213
212
  it 'does not persist updated `after_comment` attribute' do
@@ -12,16 +12,12 @@ describe Trashable do
12
12
  end
13
13
 
14
14
  # Not affected by this customization
15
- describe '#draft_creation' do
16
- end
17
-
18
- # Not affected by this customization
19
- describe '#draft_update' do
15
+ describe '#save_draft' do
20
16
  end
21
17
 
22
18
  describe '#draft_destruction' do
23
19
  context 'with `:create` draft' do
24
- before { trashable.draft_creation }
20
+ before { trashable.save_draft }
25
21
  subject { trashable.draft_destruction; return trashable }
26
22
 
27
23
  it 'is persisted' do
@@ -83,7 +79,7 @@ describe Trashable do
83
79
  trashable.published_at = Time.now
84
80
  trashable.save!
85
81
  trashable.name = 'Sam'
86
- trashable.draft_update
82
+ trashable.save_draft
87
83
  end
88
84
 
89
85
  subject { trashable.draft_destruction; return trashable.reload }
@@ -200,9 +196,9 @@ describe Trashable do
200
196
  end
201
197
 
202
198
  describe 'scopes' do
203
- let!(:drafted_trashable) { trashable.draft_creation; return trashable }
204
- let!(:published_trashable) { Trashable.create :name => 'Jane', :published_at => Time.now }
205
- let!(:trashed_trashable) { Trashable.create :name => 'Ralph' }
199
+ let!(:drafted_trashable) { trashable.save_draft; return trashable }
200
+ let!(:published_trashable) { Trashable.create(name: 'Jane', published_at: Time.now) }
201
+ let!(:trashed_trashable) { Trashable.create(name: 'Ralph') }
206
202
 
207
203
  # Not affected by this customization
208
204
  describe '.drafted' do