drafter 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
data/drafter.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "drafter"
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["futurechimp"]
12
- s.date = "2012-08-19"
12
+ s.date = "2012-08-21"
13
13
  s.description = "A"
14
14
  s.email = "dave.hrycyszyn@headlondon.com"
15
15
  s.extra_rdoc_files = [
@@ -50,7 +50,7 @@ Gem::Specification.new do |s|
50
50
  s.homepage = "http://github.com/futurechimp/drafter"
51
51
  s.licenses = ["MIT"]
52
52
  s.require_paths = ["lib"]
53
- s.rubygems_version = "1.8.24"
53
+ s.rubygems_version = "1.8.17"
54
54
  s.summary = "Simple"
55
55
 
56
56
  if s.respond_to? :specification_version then
data/lib/drafter/apply.rb CHANGED
@@ -21,7 +21,7 @@ module Drafter
21
21
  # @return [Draftable] the draftable object populated with the draft attrs.
22
22
  def restore_attrs
23
23
  draftable_columns.each do |key|
24
- self.raw_write_attribute key, self.draft.data[key]
24
+ self.send "#{key}=", self.draft.data[key]
25
25
  end
26
26
  self
27
27
  end
@@ -32,7 +32,8 @@ module Drafter
32
32
  # on the object have been replaced with their draft equivalents.
33
33
  def restore_files
34
34
  draft.draft_uploads.each do |draft_upload|
35
- self.send(draft_upload.draftable_mount_column + "=", draft_upload.file_data)
35
+ uploader = draft_upload.draftable_mount_column
36
+ self.send(uploader + "=", draft_upload.file_data)
36
37
  end
37
38
  end
38
39
 
data/lib/drafter/draft.rb CHANGED
@@ -33,6 +33,13 @@ class Draft < ActiveRecord::Base
33
33
  draftable
34
34
  end
35
35
 
36
+ # Reject the draft, basically destroying the draft object and leaving the
37
+ # draftable unchanged.
38
+ #
39
+ def reject!
40
+ self.destroy
41
+ end
42
+
36
43
  # Set things up so we can use dot notation to access draft data, e.g.
37
44
  # we can do either @foo.draft.data["title"] or (more neatly) we can
38
45
  # do @foo.draft.title
@@ -55,4 +62,4 @@ class Draft < ActiveRecord::Base
55
62
  draftabl
56
63
  end
57
64
 
58
- end
65
+ end
@@ -5,4 +5,18 @@ class DraftUploader < CarrierWave::Uploader::Base
5
5
 
6
6
  storage :file
7
7
 
8
+ ##
9
+ # Directory where uploaded files will be stored (default is /public/uploads)
10
+ #
11
+ def store_dir
12
+ "system/draft_uploads/#{model.to_param}"
13
+ end
14
+
15
+ ##
16
+ # Directory where uploaded temp files will be stored (default is [root]/tmp)
17
+ #
18
+ def cache_dir
19
+ "system/draft_uploads/tmp"
20
+ end
21
+
8
22
  end
@@ -18,7 +18,7 @@ class TestCreation < Minitest::Unit::TestCase
18
18
  it "should just return the article" do
19
19
  @article.apply_draft
20
20
  assert @article
21
- end
21
+ end
22
22
  end
23
23
 
24
24
  describe "with a draft" do
@@ -45,4 +45,4 @@ class TestCreation < Minitest::Unit::TestCase
45
45
  end
46
46
  end
47
47
 
48
- end
48
+ end
@@ -78,19 +78,19 @@ class TestDraft < Minitest::Unit::TestCase
78
78
  @article.upload = file_upload("bar.txt")
79
79
  @draft = @article.save_draft
80
80
  @draft_count = Draft.count
81
- @draft.approve!
81
+ @draft.reload.approve!
82
82
  end
83
83
 
84
84
  it "shouldn't do anything mental, like creating a new object" do
85
85
  assert_equal(@article_count, Article.count)
86
86
  end
87
87
 
88
- it "should properly populate all the attributes" do
89
- assert_equal("some draft text", @article.text)
88
+ it "should properly save all the attributes" do
89
+ assert_equal("some draft text", @article.reload.text)
90
90
  end
91
91
 
92
- it "should populate all the file uploads" do
93
- assert_equal("bar.txt", @article.upload.filename)
92
+ it "should save all the file uploads" do
93
+ assert_equal("bar.txt", @article.reload.upload.filename)
94
94
  assert_equal("bar bar bar", File.open(@article.upload.path).read)
95
95
  end
96
96
 
@@ -101,4 +101,54 @@ class TestDraft < Minitest::Unit::TestCase
101
101
  end
102
102
  end
103
103
 
104
+ describe "Rejecting a draft" do
105
+ before do
106
+ @article = Article.new(
107
+ :text => "initial text",
108
+ :upload => file_upload)
109
+ end
110
+
111
+ describe "for an article which hasn't yet been saved" do
112
+ before do
113
+ @article_count = Article.count
114
+ @draft = @article.save_draft
115
+ @draft_count = Draft.count
116
+ @article = @draft.reject!
117
+ end
118
+
119
+ it "should not create an article" do
120
+ assert_equal(@article_count, Article.count)
121
+ end
122
+
123
+ it "should delete the draft" do
124
+ assert_equal(@draft_count - 1, Draft.count)
125
+ end
126
+ end
127
+
128
+ describe "for an article which already exists" do
129
+ before do
130
+ @article.save
131
+ @article_count = Article.count
132
+ @article.text = "some draft text"
133
+ @article.upload = file_upload("bar.txt")
134
+ @draft = @article.save_draft
135
+ @draft_count = Draft.count
136
+ @draft.reject!
137
+ end
138
+
139
+ it "shouldn't do anything mental, like creating a new object" do
140
+ assert_equal(@article_count, Article.count)
141
+ end
142
+
143
+ it "should properly leave the article's attributes alone" do
144
+ assert_equal("initial text", @article.reload.text)
145
+ end
146
+
147
+ it "should delete the article's draft" do
148
+ assert_equal(@draft_count - 1, Draft.count)
149
+ refute @article.reload.draft
150
+ end
151
+ end
152
+ end
153
+
104
154
  end
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.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-19 00:00:00.000000000 Z
12
+ date: 2012-08-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &2172805820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
24
+ version_requirements: *2172805820
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: sqlite3
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &2172804980 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: '0'
38
33
  type: :development
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
35
+ version_requirements: *2172804980
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: debugger
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &2172804380 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ! '>='
@@ -53,15 +43,10 @@ dependencies:
53
43
  version: '0'
54
44
  type: :development
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
46
+ version_requirements: *2172804380
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: minitest
64
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &2172803900 !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ! '>='
@@ -69,15 +54,10 @@ dependencies:
69
54
  version: '0'
70
55
  type: :development
71
56
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
57
+ version_requirements: *2172803900
78
58
  - !ruby/object:Gem::Dependency
79
59
  name: bundler
80
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &2172803380 !ruby/object:Gem::Requirement
81
61
  none: false
82
62
  requirements:
83
63
  - - ~>
@@ -85,15 +65,10 @@ dependencies:
85
65
  version: 1.0.0
86
66
  type: :development
87
67
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ~>
92
- - !ruby/object:Gem::Version
93
- version: 1.0.0
68
+ version_requirements: *2172803380
94
69
  - !ruby/object:Gem::Dependency
95
70
  name: jeweler
96
- requirement: !ruby/object:Gem::Requirement
71
+ requirement: &2172802820 !ruby/object:Gem::Requirement
97
72
  none: false
98
73
  requirements:
99
74
  - - ~>
@@ -101,15 +76,10 @@ dependencies:
101
76
  version: 1.6.4
102
77
  type: :development
103
78
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- version: 1.6.4
79
+ version_requirements: *2172802820
110
80
  - !ruby/object:Gem::Dependency
111
81
  name: rcov
112
- requirement: !ruby/object:Gem::Requirement
82
+ requirement: &2172802280 !ruby/object:Gem::Requirement
113
83
  none: false
114
84
  requirements:
115
85
  - - ! '>='
@@ -117,15 +87,10 @@ dependencies:
117
87
  version: '0'
118
88
  type: :development
119
89
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
90
+ version_requirements: *2172802280
126
91
  - !ruby/object:Gem::Dependency
127
92
  name: turn
128
- requirement: !ruby/object:Gem::Requirement
93
+ requirement: &2172801760 !ruby/object:Gem::Requirement
129
94
  none: false
130
95
  requirements:
131
96
  - - ! '>='
@@ -133,15 +98,10 @@ dependencies:
133
98
  version: '0'
134
99
  type: :development
135
100
  prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: '0'
101
+ version_requirements: *2172801760
142
102
  - !ruby/object:Gem::Dependency
143
103
  name: carrierwave
144
- requirement: !ruby/object:Gem::Requirement
104
+ requirement: &2172801160 !ruby/object:Gem::Requirement
145
105
  none: false
146
106
  requirements:
147
107
  - - ! '>='
@@ -149,15 +109,10 @@ dependencies:
149
109
  version: '0'
150
110
  type: :development
151
111
  prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: '0'
112
+ version_requirements: *2172801160
158
113
  - !ruby/object:Gem::Dependency
159
114
  name: minitest-rails-shoulda
160
- requirement: !ruby/object:Gem::Requirement
115
+ requirement: &2172800560 !ruby/object:Gem::Requirement
161
116
  none: false
162
117
  requirements:
163
118
  - - ! '>='
@@ -165,12 +120,7 @@ dependencies:
165
120
  version: '0'
166
121
  type: :development
167
122
  prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
- requirements:
171
- - - ! '>='
172
- - !ruby/object:Gem::Version
173
- version: '0'
123
+ version_requirements: *2172800560
174
124
  description: A
175
125
  email: dave.hrycyszyn@headlondon.com
176
126
  executables: []
@@ -223,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
223
173
  version: '0'
224
174
  segments:
225
175
  - 0
226
- hash: 1415611400334149220
176
+ hash: -2617672663622739077
227
177
  required_rubygems_version: !ruby/object:Gem::Requirement
228
178
  none: false
229
179
  requirements:
@@ -232,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
182
  version: '0'
233
183
  requirements: []
234
184
  rubyforge_project:
235
- rubygems_version: 1.8.24
185
+ rubygems_version: 1.8.17
236
186
  signing_key:
237
187
  specification_version: 3
238
188
  summary: Simple