draftsman 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -2
- data/Gemfile.lock +1 -1
- data/README.md +11 -6
- data/draftsman.gemspec +1 -0
- data/lib/draftsman/draft.rb +8 -6
- data/lib/draftsman/version.rb +1 -1
- data/spec/models/child_spec.rb +18 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74e4cf230e28a0fa2b097c33c0a3bb40360b4c3e
|
4
|
+
data.tar.gz: 549d0072468f067a86480273989d6a0b86118c99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dfed02ea98a99d534b3833327f4927b47e93ee4237899fe7c75e02ccd660195c4d562b5bf1dbdafbddb0343e19280a945eb773ee80a41dfd7625a7e2d237cc2
|
7
|
+
data.tar.gz: c4df9a57b0da2602328d995557a867936560965c6f4897d991107abc019789eea7d74ba4a35274e9777f469d353163b167aa00e5f23630b5cd89b2507377d092
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## v0.1.
|
3
|
+
## v0.1.1 - March 7, 2014
|
4
4
|
|
5
|
-
|
5
|
+
- Fixed [#3](https://github.com/minimalorange/draftsman/issues/3) - draft_publication_dependencies not honoring drafts
|
6
|
+
when draft is an update.
|
7
|
+
- Fixed [#1](https://github.com/minimalorange/draftsman/issues/1) - License missing from gemspec - Added MIT license.
|
8
|
+
|
9
|
+
## v0.1.0 - November 19, 2013
|
10
|
+
|
11
|
+
- Initial release.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Draftsman v0.1.
|
1
|
+
# Draftsman v0.1.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.
|
@@ -11,9 +11,9 @@ need of simple drafts or a publishing approval queue, then Draftsman just might
|
|
11
11
|
* The RSpec tests are lacking in some areas, so I will be adding to those over time as well. (Unfortunately, this gem
|
12
12
|
was not developed with TDD best practices because it was lifted from PaperTrail and modified from there.)
|
13
13
|
|
14
|
-
This gem is inspired by the [Kentouzu][1] gem, which is based heavily on [PaperTrail][2]. In fact, much of the
|
15
|
-
this gem
|
16
|
-
|
14
|
+
This gem is inspired by the [Kentouzu][1] gem, which is based heavily on [PaperTrail][2]. In fact, much of the structure
|
15
|
+
for this gem emulates PaperTrail (because it works beautifully). You should definitely check out PaperTrail and its
|
16
|
+
source: it's a nice clean example of a gem that hooks into Rails and Sinatra.
|
17
17
|
|
18
18
|
## Features
|
19
19
|
|
@@ -50,7 +50,7 @@ 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.1.
|
53
|
+
gem 'draftsman', '0.1.1'
|
54
54
|
```
|
55
55
|
|
56
56
|
Or if you want to grab the latest from `master`:
|
@@ -77,7 +77,7 @@ Run the migration(s).
|
|
77
77
|
Add `draft_id`, `published_at`, and `trashed_at` attributes to the models you want to have drafts on. `trashed_at` is
|
78
78
|
optional if you don't want to store drafts for destroys.
|
79
79
|
|
80
|
-
$ rails g migration
|
80
|
+
$ rails g migration add_drafts_to_widgets draft_id:integer published_at:timestamp trashed_at:timestamp
|
81
81
|
$ rake db:migrate
|
82
82
|
|
83
83
|
Add `has_drafts` to the models you want to have drafts on.
|
@@ -496,6 +496,10 @@ Rails guide:
|
|
496
496
|
This gem is a work in progress. I am adding specs as I need features in my application. Please add missing ones as you
|
497
497
|
work on features or find bugs!
|
498
498
|
|
499
|
+
## License
|
500
|
+
|
501
|
+
Draftsman is released under the [MIT License][9].
|
502
|
+
|
499
503
|
|
500
504
|
[1]: https://github.com/seaneshbaugh/kentouzu
|
501
505
|
[2]: https://github.com/airblade/paper_trail
|
@@ -504,3 +508,4 @@ work on features or find bugs!
|
|
504
508
|
[6]: https://github.com/janko-m/sinatra-activerecord
|
505
509
|
[7]: https://raw.github.com/minimalorange/draftsman/master/lib/generators/draftsman/templates/create_drafts.rb
|
506
510
|
[8]: http://www.sinatrarb.com/intro.html#Modular%20vs.%20Classic%20Style
|
511
|
+
[9]: http://www.opensource.org/licenses/MIT
|
data/draftsman.gemspec
CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.homepage = 'https://github.com/minimalorange/draftsman'
|
10
10
|
s.authors = ['Chris Peters']
|
11
11
|
s.email = 'chris@minimalorange.com'
|
12
|
+
s.license = 'MIT'
|
12
13
|
|
13
14
|
s.files = `git ls-files`.split("\n")
|
14
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/draftsman/draft.rb
CHANGED
@@ -52,25 +52,27 @@ class Draftsman::Draft < ActiveRecord::Base
|
|
52
52
|
def draft_publication_dependencies
|
53
53
|
dependencies = []
|
54
54
|
|
55
|
+
my_item = self.item.draft? ? self.item.draft.reify : self.item
|
56
|
+
|
55
57
|
case self.event
|
56
58
|
when 'create', 'update'
|
57
|
-
associations =
|
59
|
+
associations = my_item.class.reflect_on_all_associations(:belongs_to)
|
58
60
|
|
59
61
|
associations.each do |association|
|
60
62
|
association_class =
|
61
63
|
if association.polymorphic?
|
62
|
-
|
64
|
+
my_item.send(association.foreign_key.sub('_id', '_type')).constantize
|
63
65
|
else
|
64
66
|
association.klass
|
65
67
|
end
|
66
68
|
|
67
69
|
if association_class.draftable? && association.name != association_class.draft_association_name.to_sym
|
68
|
-
dependency =
|
70
|
+
dependency = my_item.send(association.name)
|
69
71
|
dependencies << dependency.draft if dependency.present? && dependency.draft? && dependency.draft.create?
|
70
72
|
end
|
71
73
|
end
|
72
74
|
when 'destroy'
|
73
|
-
associations =
|
75
|
+
associations = my_item.class.reflect_on_all_associations(:has_one) + my_item.class.reflect_on_all_associations(:has_many)
|
74
76
|
|
75
77
|
associations.each do |association|
|
76
78
|
if association.klass.draftable?
|
@@ -78,9 +80,9 @@ class Draftsman::Draft < ActiveRecord::Base
|
|
78
80
|
associated_dependencies =
|
79
81
|
case association.macro
|
80
82
|
when :has_one
|
81
|
-
|
83
|
+
my_item.send(association.name).present? ? [my_item.send(association.name)] : []
|
82
84
|
when :has_many
|
83
|
-
|
85
|
+
my_item.send(association.name)
|
84
86
|
end
|
85
87
|
|
86
88
|
associated_dependencies.each do |dependency|
|
data/lib/draftsman/version.rb
CHANGED
data/spec/models/child_spec.rb
CHANGED
@@ -150,7 +150,7 @@ describe Child do
|
|
150
150
|
end
|
151
151
|
|
152
152
|
subject { child.draft }
|
153
|
-
its(:draft_publication_dependencies) {
|
153
|
+
its(:draft_publication_dependencies) { should_not be_empty }
|
154
154
|
its(:draft_publication_dependencies) { should include parent.draft }
|
155
155
|
end
|
156
156
|
|
@@ -163,10 +163,26 @@ describe Child do
|
|
163
163
|
end
|
164
164
|
|
165
165
|
subject { child.draft }
|
166
|
-
its(:draft_publication_dependencies) {
|
166
|
+
its(:draft_publication_dependencies) { should_not be_empty }
|
167
167
|
its(:draft_publication_dependencies) { should include parent.draft }
|
168
168
|
end
|
169
169
|
|
170
|
+
context 'parent `create` draft with child `update` draft pointing to new parent' do
|
171
|
+
let(:new_parent) { Parent.new(:name => 'Patty') }
|
172
|
+
before do
|
173
|
+
parent.draft_creation
|
174
|
+
child.save!
|
175
|
+
new_parent.draft_creation
|
176
|
+
child.parent = new_parent
|
177
|
+
child.draft_update
|
178
|
+
end
|
179
|
+
|
180
|
+
subject { child.draft }
|
181
|
+
its(:draft_publication_dependencies) { should_not be_empty }
|
182
|
+
its(:draft_publication_dependencies) { should_not include parent.draft}
|
183
|
+
its(:draft_publication_dependencies) { should include new_parent.draft }
|
184
|
+
end
|
185
|
+
|
170
186
|
context 'parent `destroy` draft with child `destroy` draft' do
|
171
187
|
before do
|
172
188
|
child.save!
|
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.1.
|
4
|
+
version: 0.1.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:
|
11
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -223,7 +223,8 @@ files:
|
|
223
223
|
- spec/models/whitelister_spec.rb
|
224
224
|
- spec/spec_helper.rb
|
225
225
|
homepage: https://github.com/minimalorange/draftsman
|
226
|
-
licenses:
|
226
|
+
licenses:
|
227
|
+
- MIT
|
227
228
|
metadata: {}
|
228
229
|
post_install_message:
|
229
230
|
rdoc_options: []
|