mongoid_delorean 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6046b3012b6e28a626ce3601fa23e58298e9fe91
4
+ data.tar.gz: 4ec10da2a928268a7327040ad719b230a338f796
5
+ SHA512:
6
+ metadata.gz: 8786110df221df1adcd8ca77c475c4a556f8e9245ebc5ff547f3db18083d040022fef15f38d338a1bf5110ef10691c5d45989c74060c3b017c91206b2af1d361
7
+ data.tar.gz: d8e501f26a7b05e8c6af845badc918b9b52fa6dbc9ccc64bb4ef142c64a2e859a2291732a2f0e65bc3a672492b72a47437711c4f3cbc5d0c10ee2fa670a6c36b
data/.gitignore CHANGED
@@ -1,19 +1,3 @@
1
- *.log
2
- .DS_Store
3
- doc
4
- tmp
5
- pkg
6
1
  *.gem
7
- *.pid
8
- coverage
9
- coverage.data
10
- build/*
11
- *.pbxuser
12
- *.mode1v3
13
- .svn
14
- profile
15
- .console_history
16
- .sass-cache/*
17
- .rake_tasks~
18
- *.log.lck
19
- solr/
2
+ .bundle
3
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - jruby-19mode
6
+ - rbx-19mode
7
+ services: mongodb
data/Gemfile CHANGED
@@ -2,6 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in mongoid_delorean.gemspec
4
4
  gemspec
5
-
6
- gem "rspec"
7
- gem 'database_cleaner'
data/README.md CHANGED
@@ -4,7 +4,7 @@ A simple Mongoid 3 versioning system that works with embedded documents.
4
4
 
5
5
  Tracking document changes can be really important to a lot of systems, unfortunately all of the Mongoid versioning plugins either only work with Mongoid 2.x, don't handle embedded document changes, or worse, just don't work. <code>Mongoid::Delorean</code> solves those problems.
6
6
 
7
- <code>Mongoid::Delorean</code> is a simple plugin that does just what it sets out to do. It stores each version of your document as you make changes and then allows you to revert to earlier versions of the document.
7
+ <code>Mongoid::Delorean</code> is a simple plugin that does just what it sets out to do. It stores each version of your document as you make changes and then allows you to revert to earlier versions of the document.
8
8
 
9
9
  If this wasn't great already, <code>Mongoid::Delorean</code> will even track changes made to any embedded documents, or documents that those embedded documents may have, and so on.
10
10
 
@@ -100,3 +100,9 @@ a.version # => 1
100
100
  4. Commit your changes (`git commit -am 'Add some feature'`)
101
101
  5. Push to the branch (`git push origin my-new-feature`)
102
102
  6. Create new Pull Request
103
+
104
+ ## Contributors
105
+
106
+ * Mark Bates
107
+ * Nick Muerdter
108
+ * Felipe Rodrigues
data/Rakefile CHANGED
@@ -1,9 +1,8 @@
1
- require 'bundler'
1
+ require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
- desc "Run tests"
5
- task :default => [:ruby]
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new('spec')
6
6
 
7
- task :ruby do
8
- system "bundle exec rspec"
9
- end
7
+ desc "Run tests"
8
+ task :default => :spec
@@ -52,7 +52,7 @@ module Mongoid
52
52
  end
53
53
 
54
54
  module CommonEmbeddedMethods
55
-
55
+
56
56
  def save_version
57
57
  self._parent.save_version if self._parent.respond_to?(:save_version)
58
58
  end
@@ -73,9 +73,13 @@ module Mongoid
73
73
  self.embedded_relations.each do |name, details|
74
74
  relation = self.send(name)
75
75
  relation_changes[name] = []
76
- r_changes = relation.map {|o| o.changes_with_relations}
77
- relation_changes[name] << r_changes unless r_changes.empty?
78
- relation_changes[name].flatten!
76
+ if details.relation == Mongoid::Relations::Embedded::One
77
+ relation_changes[name] = relation.changes_with_relations if relation
78
+ else
79
+ r_changes = relation.map {|o| o.changes_with_relations}
80
+ relation_changes[name] << r_changes unless r_changes.empty?
81
+ relation_changes[name].flatten!
82
+ end
79
83
  relation_changes.delete(name) if relation_changes[name].empty?
80
84
  end
81
85
 
@@ -85,15 +89,19 @@ module Mongoid
85
89
 
86
90
  def attributes_with_relations
87
91
  _attributes = self.attributes.dup
88
-
92
+
89
93
  relation_attrs = {}
90
94
  self.embedded_relations.each do |name, details|
91
95
  relation = self.send(name)
92
- relation_attrs[name] = []
93
- r_attrs = relation.map {|o| o.attributes_with_relations}
94
- relation_attrs[name] << r_attrs unless r_attrs.empty?
95
- r_changes = relation.map {|o| o.changes}
96
- relation_attrs[name].flatten!
96
+ if details.relation == Mongoid::Relations::Embedded::One
97
+ relation_attrs[name] = relation.attributes_with_relations if relation
98
+ else
99
+ relation_attrs[name] = []
100
+ r_attrs = relation.map {|o| o.attributes_with_relations}
101
+ relation_attrs[name] << r_attrs unless r_attrs.empty?
102
+ r_changes = relation.map {|o| o.changes}
103
+ relation_attrs[name].flatten!
104
+ end
97
105
  end
98
106
  _attributes.merge!(relation_attrs)
99
107
  return _attributes
@@ -103,4 +111,4 @@ module Mongoid
103
111
 
104
112
  end
105
113
  end
106
- end
114
+ end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Delorean
3
- VERSION = "1.1.1"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -19,4 +19,7 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_dependency("mongoid", ">=3.0.0")
21
21
 
22
+ gem.add_development_dependency("rake")
23
+ gem.add_development_dependency("rspec")
24
+ gem.add_development_dependency("database_cleaner")
22
25
  end
@@ -151,6 +151,12 @@ describe Mongoid::Delorean::Trackable do
151
151
 
152
152
  version = a.versions.last
153
153
  version.altered_attributes.should eql({"pages"=>[{"sections"=>[{"_id"=>[nil, section.id], "body"=>[nil, "some body text"]}]}], "version"=>[2, 3]})
154
+
155
+ footer = page.build_footer(:content => "some footer text")
156
+ a.save!
157
+
158
+ version = a.versions.last
159
+ version.altered_attributes.should eql({"pages"=>[{"sections"=>[{}], "footer"=>{"_id"=>[nil, footer.id], "content"=>[nil, "some footer text"]}}], "version"=>[3, 4]})
154
160
  end
155
161
 
156
162
  it "tracks the full set of attributes at the time of saving" do
@@ -234,4 +240,4 @@ describe Mongoid::Delorean::Trackable do
234
240
 
235
241
  end
236
242
 
237
- end
243
+ end
@@ -27,9 +27,17 @@ class Page
27
27
 
28
28
  embedded_in :article, inverse_of: :pages
29
29
  embeds_many :sections
30
+ embeds_one :footer
30
31
  end
31
32
 
33
+ class Footer
34
+ include Mongoid::Document
35
+ include Mongoid::Timestamps
32
36
 
37
+ field :content, type: String
38
+
39
+ embedded_in :page
40
+ end
33
41
 
34
42
  class User
35
43
  include Mongoid::Document
@@ -38,4 +46,4 @@ class User
38
46
 
39
47
  field :name, type: String
40
48
  field :age, type: Integer
41
- end
49
+ end
metadata CHANGED
@@ -1,32 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_delorean
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mark Bates
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-10 00:00:00.000000000 Z
11
+ date: 2013-12-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: mongoid
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.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: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
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: database_cleaner
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
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
30
69
  description: A simple Mongoid 3 versioning system that works with embedded documents.
31
70
  email:
32
71
  - mark@markbates.com
@@ -35,8 +74,8 @@ extensions: []
35
74
  extra_rdoc_files: []
36
75
  files:
37
76
  - .gitignore
77
+ - .travis.yml
38
78
  - Gemfile
39
- - Gemfile.lock
40
79
  - LICENSE.txt
41
80
  - README.md
42
81
  - Rakefile
@@ -53,27 +92,26 @@ files:
53
92
  - spec/support/models.rb
54
93
  homepage: ''
55
94
  licenses: []
95
+ metadata: {}
56
96
  post_install_message:
57
97
  rdoc_options: []
58
98
  require_paths:
59
99
  - lib
60
100
  required_ruby_version: !ruby/object:Gem::Requirement
61
- none: false
62
101
  requirements:
63
- - - ! '>='
102
+ - - '>='
64
103
  - !ruby/object:Gem::Version
65
104
  version: '0'
66
105
  required_rubygems_version: !ruby/object:Gem::Requirement
67
- none: false
68
106
  requirements:
69
- - - ! '>='
107
+ - - '>='
70
108
  - !ruby/object:Gem::Version
71
109
  version: '0'
72
110
  requirements: []
73
111
  rubyforge_project:
74
- rubygems_version: 1.8.24
112
+ rubygems_version: 2.1.11
75
113
  signing_key:
76
- specification_version: 3
114
+ specification_version: 4
77
115
  summary: A simple Mongoid 3 versioning system that works with embedded documents.
78
116
  test_files:
79
117
  - spec/config.yml
data/Gemfile.lock DELETED
@@ -1,44 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- mongoid_delorean (1.1.1)
5
- mongoid (>= 3.0.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (3.2.8)
11
- activesupport (= 3.2.8)
12
- builder (~> 3.0.0)
13
- activesupport (3.2.8)
14
- i18n (~> 0.6)
15
- multi_json (~> 1.0)
16
- builder (3.0.3)
17
- database_cleaner (0.8.0)
18
- diff-lcs (1.1.3)
19
- i18n (0.6.1)
20
- mongoid (3.0.5)
21
- activemodel (~> 3.1)
22
- moped (~> 1.1)
23
- origin (~> 1.0)
24
- tzinfo (~> 0.3.22)
25
- moped (1.2.1)
26
- multi_json (1.3.6)
27
- origin (1.0.8)
28
- rspec (2.11.0)
29
- rspec-core (~> 2.11.0)
30
- rspec-expectations (~> 2.11.0)
31
- rspec-mocks (~> 2.11.0)
32
- rspec-core (2.11.1)
33
- rspec-expectations (2.11.3)
34
- diff-lcs (~> 1.1.3)
35
- rspec-mocks (2.11.2)
36
- tzinfo (0.3.33)
37
-
38
- PLATFORMS
39
- ruby
40
-
41
- DEPENDENCIES
42
- database_cleaner
43
- mongoid_delorean!
44
- rspec