mm-draft 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +6 -7
- data/README.md +3 -3
- data/lib/mongo_mapper/plugins/draft/draft.rb +33 -31
- data/lib/mongo_mapper/plugins/draft/version.rb +1 -1
- data/test/test_helper.rb +8 -0
- data/test/unit/test_draft.rb +37 -18
- metadata +19 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 220381bc555c836661398b132bf81d72da0f555c
|
4
|
+
data.tar.gz: 246c792cc5415c90189e39f57c4b36a4fa05e1f9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f177e282b70d2073b394ec42db30d6045e17fba04593a0b63797feeb0ddbab4e574f6dd42499a8a4408eb2d4a825515f9dc7f00b7f0847ea7397d35c6c169c3c
|
7
|
+
data.tar.gz: 98e8501ff1417fd4310b2235d6bf2cc7e1351018cb267f476dd8a247b2dee33aa4bc4f30917e631670b4e0ffa102e76b4e5c852aa12bbcca3f0d8ce6b96d281a
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gem 'rake'
|
4
4
|
gem 'bson_ext', '>= 1.6.4'
|
@@ -7,14 +7,13 @@ gem 'multi_json', '>= 1.3.6'
|
|
7
7
|
group :test do
|
8
8
|
gem 'jnunemaker-matchy', '>= 0.4', :require => 'matchy'
|
9
9
|
gem 'shoulda', '>= 3.1.1'
|
10
|
-
gem 'mocha', '>= 0.12.3'
|
10
|
+
gem 'mocha', '>= 0.12.3', :require => 'mocha/setup'
|
11
11
|
gem 'database_cleaner', '>= 0.8.0'
|
12
12
|
end
|
13
13
|
|
14
|
-
group :development do
|
15
|
-
gem
|
16
|
-
gem
|
17
|
-
gem "awesome_print"
|
14
|
+
group :development, :test do
|
15
|
+
gem 'coveralls', :require => false
|
16
|
+
gem 'simplecov', :require => false
|
18
17
|
end
|
19
18
|
|
20
|
-
|
19
|
+
gem 'mongo_mapper', '> 0.12'
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# MongoMapper Draft plugin
|
2
|
+
[![Build Status](https://travis-ci.org/leifcr/mm-draft.svg?branch=master)](https://travis-ci.org/leifcr/mm-draft) [![Coverage Status](https://coveralls.io/repos/leifcr/mm-draft/badge.png)](https://coveralls.io/r/leifcr/mm-draft) [![Dependency Status](https://gemnasium.com/leifcr/mm-draft.svg)](https://gemnasium.com/leifcr/mm-draft)
|
2
3
|
|
3
|
-
Plugin for MongoMapper to have draft/published option on models.
|
4
4
|
|
5
|
-
|
5
|
+
Plugin for MongoMapper to have draft/published option on models.
|
6
6
|
|
7
|
-
NOTE:
|
7
|
+
NOTE: Can have issues with other plugins...
|
8
8
|
|
9
9
|
##Instance methods
|
10
10
|
<pre>
|
@@ -14,7 +14,7 @@ module MongoMapper
|
|
14
14
|
def draft?
|
15
15
|
self.draft
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def published?
|
19
19
|
if draft?
|
20
20
|
return false if self.draft_record_published_id == nil # save a query and return false
|
@@ -24,28 +24,28 @@ module MongoMapper
|
|
24
24
|
end
|
25
25
|
false
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def publish
|
29
|
-
if (draft? == false) # don't publish non-drafts...
|
30
|
-
|
31
|
-
end
|
32
|
-
|
29
|
+
return false if (draft? == false) # don't publish non-drafts...
|
30
|
+
|
33
31
|
if (self.changed?) # save any changes, in case publish is called directly instead of save
|
34
32
|
return false if (self.save == false)
|
35
33
|
end
|
36
34
|
|
37
|
-
|
35
|
+
|
38
36
|
# if already published, keep some old data to update instead of insert
|
39
37
|
if (self.published?)
|
40
38
|
old_published_record = self.published_record
|
41
39
|
# support for mm-tree
|
42
40
|
# remove parents from previous published record
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
# TREE Support disabled for now
|
42
|
+
# if (self.respond_to?("parent_id_field") && self.respond_to?("path_field") && self.respond_to?("depth_field"))
|
43
|
+
# old_published_record.parent = nil
|
44
|
+
# old_published_record.save
|
45
|
+
# end
|
46
|
+
# destroy old published record... Not ideal, but should work
|
47
|
+
self.published_record.destroy if self.published_record != nil
|
47
48
|
live_record = self.clone
|
48
|
-
live_record._id = self.published_record_id
|
49
49
|
live_record.created_at = old_published_record.created_at if self.respond_to?("created_at")
|
50
50
|
else
|
51
51
|
live_record = self.clone
|
@@ -57,28 +57,30 @@ module MongoMapper
|
|
57
57
|
self.save!
|
58
58
|
self.class.set_callback(:save, :before, :update_timestamps ) if self.respond_to?("updated_at")
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
|
60
|
+
|
61
|
+
# TREE Support disabled for now
|
62
|
+
# if (self.respond_to?("parent_id_field") && self.respond_to?("path_field") && self.respond_to?("depth_field"))
|
63
|
+
# # if so, remove the current parent (should have already been don)
|
64
|
+
# # set parent to nil for live_record before setting "real" parent.
|
65
|
+
# # live_record.parent = nil
|
66
|
+
|
67
|
+
# if (self.parent != nil)
|
68
|
+
# # no need to copy order value, as it's copied in the clone process
|
69
|
+
# # check draft.parent.published_record != nil, and set as parent
|
70
|
+
# if (self.parent != nil)
|
71
|
+
# if (self.parent.published_record != nil)
|
72
|
+
# live_record.parent = self.parent.published_record
|
73
|
+
# end
|
74
|
+
# end
|
75
|
+
# end
|
76
|
+
# end
|
77
|
+
|
76
78
|
live_record.draft = false;
|
77
79
|
live_record.updated_at = Time.now.utc if self.respond_to?("updated_at")
|
78
80
|
live_record.save!
|
79
81
|
return true
|
80
82
|
end
|
81
|
-
|
83
|
+
|
82
84
|
def published_record
|
83
85
|
if draft?
|
84
86
|
return nil if self.draft_record_published_id == nil # save a query and return nil of draft_record_published_id == nil
|
@@ -95,7 +97,7 @@ module MongoMapper
|
|
95
97
|
self._id
|
96
98
|
end
|
97
99
|
end
|
98
|
-
|
100
|
+
|
99
101
|
def draft_record
|
100
102
|
if draft?
|
101
103
|
self
|
@@ -103,7 +105,7 @@ module MongoMapper
|
|
103
105
|
self.class.all(:conditions => { :draft => true, :draft_record_published_id => self._id }).first
|
104
106
|
end
|
105
107
|
end
|
106
|
-
|
108
|
+
|
107
109
|
def unpublish
|
108
110
|
published_rec = self.published_record
|
109
111
|
draft_rec = self.draft_record
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
3
|
|
4
|
+
if ENV['TRAVIS']
|
5
|
+
require 'coveralls'
|
6
|
+
Coveralls.wear!
|
7
|
+
elsif ENV['COVERAGE']
|
8
|
+
require 'simplecov'
|
9
|
+
SimpleCov.start
|
10
|
+
end
|
11
|
+
|
4
12
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
13
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
14
|
require 'mm-draft'
|
data/test/unit/test_draft.rb
CHANGED
@@ -17,32 +17,32 @@ class DraftTest < Test::Unit::TestCase
|
|
17
17
|
should "be published" do
|
18
18
|
@monkey_1.published_record.should_not == nil
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
should "not have same created time as draft" do
|
22
|
-
@monkey_1.unpublish
|
22
|
+
@monkey_1.unpublish
|
23
23
|
@monkey_1.publish
|
24
24
|
@monkey_1.created_at.should_not == @monkey_1.published_record.created_at
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
should "not be published" do
|
28
28
|
@monkey_2.published?.should_not == true
|
29
29
|
@monkey_2.published_record.should == nil
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
should "not be draft" do
|
33
33
|
@monkey_1.published_record.draft?.should_not == true
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
should "be draft" do
|
37
37
|
@monkey_2.draft?.should == true
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
should "rename draft only" do
|
41
41
|
@monkey_1.name = "Sagofon"
|
42
42
|
@monkey_1.published_record.should_not == nil
|
43
43
|
@monkey_1.name.should_not == @monkey_1.published_record.name
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
should "rename both draft and published record" do
|
47
47
|
@monkey_1.name = "Sagofon"
|
48
48
|
@monkey_1.publish
|
@@ -98,15 +98,34 @@ class DraftTest < Test::Unit::TestCase
|
|
98
98
|
Monkey.find(tmp_published_id).should == nil
|
99
99
|
end
|
100
100
|
|
101
|
+
should 'get id of the published record on the published record' do
|
102
|
+
@monkey_1.published_record.published_record_id.should == @monkey_1.published_record._id
|
103
|
+
@monkey_1.draft_record_published_id.should == @monkey_1.published_record.published_record_id
|
104
|
+
end
|
105
|
+
|
106
|
+
should 'not be able to publish a published record' do
|
107
|
+
@monkey_1.published_record.publish.should == false
|
108
|
+
end
|
109
|
+
|
110
|
+
should 'return that a published_record is published' do
|
111
|
+
@monkey_1.published_record.published?.should == true
|
112
|
+
end
|
113
|
+
|
114
|
+
should 'return false for published? if a published record has been deleted instead of destroyed' do
|
115
|
+
@monkey_1.published_record.delete
|
116
|
+
@monkey_1.published?.should == false
|
117
|
+
end
|
118
|
+
|
119
|
+
|
101
120
|
end # context "draft monkey records" do
|
102
|
-
|
121
|
+
|
103
122
|
# context "tree-record" do
|
104
123
|
# setup do
|
105
124
|
# @root_1 = Dog.create(:name => "Atmel")
|
106
125
|
# @child_1 = Dog.create(:name => "ATmega644P", :parent => @root_1)
|
107
126
|
# @child_2 = Dog.create(:name => "ATmega2561", :parent => @root_1)
|
108
127
|
# @child_2_1 = Dog.create(:name => "ATtiny24", :parent => @child_2)
|
109
|
-
|
128
|
+
|
110
129
|
# @root_2 = Dog.create(:name => "ST Ericsson")
|
111
130
|
# @child_3 = Dog.create(:name => "ISP1181B", :parent => @root_2)
|
112
131
|
|
@@ -116,10 +135,10 @@ class DraftTest < Test::Unit::TestCase
|
|
116
135
|
# @child_2_1.publish
|
117
136
|
# @root_2.publish
|
118
137
|
# end
|
119
|
-
|
138
|
+
|
120
139
|
# should "test draft record parents" do
|
121
140
|
# assert_equal(@root_2, @child_3.parent)
|
122
|
-
# assert_equal(@child_2, @child_2_1.parent)
|
141
|
+
# assert_equal(@child_2, @child_2_1.parent)
|
123
142
|
# end
|
124
143
|
|
125
144
|
# should "test parents for published records" do
|
@@ -130,7 +149,7 @@ class DraftTest < Test::Unit::TestCase
|
|
130
149
|
|
131
150
|
# should "move draft record to new parent, but keep published at old parent" do
|
132
151
|
# @child_2.parent = @root_2
|
133
|
-
|
152
|
+
|
134
153
|
# assert !@root_2.is_or_is_ancestor_of?(@child_2_1)
|
135
154
|
# assert !@child_2_1.is_or_is_descendant_of?(@root_2)
|
136
155
|
# assert !@root_2.descendants.include?(@child_2_1)
|
@@ -145,12 +164,12 @@ class DraftTest < Test::Unit::TestCase
|
|
145
164
|
# # test published against root_1
|
146
165
|
# assert @root_1.published_record.is_or_is_ancestor_of?(@child_2_1.published_record)
|
147
166
|
# assert @child_2_1.published_record.is_or_is_descendant_of?(@root_1.published_record)
|
148
|
-
# assert @root_1.published_record.descendants.include?(@child_2_1.published_record)
|
167
|
+
# assert @root_1.published_record.descendants.include?(@child_2_1.published_record)
|
149
168
|
# end
|
150
|
-
|
169
|
+
|
151
170
|
# should "move both draft and published record to new parent" do
|
152
171
|
# @child_2.parent = @root_2
|
153
|
-
|
172
|
+
|
154
173
|
# assert !@root_2.is_or_is_ancestor_of?(@child_2_1)
|
155
174
|
# assert !@child_2_1.is_or_is_descendant_of?(@root_2)
|
156
175
|
# assert !@root_2.descendants.include?(@child_2_1)
|
@@ -169,10 +188,10 @@ class DraftTest < Test::Unit::TestCase
|
|
169
188
|
# assert @child_2_1.published_record.is_or_is_descendant_of?(@root_2.published_record)
|
170
189
|
# assert @root_2.published_record.descendants.include?(@child_2_1.published_record)
|
171
190
|
# end
|
172
|
-
|
191
|
+
|
173
192
|
# should "set a record as a root and check for ancestor" do
|
174
193
|
# @child_2.parent = nil
|
175
|
-
|
194
|
+
|
176
195
|
# assert !@root_2.is_or_is_ancestor_of?(@child_2_1)
|
177
196
|
# assert !@child_2_1.is_or_is_descendant_of?(@root_2)
|
178
197
|
# assert !@root_2.descendants.include?(@child_2_1)
|
@@ -189,6 +208,6 @@ class DraftTest < Test::Unit::TestCase
|
|
189
208
|
|
190
209
|
# assert !@root_1.published_record.is_or_is_ancestor_of?(@child_2_1.published_record)
|
191
210
|
# assert !@child_2_1.published_record.is_or_is_descendant_of?(@root_1.published_record)
|
192
|
-
# assert !@root_1.published_record.descendants.include?(@child_2_1.published_record)
|
211
|
+
# assert !@root_1.published_record.descendants.include?(@child_2_1.published_record)
|
193
212
|
# end
|
194
213
|
end
|
metadata
CHANGED
@@ -1,48 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mm-draft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.8
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Leif Ringstad
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-03-26 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: i18n
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: mongo_mapper
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0
|
33
|
+
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0
|
40
|
+
version: '0'
|
46
41
|
description:
|
47
42
|
email:
|
48
43
|
- leifcr@gmail.com
|
@@ -50,15 +45,15 @@ executables: []
|
|
50
45
|
extensions: []
|
51
46
|
extra_rdoc_files: []
|
52
47
|
files:
|
48
|
+
- Gemfile
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
53
51
|
- lib/locale/en.yml
|
54
52
|
- lib/mm-draft.rb
|
55
53
|
- lib/mongo_mapper/plugins/draft/callbacks.rb
|
56
54
|
- lib/mongo_mapper/plugins/draft/draft.rb
|
57
55
|
- lib/mongo_mapper/plugins/draft/keys.rb
|
58
56
|
- lib/mongo_mapper/plugins/draft/version.rb
|
59
|
-
- Gemfile
|
60
|
-
- Rakefile
|
61
|
-
- README.md
|
62
57
|
- test/models/monkey.rb
|
63
58
|
- test/performance/models/monkey.rb
|
64
59
|
- test/performance/models/monkey_no_draft.rb
|
@@ -68,33 +63,32 @@ files:
|
|
68
63
|
- test/unit/test_draft.rb
|
69
64
|
homepage: http://github.com/leifcr/mm-draft
|
70
65
|
licenses: []
|
66
|
+
metadata: {}
|
71
67
|
post_install_message:
|
72
68
|
rdoc_options: []
|
73
69
|
require_paths:
|
74
70
|
- lib
|
75
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
72
|
requirements:
|
78
|
-
- -
|
73
|
+
- - ">="
|
79
74
|
- !ruby/object:Gem::Version
|
80
75
|
version: '0'
|
81
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
77
|
requirements:
|
84
|
-
- -
|
78
|
+
- - ">="
|
85
79
|
- !ruby/object:Gem::Version
|
86
80
|
version: '0'
|
87
81
|
requirements: []
|
88
82
|
rubyforge_project:
|
89
|
-
rubygems_version:
|
83
|
+
rubygems_version: 2.2.2
|
90
84
|
signing_key:
|
91
|
-
specification_version:
|
85
|
+
specification_version: 4
|
92
86
|
summary: A MongoMapper extension adding draft/publishing support
|
93
87
|
test_files:
|
94
88
|
- test/models/monkey.rb
|
95
|
-
- test/
|
96
|
-
- test/performance/models/monkey_no_draft.rb
|
89
|
+
- test/test_helper.rb
|
97
90
|
- test/performance/performance_helper.rb
|
91
|
+
- test/performance/models/monkey_no_draft.rb
|
92
|
+
- test/performance/models/monkey.rb
|
98
93
|
- test/performance/test/read_write.rb
|
99
|
-
- test/test_helper.rb
|
100
94
|
- test/unit/test_draft.rb
|