mm-draft 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +20 -0
- data/README.md +62 -0
- data/Rakefile +36 -0
- data/lib/draft.rb +2 -0
- data/lib/locale/en.yml +6 -0
- data/lib/mongo_mapper/plugins/draft/callbacks.rb +12 -0
- data/lib/mongo_mapper/plugins/draft/draft.rb +129 -0
- data/lib/mongo_mapper/plugins/draft/keys.rb +13 -0
- data/lib/mongo_mapper/plugins/draft/version.rb +5 -0
- data/test/models/monkey.rb +10 -0
- data/test/performance/models/monkey.rb +9 -0
- data/test/performance/models/monkey_no_draft.rb +7 -0
- data/test/performance/performance_helper.rb +15 -0
- data/test/performance/test/read_write.rb +28 -0
- data/test/test_helper.rb +39 -0
- data/test/unit/test_draft.rb +194 -0
- metadata +100 -0
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
gem 'rake'
|
4
|
+
gem 'bson_ext', '>= 1.6.4'
|
5
|
+
gem 'multi_json', '>= 1.3.6'
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'jnunemaker-matchy', '>= 0.4', :require => 'matchy'
|
9
|
+
gem 'shoulda', '>= 3.1.1'
|
10
|
+
gem 'mocha', '>= 0.12.3'
|
11
|
+
gem 'database_cleaner', '>= 0.8.0'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :development do
|
15
|
+
gem "wirble"
|
16
|
+
gem "hirb"
|
17
|
+
gem "awesome_print"
|
18
|
+
end
|
19
|
+
|
20
|
+
gemspec
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# MongoMapper Draft plugin
|
2
|
+
|
3
|
+
Plugin for MongoMapper to have draft/published option on models.
|
4
|
+
|
5
|
+
Works with ramdiv-mongo_mapper_acts_as_tree.
|
6
|
+
|
7
|
+
NOTE: Since ramdiv-mongo_mapper_acts_as_tree hasn't been updated in a while, I will change this to support Oktavilla/mongo_mapper_tree instead (http://github.com/ramdiv/mongo_mapper_acts_as_tree)
|
8
|
+
|
9
|
+
##Instance methods
|
10
|
+
<pre>
|
11
|
+
.draft? - true/false
|
12
|
+
.published? - true/false
|
13
|
+
.published_record - returns the published record) (or nil, if the document never has been published)
|
14
|
+
.draft_record - returns the draft record for a published record
|
15
|
+
</pre>
|
16
|
+
|
17
|
+
*draft_record* will return self if the draft? returns true
|
18
|
+
*published_record* will return self if draft? returns false
|
19
|
+
|
20
|
+
## Usage:
|
21
|
+
Create record as normal.
|
22
|
+
|
23
|
+
*.save* - Saves draft (with normal validation)
|
24
|
+
|
25
|
+
*.publish* - Saves the current record as draft, creates a new published record (returns true/false, depending on validation of draft record)
|
26
|
+
|
27
|
+
Validation is skipped on the published record, as the draft record should be checked for validations when saving.
|
28
|
+
|
29
|
+
All records will be duplicated (draft + published) in the DB instead of beeing embedded documents, as embedding would limit the size to half of what MongoDB is capable of.
|
30
|
+
|
31
|
+
Duplicating the records also gives the benefit of working directly on the published record. (although this isn't recommended, as it kind of breaks the draft/published structure)
|
32
|
+
|
33
|
+
## Example
|
34
|
+
|
35
|
+
### Model
|
36
|
+
<pre>
|
37
|
+
class Monkey
|
38
|
+
include MongoMapper::Document
|
39
|
+
plugin MongoMapper::Draft
|
40
|
+
|
41
|
+
key :name, String, :default => "test"
|
42
|
+
end
|
43
|
+
</pre>
|
44
|
+
### Usage of model
|
45
|
+
<pre>
|
46
|
+
m = Monkey.new
|
47
|
+
m.name = "Leif"
|
48
|
+
m.save
|
49
|
+
|
50
|
+
m.is_published? (will return false)
|
51
|
+
m.publish (will return true/false)
|
52
|
+
|
53
|
+
m.name = "Artn"
|
54
|
+
m.save
|
55
|
+
|
56
|
+
m.name # returns "Artn"
|
57
|
+
|
58
|
+
m.published_model.name # returns "Leif"
|
59
|
+
</pre>
|
60
|
+
|
61
|
+
|
62
|
+
Copyright (c) 2011 Leif Ringstad, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), 'lib', 'mongo_mapper', 'plugins', 'draft', 'version')
|
5
|
+
|
6
|
+
require 'rake/testtask'
|
7
|
+
namespace :test do
|
8
|
+
Rake::TestTask.new(:units) do |test|
|
9
|
+
test.libs << 'test'
|
10
|
+
test.ruby_opts << '-rubygems'
|
11
|
+
test.pattern = 'test/unit/**/test_*.rb'
|
12
|
+
test.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
#TODO Add performance
|
16
|
+
Rake::TestTask.new(:performance) do |test|
|
17
|
+
test.libs << 'test'
|
18
|
+
test.ruby_opts << '-rubygems'
|
19
|
+
test.pattern = 'test/performance/test/**/*.rb'
|
20
|
+
test.verbose = true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
task :default => 'test:units'
|
25
|
+
|
26
|
+
desc 'Builds the gem'
|
27
|
+
task :build do
|
28
|
+
sh 'gem build mm-draft.gemspec'
|
29
|
+
Dir.mkdir('pkg') unless File.directory?('pkg')
|
30
|
+
sh "mv mm-draft-#{MongoMapper::Draft::VERSION}.gem pkg/mm-draft-#{MongoMapper::Draft::VERSION}.gem"
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Builds and Installs the gem'
|
34
|
+
task :install => :build do
|
35
|
+
sh "gem install pkg/mm-draft-#{MongoMapper::Draft::VERSION}.gem"
|
36
|
+
end
|
data/lib/draft.rb
ADDED
data/lib/locale/en.yml
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'callbacks')
|
2
|
+
require File.join(File.dirname(__FILE__), 'keys')
|
3
|
+
# I18n.load_path << File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'locale', 'en.yml'), __FILE__)
|
4
|
+
|
5
|
+
module MongoMapper
|
6
|
+
module Plugins
|
7
|
+
module Draft
|
8
|
+
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
include MongoMapper::Plugins::Draft::Callbacks
|
12
|
+
include MongoMapper::Plugins::Draft::Keys
|
13
|
+
|
14
|
+
def draft?
|
15
|
+
self.draft
|
16
|
+
end
|
17
|
+
|
18
|
+
def published?
|
19
|
+
if draft?
|
20
|
+
return false if self.draft_record_published_id == nil # save a query and return false
|
21
|
+
return true if (self.class.find(self.draft_record_published_id) != nil)
|
22
|
+
else
|
23
|
+
return true
|
24
|
+
end
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def publish
|
29
|
+
if (draft? == false) # don't publish non-drafts...
|
30
|
+
return false
|
31
|
+
end
|
32
|
+
|
33
|
+
if (self.changed?) # save any changes, in case publish is called directly instead of save
|
34
|
+
return false if (self.save == false)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# if already published, keep some old data to update instead of insert
|
39
|
+
if (self.published?)
|
40
|
+
old_published_record = self.published_record
|
41
|
+
# support for mm-tree
|
42
|
+
# remove parents from previous published record
|
43
|
+
if (self.respond_to?("parent_id_field") && self.respond_to?("path_field") && self.respond_to?("depth_field"))
|
44
|
+
old_published_record.parent = nil
|
45
|
+
old_published_record.save
|
46
|
+
end
|
47
|
+
live_record = self.clone
|
48
|
+
live_record._id = self.published_record_id
|
49
|
+
live_record.created_at = old_published_record.created_at if self.respond_to?("created_at")
|
50
|
+
else
|
51
|
+
live_record = self.clone
|
52
|
+
live_record.created_at = Time.now.utc if self.respond_to?("created_at")
|
53
|
+
end
|
54
|
+
|
55
|
+
self.draft_record_published_id = live_record._id
|
56
|
+
self.class.skip_callback(:save, :before, :update_timestamps ) if self.respond_to?("updated_at")
|
57
|
+
self.save!
|
58
|
+
self.class.set_callback(:save, :before, :update_timestamps ) if self.respond_to?("updated_at")
|
59
|
+
|
60
|
+
if (self.respond_to?("parent_id_field") && self.respond_to?("path_field") && self.respond_to?("depth_field"))
|
61
|
+
# if so, remove the current parent (should have already been don)
|
62
|
+
# set parent to nil for live_record before setting "real" parent.
|
63
|
+
# live_record.parent = nil
|
64
|
+
|
65
|
+
if (self.parent != nil)
|
66
|
+
# no need to copy order value, as it's copied in the clone process
|
67
|
+
# check draft.parent.published_record != nil, and set as parent
|
68
|
+
if (self.parent != nil)
|
69
|
+
if (self.parent.published_record != nil)
|
70
|
+
live_record.parent = self.parent.published_record
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
live_record.draft = false;
|
77
|
+
live_record.updated_at = Time.now.utc if self.respond_to?("updated_at")
|
78
|
+
live_record.save!
|
79
|
+
return true
|
80
|
+
end
|
81
|
+
|
82
|
+
def published_record
|
83
|
+
if draft?
|
84
|
+
return nil if self.draft_record_published_id == nil # save a query and return nil of draft_record_published_id == nil
|
85
|
+
self.class.find(self.draft_record_published_id)
|
86
|
+
else
|
87
|
+
self
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def published_record_id
|
92
|
+
if draft?
|
93
|
+
self.draft_record_published_id
|
94
|
+
else
|
95
|
+
self._id
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def draft_record
|
100
|
+
if draft?
|
101
|
+
self
|
102
|
+
else
|
103
|
+
self.class.all(:conditions => { :draft => true, :draft_record_published_id => self._id }).first
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def unpublish
|
108
|
+
published_rec = self.published_record
|
109
|
+
draft_rec = self.draft_record
|
110
|
+
|
111
|
+
self.class.skip_callback(:destroy, :before, :unpublish)
|
112
|
+
published_rec.destroy if published_rec != nil # destroy published record
|
113
|
+
self.class.set_callback(:destroy, :before, :unpublish)
|
114
|
+
|
115
|
+
draft_rec.draft_record_published_id = nil if draft_rec != nil # update draft record
|
116
|
+
draft_rec.save! if draft_rec != nil
|
117
|
+
# if draft?
|
118
|
+
# published = self.class.find(self.draft_record_published_id)
|
119
|
+
# published.destroy if (published != nil)
|
120
|
+
# self.draft_record_published_id = nil
|
121
|
+
# self.save! # remove draft_record_published_id
|
122
|
+
# else
|
123
|
+
# self.draft_record.unpublish
|
124
|
+
# end
|
125
|
+
end
|
126
|
+
|
127
|
+
end # Module Draft
|
128
|
+
end # Module plugins
|
129
|
+
end # module MongoMapper
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module MongoMapper
|
2
|
+
module Plugins
|
3
|
+
module Draft
|
4
|
+
module Keys
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
included do
|
7
|
+
key :draft, Boolean, :default => true
|
8
|
+
key :draft_record_published_id, ObjectId # points to the live page version if draft == true. else NIL
|
9
|
+
end # included_do
|
10
|
+
end # Keys
|
11
|
+
end # Versioned
|
12
|
+
end # Module plugins
|
13
|
+
end # module MongoMapper
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
require 'draft'
|
7
|
+
|
8
|
+
Bundler.require(:default, :test)
|
9
|
+
|
10
|
+
MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017)
|
11
|
+
MongoMapper.database = "mm-draft-performance"
|
12
|
+
|
13
|
+
Dir["#{File.dirname(__FILE__)}/models/*.rb"].each {|file| require file}
|
14
|
+
|
15
|
+
DatabaseCleaner.strategy = :truncation
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'performance_helper'))
|
2
|
+
|
3
|
+
require 'benchmark'
|
4
|
+
|
5
|
+
DatabaseCleaner.start
|
6
|
+
|
7
|
+
Benchmark.bm(22) do |x|
|
8
|
+
ids_draft = []
|
9
|
+
ids_no_draft = []
|
10
|
+
|
11
|
+
# Write performance
|
12
|
+
x.report("write without draft ") do
|
13
|
+
500.times { |i| ids_no_draft << MonkeyNodraft.create(:name => "Baboo", :age => 12, ).id }
|
14
|
+
end
|
15
|
+
x.report("write with draft ") do
|
16
|
+
500.times { |i| ids_draft << Monkey.create(:name => "Baboo", :age => 12, ).id }
|
17
|
+
end
|
18
|
+
|
19
|
+
# Read performance
|
20
|
+
x.report("read with draft ") do
|
21
|
+
ids_draft.each { |id| Monkey.first(:id => id) }
|
22
|
+
end
|
23
|
+
x.report("read without draft ") do
|
24
|
+
ids_no_draft.each { |id| MonkeyNodraft.first(:id => id) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
DatabaseCleaner.clean
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
require 'draft'
|
7
|
+
|
8
|
+
Bundler.require(:default, :test)
|
9
|
+
|
10
|
+
MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017)
|
11
|
+
MongoMapper.database = "mm-draft-test"
|
12
|
+
|
13
|
+
Dir["#{File.dirname(__FILE__)}/models/*.rb"].each {|file| require file}
|
14
|
+
|
15
|
+
DatabaseCleaner.strategy = :truncation
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
# Drop all collections after each test case.
|
19
|
+
def setup
|
20
|
+
DatabaseCleaner.start
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
DatabaseCleaner.clean
|
25
|
+
end
|
26
|
+
|
27
|
+
# Make sure that each test case has a teardown
|
28
|
+
# method to clear the db after each test.
|
29
|
+
def inherited(base)
|
30
|
+
base.define_method setup do
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
base.define_method teardown do
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DraftTest < Test::Unit::TestCase
|
4
|
+
context "draft monkey records" do
|
5
|
+
setup do
|
6
|
+
@monkey_1 = Monkey.create(:name => "Chip")
|
7
|
+
@monkey_2 = Monkey.create(:name => "Unaton")
|
8
|
+
@monkey_1.publish
|
9
|
+
end
|
10
|
+
|
11
|
+
should "have same name as draft" do
|
12
|
+
@monkey_1.name.should == "Chip"
|
13
|
+
@monkey_1.published_record.name.should == "Chip"
|
14
|
+
@monkey_1.published_record.name.should == @monkey_1.name
|
15
|
+
end
|
16
|
+
|
17
|
+
should "be published" do
|
18
|
+
@monkey_1.published_record.should_not == nil
|
19
|
+
end
|
20
|
+
|
21
|
+
should "not have same created time as draft" do
|
22
|
+
@monkey_1.unpublish
|
23
|
+
@monkey_1.publish
|
24
|
+
@monkey_1.created_at.should_not == @monkey_1.published_record.created_at
|
25
|
+
end
|
26
|
+
|
27
|
+
should "not be published" do
|
28
|
+
@monkey_2.published?.should_not == true
|
29
|
+
@monkey_2.published_record.should == nil
|
30
|
+
end
|
31
|
+
|
32
|
+
should "not be draft" do
|
33
|
+
@monkey_1.published_record.draft?.should_not == true
|
34
|
+
end
|
35
|
+
|
36
|
+
should "be draft" do
|
37
|
+
@monkey_2.draft?.should == true
|
38
|
+
end
|
39
|
+
|
40
|
+
should "rename draft only" do
|
41
|
+
@monkey_1.name = "Sagofon"
|
42
|
+
@monkey_1.published_record.should_not == nil
|
43
|
+
@monkey_1.name.should_not == @monkey_1.published_record.name
|
44
|
+
end
|
45
|
+
|
46
|
+
should "rename both draft and published record" do
|
47
|
+
@monkey_1.name = "Sagofon"
|
48
|
+
@monkey_1.publish
|
49
|
+
@monkey_1.published_record.should_not == nil
|
50
|
+
@monkey_1.name.should == @monkey_1.published_record.name
|
51
|
+
end
|
52
|
+
|
53
|
+
should "have updated updated_at both published record" do
|
54
|
+
@monkey_1.name ="Kake"
|
55
|
+
@monkey_1.save
|
56
|
+
@monkey_1.publish
|
57
|
+
@monkey_1.published_record.updated_at.should_not == @monkey_1.updated_at
|
58
|
+
end
|
59
|
+
|
60
|
+
should "unpublish draft record" do
|
61
|
+
@monkey_1.unpublish
|
62
|
+
assert !@monkey_1.published?
|
63
|
+
@monkey_1.published_record_id.should == nil
|
64
|
+
@monkey_1.published_record.should == nil
|
65
|
+
end
|
66
|
+
|
67
|
+
should "unpublish published record directly" do
|
68
|
+
# It is recommended to unpublish a draft record instead of unpublising a published record
|
69
|
+
@monkey_1.publish # publish record again...
|
70
|
+
@monkey_1.published_record.unpublish
|
71
|
+
# reload monkey_1
|
72
|
+
@monkey_1.reload
|
73
|
+
@monkey_1.published?.should_not == true
|
74
|
+
@monkey_1.published_record_id.should == nil
|
75
|
+
@monkey_1.published_record.should == nil
|
76
|
+
end
|
77
|
+
|
78
|
+
should "destroy published record only" do
|
79
|
+
@monkey_2.publish
|
80
|
+
tmp_id = @monkey_2.published_record_id
|
81
|
+
@monkey_2.published_record.destroy
|
82
|
+
@monkey_2.reload
|
83
|
+
@monkey_2.published_record_id.should == nil
|
84
|
+
@monkey_2.published_record.should == nil
|
85
|
+
@monkey_2.name.should == "Unaton" # make sure we didn't loose the draft
|
86
|
+
@monkey_2.published?.should_not == true
|
87
|
+
@monkey_2.draft?.should == true
|
88
|
+
Monkey.find(tmp_id).should == nil
|
89
|
+
end
|
90
|
+
|
91
|
+
should "destroy draft and published record" do
|
92
|
+
@monkey_2.publish # publish record again...
|
93
|
+
tmp_draft_id = @monkey_2._id
|
94
|
+
tmp_published_id = @monkey_2.published_record_id
|
95
|
+
@monkey_2.destroy
|
96
|
+
# keep ID's in order to check that they are destroyed!
|
97
|
+
Monkey.find(tmp_draft_id).should == nil
|
98
|
+
Monkey.find(tmp_published_id).should == nil
|
99
|
+
end
|
100
|
+
|
101
|
+
end # context "draft monkey records" do
|
102
|
+
|
103
|
+
# context "tree-record" do
|
104
|
+
# setup do
|
105
|
+
# @root_1 = Dog.create(:name => "Atmel")
|
106
|
+
# @child_1 = Dog.create(:name => "ATmega644P", :parent => @root_1)
|
107
|
+
# @child_2 = Dog.create(:name => "ATmega2561", :parent => @root_1)
|
108
|
+
# @child_2_1 = Dog.create(:name => "ATtiny24", :parent => @child_2)
|
109
|
+
|
110
|
+
# @root_2 = Dog.create(:name => "ST Ericsson")
|
111
|
+
# @child_3 = Dog.create(:name => "ISP1181B", :parent => @root_2)
|
112
|
+
|
113
|
+
# @root_1.publish
|
114
|
+
# @child_1.publish
|
115
|
+
# @child_2.publish
|
116
|
+
# @child_2_1.publish
|
117
|
+
# @root_2.publish
|
118
|
+
# end
|
119
|
+
|
120
|
+
# should "test draft record parents" do
|
121
|
+
# assert_equal(@root_2, @child_3.parent)
|
122
|
+
# assert_equal(@child_2, @child_2_1.parent)
|
123
|
+
# end
|
124
|
+
|
125
|
+
# should "test parents for published records" do
|
126
|
+
# assert_equal(@root_1.published_record, @child_1.published_record.parent)
|
127
|
+
# assert_equal(@root_1.published_record, @child_2.published_record.parent)
|
128
|
+
# assert_equal(@child_2.published_record, @child_2_1.published_record.parent)
|
129
|
+
# end
|
130
|
+
|
131
|
+
# should "move draft record to new parent, but keep published at old parent" do
|
132
|
+
# @child_2.parent = @root_2
|
133
|
+
|
134
|
+
# assert !@root_2.is_or_is_ancestor_of?(@child_2_1)
|
135
|
+
# assert !@child_2_1.is_or_is_descendant_of?(@root_2)
|
136
|
+
# assert !@root_2.descendants.include?(@child_2_1)
|
137
|
+
|
138
|
+
# @child_2.save
|
139
|
+
# @child_2_1.reload
|
140
|
+
|
141
|
+
# assert @root_2.is_or_is_ancestor_of?(@child_2_1)
|
142
|
+
# assert @child_2_1.is_or_is_descendant_of?(@root_2)
|
143
|
+
# assert @root_2.descendants.include?(@child_2_1)
|
144
|
+
|
145
|
+
# # test published against root_1
|
146
|
+
# assert @root_1.published_record.is_or_is_ancestor_of?(@child_2_1.published_record)
|
147
|
+
# 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)
|
149
|
+
# end
|
150
|
+
|
151
|
+
# should "move both draft and published record to new parent" do
|
152
|
+
# @child_2.parent = @root_2
|
153
|
+
|
154
|
+
# assert !@root_2.is_or_is_ancestor_of?(@child_2_1)
|
155
|
+
# assert !@child_2_1.is_or_is_descendant_of?(@root_2)
|
156
|
+
# assert !@root_2.descendants.include?(@child_2_1)
|
157
|
+
|
158
|
+
# # can only test published after saving and publishing
|
159
|
+
# @child_2.save
|
160
|
+
# @child_2.publish # will also save
|
161
|
+
# @child_2.reload
|
162
|
+
# @child_2_1.reload
|
163
|
+
|
164
|
+
# assert @root_2.is_or_is_ancestor_of?(@child_2_1)
|
165
|
+
# assert @child_2_1.is_or_is_descendant_of?(@root_2)
|
166
|
+
# assert @root_2.descendants.include?(@child_2_1)
|
167
|
+
|
168
|
+
# assert @root_2.published_record.is_or_is_ancestor_of?(@child_2_1.published_record)
|
169
|
+
# assert @child_2_1.published_record.is_or_is_descendant_of?(@root_2.published_record)
|
170
|
+
# assert @root_2.published_record.descendants.include?(@child_2_1.published_record)
|
171
|
+
# end
|
172
|
+
|
173
|
+
# should "set a record as a root and check for ancestor" do
|
174
|
+
# @child_2.parent = nil
|
175
|
+
|
176
|
+
# assert !@root_2.is_or_is_ancestor_of?(@child_2_1)
|
177
|
+
# assert !@child_2_1.is_or_is_descendant_of?(@root_2)
|
178
|
+
# assert !@root_2.descendants.include?(@child_2_1)
|
179
|
+
|
180
|
+
# # can only test published after saving and publishing
|
181
|
+
# @child_2.save
|
182
|
+
# @child_2.publish # will also save
|
183
|
+
# @child_2.reload
|
184
|
+
# @child_2_1.reload
|
185
|
+
|
186
|
+
# assert @child_2.root?
|
187
|
+
# assert @child_2.published_record.root?
|
188
|
+
# assert @child_2_1.is_or_is_descendant_of?(@child_2)
|
189
|
+
|
190
|
+
# assert !@root_1.published_record.is_or_is_ancestor_of?(@child_2_1.published_record)
|
191
|
+
# 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)
|
193
|
+
# end
|
194
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mm-draft
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Leif Ringstad
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: i18n
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mongo_mapper
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.12.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.12.0
|
46
|
+
description:
|
47
|
+
email:
|
48
|
+
- leifcr@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- lib/draft.rb
|
54
|
+
- lib/locale/en.yml
|
55
|
+
- lib/mongo_mapper/plugins/draft/callbacks.rb
|
56
|
+
- lib/mongo_mapper/plugins/draft/draft.rb
|
57
|
+
- lib/mongo_mapper/plugins/draft/keys.rb
|
58
|
+
- lib/mongo_mapper/plugins/draft/version.rb
|
59
|
+
- Gemfile
|
60
|
+
- Rakefile
|
61
|
+
- README.md
|
62
|
+
- test/models/monkey.rb
|
63
|
+
- test/performance/models/monkey.rb
|
64
|
+
- test/performance/models/monkey_no_draft.rb
|
65
|
+
- test/performance/performance_helper.rb
|
66
|
+
- test/performance/test/read_write.rb
|
67
|
+
- test/test_helper.rb
|
68
|
+
- test/unit/test_draft.rb
|
69
|
+
homepage: http://github.com/leifcr/mm-draft
|
70
|
+
licenses: []
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.8.24
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: A MongoMapper extension adding draft/publishing support
|
93
|
+
test_files:
|
94
|
+
- test/models/monkey.rb
|
95
|
+
- test/performance/models/monkey.rb
|
96
|
+
- test/performance/models/monkey_no_draft.rb
|
97
|
+
- test/performance/performance_helper.rb
|
98
|
+
- test/performance/test/read_write.rb
|
99
|
+
- test/test_helper.rb
|
100
|
+
- test/unit/test_draft.rb
|