mongoid_relations_dirty_tracking 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,65 +1,70 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'mongoid'
4
- require 'mongoid/relations_dirty_tracking'
5
-
6
- require 'rspec'
7
-
8
- class TestDocument
9
- include Mongoid::Document
10
- include Mongoid::RelationsDirtyTracking
11
-
12
- embeds_one :one_document, class_name: 'TestEmbeddedDocument'
13
- embeds_many :many_documents, class_name: 'TestEmbeddedDocument'
14
-
15
- has_one :one_related, class_name: 'TestRelatedDocument'
16
- has_many :many_related, class_name: 'TestRelatedDocument'
17
- has_and_belongs_to_many :many_to_many_related, class_name: 'TestRelatedDocument'
18
- end
19
-
20
- class TestEmbeddedDocument
21
- include Mongoid::Document
22
-
23
- embedded_in :test_document
24
-
25
- field :title, type: String
26
- end
27
-
28
- class TestRelatedDocument
29
- include Mongoid::Document
30
- include Mongoid::RelationsDirtyTracking
31
-
32
- belongs_to :test_document, inverse_of: :one_related
33
-
34
- field :title, type: String
35
- end
36
-
37
- class TestDocumentWithOnlyOption
38
- include Mongoid::Document
39
- include Mongoid::RelationsDirtyTracking
40
-
41
- embeds_many :many_documents, class_name: 'TestEmbeddedDocument'
42
- has_one :one_related, class_name: 'TestRelatedDocument'
43
-
44
- relations_dirty_tracking only: :many_documents
45
- end
46
-
47
- class TestDocumentWithExceptOption
48
- include Mongoid::Document
49
- include Mongoid::RelationsDirtyTracking
50
-
51
- embeds_many :many_documents, class_name: 'TestEmbeddedDocument'
52
- has_one :one_related, class_name: 'TestRelatedDocument'
53
-
54
- relations_dirty_tracking except: 'many_documents'
55
- end
56
-
57
-
58
- Mongoid.configure do |config|
59
- config.connect_to('mongoid_relations_dirty_tracking_test')
60
- end
61
-
62
- RSpec.configure do |config|
63
- config.mock_with :rspec
64
- config.after(:each) { Mongoid.purge! }
65
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'rspec'
6
+ require 'rspec/its'
7
+ require 'mongoid'
8
+ require 'mongoid/relations_dirty_tracking'
9
+
10
+ Mongo::Logger.logger.level = 2
11
+
12
+ Mongoid.configure do |config|
13
+ config.logger.level = 2
14
+ config.connect_to('mongoid_relations_dirty_tracking_test')
15
+ config.belongs_to_required_by_default = false
16
+ end
17
+
18
+ RSpec.configure do |config|
19
+ config.mock_with :rspec
20
+ config.after(:all) { Mongoid.purge! }
21
+ end
22
+
23
+ class TestDocument
24
+ include Mongoid::Document
25
+ include Mongoid::RelationsDirtyTracking
26
+
27
+ embeds_one :one_document, class_name: 'TestEmbeddedDocument'
28
+ embeds_many :many_documents, class_name: 'TestEmbeddedDocument'
29
+
30
+ has_one :one_related, class_name: 'TestRelatedDocument'
31
+ has_many :many_related, class_name: 'TestRelatedDocument'
32
+ has_and_belongs_to_many :many_to_many_related, class_name: 'TestRelatedDocument'
33
+ end
34
+
35
+ class TestEmbeddedDocument
36
+ include Mongoid::Document
37
+
38
+ embedded_in :test_document
39
+
40
+ field :title, type: String
41
+ end
42
+
43
+ class TestRelatedDocument
44
+ include Mongoid::Document
45
+ include Mongoid::RelationsDirtyTracking
46
+
47
+ belongs_to :test_document, inverse_of: :one_related
48
+
49
+ field :title, type: String
50
+ end
51
+
52
+ class TestDocumentWithOnlyOption
53
+ include Mongoid::Document
54
+ include Mongoid::RelationsDirtyTracking
55
+
56
+ embeds_many :many_documents, class_name: 'TestEmbeddedDocument'
57
+ has_one :one_related, class_name: 'TestRelatedDocument'
58
+
59
+ relations_dirty_tracking only: :many_documents
60
+ end
61
+
62
+ class TestDocumentWithExceptOption
63
+ include Mongoid::Document
64
+ include Mongoid::RelationsDirtyTracking
65
+
66
+ embeds_many :many_documents, class_name: 'TestEmbeddedDocument'
67
+ has_one :one_related, class_name: 'TestRelatedDocument'
68
+
69
+ relations_dirty_tracking except: 'many_documents'
70
+ end
metadata CHANGED
@@ -1,103 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_relations_dirty_tracking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Sevcik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-14 00:00:00.000000000 Z
11
+ date: 2020-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '5.1'
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
- version: '3.0'
26
+ version: '5.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mongoid
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 3.1.0
34
- - - <
35
- - !ruby/object:Gem::Version
36
- version: '4.0'
33
+ version: '7.0'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - '>='
38
+ - - ">="
42
39
  - !ruby/object:Gem::Version
43
- version: 3.1.0
44
- - - <
40
+ version: '7.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: gem-release
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
45
46
  - !ruby/object:Gem::Version
46
- version: '4.0'
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'
47
55
  - !ruby/object:Gem::Dependency
48
- name: bundler
56
+ name: pry-byebug
49
57
  requirement: !ruby/object:Gem::Requirement
50
58
  requirements:
51
- - - ~>
59
+ - - ">="
52
60
  - !ruby/object:Gem::Version
53
- version: '1.3'
61
+ version: '0'
54
62
  type: :development
55
63
  prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
65
  requirements:
58
- - - ~>
66
+ - - ">="
59
67
  - !ruby/object:Gem::Version
60
- version: '1.3'
68
+ version: '0'
61
69
  - !ruby/object:Gem::Dependency
62
70
  name: rake
63
71
  requirement: !ruby/object:Gem::Requirement
64
72
  requirements:
65
- - - '>='
73
+ - - ">="
66
74
  - !ruby/object:Gem::Version
67
75
  version: '0'
68
76
  type: :development
69
77
  prerelease: false
70
78
  version_requirements: !ruby/object:Gem::Requirement
71
79
  requirements:
72
- - - '>='
80
+ - - ">="
73
81
  - !ruby/object:Gem::Version
74
82
  version: '0'
75
83
  - !ruby/object:Gem::Dependency
76
84
  name: rspec
77
85
  requirement: !ruby/object:Gem::Requirement
78
86
  requirements:
79
- - - ~>
87
+ - - "~>"
80
88
  - !ruby/object:Gem::Version
81
- version: '2.8'
89
+ version: 3.8.0
82
90
  type: :development
83
91
  prerelease: false
84
92
  version_requirements: !ruby/object:Gem::Requirement
85
93
  requirements:
86
- - - ~>
94
+ - - "~>"
87
95
  - !ruby/object:Gem::Version
88
- version: '2.8'
96
+ version: 3.8.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-its
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
89
111
  - !ruby/object:Gem::Dependency
90
- name: pry
112
+ name: rubocop
91
113
  requirement: !ruby/object:Gem::Requirement
92
114
  requirements:
93
- - - '>='
115
+ - - ">="
94
116
  - !ruby/object:Gem::Version
95
117
  version: '0'
96
118
  type: :development
97
119
  prerelease: false
98
120
  version_requirements: !ruby/object:Gem::Requirement
99
121
  requirements:
100
- - - '>='
122
+ - - ">="
101
123
  - !ruby/object:Gem::Version
102
124
  version: '0'
103
125
  description: Mongoid extension for tracking changes on document relations
@@ -107,16 +129,15 @@ executables: []
107
129
  extensions: []
108
130
  extra_rdoc_files: []
109
131
  files:
110
- - .gitignore
111
- - Gemfile
112
- - LICENSE.txt
132
+ - LICENSE
113
133
  - README.md
114
- - Rakefile
115
134
  - lib/mongoid/relations_dirty_tracking.rb
116
135
  - lib/mongoid/relations_dirty_tracking/version.rb
117
- - lib/mongoid/relations_dirty_tracking/versioning.rb
118
136
  - lib/mongoid_relations_dirty_tracking.rb
119
- - mongoid_relations_dirty_tracking.gemspec
137
+ - spec/gemfiles/Gemfile.master
138
+ - spec/gemfiles/Gemfile.rails51
139
+ - spec/gemfiles/Gemfile.rails52
140
+ - spec/gemfiles/Gemfile.rails60
120
141
  - spec/lib/mongoid/relations_dirty_tracking_spec.rb
121
142
  - spec/spec_helper.rb
122
143
  homepage: http://github.com/versative/relations_dirty_tracking
@@ -129,20 +150,23 @@ require_paths:
129
150
  - lib
130
151
  required_ruby_version: !ruby/object:Gem::Requirement
131
152
  requirements:
132
- - - '>='
153
+ - - ">="
133
154
  - !ruby/object:Gem::Version
134
155
  version: '0'
135
156
  required_rubygems_version: !ruby/object:Gem::Requirement
136
157
  requirements:
137
- - - '>='
158
+ - - ">="
138
159
  - !ruby/object:Gem::Version
139
160
  version: '0'
140
161
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.1.11
162
+ rubygems_version: 3.0.3
143
163
  signing_key:
144
164
  specification_version: 4
145
165
  summary: Mongoid extension for tracking changes on document relations
146
166
  test_files:
167
+ - spec/gemfiles/Gemfile.master
168
+ - spec/gemfiles/Gemfile.rails51
169
+ - spec/gemfiles/Gemfile.rails52
170
+ - spec/gemfiles/Gemfile.rails60
147
171
  - spec/lib/mongoid/relations_dirty_tracking_spec.rb
148
172
  - spec/spec_helper.rb
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in mongoid_track_embedded_changes.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
-
3
- require 'rspec/core/rake_task'
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,54 +0,0 @@
1
- module Mongoid
2
- module RelationsDirtyTracking
3
- module Versioning
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- alias_method_chain :revise, :relations
8
- alias_method_chain :versioned_changes, :relations
9
- alias_method_chain :revisable?, :relations
10
- end
11
-
12
-
13
- def revise_with_relations
14
- previous = previous_revision
15
- if previous && (versioned_attributes_changed? || relations_changed?)
16
- new_version = versions.build(previous.versioned_attributes, without_protection: true)
17
-
18
- rel_changes = relation_changes
19
-
20
- self.class.tracked_relations.each do |rel_name|
21
- # from some reason previous contaion also newly added relations
22
- prev_value = rel_changes.include?(rel_name) ? rel_changes[rel_name][0] : previous[rel_name.to_sym]
23
- new_version.send "#{rel_name}=", preserve_versioned_relation(reflect_on_association(rel_name), prev_value)
24
- end
25
-
26
-
27
- if version_max.present? && versions.length > version_max
28
- deleted = versions.first
29
- if deleted.paranoid?
30
- versions.delete_one(deleted)
31
- collection.find(atomic_selector).
32
- update({ "$pull" => { "versions" => { "version" => deleted.version }}})
33
- else
34
- versions.delete(deleted)
35
- end
36
- end
37
- self.version = (version || 1) + 1
38
- end
39
- end
40
-
41
- def revisable_with_relations?
42
- (versioned_attributes_changed? || relations_changed?) && !versionless?
43
- end
44
-
45
- def versioned_changes_with_relations
46
- only_versioned_attributes(changes_without_relations.except("updated_at"))
47
- end
48
-
49
- def preserve_versioned_relation(rel_meta, value)
50
- value
51
- end
52
- end
53
- end
54
- end
@@ -1,26 +0,0 @@
1
- # coding: utf-8
2
- require File.expand_path('../lib/mongoid/relations_dirty_tracking/version', __FILE__)
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = "mongoid_relations_dirty_tracking"
6
- spec.version = Mongoid::RelationsDirtyTracking::VERSION
7
- spec.authors = ["David Sevcik"]
8
- spec.email = ["david.sevcik@gmail.com"]
9
- spec.description = "Mongoid extension for tracking changes on document relations"
10
- spec.summary = "Mongoid extension for tracking changes on document relations"
11
- spec.homepage = "http://github.com/versative/relations_dirty_tracking"
12
- spec.license = "MIT"
13
-
14
- spec.add_runtime_dependency 'activesupport', '~> 3.0'
15
- spec.add_runtime_dependency 'mongoid', '>= 3.1.0', '< 4.0'
16
-
17
- spec.add_development_dependency "bundler", "~> 1.3"
18
- spec.add_development_dependency "rake"
19
- spec.add_development_dependency "rspec", "~> 2.8"
20
- spec.add_development_dependency "pry"
21
-
22
- spec.files = `git ls-files`.split($/)
23
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
- spec.require_paths = ["lib"]
26
- end