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.
- checksums.yaml +4 -4
- data/.travis.yml +12 -0
- data/CHANGELOG.md +34 -0
- data/README.md +244 -181
- data/lib/draftsman/config.rb +4 -1
- data/lib/draftsman/draft.rb +117 -80
- data/lib/draftsman/frameworks/rspec.rb +1 -1
- data/lib/draftsman/model.rb +253 -235
- data/lib/draftsman/version.rb +1 -1
- data/lib/draftsman.rb +26 -5
- data/lib/generators/draftsman/templates/config/initializers/draftsman.rb +16 -7
- data/spec/draftsman_spec.rb +7 -9
- data/spec/dummy/app/controllers/application_controller.rb +2 -2
- data/spec/dummy/app/models/overridden_draft.rb +7 -0
- data/spec/dummy/app/models/talkative.rb +21 -43
- data/spec/dummy/db/schema.rb +1 -0
- data/spec/models/child_spec.rb +17 -17
- data/spec/models/draft_spec.rb +893 -305
- data/spec/models/enumable_spec.rb +3 -2
- data/spec/models/overridden_draft_spec.rb +41 -0
- data/spec/models/parent_spec.rb +10 -10
- data/spec/models/skipper_spec.rb +221 -219
- data/spec/models/talkative_spec.rb +107 -108
- data/spec/models/trashable_spec.rb +6 -10
- data/spec/models/vanilla_spec.rb +570 -229
- data/spec/models/whitelister_spec.rb +489 -348
- metadata +7 -10
- data/spec/dummy/db/migrate/20110208155312_set_up_test_tables.rb +0 -95
- data/spec/dummy/db/migrate/20150404203627_add_talkatives_table_to_tests.rb +0 -18
- data/spec/dummy/db/migrate/20150408234937_add_only_children.rb +0 -16
- data/spec/dummy/db/migrate/20160328184419_create_enumables.rb +0 -9
@@ -1,17 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
# A Talkative has a call to `has_drafts` and all
|
3
|
+
# A Talkative has a call to `has_drafts` and all six callbacks defined:
|
4
4
|
#
|
5
|
-
# - `
|
6
|
-
# - `
|
7
|
-
# - `
|
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 '#
|
24
|
-
|
20
|
+
describe '#save_draft' do
|
21
|
+
context 'on create' do
|
22
|
+
before { talkative.save_draft }
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
112
|
-
|
113
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
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
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
127
|
-
|
128
|
-
|
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
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
-
|
137
|
-
|
138
|
-
|
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.
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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 '#
|
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.
|
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.
|
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.
|
204
|
-
let!(:published_trashable) { Trashable.create
|
205
|
-
let!(:trashed_trashable) { Trashable.create
|
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
|