mm-draft 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 73d13795e0d5e002fb08f837f432afd0b22d65c0
4
- data.tar.gz: 1c978faf0f27857b7d14594879aed1b9d59ab8dd
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTdiMWNlNGY1Nzg0ZGFiNTE2ZTI0MzhhMzFhNjJkM2IxN2M4MjcwNQ==
5
+ data.tar.gz: !binary |-
6
+ MWJmYmNlYWQ0ZWU1Y2YzZjFjN2VlMzZmM2JmZThjZmQyN2I0MTRhMg==
5
7
  SHA512:
6
- metadata.gz: aecee7907f69b0128c836469d9fd44939922e7e8de5939115d18888aed82a3f395bfbabd438f7e4526918c6f56e28bf4c7245c4e3957e761f2601d9e9ec13046
7
- data.tar.gz: 1452006b11cd9ed6c52734bef6bc563f31c32dea2b8297910267351baef83de44022dcf2ccf5a567499fd62238a67b16bd8917137ab922e35b3a0fcd6040bfc6
8
+ metadata.gz: !binary |-
9
+ ZmUzMTVjMDBiMmI3NTllYTYxODc3MDVhZmVmODQzZjAzOTA5ZTc5OGYxMzhl
10
+ YmZiNGRkODI4M2QyZTA1MTJlZjE1YzAxMGI0MDFiMWRmNzQyOTI5ZmE1MDA5
11
+ ODNhMTAzNGFjNDNmNTNlMzg0MWYyZjhkNWI2MTUzYTI1ODQzMTY=
12
+ data.tar.gz: !binary |-
13
+ MjM3ODgyYmQ5YzE4ZjIxODAzMDIzZmJhOTFlNzUxNGRkMzMyZmI0ZjU2Y2I0
14
+ OWM4ODQzMGQ1MjAwNTc2NzExOWIxZjBlZmNlMmNlMTEwMjU4ZGI2MWZjYmY2
15
+ OGM1ZTc2YzY4YmY5MjVkOTRhMzFjNWFhMzhlYTI0YTc3NTIxMGY=
data/Gemfile CHANGED
@@ -5,10 +5,9 @@ gem 'bson_ext', '>= 1.6.4'
5
5
  gem 'multi_json', '>= 1.3.6'
6
6
 
7
7
  group :test do
8
- gem 'jnunemaker-matchy', '>= 0.4', :require => 'matchy'
9
- gem 'shoulda', '>= 3.1.1'
10
- gem 'mocha', '>= 0.12.3', :require => 'mocha/setup'
8
+ gem 'rspec', "~> 2.8"
11
9
  gem 'database_cleaner', '>= 0.8.0'
10
+ gem 'timecop'
12
11
  end
13
12
 
14
13
  group :development, :test do
@@ -16,4 +15,4 @@ group :development, :test do
16
15
  gem 'simplecov', :require => false
17
16
  end
18
17
 
19
- gem 'mongo_mapper', '> 0.12'
18
+ gem 'mongo_mapper', '0.13.0'
data/Rakefile CHANGED
@@ -1,19 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
- require 'rubygems'
3
- require 'rake'
2
+ require 'rspec/core/rake_task'
4
3
 
5
4
  require File.join(File.dirname(__FILE__), 'lib', 'mongo_mapper', 'plugins', 'draft', 'version')
6
5
 
7
6
  require 'rake/testtask'
8
7
  namespace :test do
9
- Rake::TestTask.new(:units) do |test|
10
- test.libs << 'test'
11
- test.ruby_opts << '-rubygems'
12
- test.pattern = 'test/unit/**/test_*.rb'
13
- test.verbose = true
14
- end
15
-
16
- #TODO Add performance
17
8
  Rake::TestTask.new(:performance) do |test|
18
9
  test.libs << 'test'
19
10
  test.ruby_opts << '-rubygems'
@@ -22,5 +13,6 @@ namespace :test do
22
13
  end
23
14
  end
24
15
 
25
- task :default => 'test:units'
26
-
16
+ RSpec::Core::RakeTask.new(:spec)
17
+ task :default => :spec
18
+ gemspec = eval(File.read("mm-draft.gemspec"))
@@ -125,22 +125,13 @@ module MongoMapper
125
125
 
126
126
  def unpublish
127
127
  published_rec = self.published_record
128
- draft_rec = self.draft_record
128
+ draft_rec = self.draft_record
129
129
 
130
130
  self.class.skip_callback(:destroy, :before, :unpublish)
131
131
  published_rec.destroy if published_rec != nil # destroy published record
132
132
  self.class.set_callback(:destroy, :before, :unpublish)
133
-
134
- draft_rec.draft_record_published_id = nil if draft_rec != nil # update draft record
135
- draft_rec.save! if draft_rec != nil
136
- # if draft?
137
- # published = self.class.find(self.draft_record_published_id)
138
- # published.destroy if (published != nil)
139
- # self.draft_record_published_id = nil
140
- # self.save! # remove draft_record_published_id
141
- # else
142
- # self.draft_record.unpublish
143
- # end
133
+ draft_rec.set(published_at: nil) if self.respond_to?("published_at")
134
+ draft_rec.set(draft_record_published_id: nil)
144
135
  end
145
136
 
146
137
  end # Module Draft
@@ -1,5 +1,5 @@
1
1
  module MongoMapper
2
2
  module Draft
3
- VERSION = '0.1.10'
3
+ VERSION = '0.1.11'
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- class MonkeyNoVersion
1
+ class MonkeyNoDraft
2
2
  include MongoMapper::Document
3
3
  attr_accessible :name, :age
4
4
 
@@ -1,9 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
- require 'draft'
6
+ require 'mm-draft'
7
7
 
8
8
  Bundler.require(:default, :test)
9
9
 
@@ -7,10 +7,10 @@ DatabaseCleaner.start
7
7
  Benchmark.bm(22) do |x|
8
8
  ids_draft = []
9
9
  ids_no_draft = []
10
-
10
+
11
11
  # Write performance
12
12
  x.report("write without draft ") do
13
- 500.times { |i| ids_no_draft << MonkeyNodraft.create(:name => "Baboo", :age => 12, ).id }
13
+ 500.times { |i| ids_no_draft << MonkeyNoDraft.create(:name => "Baboo", :age => 12, ).id }
14
14
  end
15
15
  x.report("write with draft ") do
16
16
  500.times { |i| ids_draft << Monkey.create(:name => "Baboo", :age => 12, ).id }
@@ -21,8 +21,9 @@ Benchmark.bm(22) do |x|
21
21
  ids_draft.each { |id| Monkey.first(:id => id) }
22
22
  end
23
23
  x.report("read without draft ") do
24
- ids_no_draft.each { |id| MonkeyNodraft.first(:id => id) }
24
+ ids_no_draft.each { |id| MonkeyNoDraft.first(:id => id) }
25
25
  end
26
26
  end
27
27
 
28
28
  DatabaseCleaner.clean
29
+ MongoMapper.database.command({dropDatabase: 1})
metadata CHANGED
@@ -1,41 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mm-draft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leif Ringstad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mongo_mapper
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: timecop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  description:
@@ -54,14 +82,10 @@ files:
54
82
  - lib/mongo_mapper/plugins/draft/draft.rb
55
83
  - lib/mongo_mapper/plugins/draft/keys.rb
56
84
  - lib/mongo_mapper/plugins/draft/version.rb
57
- - test/models/dog.rb
58
- - test/models/monkey.rb
59
85
  - test/performance/models/monkey.rb
60
86
  - test/performance/models/monkey_no_draft.rb
61
87
  - test/performance/performance_helper.rb
62
88
  - test/performance/test/read_write.rb
63
- - test/test_helper.rb
64
- - test/unit/test_draft.rb
65
89
  homepage: http://github.com/leifcr/mm-draft
66
90
  licenses: []
67
91
  metadata: {}
@@ -71,12 +95,12 @@ require_paths:
71
95
  - lib
72
96
  required_ruby_version: !ruby/object:Gem::Requirement
73
97
  requirements:
74
- - - ">="
98
+ - - ! '>='
75
99
  - !ruby/object:Gem::Version
76
100
  version: '0'
77
101
  required_rubygems_version: !ruby/object:Gem::Requirement
78
102
  requirements:
79
- - - ">="
103
+ - - ! '>='
80
104
  - !ruby/object:Gem::Version
81
105
  version: '0'
82
106
  requirements: []
@@ -86,11 +110,7 @@ signing_key:
86
110
  specification_version: 4
87
111
  summary: A MongoMapper extension adding draft/publishing support
88
112
  test_files:
89
- - test/models/dog.rb
90
- - test/models/monkey.rb
91
- - test/test_helper.rb
92
113
  - test/performance/performance_helper.rb
93
114
  - test/performance/models/monkey_no_draft.rb
94
115
  - test/performance/models/monkey.rb
95
116
  - test/performance/test/read_write.rb
96
- - test/unit/test_draft.rb
data/test/models/dog.rb DELETED
@@ -1,11 +0,0 @@
1
- class Dog
2
- include MongoMapper::Document
3
- plugin MongoMapper::Plugins::Draft
4
-
5
- attr_accessible :name
6
-
7
- key :name, String
8
- key :published_at, Time
9
-
10
- timestamps!
11
- end
@@ -1,10 +0,0 @@
1
- class Monkey
2
- include MongoMapper::Document
3
- plugin MongoMapper::Plugins::Draft
4
-
5
- attr_accessible :name
6
-
7
- key :name, String
8
-
9
- timestamps!
10
- end
data/test/test_helper.rb DELETED
@@ -1,47 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
-
4
- if ENV['TRAVIS']
5
- require 'coveralls'
6
- Coveralls.wear!
7
- elsif ENV['COVERAGE']
8
- require 'simplecov'
9
- SimpleCov.start
10
- end
11
-
12
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
- $LOAD_PATH.unshift(File.dirname(__FILE__))
14
- require 'mm-draft'
15
-
16
- Bundler.require(:default, :test)
17
-
18
- MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017)
19
- MongoMapper.database = "mm-draft-test"
20
-
21
- Dir["#{File.dirname(__FILE__)}/models/*.rb"].each {|file| require file}
22
-
23
- DatabaseCleaner.strategy = :truncation
24
-
25
- class Test::Unit::TestCase
26
- # Drop all collections after each test case.
27
- def setup
28
- DatabaseCleaner.start
29
- end
30
-
31
- def teardown
32
- DatabaseCleaner.clean
33
- end
34
-
35
- # Make sure that each test case has a teardown
36
- # method to clear the db after each test.
37
- def inherited(base)
38
- base.define_method setup do
39
- super
40
- end
41
-
42
- base.define_method teardown do
43
- super
44
- end
45
- end
46
-
47
- end
@@ -1,226 +0,0 @@
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
- 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
-
120
- end # context "draft monkey records" do
121
- context "draft dog records with pubished_at" do
122
- setup do
123
- @monkey_1 = Dog.create(:name => "Chip")
124
- end
125
-
126
- should "should set published_at when publishing" do
127
- @monkey_1.publish
128
- @monkey_1.published_record.should_not == nil
129
- @monkey_1.published_at.should_not == nil
130
- @monkey_1.published_record.published_at.should_not == nil
131
- @monkey_1.published_record.published_at.should == @monkey_1.published_at
132
- end
133
- end
134
-
135
- # context "tree-record" do
136
- # setup do
137
- # @root_1 = Dog.create(:name => "Atmel")
138
- # @child_1 = Dog.create(:name => "ATmega644P", :parent => @root_1)
139
- # @child_2 = Dog.create(:name => "ATmega2561", :parent => @root_1)
140
- # @child_2_1 = Dog.create(:name => "ATtiny24", :parent => @child_2)
141
-
142
- # @root_2 = Dog.create(:name => "ST Ericsson")
143
- # @child_3 = Dog.create(:name => "ISP1181B", :parent => @root_2)
144
-
145
- # @root_1.publish
146
- # @child_1.publish
147
- # @child_2.publish
148
- # @child_2_1.publish
149
- # @root_2.publish
150
- # end
151
-
152
- # should "test draft record parents" do
153
- # assert_equal(@root_2, @child_3.parent)
154
- # assert_equal(@child_2, @child_2_1.parent)
155
- # end
156
-
157
- # should "test parents for published records" do
158
- # assert_equal(@root_1.published_record, @child_1.published_record.parent)
159
- # assert_equal(@root_1.published_record, @child_2.published_record.parent)
160
- # assert_equal(@child_2.published_record, @child_2_1.published_record.parent)
161
- # end
162
-
163
- # should "move draft record to new parent, but keep published at old parent" do
164
- # @child_2.parent = @root_2
165
-
166
- # assert !@root_2.is_or_is_ancestor_of?(@child_2_1)
167
- # assert !@child_2_1.is_or_is_descendant_of?(@root_2)
168
- # assert !@root_2.descendants.include?(@child_2_1)
169
-
170
- # @child_2.save
171
- # @child_2_1.reload
172
-
173
- # assert @root_2.is_or_is_ancestor_of?(@child_2_1)
174
- # assert @child_2_1.is_or_is_descendant_of?(@root_2)
175
- # assert @root_2.descendants.include?(@child_2_1)
176
-
177
- # # test published against root_1
178
- # assert @root_1.published_record.is_or_is_ancestor_of?(@child_2_1.published_record)
179
- # assert @child_2_1.published_record.is_or_is_descendant_of?(@root_1.published_record)
180
- # assert @root_1.published_record.descendants.include?(@child_2_1.published_record)
181
- # end
182
-
183
- # should "move both draft and published record to new parent" do
184
- # @child_2.parent = @root_2
185
-
186
- # assert !@root_2.is_or_is_ancestor_of?(@child_2_1)
187
- # assert !@child_2_1.is_or_is_descendant_of?(@root_2)
188
- # assert !@root_2.descendants.include?(@child_2_1)
189
-
190
- # # can only test published after saving and publishing
191
- # @child_2.save
192
- # @child_2.publish # will also save
193
- # @child_2.reload
194
- # @child_2_1.reload
195
-
196
- # assert @root_2.is_or_is_ancestor_of?(@child_2_1)
197
- # assert @child_2_1.is_or_is_descendant_of?(@root_2)
198
- # assert @root_2.descendants.include?(@child_2_1)
199
-
200
- # assert @root_2.published_record.is_or_is_ancestor_of?(@child_2_1.published_record)
201
- # assert @child_2_1.published_record.is_or_is_descendant_of?(@root_2.published_record)
202
- # assert @root_2.published_record.descendants.include?(@child_2_1.published_record)
203
- # end
204
-
205
- # should "set a record as a root and check for ancestor" do
206
- # @child_2.parent = nil
207
-
208
- # assert !@root_2.is_or_is_ancestor_of?(@child_2_1)
209
- # assert !@child_2_1.is_or_is_descendant_of?(@root_2)
210
- # assert !@root_2.descendants.include?(@child_2_1)
211
-
212
- # # can only test published after saving and publishing
213
- # @child_2.save
214
- # @child_2.publish # will also save
215
- # @child_2.reload
216
- # @child_2_1.reload
217
-
218
- # assert @child_2.root?
219
- # assert @child_2.published_record.root?
220
- # assert @child_2_1.is_or_is_descendant_of?(@child_2)
221
-
222
- # assert !@root_1.published_record.is_or_is_ancestor_of?(@child_2_1.published_record)
223
- # assert !@child_2_1.published_record.is_or_is_descendant_of?(@root_1.published_record)
224
- # assert !@root_1.published_record.descendants.include?(@child_2_1.published_record)
225
- # end
226
- end