drafter 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -1
- data/VERSION +1 -1
- data/drafter.gemspec +1 -1
- data/lib/drafter.rb +3 -3
- data/lib/drafter/apply.rb +1 -1
- data/lib/drafter/draft.rb +2 -2
- data/lib/drafter/id_hash.rb +1 -1
- data/lib/drafter/subdrafts.rb +1 -1
- data/test/drafter/test_apply.rb +3 -3
- data/test/drafter/test_draft.rb +4 -4
- data/test/drafter/test_subdrafts.rb +8 -8
- data/test/support/models.rb +1 -1
- metadata +26 -26
data/README.rdoc
CHANGED
@@ -3,7 +3,14 @@
|
|
3
3
|
This is an experimental gem designed to version ActiveRecord objects with
|
4
4
|
attached CarrierWave uploads.
|
5
5
|
|
6
|
-
|
6
|
+
It's still in development, so don't use it unless you're ready for that.
|
7
|
+
|
8
|
+
So far, it can correctly handle the following cases:
|
9
|
+
|
10
|
+
* drafts for new records
|
11
|
+
* drafts for saved records
|
12
|
+
* drafts for new and saved records, with attached CarrierWave uploads
|
13
|
+
* drafts for new and saved records, properly saving drafts for sub-objects in has_many associations, with or without attached CarrierWave uploads.
|
7
14
|
|
8
15
|
== Contributing to drafter
|
9
16
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/drafter.gemspec
CHANGED
data/lib/drafter.rb
CHANGED
@@ -39,9 +39,9 @@ module Drafter
|
|
39
39
|
include Subdrafts
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
43
|
-
cattr_accessor :
|
44
|
-
self.
|
42
|
+
def saves_subdrafts_for(*associations)
|
43
|
+
cattr_accessor :saves_subdrafts_for
|
44
|
+
self.saves_subdrafts_for = associations
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
data/lib/drafter/apply.rb
CHANGED
@@ -82,7 +82,7 @@ module Drafter
|
|
82
82
|
#
|
83
83
|
def restore_subdrafts
|
84
84
|
draft.subdrafts.each_with_index do |subdraft, index|
|
85
|
-
inflated_object = subdraft.
|
85
|
+
inflated_object = subdraft.inflate
|
86
86
|
self.send(subdraft.parent_association_name.to_sym) << inflated_object
|
87
87
|
# THE HACK
|
88
88
|
if inflated_object.class.polymorphic_as
|
data/lib/drafter/draft.rb
CHANGED
@@ -36,7 +36,7 @@ class Draft < ActiveRecord::Base
|
|
36
36
|
# contain the draft content, saving the draftable, and destroying the draft.
|
37
37
|
#
|
38
38
|
def approve!
|
39
|
-
draftable =
|
39
|
+
draftable = inflate
|
40
40
|
draftable.save!
|
41
41
|
self.destroy
|
42
42
|
draftable
|
@@ -65,7 +65,7 @@ class Draft < ActiveRecord::Base
|
|
65
65
|
#
|
66
66
|
# @return the existing draftable object, or a new one of the proper
|
67
67
|
# type, with attributes and files hanging off it.
|
68
|
-
def
|
68
|
+
def inflate
|
69
69
|
draftabl = draftable.nil? ? self.draftable_type.constantize.new(:draft => self) : draftable
|
70
70
|
draftabl.draft = self # this should absolutely *not* be necessary, there's an STI bug in AR.
|
71
71
|
draftabl.apply_draft
|
data/lib/drafter/id_hash.rb
CHANGED
@@ -9,7 +9,7 @@ module IdHash
|
|
9
9
|
# identify the object by its :id; other times, you're dealing with an object
|
10
10
|
# that only has a Draft but no actual object identity, in which case you'll
|
11
11
|
# want to retrieve the Draft object by its :draft_id, and call
|
12
|
-
# @draft.
|
12
|
+
# @draft.inflate on that.
|
13
13
|
#
|
14
14
|
# @return [Hash] a hash with either :draft_id => this object's draft's id,
|
15
15
|
# or :id => this object's id.
|
data/lib/drafter/subdrafts.rb
CHANGED
data/test/drafter/test_apply.rb
CHANGED
@@ -16,7 +16,7 @@ class TestCreation < Minitest::Unit::TestCase
|
|
16
16
|
|
17
17
|
describe "with no comments" do
|
18
18
|
before do
|
19
|
-
@article = @draft.
|
19
|
+
@article = @draft.inflate
|
20
20
|
@article.apply_draft
|
21
21
|
end
|
22
22
|
|
@@ -28,10 +28,10 @@ class TestCreation < Minitest::Unit::TestCase
|
|
28
28
|
|
29
29
|
describe "with comments" do
|
30
30
|
before do
|
31
|
-
@article = @draft.
|
31
|
+
@article = @draft.inflate
|
32
32
|
@article.comments.build(:text => "I'm a comment on a draft article")
|
33
33
|
@draft = @article.save_draft
|
34
|
-
@article = @draft.
|
34
|
+
@article = @draft.inflate
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should restore the article, unsaved" do
|
data/test/drafter/test_draft.rb
CHANGED
@@ -159,7 +159,7 @@ class TestDraft < Minitest::Unit::TestCase
|
|
159
159
|
describe "for an unsaved object" do
|
160
160
|
before do
|
161
161
|
@draft = @article.save_draft
|
162
|
-
@article = @draft.
|
162
|
+
@article = @draft.inflate
|
163
163
|
end
|
164
164
|
|
165
165
|
it "should build the object's attributes properly" do
|
@@ -187,7 +187,7 @@ class TestDraft < Minitest::Unit::TestCase
|
|
187
187
|
before do
|
188
188
|
@article.comments << Comment.new(:text => "comment 3")
|
189
189
|
@draft = @article.save_draft
|
190
|
-
@article = @draft.
|
190
|
+
@article = @draft.inflate
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should build the object's attributes properly" do
|
@@ -216,7 +216,7 @@ class TestDraft < Minitest::Unit::TestCase
|
|
216
216
|
before do
|
217
217
|
@article.text = "ChChChanges"
|
218
218
|
@draft = @article.save_draft
|
219
|
-
@article = @draft.
|
219
|
+
@article = @draft.inflate
|
220
220
|
end
|
221
221
|
it "should build the object's attributes properly" do
|
222
222
|
assert_equal("ChChChanges", @article.text)
|
@@ -247,7 +247,7 @@ class TestDraft < Minitest::Unit::TestCase
|
|
247
247
|
@article.save!
|
248
248
|
@article.text = "flappa flap flap"
|
249
249
|
@draft = @article.save_draft
|
250
|
-
@article = @draft.
|
250
|
+
@article = @draft.inflate
|
251
251
|
end
|
252
252
|
|
253
253
|
it "should build the object's attributes properly" do
|
@@ -32,22 +32,22 @@ class TestSubdrafts < Minitest::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should serialize the comment draft fields properly" do
|
35
|
-
assert @comment_draft.
|
35
|
+
assert @comment_draft.inflate.is_a? Comment
|
36
36
|
assert_equal("What a great article!", @comment_draft.text)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should save a draft upload for the comment's uploaded file" do
|
40
40
|
assert_equal(@draft_upload_count + 1, DraftUpload.count)
|
41
|
-
assert_equal(file_upload.size, File.new(@comment_draft.
|
41
|
+
assert_equal(file_upload.size, File.new(@comment_draft.inflate.upload.path).size)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should correctly associate the comment draft with its parent" do
|
45
45
|
assert_equal(@article_draft, @comment_draft.parent)
|
46
46
|
end
|
47
47
|
|
48
|
-
describe "after calling
|
48
|
+
describe "after calling inflate on a draft" do
|
49
49
|
before do
|
50
|
-
@article = @draft.
|
50
|
+
@article = @draft.inflate
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should still have 1 comment on it" do
|
@@ -56,7 +56,7 @@ class TestSubdrafts < Minitest::Unit::TestCase
|
|
56
56
|
|
57
57
|
describe "restoring the draft" do
|
58
58
|
it "should work" do
|
59
|
-
assert (@article = @draft.
|
59
|
+
assert (@article = @draft.inflate).is_a? Article
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -64,7 +64,7 @@ class TestSubdrafts < Minitest::Unit::TestCase
|
|
64
64
|
before do
|
65
65
|
@article.comments << Comment.new(:text => "SuperComment")
|
66
66
|
@draft = @article.save_draft
|
67
|
-
@article = @draft.
|
67
|
+
@article = @draft.inflate
|
68
68
|
@article.comments << Comment.new(:text => "AnotherComment")
|
69
69
|
end
|
70
70
|
|
@@ -93,7 +93,7 @@ class TestSubdrafts < Minitest::Unit::TestCase
|
|
93
93
|
|
94
94
|
describe "restoring the like subdraft to the article" do
|
95
95
|
before do
|
96
|
-
@article = @article_draft.
|
96
|
+
@article = @article_draft.inflate
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should work" do
|
@@ -140,7 +140,7 @@ class TestSubdrafts < Minitest::Unit::TestCase
|
|
140
140
|
|
141
141
|
describe "restoring the like subdraft to the article" do
|
142
142
|
before do
|
143
|
-
@article = @article_draft.
|
143
|
+
@article = @article_draft.inflate
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should work, using the parent class association" do
|
data/test/support/models.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drafter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-09-05 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &2168697080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2168697080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: diffy
|
27
|
-
requirement: &
|
27
|
+
requirement: &2168689840 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2168689840
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &2168688720 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2168688720
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: database_cleaner
|
49
|
-
requirement: &
|
49
|
+
requirement: &2168687540 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2168687540
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: debugger
|
60
|
-
requirement: &
|
60
|
+
requirement: &2168686500 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2168686500
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: minitest
|
71
|
-
requirement: &
|
71
|
+
requirement: &2168685820 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2168685820
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: bundler
|
82
|
-
requirement: &
|
82
|
+
requirement: &2168684900 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 1.0.0
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2168684900
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: jeweler
|
93
|
-
requirement: &
|
93
|
+
requirement: &2168684240 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 1.6.4
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *2168684240
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: rcov
|
104
|
-
requirement: &
|
104
|
+
requirement: &2168683540 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *2168683540
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: turn
|
115
|
-
requirement: &
|
115
|
+
requirement: &2168682640 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *2168682640
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: carrierwave
|
126
|
-
requirement: &
|
126
|
+
requirement: &2168676860 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *2168676860
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: minitest-rails-shoulda
|
137
|
-
requirement: &
|
137
|
+
requirement: &2168676200 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,7 +142,7 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *2168676200
|
146
146
|
description: A
|
147
147
|
email: dave.hrycyszyn@headlondon.com
|
148
148
|
executables: []
|
@@ -201,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
201
201
|
version: '0'
|
202
202
|
segments:
|
203
203
|
- 0
|
204
|
-
hash:
|
204
|
+
hash: 1334542519238778841
|
205
205
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
206
|
none: false
|
207
207
|
requirements:
|