draftsman 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ecc44a2da54f76db70765c3faf9e515c3aba215
4
- data.tar.gz: e54643b21e29a16872f83ca756592c2901220db7
3
+ metadata.gz: 9fe742f1e72bfd060d5d737fb6de9ee7cec1119f
4
+ data.tar.gz: f846ec1b196415f5f33609d2a8516ca2fc087294
5
5
  SHA512:
6
- metadata.gz: 5ec70e969b6bf40a9a8f69c87e504d2cd1fd0aa215757f022798b53d9d6d55ecc46d4282459058c277467d0eb47f397470432ab7c08e4d0641c7baf21396ec22
7
- data.tar.gz: 6bcef513664f7de84d96ec42996a8d4130a37794446b0a8ff8df39866fc556d6dbeb24b2d2f8543c67bd9fdaddb9daadb177c2df475bed0ed7ea6af74a484171
6
+ metadata.gz: a355e08da8ff267cc30be5b6a8bfa7dab673ca84bbda56997bd34dbc574606735b7ef312155cfd840a9ecc42e31513f352c98ef7f682888c4d316c8efaa854c8
7
+ data.tar.gz: 8f0d1d623df2fa66e332e1d715afa0c80a25f1d5218c6816c6a2110e283bef31587319dafec28f491217e8d4856b23bd44c8983c25f30d453475e7a1dc8d28b8
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
- ## v0.2 - June 3, 2014
3
+ ## v0.2.1 - June 28, 2014
4
+
5
+ - Commit [dbc6c83abb](https://github.com/live-editor/draftsman/commit/dbc6c83abbea5211f67ad883f4a2d18a9f5ac181) - Reifying a record that was drafted for destruction uses data from a drafted update before that if that's what happened.
6
+
7
+ ## v0.2.0 - June 3, 2014
4
8
 
5
9
  - Fixed [#4](https://github.com/live-editor/draftsman/issues/4) - Added `referenced_table_name` argument to scopes.
6
10
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- draftsman (0.2)
4
+ draftsman (0.2.1)
5
5
  activerecord (>= 3.0, < 5.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Draftsman v0.2 (alpha)
1
+ # Draftsman v0.2.1 (alpha)
2
2
 
3
3
  Draftsman is a Ruby gem that lets you create draft versions of your database records. If you're developing a system in
4
4
  need of simple drafts or a publishing approval queue, then Draftsman just might be what you need.
@@ -50,13 +50,13 @@ Works well with Rails, Sinatra, or any other application that depends on ActiveR
50
50
  Add Draftsman to your `Gemfile`.
51
51
 
52
52
  ```ruby
53
- gem 'draftsman', '0.2'
53
+ gem 'draftsman', '0.2.1'
54
54
  ```
55
55
 
56
56
  Or if you want to grab the latest from `master`:
57
57
 
58
58
  ```ruby
59
- gem 'draftsman', :github => 'minimalorange/draftsman'
59
+ gem 'draftsman', :github => 'live-editor/draftsman'
60
60
  ```
61
61
 
62
62
  Generate a migration which will add a `drafts` table to your database.
@@ -92,7 +92,7 @@ ActiveRecord Extension, steps for setting up your app with Draftsman will look s
92
92
  Add Draftsman to your `Gemfile`.
93
93
 
94
94
  ```ruby
95
- gem 'draftsman', :github => 'minimalorange/draftsman'
95
+ gem 'draftsman', :github => 'live-editor/draftsman'
96
96
  ```
97
97
 
98
98
  Generate a migration to add a `drafts` table to your database.
@@ -516,6 +516,6 @@ Draftsman is released under the [MIT License][9].
516
516
  [4]: http://railscasts.com/episodes/416-form-objects
517
517
  [5]: http://www.sinatrarb.com/
518
518
  [6]: https://github.com/janko-m/sinatra-activerecord
519
- [7]: https://raw.github.com/minimalorange/draftsman/master/lib/generators/draftsman/templates/create_drafts.rb
519
+ [7]: https://raw.github.com/live-editor/draftsman/master/lib/generators/draftsman/templates/create_drafts.rb
520
520
  [8]: http://www.sinatrarb.com/intro.html#Modular%20vs.%20Classic%20Style
521
521
  [9]: http://www.opensource.org/licenses/MIT
@@ -186,7 +186,9 @@ class Draftsman::Draft < ActiveRecord::Base
186
186
  # `@category = @category.reify if @category.draft?`
187
187
  def reify
188
188
  without_identity_map do
189
- unless self.object.nil?
189
+ if !self.previous_draft.nil?
190
+ reify_previous_draft.reify
191
+ elsif !self.object.nil?
190
192
  # This appears to be necessary if for some reason the draft's model hasn't been loaded (such as when done in the console).
191
193
  require self.item_type.underscore
192
194
 
@@ -228,6 +230,8 @@ class Draftsman::Draft < ActiveRecord::Base
228
230
  # Restore previous draft if one was stashed away
229
231
  if self.previous_draft.present?
230
232
  prev_draft = reify_previous_draft
233
+ prev_draft.save!
234
+
231
235
  self.item.class.where(:id => self.item).update_all "#{self.item.class.draft_association_name}_id".to_sym => prev_draft.id,
232
236
  self.item.class.trashed_at_attribute_name => nil
233
237
  else
@@ -261,7 +265,6 @@ private
261
265
  end
262
266
  end
263
267
 
264
- draft.save!
265
268
  draft
266
269
  end
267
270
 
@@ -1,3 +1,3 @@
1
1
  module Draftsman
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -294,4 +294,81 @@ describe Draftsman::Draft do
294
294
  end
295
295
  end
296
296
  end
297
+
298
+ describe :reify do
299
+ subject { trashable.draft.reify }
300
+
301
+ context 'with `create` draft' do
302
+ before { trashable.draft_creation }
303
+ its(:title) { should eql trashable.title }
304
+
305
+ context 'updated create' do
306
+ before do
307
+ trashable.name = 'Sam'
308
+ trashable.draft_update
309
+ end
310
+
311
+ its(:name) { should eql 'Sam' }
312
+ its(:title) { should be_nil }
313
+ end
314
+ end
315
+
316
+ context 'with `update` draft' do
317
+ before do
318
+ trashable.save!
319
+ trashable.name = 'Sam'
320
+ trashable.title = 'My Title'
321
+ trashable.draft_update
322
+ end
323
+
324
+ its(:name) { should eql 'Sam' }
325
+ its(:title) { should eql 'My Title' }
326
+
327
+ context 'updating the update' do
328
+ before do
329
+ trashable.title = nil
330
+ trashable.draft_update
331
+ end
332
+
333
+ its(:name) { should eql 'Sam' }
334
+ its(:title) { should be_nil }
335
+ end
336
+ end
337
+
338
+ context 'with `destroy` draft' do
339
+ context 'without previous draft' do
340
+ before do
341
+ trashable.save!
342
+ trashable.draft_destroy
343
+ end
344
+
345
+ its(:name) { should eql 'Bob' }
346
+ its(:title) { should be_nil }
347
+ end
348
+
349
+ context 'with previous `create` draft' do
350
+ before do
351
+ trashable.draft_creation
352
+ trashable.draft_destroy
353
+ end
354
+
355
+ its(:name) { should eql 'Bob' }
356
+ its(:title) { should be_nil }
357
+ end
358
+
359
+ context 'with previous `update` draft' do
360
+ before do
361
+ trashable.save!
362
+ trashable.name = 'Sam'
363
+ trashable.title = 'My Title'
364
+ trashable.draft_update
365
+ # Typically, 2 draft operations won't happen in the same request, so reload before draft-destroying.
366
+ trashable.reload.draft_destroy
367
+ end
368
+
369
+ its(:name) { should eql 'Sam' }
370
+ its(:title) { should eql 'My Title' }
371
+ end
372
+ end
373
+ end
297
374
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: draftsman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Peters
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-03 00:00:00.000000000 Z
11
+ date: 2014-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord